Skip to content

Commit 97d2cd4

Browse files
authored
test(validations): verify mode parameter (JhaSourav07#1191)
## Description Fixes JhaSourav07#1044 Added validation tests for the `mode` parameter in `streakParamsSchema`. ### Test Coverage Added * Validates `mode: 'commits'`. * Validates `mode: 'loc'`. * Verifies unknown values fall back to `'commits'`. * Verifies omitted values default to `'commits'`. ## Pillar * [ ] 🎨 Pillar 1 — New Theme Design * [ ] 📐 Pillar 2 — Geometric SVG Improvement * [ ] 🕐 Pillar 3 — Timezone Logic Optimization * [x] 🛠️ Other (Bug fix, refactoring, docs) ## Visual Preview Not applicable — test-only change. ## Checklist before requesting a review: * [x] I have read the `CONTRIBUTING.md` file. * [x] I have tested these changes locally (`localhost:3000/api/streak?user=YOUR_USERNAME`). * [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 required. * [x] I have starred the repo. * [x] I have made sure that I have only one commit to merge in this PR. * [x] I joined the Discord community.
2 parents f4ddd7f + 03f91f7 commit 97d2cd4

1 file changed

Lines changed: 51 additions & 0 deletions

File tree

lib/validations.test.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,57 @@ describe('streakParamsSchema user validation', () => {
6262
});
6363

6464
describe('streakParamsSchema', () => {
65+
it('accepts commits mode', () => {
66+
const result = streakParamsSchema.safeParse({
67+
user: 'octocat',
68+
mode: 'commits',
69+
});
70+
71+
expect(result.success).toBe(true);
72+
73+
if (result.success) {
74+
expect(result.data.mode).toBe('commits');
75+
}
76+
});
77+
78+
it('accepts loc mode', () => {
79+
const result = streakParamsSchema.safeParse({
80+
user: 'octocat',
81+
mode: 'loc',
82+
});
83+
84+
expect(result.success).toBe(true);
85+
86+
if (result.success) {
87+
expect(result.data.mode).toBe('loc');
88+
}
89+
});
90+
91+
it('falls back to commits for unknown mode', () => {
92+
const result = streakParamsSchema.safeParse({
93+
user: 'octocat',
94+
mode: 'unknown',
95+
});
96+
97+
expect(result.success).toBe(true);
98+
99+
if (result.success) {
100+
expect(result.data.mode).toBe('commits');
101+
}
102+
});
103+
104+
it('defaults to commits when mode is omitted', () => {
105+
const result = streakParamsSchema.safeParse({
106+
user: 'octocat',
107+
});
108+
109+
expect(result.success).toBe(true);
110+
111+
if (result.success) {
112+
expect(result.data.mode).toBe('commits');
113+
}
114+
});
115+
65116
it('accepts a valid width value', () => {
66117
const result = streakParamsSchema.safeParse({
67118
user: 'octocat',

0 commit comments

Comments
 (0)