@@ -57,7 +57,7 @@ describe('Test for body params', () => {
5757 expect ( resp . send ) . toHaveBeenCalledWith ( {
5858 error : [
5959 {
60- location : 'body.page ' ,
60+ location : 'body' ,
6161 message : 'Invalid Field Error' ,
6262 param : 'sorted' ,
6363 }
@@ -236,7 +236,7 @@ describe('Test for body params', () => {
236236 expect ( req . locals . data ) . toEqual ( {
237237 error : [
238238 {
239- location : 'body.page ' ,
239+ location : 'body' ,
240240 message : 'Invalid Field Error' ,
241241 param : 'sorted' ,
242242 }
@@ -267,7 +267,7 @@ describe('Test for body params', () => {
267267 expect ( resp . send ) . toHaveBeenCalledWith ( {
268268 error : [
269269 {
270- location : 'body.page ' ,
270+ location : 'body' ,
271271 message : 'Invalid Field Error' ,
272272 param : 'sorted' ,
273273 }
@@ -299,7 +299,7 @@ describe('Test for body params', () => {
299299 expect ( resp . send ) . toHaveBeenCalledWith ( {
300300 error : [
301301 {
302- location : 'body.page ' ,
302+ location : 'body' ,
303303 message : 'Invalid Field Error' ,
304304 param : 'sorted' ,
305305 }
@@ -330,7 +330,7 @@ describe('Test for body params', () => {
330330 expect ( resp . send ) . toHaveBeenCalledWith ( {
331331 error : [
332332 {
333- location : 'body.page ' ,
333+ location : 'body' ,
334334 message : 'Mandatory field sorted missing' ,
335335 param : 'sorted' ,
336336 }
@@ -361,7 +361,7 @@ describe('Test for body params', () => {
361361 expect ( resp . send ) . toHaveBeenCalledWith ( {
362362 error : [
363363 {
364- location : 'body.page ' ,
364+ location : 'body' ,
365365 message : 'Invalid Field Error' ,
366366 param : 'sorted' ,
367367 }
@@ -434,7 +434,7 @@ describe('Test for body params', () => {
434434 expect ( resp . send ) . toHaveBeenCalledWith ( {
435435 error : [
436436 {
437- location : 'body.page ' ,
437+ location : 'body' ,
438438 message : 'Invalid Field Error' ,
439439 param : 'sorted' ,
440440 }
@@ -488,7 +488,7 @@ describe('Test for body params', () => {
488488 expect ( resp . send ) . toHaveBeenCalledWith ( {
489489 error : [
490490 {
491- location : 'body.page ' ,
491+ location : 'body' ,
492492 message : 'Invalid Field Error' ,
493493 param : 'sorted' ,
494494 }
@@ -542,7 +542,7 @@ describe('Test for body params', () => {
542542 expect ( resp . send ) . toHaveBeenCalledWith ( {
543543 error : [
544544 {
545- location : 'body.page ' ,
545+ location : 'body' ,
546546 message : 'Invalid Field Error' ,
547547 param : 'sorted' ,
548548 }
@@ -711,7 +711,7 @@ describe('Test for body params', () => {
711711 expect ( resp . send ) . toHaveBeenCalledWith ( {
712712 error : [
713713 {
714- location : 'body.page ' ,
714+ location : 'body' ,
715715 message : 'Invalid Field Error' ,
716716 param : 'sorted' ,
717717 }
@@ -742,7 +742,7 @@ describe('Test for body params', () => {
742742 expect ( resp . send ) . toHaveBeenCalledWith ( {
743743 error : [
744744 {
745- location : 'body.page ' ,
745+ location : 'body' ,
746746 message : 'Invalid Field Error' ,
747747 param : 'sorted' ,
748748 }
@@ -773,7 +773,7 @@ describe('Test for body params', () => {
773773 expect ( resp . send ) . toHaveBeenCalledWith ( {
774774 error : [
775775 {
776- location : 'body.page ' ,
776+ location : 'body' ,
777777 message : 'Invalid Field Error' ,
778778 param : 'sorted' ,
779779 }
@@ -850,7 +850,7 @@ describe('Test for body params', () => {
850850 expect ( resp . send ) . toHaveBeenCalledWith ( {
851851 error : [
852852 {
853- location : 'body.page ' ,
853+ location : 'body' ,
854854 message : 'Invalid Field Error' ,
855855 param : 'sorted' ,
856856 }
@@ -881,7 +881,7 @@ describe('Test for body params', () => {
881881 expect ( resp . send ) . toHaveBeenCalledWith ( {
882882 error : [
883883 {
884- location : 'body.page ' ,
884+ location : 'body' ,
885885 message : 'Invalid Field Error' ,
886886 param : 'sorted' ,
887887 }
@@ -912,7 +912,7 @@ describe('Test for body params', () => {
912912 expect ( resp . send ) . toHaveBeenCalledWith ( {
913913 error : [
914914 {
915- location : 'body.page ' ,
915+ location : 'body' ,
916916 message : 'Invalid Field Error' ,
917917 param : 'sorted' ,
918918 }
@@ -943,7 +943,7 @@ describe('Test for body params', () => {
943943 expect ( resp . send ) . toHaveBeenCalledWith ( {
944944 error : [
945945 {
946- location : 'body.page ' ,
946+ location : 'body' ,
947947 message : 'Invalid Field Error' ,
948948 param : 'sorted' ,
949949 }
@@ -997,7 +997,7 @@ describe('Test for body params', () => {
997997 expect ( resp . send ) . toHaveBeenCalledWith ( {
998998 error : [
999999 {
1000- location : 'body.page ' ,
1000+ location : 'body' ,
10011001 message : 'Invalid Field Error' ,
10021002 param : 'sorted' ,
10031003 }
@@ -1051,7 +1051,7 @@ describe('Test for body params', () => {
10511051 expect ( resp . send ) . toHaveBeenCalledWith ( {
10521052 error : [
10531053 {
1054- location : 'body.page ' ,
1054+ location : 'body' ,
10551055 message : 'Invalid Field Error' ,
10561056 param : 'sorted' ,
10571057 }
@@ -1105,11 +1105,123 @@ describe('Test for body params', () => {
11051105 expect ( resp . send ) . toHaveBeenCalledWith ( {
11061106 error : [
11071107 {
1108- location : 'body.page ' ,
1108+ location : 'body' ,
11091109 message : 'Invalid Field Error' ,
11101110 param : 'sorted' ,
11111111 }
11121112 ]
11131113 } ) ;
11141114 } ) ;
1115+ test ( 'Test nested objects Failure case - Array test' , ( ) => {
1116+ const req = {
1117+ body : {
1118+ page : [
1119+ 1 , 2 , 3 , 'sdsd'
1120+ ]
1121+ }
1122+ } ;
1123+ const validation = [
1124+ { param : 'page' , location : 'body' , isArray : true , children : [
1125+ { param : 'page-array' , isRequired : true , isNumber : true } ,
1126+ ] }
1127+ ] ;
1128+ const response = {
1129+ mode : 'reject'
1130+ } ;
1131+ const validatorfn = validaor ( 'body' , validation , response ) ;
1132+ validatorfn ( req , resp , next ) ;
1133+ expect ( next ) . toHaveBeenCalledTimes ( 0 ) ;
1134+ expect ( resp . status ) . toHaveBeenCalledTimes ( 1 ) ;
1135+ expect ( resp . send ) . toHaveBeenCalledWith ( {
1136+ error : [
1137+ {
1138+ location : 'body' ,
1139+ message : 'Invalid Field Error' ,
1140+ param : 'page-array' ,
1141+ }
1142+ ]
1143+ } ) ;
1144+ } ) ;
1145+ test ( 'Test nested objects Success case - Array test' , ( ) => {
1146+ const req = {
1147+ body : {
1148+ page : [
1149+ 1 , 2 , 3
1150+ ]
1151+ }
1152+ } ;
1153+ const validation = [
1154+ { param : 'page' , location : 'body' , isArray : true , children : [
1155+ { param : 'page-array' , isRequired : true , isNumber : true } ,
1156+ ] }
1157+ ] ;
1158+ const response = {
1159+ mode : 'reject'
1160+ } ;
1161+ const validatorfn = validaor ( 'body' , validation , response ) ;
1162+ validatorfn ( req , resp , next ) ;
1163+ expect ( next ) . toHaveBeenCalledTimes ( 1 ) ;
1164+ expect ( resp . status ) . toHaveBeenCalledTimes ( 0 ) ;
1165+ } ) ;
1166+ test ( 'Test nested objects Failure case - Array test 2' , ( ) => {
1167+ const req = {
1168+ body : {
1169+ page : [
1170+ { test : 1 , test2 : 2 } ,
1171+ { test : 1 , test2 : 2 } ,
1172+ { test : 1 , test2 : 'test' }
1173+ ]
1174+ }
1175+ } ;
1176+ const validation = [
1177+ { param : 'page' , location : 'body' , isArray : true , children : [
1178+ { param : 'page-array' , isRequired : true , isObject : true , children : [
1179+ { param : 'test' , isNumber : true } ,
1180+ { param : 'test2' , isNumber : true } ,
1181+ ] } ,
1182+ ] }
1183+ ] ;
1184+ const response = {
1185+ mode : 'reject'
1186+ } ;
1187+ const validatorfn = validaor ( 'body' , validation , response ) ;
1188+ validatorfn ( req , resp , next ) ;
1189+ expect ( next ) . toHaveBeenCalledTimes ( 0 ) ;
1190+ expect ( resp . status ) . toHaveBeenCalledTimes ( 1 ) ;
1191+ expect ( resp . send ) . toHaveBeenCalledWith ( {
1192+ error : [
1193+ {
1194+ location : 'body' ,
1195+ message : 'Invalid Field Error' ,
1196+ param : 'test2' ,
1197+ }
1198+ ]
1199+ } ) ;
1200+ } ) ;
1201+ test ( 'Test nested objects Success case - Array test 2' , ( ) => {
1202+ const req = {
1203+ body : {
1204+ page : [
1205+ { test : 1 , test2 : 2 } ,
1206+ { test : 1 , test2 : 2 } ,
1207+ { test : 1 , test2 : 323 }
1208+ ]
1209+ }
1210+ } ;
1211+ const validation = [
1212+ { param : 'page' , location : 'body' , isArray : true , children : [
1213+ { param : 'page-array' , isRequired : true , isObject : true , children : [
1214+ { param : 'test' , isNumber : true } ,
1215+ { param : 'test2' , isNumber : true } ,
1216+ ] } ,
1217+ ] }
1218+ ] ;
1219+ const response = {
1220+ mode : 'reject'
1221+ } ;
1222+ const validatorfn = validaor ( 'body' , validation , response ) ;
1223+ validatorfn ( req , resp , next ) ;
1224+ expect ( next ) . toHaveBeenCalledTimes ( 1 ) ;
1225+ expect ( resp . status ) . toHaveBeenCalledTimes ( 0 ) ;
1226+ } ) ;
11151227} ) ;
0 commit comments