|
| 1 | +import { validateAndEnrichConfig } from '../../../../frameworks/config/configLoader.js' |
| 2 | + |
| 3 | +function createValidConfig(userOverrides: Record<string, unknown> = {}) { |
| 4 | + return { |
| 5 | + server: { port: 3000 }, |
| 6 | + user: { |
| 7 | + gitlabUsername: 'my-gitlab-user', |
| 8 | + githubUsername: 'my-github-user', |
| 9 | + ...userOverrides, |
| 10 | + }, |
| 11 | + queue: { maxConcurrent: 2, deduplicationWindowMs: 5000 }, |
| 12 | + repositories: [], |
| 13 | + } |
| 14 | +} |
| 15 | + |
| 16 | +describe('validateAndEnrichConfig', () => { |
| 17 | + describe('username validation', () => { |
| 18 | + it('should accept both non-empty usernames', () => { |
| 19 | + const config = createValidConfig() |
| 20 | + |
| 21 | + const result = validateAndEnrichConfig(config) |
| 22 | + |
| 23 | + expect(result.user.gitlabUsername).toBe('my-gitlab-user') |
| 24 | + expect(result.user.githubUsername).toBe('my-github-user') |
| 25 | + }) |
| 26 | + |
| 27 | + it('should accept empty gitlabUsername with non-empty githubUsername', () => { |
| 28 | + const config = createValidConfig({ |
| 29 | + gitlabUsername: '', |
| 30 | + githubUsername: 'my-github-user', |
| 31 | + }) |
| 32 | + |
| 33 | + const result = validateAndEnrichConfig(config) |
| 34 | + |
| 35 | + expect(result.user.gitlabUsername).toBe('') |
| 36 | + expect(result.user.githubUsername).toBe('my-github-user') |
| 37 | + }) |
| 38 | + |
| 39 | + it('should accept empty githubUsername with non-empty gitlabUsername', () => { |
| 40 | + const config = createValidConfig({ |
| 41 | + gitlabUsername: 'my-gitlab-user', |
| 42 | + githubUsername: '', |
| 43 | + }) |
| 44 | + |
| 45 | + const result = validateAndEnrichConfig(config) |
| 46 | + |
| 47 | + expect(result.user.gitlabUsername).toBe('my-gitlab-user') |
| 48 | + expect(result.user.githubUsername).toBe('') |
| 49 | + }) |
| 50 | + |
| 51 | + it('should accept both usernames empty', () => { |
| 52 | + const config = createValidConfig({ |
| 53 | + gitlabUsername: '', |
| 54 | + githubUsername: '', |
| 55 | + }) |
| 56 | + |
| 57 | + const result = validateAndEnrichConfig(config) |
| 58 | + |
| 59 | + expect(result.user.gitlabUsername).toBe('') |
| 60 | + expect(result.user.githubUsername).toBe('') |
| 61 | + }) |
| 62 | + |
| 63 | + it('should reject non-string gitlabUsername', () => { |
| 64 | + const config = createValidConfig({ gitlabUsername: 123 }) |
| 65 | + |
| 66 | + expect(() => validateAndEnrichConfig(config)).toThrow( |
| 67 | + 'gitlabUsername', |
| 68 | + ) |
| 69 | + }) |
| 70 | + |
| 71 | + it('should reject missing gitlabUsername field', () => { |
| 72 | + const config = createValidConfig() |
| 73 | + ;(config.user as Record<string, unknown>).gitlabUsername = undefined |
| 74 | + |
| 75 | + expect(() => validateAndEnrichConfig(config)).toThrow( |
| 76 | + 'gitlabUsername', |
| 77 | + ) |
| 78 | + }) |
| 79 | + |
| 80 | + it('should reject non-string githubUsername', () => { |
| 81 | + const config = createValidConfig({ githubUsername: true }) |
| 82 | + |
| 83 | + expect(() => validateAndEnrichConfig(config)).toThrow( |
| 84 | + 'githubUsername', |
| 85 | + ) |
| 86 | + }) |
| 87 | + |
| 88 | + it('should reject missing githubUsername field', () => { |
| 89 | + const config = createValidConfig() |
| 90 | + ;(config.user as Record<string, unknown>).githubUsername = undefined |
| 91 | + |
| 92 | + expect(() => validateAndEnrichConfig(config)).toThrow( |
| 93 | + 'githubUsername', |
| 94 | + ) |
| 95 | + }) |
| 96 | + }) |
| 97 | +}) |
0 commit comments