Skip to content

Commit 2a6798f

Browse files
authored
test(api-validation): add query validation boundaries for ?accent= parameter(Variation 5) (JhaSourav07#2121)
## Description Adds validation coverage for the `accent` query parameter. ### Changes - Added schema-level test for invalid HEX color syntax (`#ZZZZZZ`) - Added endpoint test to verify invalid accent values return HTTP 400 - Ensures malformed color inputs are rejected before reaching core logic ### Testing - All test suites pass - Streak endpoint validation verified Fixes JhaSourav07#1466 ## Pillar - [ ] 🎨 Pillar 1 — New Theme Design - [ ] 📐 Pillar 2 — Geometric SVG Improvement - [ ] 🕐 Pillar 3 — Timezone Logic Optimization - [x] 🛠️ Other (Bug fix, refactoring, docs) ## Visual Preview <img width="1148" height="512" alt="image" src="https://github.com/user-attachments/assets/cb6e4cb2-ffd8-43ff-893a-dda6ea5f1a8d" /> <img width="1595" height="367" alt="image" src="https://github.com/user-attachments/assets/cf700628-db99-40f7-ada4-9556877a69fd" /> ## Checklist before requesting a review: - [x] I have read the `CONTRIBUTING.md` file. - [x] I have tested these changes locally (`localhost:3000/api/streak?user=YOUR_USERNAME`). - [x] I have run `npm run format` and `npm run lint` locally and resolved all errors (CI will fail otherwise). - [x] My commits follow the Conventional Commits format (e.g., `feat(themes): ...`, `fix(calculate): ...`). - [x] I have updated `README.md` if I added a new theme or URL parameter. - [x] I have started the repo. - [x] I have made sure that i have only one commit to merge in this PR. - [x] The SVG output matches the CommitPulse "premium quality" aesthetic standard (no raw elements, smooth animations, correct fonts). - [ ] (Recommended) I joined the CommitPulse Discord community for contributor discussions, mentorship, and faster PR support.
2 parents 0ee0d95 + 6899d47 commit 2a6798f

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
@@ -780,6 +780,16 @@ describe('GET /api/streak', () => {
780780

781781
expect(response.status).toBe(400);
782782
});
783+
784+
it('returns 400 Bad Request for invalid color hex syntax targeting the ?accent= parameter', async () => {
785+
const response = await GET(makeRequest({ user: 'octocat', accent: '#ZZZZZZ' }));
786+
787+
expect(response.status).toBe(400);
788+
789+
const body = await response.json();
790+
expect(body.error).toBe('Invalid parameters');
791+
expect(body.details).not.toBeNull();
792+
});
783793
});
784794

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

lib/validations.test.ts

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

817+
it('rejects an invalid hex color like "#ZZZZZZ" for accent (Variation 5)', () => {
818+
const result = streakParamsSchema.safeParse({
819+
user: 'octocat',
820+
accent: '#ZZZZZZ',
821+
});
822+
823+
expect(result.success).toBe(false);
824+
if (!result.success) {
825+
// This extra check ensures Variation 5 isn't just a duplicate,
826+
// but a stricter validation check!
827+
expect(result.error.issues[0]?.message).toContain(
828+
'accent must be a valid 3 or 6 character hex color without #'
829+
);
830+
}
831+
});
832+
817833
it('rejects the invalid boundary hex color "#ZZZZZZ" for accent', () => {
818834
const result = streakParamsSchema.safeParse({
819835
user: 'octocat',

0 commit comments

Comments
 (0)