Skip to content

Commit 2abf8c9

Browse files
authored
test(api validation): check query validation boundaries for ?user= parameter (Variation 3) (JhaSourav07#2058)
## Description Fixes JhaSourav07#1444 ## Pillar - [ ] 🎨 Pillar 1 — New Theme Design - [ ] 📐 Pillar 2 — Geometric SVG Improvement - [ ] 🕐 Pillar 3 — Timezone Logic Optimization - [x] 🛠️ Other (Security / Input Validation Testing) ## Summary of Changes - Added a query validation boundary unit test under a dedicated layout block comment to `lib/validations.test.ts`. - Verified that passing a simulated input string exceeding 39 characters (`'a'.repeat(40)`) to the `?user=` parameter correctly triggers a schema validation error containing the expected message: `'cannot exceed 39 characters'`. - Added a complementary boundary test to confirm that a username at the exact maximum permissible boundary limit of 39 characters (`'a'.repeat(39)`) passes validation successfully. ## Checklist before requesting a review: - [x] I have read the `CONTRIBUTING.md` file. - [x] I have tested these changes locally using the isolated Vitest runner. - [x] My commits follow the Conventional Commits format (`test(api validation): ...`).
2 parents 12f3064 + 55d3513 commit 2abf8c9

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

lib/validations.test.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,3 +1031,33 @@ describe('streakParamsSchema — layout query validation boundaries (Variation 2
10311031
}
10321032
});
10331033
});
1034+
1035+
/* ==========================================================================
1036+
* USER PARAMETER — QUERY VALIDATION BOUNDARIES (VARIATION 3)
1037+
* ========================================================================== */
1038+
1039+
describe('streakParamsSchema user maxLength validation boundaries (Variation 3)', () => {
1040+
it('rejects a GitHub username that exceeds the 39 character length threshold', () => {
1041+
const invalidPayload = {
1042+
user: 'a'.repeat(40),
1043+
};
1044+
1045+
const parseResult = streakParamsSchema.safeParse(invalidPayload);
1046+
1047+
expect(parseResult.success).toBe(false);
1048+
if (!parseResult.success) {
1049+
const fieldErrors = parseResult.error.flatten().fieldErrors;
1050+
expect(fieldErrors.user).toBeDefined();
1051+
expect(fieldErrors.user?.[0]).toContain('cannot exceed 39 characters');
1052+
}
1053+
});
1054+
1055+
it('accepts a username exactly at the upper limit of 39 characters', () => {
1056+
const validPayload = {
1057+
user: 'a'.repeat(39),
1058+
};
1059+
1060+
const parseResult = streakParamsSchema.safeParse(validPayload);
1061+
expect(parseResult.success).toBe(true);
1062+
});
1063+
});

0 commit comments

Comments
 (0)