@@ -550,11 +550,11 @@ describe('Test for body params', () => {
550550 } )
551551 } ) ;
552552
553- test ( 'Test nested objects Success case - Date test' , ( ) => {
553+ test ( 'Test nested objects Success case - Date test Format defauly YYYY-MM-DD ' , ( ) => {
554554 const req = {
555555 body : {
556556 page : {
557- sorted : '2012-09-09 '
557+ sorted : '2012-09-19 '
558558 }
559559 }
560560 }
@@ -573,11 +573,11 @@ describe('Test for body params', () => {
573573 expect ( resp . send ) . toHaveBeenCalledTimes ( 0 )
574574 } ) ;
575575
576- test ( 'Test nested objects Success case - Date test - Format' , ( ) => {
576+ test ( 'Test nested objects Success case - Date test - Format DD-MM-YYYY ' , ( ) => {
577577 const req = {
578578 body : {
579579 page : {
580- sorted : '09 -08-2019'
580+ sorted : '19 -08-2019'
581581 }
582582 }
583583 }
@@ -596,6 +596,98 @@ describe('Test for body params', () => {
596596 expect ( resp . send ) . toHaveBeenCalledTimes ( 0 )
597597 } ) ;
598598
599+ test ( 'Test nested objects Success case - Date test - Format MM-DD-YYYY' , ( ) => {
600+ const req = {
601+ body : {
602+ page : {
603+ sorted : '08-18-2019'
604+ }
605+ }
606+ }
607+ const validation = [
608+ { param : 'page' , location : 'body' , isObject : true , children : [
609+ { param : 'sorted' , location : 'body.page' , isRequired : true , isDate : true , format : 'MM-DD-YYYY' } ,
610+ ] }
611+ ]
612+ const response = {
613+ mode : 'reject'
614+ }
615+ const validatorfn = validaor ( validation , response ) ;
616+ validatorfn ( req , resp , next ) ;
617+ expect ( next ) . toHaveBeenCalledTimes ( 1 ) ;
618+ expect ( resp . status ) . toHaveBeenCalledTimes ( 0 ) ;
619+ expect ( resp . send ) . toHaveBeenCalledTimes ( 0 )
620+ } ) ;
621+
622+ test ( 'Test nested objects Success case - Date test - Format MM/DD/YYYY' , ( ) => {
623+ const req = {
624+ body : {
625+ page : {
626+ sorted : '12/18/2019'
627+ }
628+ }
629+ }
630+ const validation = [
631+ { param : 'page' , location : 'body' , isObject : true , children : [
632+ { param : 'sorted' , location : 'body.page' , isRequired : true , isDate : true , format : 'MM/DD/YYYY' } ,
633+ ] }
634+ ]
635+ const response = {
636+ mode : 'reject'
637+ }
638+ const validatorfn = validaor ( validation , response ) ;
639+ validatorfn ( req , resp , next ) ;
640+ expect ( next ) . toHaveBeenCalledTimes ( 1 ) ;
641+ expect ( resp . status ) . toHaveBeenCalledTimes ( 0 ) ;
642+ expect ( resp . send ) . toHaveBeenCalledTimes ( 0 )
643+ } ) ;
644+
645+ test ( 'Test nested objects Success case - Date test - Format DD/MM/YYYY' , ( ) => {
646+ const req = {
647+ body : {
648+ page : {
649+ sorted : '12/07/2019'
650+ }
651+ }
652+ }
653+ const validation = [
654+ { param : 'page' , location : 'body' , isObject : true , children : [
655+ { param : 'sorted' , location : 'body.page' , isRequired : true , isDate : true , format : 'DD/MM/YYYY' } ,
656+ ] }
657+ ]
658+ const response = {
659+ mode : 'reject'
660+ }
661+ const validatorfn = validaor ( validation , response ) ;
662+ validatorfn ( req , resp , next ) ;
663+ expect ( next ) . toHaveBeenCalledTimes ( 1 ) ;
664+ expect ( resp . status ) . toHaveBeenCalledTimes ( 0 ) ;
665+ expect ( resp . send ) . toHaveBeenCalledTimes ( 0 )
666+ } ) ;
667+
668+ test ( 'Test nested objects Success case - Date test - Format YYYY/MM/DD' , ( ) => {
669+ const req = {
670+ body : {
671+ page : {
672+ sorted : '2901/07/19'
673+ }
674+ }
675+ }
676+ const validation = [
677+ { param : 'page' , location : 'body' , isObject : true , children : [
678+ { param : 'sorted' , location : 'body.page' , isRequired : true , isDate : true , format : 'YYYY/MM/DD' } ,
679+ ] }
680+ ]
681+ const response = {
682+ mode : 'reject'
683+ }
684+ const validatorfn = validaor ( validation , response ) ;
685+ validatorfn ( req , resp , next ) ;
686+ expect ( next ) . toHaveBeenCalledTimes ( 1 ) ;
687+ expect ( resp . status ) . toHaveBeenCalledTimes ( 0 ) ;
688+ expect ( resp . send ) . toHaveBeenCalledTimes ( 0 )
689+ } ) ;
690+
599691 test ( 'Test nested objects Error case - Date test' , ( ) => {
600692 const req = {
601693 body : {
@@ -658,6 +750,37 @@ describe('Test for body params', () => {
658750 } )
659751 } ) ;
660752
753+ test ( 'Test nested objects Error case - Date test - Invalid Format' , ( ) => {
754+ const req = {
755+ body : {
756+ page : {
757+ sorted : '2019-23-02'
758+ }
759+ }
760+ }
761+ const validation = [
762+ { param : 'page' , location : 'body' , isObject : true , children : [
763+ { param : 'sorted' , location : 'body.page' , isRequired : true , isDate : true , format : 'YYYY/DD/MM' } ,
764+ ] }
765+ ]
766+ const response = {
767+ mode : 'reject'
768+ }
769+ const validatorfn = validaor ( validation , response ) ;
770+ validatorfn ( req , resp , next ) ;
771+ expect ( next ) . toHaveBeenCalledTimes ( 0 ) ;
772+ expect ( resp . status ) . toHaveBeenCalledTimes ( 1 ) ;
773+ expect ( resp . send ) . toHaveBeenCalledWith ( {
774+ error : [
775+ {
776+ location : 'body.page' ,
777+ message : 'Invalid Field Error' ,
778+ param : 'sorted' ,
779+ }
780+ ]
781+ } )
782+ } ) ;
783+
661784 test ( 'Test nested objects Success case - Mobile number test' , ( ) => {
662785 const req = {
663786 body : {
0 commit comments