Skip to content

Commit 0abf549

Browse files
test(api): reject fictitious tz value Mars/Cyonia with 400 Bad Request
1 parent 10a1634 commit 0abf549

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
@@ -820,6 +820,20 @@ describe('GET /api/streak', () => {
820820

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

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

lib/validations.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -713,3 +713,24 @@ describe('streakParamsSchema — Date Range Boundary Robustness (Variation 1)',
713713
}
714714
});
715715
});
716+
717+
/* ==========================================================================
718+
* TZ PARAMETER — IANA TIMEZONE VALIDATION (VARIATION 4)
719+
* ========================================================================== */
720+
721+
describe('streakParamsSchema — tz IANA timezone validation (Variation 4)', () => {
722+
it('rejects a fictitious planetary timezone that is not a valid IANA zone', () => {
723+
// Mars/Cyonia looks structurally plausible (Region/City format) but does not
724+
// exist in the IANA tz database, so Intl.DateTimeFormat must throw and the
725+
// schema must surface a field-level validation error.
726+
const result = streakParamsSchema.safeParse({
727+
user: 'octocat',
728+
tz: 'Mars/Cyonia',
729+
});
730+
731+
expect(result.success).toBe(false);
732+
if (!result.success) {
733+
expect(result.error.issues[0]?.message).toContain('Invalid timezone');
734+
}
735+
});
736+
});

0 commit comments

Comments
 (0)