Skip to content

Commit 1cdbe01

Browse files
authored
test: add streakParamsSchema user validation tests (JhaSourav07#854)
* test: add streakParamsSchema user validation tests * fix: resolve validation test syntax issues
1 parent ced67e8 commit 1cdbe01

1 file changed

Lines changed: 25 additions & 10 deletions

File tree

lib/validations.test.ts

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,9 @@ 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-
});
6254

63-
it('should fail when user is omitted', () => {
55+
describe('streakParamsSchema', () => {
56+
it('should fail when user is missing', () => {
6457
const result = streakParamsSchema.safeParse({});
6558

6659
expect(result.success).toBe(false);
@@ -69,7 +62,7 @@ describe('streakParamsSchema user validation', () => {
6962
}
7063
});
7164

72-
it('should fail when user is empty', () => {
65+
it('should fail when user is empty string', () => {
7366
const result = streakParamsSchema.safeParse({
7467
user: '',
7568
});
@@ -80,6 +73,28 @@ describe('streakParamsSchema user validation', () => {
8073
}
8174
});
8275

76+
it('should succeed when user is a valid username', () => {
77+
const result = streakParamsSchema.safeParse({
78+
user: 'octocat',
79+
});
80+
81+
expect(result.success).toBe(true);
82+
if (result.success) {
83+
expect(result.data.user).toBe('octocat');
84+
}
85+
});
86+
87+
it('should fail when user is whitespace-only input', () => {
88+
const result = streakParamsSchema.safeParse({
89+
user: ' ',
90+
});
91+
92+
expect(result.success).toBe(false);
93+
if (!result.success) {
94+
expect(result.error.issues[0]?.message).toBe('Invalid GitHub username');
95+
}
96+
});
97+
8398
it('should fail when user exceeds 39 characters', () => {
8499
const result = streakParamsSchema.safeParse({
85100
user: 'a'.repeat(40),

0 commit comments

Comments
 (0)