Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion app/api/streak/route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,21 @@ describe('GET /api/streak', () => {

expect(response.status).toBe(400);
const body = await response.json();
expect(response.status).toBe(400);
expect(body.error).toBe('Invalid parameters');
expect(body.details).not.toBeNull();
expect(typeof body.details).toBe('object');
expect(Array.isArray(body.details)).toBe(false);
});
it('returns 400 when org parameter contains spaces and invalid characters', async () => {
const response = await GET(
makeRequest({ user: 'octocat', org: 'invalid_org_name_with_spaces' })
);

expect(response.status).toBe(400);
const body = await response.json();
expect(body.details.fieldErrors.org[0]).toBe('Invalid organization name format');
expect(getOrgDashboardData).not.toHaveBeenCalled();
});

it('does not hit the GitHub API at all when user is missing', async () => {
await GET(makeRequest());
Expand Down
15 changes: 15 additions & 0 deletions lib/validations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,21 @@ describe('streakParamsSchema β€” boolean transform fields', () => {
});
});

describe('streakParamsSchema β€” org parameter validation', () => {
it('should reject org parameter with spaces and special characters', () => {
const result = streakParamsSchema.safeParse({
user: 'octocat',
org: 'invalid_org_name_with_spaces',
});

expect(result.success).toBe(false);
if (!result.success) {
const fieldError = result.error.flatten().fieldErrors.org?.[0];
expect(fieldError).toBe('Invalid organization name format');
}
});
});

describe('ogParamsSchema', () => {
it('should keep provided user value', () => {
const result = ogParamsSchema.safeParse({
Expand Down
Loading