Skip to content

Commit 84556f6

Browse files
authored
test(api): reject fictitious tz value Mars/Cyonia with 400 Bad Request (JhaSourav07#1904)
## Description Fixes JhaSourav07#1457 ## Pillar - [ ] 🎨 Pillar 1 — New Theme Design - [ ] 📐 Pillar 2 — Geometric SVG Improvement - [ ] 🕐 Pillar 3 — Timezone Logic Optimization - [x] 🛠️ Other (Bug fix, refactoring, docs) ## Visual Preview N/A - test only change, no SVG output modified. ## 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). - [ ] (Recommended) I joined the CommitPulse Discord community for contributor discussions, mentorship, and faster PR support.
2 parents 748f809 + 0abf549 commit 84556f6

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

app/api/streak/route.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,20 @@ describe('GET /api/streak', () => {
826826

827827
expect(getSecondsUntilMidnightInTimezone).toHaveBeenCalledWith('Australia/Sydney');
828828
});
829+
830+
// =========================================================================
831+
// ISSUE OBJECTIVE: Reject fictitious planetary timezone (Variation 4)
832+
// =========================================================================
833+
it('returns 400 when a fictitious planetary timezone Mars/Cyonia is supplied', async () => {
834+
// Mars/Cyonia is structurally plausible (Region/City format) but does not
835+
// exist in the IANA tz database — the schema must reject it before the
836+
// request reaches the GitHub API.
837+
const response = await GET(makeRequest({ user: 'octocat', tz: 'Mars/Cyonia' }));
838+
839+
expect(response.status).toBe(400);
840+
const body = await response.json();
841+
expect(body.details.fieldErrors.tz[0]).toContain('Invalid timezone');
842+
});
829843
});
830844

831845
describe('hide_background parameter', () => {

lib/validations.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -756,3 +756,24 @@ describe('streakParamsSchema — Date Range Boundary Robustness (Variation 1)',
756756
}
757757
});
758758
});
759+
760+
/* ==========================================================================
761+
* TZ PARAMETER — IANA TIMEZONE VALIDATION (VARIATION 4)
762+
* ========================================================================== */
763+
764+
describe('streakParamsSchema — tz IANA timezone validation (Variation 4)', () => {
765+
it('rejects a fictitious planetary timezone that is not a valid IANA zone', () => {
766+
// Mars/Cyonia looks structurally plausible (Region/City format) but does not
767+
// exist in the IANA tz database, so Intl.DateTimeFormat must throw and the
768+
// schema must surface a field-level validation error.
769+
const result = streakParamsSchema.safeParse({
770+
user: 'octocat',
771+
tz: 'Mars/Cyonia',
772+
});
773+
774+
expect(result.success).toBe(false);
775+
if (!result.success) {
776+
expect(result.error.issues[0]?.message).toContain('Invalid timezone');
777+
}
778+
});
779+
});

0 commit comments

Comments
 (0)