Skip to content

Commit 65da980

Browse files
authored
test: add streakParamsSchema user validation tests (JhaSourav07#850)
## Description Added unit tests for `streakParamsSchema` user field validation. ### Changes Made - Added success test for valid user - Added failure test for omitted user - Added failure test for empty user - Added failure test for username exceeding 39 characters - Added failure test for invalid username characters Closes JhaSourav07#659 --- ## Pillar - [x] Tests - [ ] Bug Fix - [ ] Feature - [ ] Documentation - [ ] Refactor --- ## Checklist - [x] My code follows the project style guidelines - [x] I have tested my changes locally - [x] All tests are passing - [x] I have linked the related issue - [x] This PR is ready for review
2 parents b554228 + f532aa4 commit 65da980

1 file changed

Lines changed: 52 additions & 1 deletion

File tree

lib/validations.test.ts

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { describe, expect, it } from 'vitest';
2-
import { githubParamsSchema } from './validations';
2+
import { githubParamsSchema, streakParamsSchema } from './validations';
33

44
describe('githubParamsSchema', () => {
55
it('should pass when username is valid', () => {
@@ -51,3 +51,54 @@ describe('githubParamsSchema', () => {
5151
}
5252
});
5353
});
54+
describe('streakParamsSchema user validation', () => {
55+
it('should pass when user is valid', () => {
56+
const result = streakParamsSchema.safeParse({
57+
user: 'octocat',
58+
});
59+
60+
expect(result.success).toBe(true);
61+
});
62+
63+
it('should fail when user is omitted', () => {
64+
const result = streakParamsSchema.safeParse({});
65+
66+
expect(result.success).toBe(false);
67+
if (!result.success) {
68+
expect(result.error.issues[0]?.message).toBe('Missing user parameter');
69+
}
70+
});
71+
72+
it('should fail when user is empty', () => {
73+
const result = streakParamsSchema.safeParse({
74+
user: '',
75+
});
76+
77+
expect(result.success).toBe(false);
78+
if (!result.success) {
79+
expect(result.error.issues[0]?.message).toBe('Missing user parameter');
80+
}
81+
});
82+
83+
it('should fail when user exceeds 39 characters', () => {
84+
const result = streakParamsSchema.safeParse({
85+
user: 'a'.repeat(40),
86+
});
87+
88+
expect(result.success).toBe(false);
89+
if (!result.success) {
90+
expect(result.error.issues[0]?.message).toBe('GitHub username cannot exceed 39 characters');
91+
}
92+
});
93+
94+
it('should fail when user has invalid characters', () => {
95+
const result = streakParamsSchema.safeParse({
96+
user: 'octo_cat',
97+
});
98+
99+
expect(result.success).toBe(false);
100+
if (!result.success) {
101+
expect(result.error.issues[0]?.message).toBe('Invalid GitHub username');
102+
}
103+
});
104+
});

0 commit comments

Comments
 (0)