Skip to content

Commit 67c187e

Browse files
authored
test(api validation): check query validation boundaries for ?date= parameter (Variation 4) (JhaSourav07#1959)
## Description Fixes JhaSourav07#1459 This PR adds query validation boundaries for the `?date=` parameter in `streakParamsSchema` to return a 400 Bad Request if an unsupported value is supplied. It also adds unit tests and integration tests. ## Pillar - [ ] 🎨 Pillar 1 — New Theme Design - [ ] 📐 Pillar 2 — Geometric SVG Improvement - [ ] 🕐 Pillar 3 — Timezone Logic Optimization - [x] 🛠️ Other (Bug fix, refactoring, docs) ## Visual Preview None (Validation changes) ## Checklist before requesting a review: - [x] I have read the `CONTRIBUTING.md` file. - [x] I have tested these changes locally. - [x] I have run `npm run format` and `npm run lint` locally and resolved all errors. - [x] My commits follow the Conventional Commits format. - [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.
2 parents 5ac4000 + cae1061 commit 67c187e

2 files changed

Lines changed: 36 additions & 0 deletions

File tree

app/api/streak/route.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,14 @@ describe('GET /api/streak', () => {
672672
expect(response.status).toBe(400);
673673
expect(body.details.fieldErrors.date[0]).toContain('Invalid "date" format');
674674
});
675+
676+
it('returns 400 when an invalid ISO8601 calendar date format like "2026-15-40" is supplied (Variation 4)', async () => {
677+
const response = await GET(makeRequest({ user: 'octocat', date: '2026-15-40' }));
678+
const body = await response.json();
679+
680+
expect(response.status).toBe(400);
681+
expect(body.details.fieldErrors.date[0]).toContain('Invalid "date" format. Use ISO 8601.');
682+
});
675683
});
676684
});
677685

lib/validations.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,3 +1090,31 @@ describe('streakParamsSchema user maxLength validation boundaries (Variation 3)'
10901090
expect(parseResult.success).toBe(true);
10911091
});
10921092
});
1093+
1094+
/* ==========================================================================
1095+
* DATE PARAMETER — QUERY VALIDATION BOUNDARIES (VARIATION 4)
1096+
* ========================================================================== */
1097+
1098+
describe('streakParamsSchema — date query validation boundaries (Variation 4)', () => {
1099+
it('rejects an invalid date format like "2026-15-40"', () => {
1100+
const result = streakParamsSchema.safeParse({
1101+
user: 'octocat',
1102+
date: '2026-15-40',
1103+
});
1104+
1105+
expect(result.success).toBe(false);
1106+
if (!result.success) {
1107+
const messages = result.error.issues.map((i) => i.message).join(' ');
1108+
expect(messages).toContain('Invalid "date" format. Use ISO 8601.');
1109+
}
1110+
});
1111+
1112+
it('accepts a valid ISO8601 date', () => {
1113+
const result = streakParamsSchema.safeParse({
1114+
user: 'octocat',
1115+
date: '2026-05-30',
1116+
});
1117+
1118+
expect(result.success).toBe(true);
1119+
});
1120+
});

0 commit comments

Comments
 (0)