Skip to content

Commit 03fca35

Browse files
fix: validate monthly badge dimensions (JhaSourav07#1913)
* fix: validate monthly badge dimensions * fix: resolve validation syntax error
1 parent 7fa60d0 commit 03fca35

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

app/api/streak/route.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,17 @@ describe('GET /api/streak', () => {
209209
const textOutput = await response.text();
210210
expect(textOutput).toContain('<svg');
211211
});
212+
213+
it('returns 400 when org contains invalid characters', async () => {
214+
const response = await GET(
215+
makeRequest({ user: 'octocat', org: 'invalid_org_name_with_spaces' })
216+
);
217+
const body = await response.json();
218+
219+
expect(response.status).toBe(400);
220+
expect(body.details.fieldErrors.org[0]).toBe('Invalid organization name format');
221+
expect(getOrgDashboardData).not.toHaveBeenCalled();
222+
});
212223
});
213224

214225
describe('successful response', () => {

lib/validations.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,18 @@ describe('streakParamsSchema — size fallback behavior', () => {
463463
}
464464
});
465465

466+
it('should fail when org contains invalid characters', () => {
467+
const result = streakParamsSchema.safeParse({
468+
user: 'octocat',
469+
org: 'invalid_org_name_with_spaces',
470+
});
471+
472+
expect(result.success).toBe(false);
473+
if (!result.success) {
474+
expect(result.error.flatten().fieldErrors.org?.[0]).toBe('Invalid organization name format');
475+
}
476+
});
477+
466478
it('should keep org undefined when omitted', () => {
467479
const result = streakParamsSchema.safeParse({
468480
user: 'octocat',

0 commit comments

Comments
 (0)