Skip to content

Commit 9626d2b

Browse files
committed
test(api): add schema-level validation test for invalid accent hex color
1 parent 4538996 commit 9626d2b

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

app/api/streak/route.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,12 @@ describe('GET /api/streak', () => {
608608
it('does not crash when an invalid text color is provided', async () => {
609609
const response = await GET(makeRequest({ user: 'octocat', text: 'notacolor' }));
610610

611+
expect(response.status).toBe(400);
612+
});
613+
it('returns 400 when an invalid hex color is passed as accent', async () => {
614+
// #ZZZZZZZ contains non-hex characters — schema must reject it with 400
615+
const response = await GET(makeRequest({ user: 'octocat', accent: '#ZZZZZZZ' }));
616+
611617
expect(response.status).toBe(400);
612618
});
613619
});

lib/validations.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,3 +647,24 @@ describe('streakParamsSchema — view fallback behavior', () => {
647647
expect(parse({}).view).toBe('default');
648648
});
649649
});
650+
651+
describe('streakParamsSchema — accent parameter HEX color validation', () => {
652+
it('rejects an invalid hex color like "#ZZZZZZZ" for accent', () => {
653+
// #ZZZZZZZ contains non-hex characters — must fail schema validation
654+
const result = streakParamsSchema.safeParse({
655+
user: 'octocat',
656+
accent: '#ZZZZZZZ',
657+
});
658+
659+
expect(result.success).toBe(false);
660+
});
661+
662+
it('accepts a valid 6-character hex color for accent', () => {
663+
const result = streakParamsSchema.safeParse({
664+
user: 'octocat',
665+
accent: 'ff0000',
666+
});
667+
668+
expect(result.success).toBe(true);
669+
});
670+
});

0 commit comments

Comments
 (0)