Skip to content
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

Merged
merged 7 commits into from
Nov 12, 2024
Merged

customValidator Test Update #597

merged 7 commits into from
Nov 12, 2024

Conversation

icemedia001
Copy link
Contributor

@icemedia001 icemedia001 commented Oct 28, 2024

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

Copy link

stackblitz bot commented Oct 28, 2024

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@icemedia001 icemedia001 requested a review from AshakaE October 28, 2024 11:00
Copy link

codeclimate bot commented Oct 28, 2024

Code Climate has analyzed commit 860fd25 and detected 0 issues on this pull request.

View more on Code Climate.

@icemedia001 icemedia001 requested review from AshakaE and removed request for AshakaE November 4, 2024 16:41
Comment on lines 44 to 64
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)
}
})
Copy link
Collaborator

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

Comment on lines 203 to 231
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')
})
})
Copy link
Collaborator

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'

@icemedia001 icemedia001 requested a review from AshakaE November 5, 2024 11:43
@AshakaE AshakaE merged commit 4358631 into main Nov 12, 2024
1 check passed
@AshakaE AshakaE deleted the customValidatorTest branch November 12, 2024 08:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cutomValidator Test update
2 participants