@@ -1211,6 +1211,72 @@ describe('MaxDate', () => {
12111211 } ) ;
12121212} ) ;
12131213
1214+ describe ( 'MinDate function constraint' , ( ) => {
1215+ const constraint = ( ) => new Date ( 1995 , 11 , 17 ) ;
1216+ const validValues = [ new Date ( ) ] ;
1217+ const invalidValues = [ new Date ( 1994 , 11 , 17 ) ] ;
1218+
1219+ class MyClass {
1220+ @MinDate ( constraint )
1221+ someProperty : Date ;
1222+ }
1223+
1224+ it ( 'should not fail if validator.validate said that its valid' , ( ) => {
1225+ return checkValidValues ( new MyClass ( ) , validValues ) ;
1226+ } ) ;
1227+
1228+ it ( 'should fail if validator.validate said that its invalid' , ( ) => {
1229+ return checkInvalidValues ( new MyClass ( ) , invalidValues ) ;
1230+ } ) ;
1231+
1232+ it ( 'should not fail if method in validator said that its valid' , ( ) => {
1233+ validValues . forEach ( value => expect ( minDate ( value , constraint ) ) . toBeTruthy ( ) ) ;
1234+ } ) ;
1235+
1236+ it ( 'should fail if method in validator said that its invalid' , ( ) => {
1237+ invalidValues . forEach ( value => expect ( minDate ( value , constraint ) ) . toBeFalsy ( ) ) ;
1238+ } ) ;
1239+
1240+ it ( 'should return error object with proper data' , ( ) => {
1241+ const validationType = 'minDate' ;
1242+ const message = 'minimal allowed date for someProperty is ' + constraintToString ( constraint ) ;
1243+ return checkReturnedError ( new MyClass ( ) , invalidValues , validationType , message ) ;
1244+ } ) ;
1245+ } ) ;
1246+
1247+ describe ( 'MaxDate function constraint' , ( ) => {
1248+ const constraint = ( ) => new Date ( 1995 , 11 , 17 ) ;
1249+ const validValues = [ new Date ( 1994 , 11 , 17 ) ] ;
1250+ const invalidValues = [ new Date ( ) ] ;
1251+
1252+ class MyClass {
1253+ @MaxDate ( constraint )
1254+ someProperty : Date ;
1255+ }
1256+
1257+ it ( 'should not fail if validator.validate said that its valid' , ( ) => {
1258+ return checkValidValues ( new MyClass ( ) , validValues ) ;
1259+ } ) ;
1260+
1261+ it ( 'should fail if validator.validate said that its invalid' , ( ) => {
1262+ return checkInvalidValues ( new MyClass ( ) , invalidValues ) ;
1263+ } ) ;
1264+
1265+ it ( 'should not fail if method in validator said that its valid' , ( ) => {
1266+ validValues . forEach ( value => expect ( maxDate ( value , constraint ) ) . toBeTruthy ( ) ) ;
1267+ } ) ;
1268+
1269+ it ( 'should fail if method in validator said that its invalid' , ( ) => {
1270+ invalidValues . forEach ( value => expect ( maxDate ( value , constraint ) ) . toBeFalsy ( ) ) ;
1271+ } ) ;
1272+
1273+ it ( 'should return error object with proper data' , ( ) => {
1274+ const validationType = 'maxDate' ;
1275+ const message = 'maximal allowed date for someProperty is ' + constraintToString ( constraint ) ;
1276+ return checkReturnedError ( new MyClass ( ) , invalidValues , validationType , message ) ;
1277+ } ) ;
1278+ } ) ;
1279+
12141280describe ( 'IsBooleanString' , ( ) => {
12151281 const validValues = [ '1' , '0' , 'true' , 'false' ] ;
12161282 const invalidValues = [ '2' , '3' , 'falze' ] ;
0 commit comments