11import request from 'supertest' ;
2+ import { agent , app , closeApplication } from './testApp' ;
23
3- const agent = request . agent ( 'localhost:3333' ) ;
44let authCookie : string ;
55
6+ afterAll ( async ( ) => {
7+ await closeApplication ( ) ;
8+ } ) ;
9+
610describe ( 'POST /create_record' , ( ) => {
711 const requestBody : any = {
812 "resourceId" : "cars_sl" ,
@@ -31,13 +35,17 @@ describe('POST /create_record', () => {
3135 password : 'adminforth' ,
3236 } ) ;
3337 expect ( res . status ) . toEqual ( 200 ) ;
34- authCookie = res . headers [ 'set-cookie' ] ?. [ 0 ] ;
38+ authCookie = res . headers [ 'set-cookie' ] ?. [ 0 ] ?. split ( ';' ) [ 0 ] ;
3539 expect ( authCookie ) . toContain ( 'adminforth_' ) ;
3640 } ) ;
3741
38- it ( 'throw an error, that unauthorized access is blocked after login' , async ( ) => {
39- const res = await agent
40- . post ( '/adminapi/v1/create_record' ) ;
42+ it ( 'blocks create_record for unauthenticated requests' , async ( ) => {
43+ const res = await request ( app )
44+ . post ( '/adminapi/v1/create_record' )
45+ . send ( {
46+ ...requestBody ,
47+ resourceId : 'cars_sl' ,
48+ } ) ;
4149 expect ( res . status ) . toEqual ( 401 ) ;
4250 } ) ;
4351
@@ -298,7 +306,7 @@ describe('POST /update_record', () => {
298306 password : 'adminforth' ,
299307 } ) ;
300308 expect ( res . status ) . toEqual ( 200 ) ;
301- authCookie = res . headers [ 'set-cookie' ] ?. [ 0 ] ;
309+ authCookie = res . headers [ 'set-cookie' ] ?. [ 0 ] ?. split ( ';' ) [ 0 ] ;
302310 expect ( authCookie ) . toContain ( 'adminforth_' ) ;
303311 } ) ;
304312
@@ -377,6 +385,11 @@ describe('POST /update_record', () => {
377385 . post ( '/adminapi/v1/update_record' )
378386 . send ( {
379387 resourceId : 'non_existent_resource' ,
388+ recordId : '21345667' ,
389+ meta : { } ,
390+ record : {
391+ model : 'Abobus2' ,
392+ } ,
380393 } ) ;
381394 expect ( res . status ) . toEqual ( 200 ) ;
382395 expect ( res . body . error ) . toBe ( "Resource 'non_existent_resource' not found" ) ;
@@ -676,6 +689,31 @@ describe('POST /get_resource_data', () => {
676689 } ) ;
677690 } ) ;
678691
692+ it ( 'returns list data for boolean filters without mutating the count path input' , async ( ) => {
693+ const res = await agent
694+ . set ( 'Cookie' , authCookie )
695+ . post ( '/adminapi/v1/get_resource_data' )
696+ . send ( {
697+ resourceId : 'cars_sl' ,
698+ source : 'list' ,
699+ limit : 1 ,
700+ offset : 0 ,
701+ sort : [ { field : 'price' , direction : 'desc' } ] ,
702+ filters : [
703+ { field : 'id' , operator : 'eq' , value : createdRecordId } ,
704+ { field : 'listed' , operator : 'eq' , value : true } ,
705+ ] ,
706+ } ) ;
707+
708+ expect ( res . status ) . toEqual ( 200 ) ;
709+ expect ( res . body . error ) . toBeUndefined ( ) ;
710+ expect ( res . body . total ) . toBeGreaterThanOrEqual ( 1 ) ;
711+ expect ( res . body . data [ 0 ] ) . toMatchObject ( {
712+ id : createdRecordId ,
713+ listed : true ,
714+ } ) ;
715+ } ) ;
716+
679717 describe ( 'POST /get_resource' , ( ) => {
680718 beforeAll ( async ( ) => {
681719 const res = await agent
@@ -685,7 +723,7 @@ describe('POST /get_resource_data', () => {
685723 password : 'adminforth' ,
686724 } ) ;
687725 expect ( res . status ) . toEqual ( 200 ) ;
688- authCookie = res . headers [ 'set-cookie' ] ?. [ 0 ] ;
726+ authCookie = res . headers [ 'set-cookie' ] ?. [ 0 ] ?. split ( ';' ) [ 0 ] ;
689727 expect ( authCookie ) . toContain ( 'adminforth_' ) ;
690728 } ) ;
691729
@@ -846,6 +884,7 @@ describe('POST /delete_record', () => {
846884 . post ( '/adminapi/v1/delete_record' )
847885 . send ( {
848886 resourceId : 'non_existent_resource' ,
887+ primaryKey : 'non_existent_id' ,
849888 } ) ;
850889 expect ( res . status ) . toEqual ( 200 ) ;
851890 expect ( res . body . error ) . toBe ( "Resource 'non_existent_resource' not found" ) ;
0 commit comments