Skip to content

Commit cae1061

Browse files
committed
test(api validation): check query validation boundaries for ?date= parameter (Variation 4) (JhaSourav07#1459)
1 parent 59b37f4 commit cae1061

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
@@ -650,6 +650,14 @@ describe('GET /api/streak', () => {
650650
expect(response.status).toBe(400);
651651
expect(body.details.fieldErrors.date[0]).toContain('Invalid "date" format');
652652
});
653+
654+
it('returns 400 when an invalid ISO8601 calendar date format like "2026-15-40" is supplied (Variation 4)', async () => {
655+
const response = await GET(makeRequest({ user: 'octocat', date: '2026-15-40' }));
656+
const body = await response.json();
657+
658+
expect(response.status).toBe(400);
659+
expect(body.details.fieldErrors.date[0]).toContain('Invalid "date" format. Use ISO 8601.');
660+
});
653661
});
654662
});
655663

lib/validations.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,3 +1061,31 @@ describe('streakParamsSchema user maxLength validation boundaries (Variation 3)'
10611061
expect(parseResult.success).toBe(true);
10621062
});
10631063
});
1064+
1065+
/* ==========================================================================
1066+
* DATE PARAMETER — QUERY VALIDATION BOUNDARIES (VARIATION 4)
1067+
* ========================================================================== */
1068+
1069+
describe('streakParamsSchema — date query validation boundaries (Variation 4)', () => {
1070+
it('rejects an invalid date format like "2026-15-40"', () => {
1071+
const result = streakParamsSchema.safeParse({
1072+
user: 'octocat',
1073+
date: '2026-15-40',
1074+
});
1075+
1076+
expect(result.success).toBe(false);
1077+
if (!result.success) {
1078+
const messages = result.error.issues.map((i) => i.message).join(' ');
1079+
expect(messages).toContain('Invalid "date" format. Use ISO 8601.');
1080+
}
1081+
});
1082+
1083+
it('accepts a valid ISO8601 date', () => {
1084+
const result = streakParamsSchema.safeParse({
1085+
user: 'octocat',
1086+
date: '2026-05-30',
1087+
});
1088+
1089+
expect(result.success).toBe(true);
1090+
});
1091+
});

0 commit comments

Comments
 (0)