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
31 changes: 30 additions & 1 deletion app/api/github/route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,37 @@ describe('GET /api/github', () => {

it('calls getFullDashboardData with { bypassCache: false } when refresh is omitted', async () => {
await GET(makeRequest({ username: 'octocat' }));
expect(getFullDashboardData).toHaveBeenCalledWith('octocat', {
bypassCache: false,
});
});
it('returns 400 when username contains invalid characters', async () => {
const response = await GET(makeRequest({ username: '@@@@@' }));
const body = await response.json();

expect(getFullDashboardData).toHaveBeenCalledWith('octocat', { bypassCache: false });
expect(response.status).toBe(400);
expect(body.error).toContain('Invalid parameters');
});

it('returns 400 when username contains only whitespace', async () => {
const response = await GET(makeRequest({ username: ' ' }));
const body = await response.json();

expect(response.status).toBe(400);
expect(body.error).toContain('Invalid parameters');
});

it('returns 400 when username exceeds GitHub maximum length', async () => {
const response = await GET(
makeRequest({
username: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
})
);

const body = await response.json();

expect(response.status).toBe(400);
expect(body.error).toContain('Invalid parameters');
});

// Test 1 — missing username → 400
Expand Down
1 change: 1 addition & 0 deletions lib/validations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ export const streakParamsSchema = z.object({
export const githubParamsSchema = z.object({
username: z
.string({ error: 'Missing "username" parameter' })
.trim()
.min(1, { message: 'Username is required' })
.max(39, { message: 'GitHub username cannot exceed 39 characters' })
.regex(GITHUB_USERNAME_REGEX, {
Expand Down
Loading