Skip to content

Commit 8ba200e

Browse files
authored
test(validations-ogParamsSchema): add comprehensive schema tests (JhaSourav07#3094)
## Description Fixes JhaSourav07#2326 ## Title test(validations-ogParamsSchema): add comprehensive schema tests ## Summary Added a dedicated test suite for `ogParamsSchema` in `lib/validations.ogParamsSchema.test.ts`. The tests cover: * successful parsing of valid OpenGraph parameters * default theme handling * username fallback behavior * fallback to `"unknown"` when no user values are provided * valid hex color parsing behavior * invalid color handling for malformed hex values ## Changes Made * Created `lib/validations.ogParamsSchema.test.ts` * Added 6 focused Vitest test cases * Verified schema transforms and fallback behavior using `safeParse` ## Validation ```bash npx vitest lib/validations.ogParamsSchema.test.ts npm run lint npm run format ``` ## Pillar - [ ] 🎨 Pillar 1 — New Theme Design - [ ] 📐 Pillar 2 — Geometric SVG Improvement - [ ] 🕐 Pillar 3 — Timezone Logic Optimization - [x] 🛠️ Other (Bug fix, refactoring, docs) ## Visual Preview ## 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 (CI will fail otherwise). - [x] My commits follow the Conventional Commits format (e.g., `feat(themes): ...`, `fix(calculate): ...`). - [x] 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 "premium quality" aesthetic standard (no raw elements, smooth animations, correct fonts). - [x] (Recommended) I joined the CommitPulse Discord community for contributor discussions, mentorship, and faster PR support.
2 parents 3bb0ec3 + 74a9022 commit 8ba200e

1 file changed

Lines changed: 92 additions & 0 deletions

File tree

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import { describe, expect, it } from 'vitest';
2+
import { ogParamsSchema } from './validations';
3+
4+
describe('ogParamsSchema', () => {
5+
it('parses valid OpenGraph parameters successfully', () => {
6+
const result = ogParamsSchema.safeParse({
7+
user: 'octocat',
8+
theme: 'dark',
9+
bg: 'ffffff',
10+
text: '000000',
11+
accent: 'ff0000',
12+
});
13+
14+
expect(result.success).toBe(true);
15+
16+
if (result.success) {
17+
expect(result.data.user).toBe('octocat');
18+
expect(result.data.theme).toBe('dark');
19+
expect(result.data.bg).toBe('ffffff');
20+
expect(result.data.text).toBe('000000');
21+
expect(result.data.accent).toBe('ff0000');
22+
}
23+
});
24+
25+
it('applies default theme when omitted', () => {
26+
const result = ogParamsSchema.safeParse({
27+
user: 'octocat',
28+
});
29+
30+
expect(result.success).toBe(true);
31+
32+
if (result.success) {
33+
expect(result.data.theme).toBe('dark');
34+
}
35+
});
36+
37+
it('falls back to username when user is not provided', () => {
38+
const result = ogParamsSchema.safeParse({
39+
username: 'fallback-user',
40+
});
41+
42+
expect(result.success).toBe(true);
43+
44+
if (result.success) {
45+
expect(result.data.user).toBe('fallback-user');
46+
}
47+
});
48+
49+
it('falls back to unknown when both user and username are missing', () => {
50+
const result = ogParamsSchema.safeParse({});
51+
52+
expect(result.success).toBe(true);
53+
54+
if (result.success) {
55+
expect(result.data.user).toBe('unknown');
56+
}
57+
});
58+
59+
it('normalizes valid hex color values', () => {
60+
const result = ogParamsSchema.safeParse({
61+
user: 'octocat',
62+
bg: 'ABCDEF',
63+
text: '123456',
64+
accent: 'ff00ff',
65+
});
66+
67+
expect(result.success).toBe(true);
68+
69+
if (result.success) {
70+
expect(result.data.bg).toBe('ABCDEF');
71+
expect(result.data.text).toBe('123456');
72+
expect(result.data.accent).toBe('ff00ff');
73+
}
74+
});
75+
76+
it('falls back to default color for invalid hex values', () => {
77+
const result = ogParamsSchema.safeParse({
78+
user: 'octocat',
79+
bg: 'invalid-color',
80+
text: 'xyz',
81+
accent: '12345',
82+
});
83+
84+
expect(result.success).toBe(true);
85+
86+
if (result.success) {
87+
expect(result.data.bg).toBeUndefined();
88+
expect(result.data.text).toBeUndefined();
89+
expect(result.data.accent).toBeUndefined();
90+
}
91+
});
92+
});

0 commit comments

Comments
 (0)