|
1 | 1 | import { describe, expect, it } from 'vitest'; |
2 | | -import { githubParamsSchema } from './validations'; |
| 2 | +import { githubParamsSchema, streakParamsSchema } from './validations'; |
3 | 3 |
|
4 | 4 | describe('githubParamsSchema', () => { |
5 | 5 | it('should pass when username is valid', () => { |
@@ -51,3 +51,54 @@ describe('githubParamsSchema', () => { |
51 | 51 | } |
52 | 52 | }); |
53 | 53 | }); |
| 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