Skip to content

Commit 6395ed6

Browse files
authored
test: add ogParamsSchema user default tests (JhaSourav07#999)
## Description Added unit tests for ogParamsSchema user field default behavior. Fixes JhaSourav07#662 ## Pillar - [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. - [x] My commits follow the Conventional Commits format. - [x] I have made sure that I have only one commit to merge in this PR.
2 parents dbd0861 + b6bad20 commit 6395ed6

1 file changed

Lines changed: 37 additions & 8 deletions

File tree

lib/validations.test.ts

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { describe, expect, it } from 'vitest';
2-
import { githubParamsSchema, streakParamsSchema } from './validations';
2+
import { githubParamsSchema, ogParamsSchema, streakParamsSchema } from './validations';
33

44
describe('githubParamsSchema', () => {
55
it('should pass when username is valid', () => {
@@ -118,15 +118,11 @@ describe('streakParamsSchema', () => {
118118
});
119119
});
120120

121-
// Helper — parse only the fields we care about, supplying the required `user` field.
122121
function parse(params: Record<string, string>) {
123122
return streakParamsSchema.parse({ user: 'octocat', ...params });
124123
}
125124

126125
describe('streakParamsSchema — scale fallback behavior', () => {
127-
// z.enum(['linear', 'log']).catch('linear') — unknown values silently fall
128-
// back to 'linear' instead of throwing a validation error.
129-
130126
it('accepts "log" as a valid scale value', () => {
131127
expect(parse({ scale: 'log' }).scale).toBe('log');
132128
});
@@ -149,9 +145,6 @@ describe('streakParamsSchema — scale fallback behavior', () => {
149145
});
150146

151147
describe('streakParamsSchema — size fallback behavior', () => {
152-
// z.enum(['small', 'medium', 'large']).catch('medium') — unknown values
153-
// silently fall back to 'medium' to preserve badge rendering.
154-
155148
it('accepts "small" as a valid size value', () => {
156149
expect(parse({ size: 'small' }).size).toBe('small');
157150
});
@@ -176,3 +169,39 @@ describe('streakParamsSchema — size fallback behavior', () => {
176169
expect(parse({ size: '' }).size).toBe('medium');
177170
});
178171
});
172+
173+
describe('ogParamsSchema', () => {
174+
it('should keep provided user value', () => {
175+
const result = ogParamsSchema.safeParse({
176+
user: 'octocat',
177+
});
178+
179+
expect(result.success).toBe(true);
180+
181+
if (result.success) {
182+
expect(result.data.user).toBe('octocat');
183+
}
184+
});
185+
186+
it('should default user to unknown when omitted', () => {
187+
const result = ogParamsSchema.safeParse({});
188+
189+
expect(result.success).toBe(true);
190+
191+
if (result.success) {
192+
expect(result.data.user).toBe('unknown');
193+
}
194+
});
195+
196+
it('should allow empty string user', () => {
197+
const result = ogParamsSchema.safeParse({
198+
user: '',
199+
});
200+
201+
expect(result.success).toBe(true);
202+
203+
if (result.success) {
204+
expect(result.data.user).toBe('');
205+
}
206+
});
207+
});

0 commit comments

Comments
 (0)