Skip to content

Commit 8bbdb32

Browse files
authored
test(validations): verify width and height ranges (JhaSourav07#1181)
## Description Fixes JhaSourav07#1045 Added boundary and validation tests for the `width` and `height` parameters in `streakParamsSchema`. ### Test Coverage Added * Valid width parsing (`400`). * Width minimum boundary validation (`99`). * Width maximum boundary validation (`1201`). * Valid height parsing (`120`). * Height minimum boundary validation (`79`). * Height maximum boundary validation (`801`). * Non-numeric width validation (`abc`). * Omitted width handling (`undefined`). ## 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 (CI will fail otherwise). * [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 starred 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. * [x] (Recommended) I joined the CommitPulse Discord community for contributor discussions, mentorship, and faster PR support.
2 parents 7e3d6a5 + 20da42b commit 8bbdb32

1 file changed

Lines changed: 83 additions & 0 deletions

File tree

lib/validations.test.ts

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

6464
describe('streakParamsSchema', () => {
65+
it('accepts a valid width value', () => {
66+
const result = streakParamsSchema.safeParse({
67+
user: 'octocat',
68+
width: '400',
69+
});
70+
71+
expect(result.success).toBe(true);
72+
73+
if (result.success) {
74+
expect(result.data.width).toBe(400);
75+
}
76+
});
77+
78+
it('rejects width below minimum', () => {
79+
const result = streakParamsSchema.safeParse({
80+
user: 'octocat',
81+
width: '99',
82+
});
83+
84+
expect(result.success).toBe(false);
85+
});
86+
87+
it('rejects width above maximum', () => {
88+
const result = streakParamsSchema.safeParse({
89+
user: 'octocat',
90+
width: '1201',
91+
});
92+
93+
expect(result.success).toBe(false);
94+
});
95+
96+
it('accepts a valid height value', () => {
97+
const result = streakParamsSchema.safeParse({
98+
user: 'octocat',
99+
height: '120',
100+
});
101+
102+
expect(result.success).toBe(true);
103+
104+
if (result.success) {
105+
expect(result.data.height).toBe(120);
106+
}
107+
});
108+
109+
it('rejects height below minimum', () => {
110+
const result = streakParamsSchema.safeParse({
111+
user: 'octocat',
112+
height: '79',
113+
});
114+
115+
expect(result.success).toBe(false);
116+
});
117+
118+
it('rejects height above maximum', () => {
119+
const result = streakParamsSchema.safeParse({
120+
user: 'octocat',
121+
height: '801',
122+
});
123+
124+
expect(result.success).toBe(false);
125+
});
126+
127+
it('rejects non-numeric width values', () => {
128+
const result = streakParamsSchema.safeParse({
129+
user: 'octocat',
130+
width: 'abc',
131+
});
132+
133+
expect(result.success).toBe(false);
134+
});
135+
136+
it('leaves width undefined when omitted', () => {
137+
const result = streakParamsSchema.safeParse({
138+
user: 'octocat',
139+
});
140+
141+
expect(result.success).toBe(true);
142+
143+
if (result.success) {
144+
expect(result.data.width).toBeUndefined();
145+
}
146+
});
147+
65148
it('should fail when user is missing', () => {
66149
const result = streakParamsSchema.safeParse({});
67150

0 commit comments

Comments
 (0)