|
1 | 1 | import { describe, expect, it } from 'vitest'; |
2 | | -import { githubParamsSchema, ogParamsSchema, streakParamsSchema } from './validations'; |
| 2 | +import { |
| 3 | + githubParamsSchema, |
| 4 | + ogParamsSchema, |
| 5 | + streakParamsSchema, |
| 6 | + validateGitHubUsername, |
| 7 | +} from './validations'; |
3 | 8 |
|
4 | 9 | describe('streakParamsSchema — grace fallback behavior', () => { |
5 | 10 | it('accepts "0" as a valid grace value', () => { |
@@ -40,6 +45,36 @@ describe('streakParamsSchema — grace fallback behavior', () => { |
40 | 45 | }); |
41 | 46 | }); |
42 | 47 |
|
| 48 | +describe('validateGitHubUsername', () => { |
| 49 | + it('returns true for a valid username', () => { |
| 50 | + expect(validateGitHubUsername('valid-username-123')).toBe(true); |
| 51 | + }); |
| 52 | + |
| 53 | + it('returns false for a too long username', () => { |
| 54 | + expect(validateGitHubUsername('a'.repeat(40))).toBe(false); |
| 55 | + }); |
| 56 | + |
| 57 | + it('returns false for a username with underscore', () => { |
| 58 | + expect(validateGitHubUsername('invalid_username')).toBe(false); |
| 59 | + }); |
| 60 | + |
| 61 | + it('returns false for empty string', () => { |
| 62 | + expect(validateGitHubUsername('')).toBe(false); |
| 63 | + }); |
| 64 | + |
| 65 | + it('returns false for leading hyphen', () => { |
| 66 | + expect(validateGitHubUsername('-octocat')).toBe(false); |
| 67 | + }); |
| 68 | + |
| 69 | + it('returns false for trailing hyphen', () => { |
| 70 | + expect(validateGitHubUsername('octocat-')).toBe(false); |
| 71 | + }); |
| 72 | + |
| 73 | + it('returns false for consecutive hyphens', () => { |
| 74 | + expect(validateGitHubUsername('octo--cat')).toBe(false); |
| 75 | + }); |
| 76 | +}); |
| 77 | + |
43 | 78 | describe('githubParamsSchema', () => { |
44 | 79 | it('should pass when username is valid', () => { |
45 | 80 | const result = githubParamsSchema.safeParse({ |
|
0 commit comments