Skip to content

Commit 09f0709

Browse files
authored
test(validations): add tests for scale and size fallback behavior in streakParamsSchema (JhaSourav07#881)
## Description Fixes JhaSourav07#661 ## Pillar - [ ] 🎨 Pillar 1 — New Theme Design - [ ] 📐 Pillar 2 — Geometric SVG Improvement - [ ] 🕐 Pillar 3 — Timezone Logic Optimization - [x] 🛠️ Other (Bug fix, refactoring, docs) ## Visual Preview N/A — test-only PR, no SVG output changes ## Checklist before requesting a review: - [x] I have read the `CONTRIBUTING.md` file. - [x] I have tested these changes locally (21 tests pass via npx vitest run lib/validations.test.ts) - [x] I have run `npm run format` and `npm run lint` locally and resolved all errors. - [x] My commits follow the Conventional Commits format. - [ ] I have updated `README.md` if I added a new theme or URL parameter. - [x] I have started the repo. - [x] I have made sure that i have only one commit to merge in this PR. - [x] The SVG output matches the CommitPulse quality standard. - [x] I joined the CommitPulse Discord community.
2 parents 0368aee + 988c6ec commit 09f0709

1 file changed

Lines changed: 59 additions & 0 deletions

File tree

lib/validations.test.ts

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,62 @@ describe('streakParamsSchema user validation', () => {
102102
}
103103
});
104104
});
105+
106+
// Helper — parse only the fields we care about, supplying the required `user` field.
107+
function parse(params: Record<string, string>) {
108+
return streakParamsSchema.parse({ user: 'octocat', ...params });
109+
}
110+
111+
describe('streakParamsSchema — scale fallback behavior', () => {
112+
// z.enum(['linear', 'log']).catch('linear') — unknown values silently fall
113+
// back to 'linear' instead of throwing a validation error.
114+
115+
it('accepts "log" as a valid scale value', () => {
116+
expect(parse({ scale: 'log' }).scale).toBe('log');
117+
});
118+
119+
it('accepts "linear" as a valid scale value', () => {
120+
expect(parse({ scale: 'linear' }).scale).toBe('linear');
121+
});
122+
123+
it('falls back to "linear" for unknown scale value', () => {
124+
expect(parse({ scale: 'exponential' }).scale).toBe('linear');
125+
});
126+
127+
it('falls back to "linear" for empty string', () => {
128+
expect(parse({ scale: '' }).scale).toBe('linear');
129+
});
130+
131+
it('defaults to "linear" when scale is omitted', () => {
132+
expect(parse({}).scale).toBe('linear');
133+
});
134+
});
135+
136+
describe('streakParamsSchema — size fallback behavior', () => {
137+
// z.enum(['small', 'medium', 'large']).catch('medium') — unknown values
138+
// silently fall back to 'medium' to preserve badge rendering.
139+
140+
it('accepts "small" as a valid size value', () => {
141+
expect(parse({ size: 'small' }).size).toBe('small');
142+
});
143+
144+
it('accepts "medium" as a valid size value', () => {
145+
expect(parse({ size: 'medium' }).size).toBe('medium');
146+
});
147+
148+
it('accepts "large" as a valid size value', () => {
149+
expect(parse({ size: 'large' }).size).toBe('large');
150+
});
151+
152+
it('falls back to "medium" for unknown size value', () => {
153+
expect(parse({ size: 'giant' }).size).toBe('medium');
154+
});
155+
156+
it('defaults to "medium" when size is omitted', () => {
157+
expect(parse({}).size).toBe('medium');
158+
});
159+
160+
it('falls back to "medium" for empty string', () => {
161+
expect(parse({ size: '' }).size).toBe('medium');
162+
});
163+
});

0 commit comments

Comments
 (0)