Skip to content

Commit

Permalink
fix: pass options to validator in @IsDateString decorator (#1720)
Browse files Browse the repository at this point in the history
  • Loading branch information
hakimio authored Nov 20, 2022
1 parent c183cb3 commit 23071f6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/decorator/string/IsDateString.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export function IsDateString(
name: IS_DATE_STRING,
constraints: [options],
validator: {
validate: (value, args): boolean => isDateString(value),
validate: (value): boolean => isDateString(value, options),
defaultMessage: buildMessage(
eachPrefix => eachPrefix + '$property must be a valid ISO 8601 date string',
validationOptions
Expand Down
14 changes: 8 additions & 6 deletions test/functional/validation-functions-and-decorators.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,7 @@ describe('IsDateString', () => {
'text',
'text2018-01-04T08:15:30+04',
'2018-01-04T08:15:30Ztext',
'2009-02-29', // non-existent-day
'2019-18-13T22:14:14.761Z', // month greater than 12
'2019-12-39T22:14:14.761Z', // day greater than 31
'2019-12-31T29:14:14.761Z', // hour greater than 24
Expand All @@ -815,7 +816,7 @@ describe('IsDateString', () => {
];

class MyClass {
@IsDateString()
@IsDateString({ strict: true })
someProperty: string;
}

Expand All @@ -828,11 +829,11 @@ describe('IsDateString', () => {
});

it('should not fail if method in validator said that its valid', () => {
validValues.forEach(value => expect(isDateString(value)).toBeTruthy());
validValues.forEach(value => expect(isDateString(value, { strict: true })).toBeTruthy());
});

it('should fail if method in validator said that its invalid', () => {
invalidValues.forEach(value => expect(isDateString(value as any)).toBeFalsy());
invalidValues.forEach(value => expect(isDateString(value as any, { strict: true })).toBeFalsy());
});

it('should return error object with proper data', () => {
Expand Down Expand Up @@ -2980,10 +2981,11 @@ describe('IsISO8601', () => {
'2009-05-19 14.5.44',
'2010-02-18T16:23.33.600',
'2010-02-18T16,25:23:48,444',
'2009-02-29',
];

class MyClass {
@IsISO8601()
@IsISO8601({ strict: true })
someProperty: string;
}

Expand All @@ -2996,11 +2998,11 @@ describe('IsISO8601', () => {
});

it('should not fail if method in validator said that its valid', () => {
validValues.forEach(value => expect(isISO8601(value)).toBeTruthy());
validValues.forEach(value => expect(isISO8601(value, { strict: true })).toBeTruthy());
});

it('should fail if method in validator said that its invalid', () => {
invalidValues.forEach(value => expect(isISO8601(value)).toBeFalsy());
invalidValues.forEach(value => expect(isISO8601(value, { strict: true })).toBeFalsy());
});

it('should return error object with proper data', () => {
Expand Down

0 comments on commit 23071f6

Please sign in to comment.