Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions app/api/streak/route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -558,10 +558,10 @@ describe('GET /api/streak', () => {
expect(body.details.fieldErrors.year[0]).toContain('GitHub was founded in 2008');
});

it('returns 200 for unknown ?date= parameter (not part of schema)', async () => {
const response = await GET(makeRequest({ user: 'octocat', date: '2026-15-40' }));
expect(response.status).toBe(200);
});
// it('returns 200 for unknown ?date= parameter (not part of schema)', async () => {
// const response = await GET(makeRequest({ user: 'octocat', date: '2026-15-40' }));
// expect(response.status).toBe(200);
// });

it('returns 400 for malformed numeric year', async () => {
const response = await GET(makeRequest({ user: 'octocat', year: '100000' }));
Expand Down Expand Up @@ -611,6 +611,16 @@ describe('GET /api/streak', () => {

expect(response.status).toBe(200);
});

describe('date parameter', () => {
it('returns 400 when an invalid ISO8601 calendar date format like "2026-15-40" is supplied', async () => {
const response = await GET(makeRequest({ user: 'octocat', date: '2026-15-40' }));
const body = await response.json();

expect(response.status).toBe(400);
expect(body.details.fieldErrors.date[0]).toContain('Invalid "date" format');
});
});
});

describe('radius parameter', () => {
Expand Down
11 changes: 11 additions & 0 deletions lib/validations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -789,3 +789,14 @@ describe('streakParamsSchema β€” tz IANA timezone validation (Variation 4)', ()
}
});
});

describe('streakParamsSchema β€” date parameter validation', () => {
it('rejects an invalid ISO8601 calendar date format like "2026-15-40"', () => {
const result = streakParamsSchema.safeParse({
user: 'octocat',
date: '2026-15-40',
});

expect(result.success).toBe(false);
});
});
10 changes: 10 additions & 0 deletions lib/validations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,16 @@ const baseStreakParamsSchema = z.object({
},
{ message: 'Invalid "to" date format. Use ISO 8601 (e.g. 2023-12-31).' }
),
date: z
.string()
.optional()
.refine(
(val) => {
if (!val) return true;
return !isNaN(Date.parse(val));
},
{ message: 'Invalid "date" format. Use ISO 8601.' }
),
tz: z
.string()
.optional()
Expand Down
Loading