Skip to content

Commit f623f98

Browse files
author
tamilr0727-ux
committed
test(api-validation): add query validation boundaries for ?accent= parameter(Variation 5)
1 parent a4dcf09 commit f623f98

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

app/api/streak/route.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -766,6 +766,16 @@ describe('GET /api/streak', () => {
766766

767767
expect(response.status).toBe(400);
768768
});
769+
770+
it('returns 400 Bad Request for invalid color hex syntax targeting the ?accent= parameter', async () => {
771+
const response = await GET(makeRequest({ user: 'octocat', accent: '#ZZZZZZ' }));
772+
773+
expect(response.status).toBe(400);
774+
775+
const body = await response.json();
776+
expect(body.error).toBe('Invalid parameters');
777+
expect(body.details).not.toBeNull();
778+
});
769779
});
770780

771781
describe('hide parameters', () => {

lib/validations.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,22 @@ describe('streakParamsSchema — accent parameter HEX color validation', () => {
795795
expect(result.success).toBe(false);
796796
});
797797

798+
it('rejects an invalid hex color like "#ZZZZZZ" for accent (Variation 5)', () => {
799+
const result = streakParamsSchema.safeParse({
800+
user: 'octocat',
801+
accent: '#ZZZZZZ',
802+
});
803+
804+
expect(result.success).toBe(false);
805+
if (!result.success) {
806+
// This extra check ensures Variation 5 isn't just a duplicate,
807+
// but a stricter validation check!
808+
expect(result.error.issues[0]?.message).toContain(
809+
'accent must be a valid 3 or 6 character hex color without #'
810+
);
811+
}
812+
});
813+
798814
it('rejects the invalid boundary hex color "#ZZZZZZ" for accent', () => {
799815
const result = streakParamsSchema.safeParse({
800816
user: 'octocat',

0 commit comments

Comments
 (0)