-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
customValidator Test Update #597
Conversation
Run & review this pull request in StackBlitz Codeflow. |
Code Climate has analyzed commit 860fd25 and detected 0 issues on this pull request. View more on Code Climate. |
860fd25
to
dc7ed51
Compare
it('should return true for valid strings with alphanumeric characters', async () => { | ||
const validInputs = [ | ||
'abc123', | ||
'ABC123', | ||
'Test123', | ||
'Hello World', | ||
'Test-123', | ||
'Test.123', | ||
'Test/123', | ||
'Test (123)', | ||
'', | ||
] | ||
|
||
for (const input of validInputs) { | ||
const result = await validStringParams.validate( | ||
input, | ||
mockValidationArguments, | ||
) | ||
expect(result).toBe(true) | ||
} | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to update the regex, valid string params should contain at most the hyphen -
special character otherwise it's invalid .. examples 54dd0bb4-f570-4771-8ba4-59bade1debc8
and test123
describe('validDateParams', () => { | ||
it('should return true for valid date strings in YYYY-MM-DD format', async () => { | ||
const validDates = ['2024-01-01', '1999-12-31', '2020-02-29'] | ||
for (const date of validDates) { | ||
const result = await validDateParams.validate( | ||
date, | ||
mockValidationArguments, | ||
) | ||
expect(result).toBe(true) | ||
} | ||
}) | ||
|
||
it('should return true for null or undefined dates', async () => { | ||
expect( | ||
await validDateParams.validate(null as any, mockValidationArguments), | ||
).toBe(true) | ||
expect( | ||
await validDateParams.validate( | ||
undefined as any, | ||
mockValidationArguments, | ||
), | ||
).toBe(true) | ||
}) | ||
|
||
it('should return the default error message for invalid date strings', () => { | ||
const message = validDateParams.defaultMessage(mockValidationArguments) | ||
expect(message).toBe('Invalid date string parameters') | ||
}) | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should also update this regex, validDateParams should take values like '2024-01-01'
or '2024/01/01'
customValidator Test Update
Update unit tests for customValidator to validate alphanumeric strings with specific allowed characters and ensure proper error messaging for invalid inputs.
pnpm test customValidator.spec.ts
closes EveripediaNetwork/issues#3482