Skip to content

Commit 3f40d88

Browse files
authored
test(github route): verify ?org= parameter returns 200 (JhaSourav07#1149)
2 parents 9999e0e + cf8d8f6 commit 3f40d88

1 file changed

Lines changed: 35 additions & 1 deletion

File tree

app/api/streak/route.test.ts

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@ import { GET } from './route';
66
// calculateStreak and generateSVG run for real, giving us genuine end-to-end coverage.
77
vi.mock('../../../lib/github', () => ({
88
fetchGitHubContributions: vi.fn(),
9+
getOrgDashboardData: vi.fn(),
910
}));
1011

1112
vi.mock('../../../utils/time', () => ({
1213
getSecondsUntilUTCMidnight: vi.fn(),
1314
getSecondsUntilMidnightInTimezone: vi.fn(),
1415
}));
1516

16-
import { fetchGitHubContributions } from '../../../lib/github';
17+
import { fetchGitHubContributions, getOrgDashboardData } from '../../../lib/github';
1718
import { getSecondsUntilUTCMidnight, getSecondsUntilMidnightInTimezone } from '../../../utils/time';
1819
import type { ContributionCalendar } from '../../../types';
1920

@@ -59,6 +60,28 @@ describe('GET /api/streak', () => {
5960
beforeEach(() => {
6061
vi.clearAllMocks(); // reset call counts so per-test call assertions are isolated
6162
vi.mocked(fetchGitHubContributions).mockResolvedValue(mockCalendar);
63+
vi.mocked(getOrgDashboardData).mockResolvedValue({
64+
profile: {
65+
username: 'octocat',
66+
name: 'The Octocat',
67+
avatarUrl: 'https://github.com/octocat.png',
68+
isPro: false,
69+
bio: 'Testing organization mock pipelines',
70+
location: 'San Francisco, CA',
71+
joinedDate: '2011-01-25',
72+
developerScore: 85,
73+
stats: { repositories: 10, followers: 2500, following: 9, stars: 450 },
74+
},
75+
stats: {
76+
totalCommits: 10,
77+
totalIssues: 2,
78+
totalPRs: 5,
79+
totalReviews: 1,
80+
totalDiscussions: 0,
81+
contributedTo: 3,
82+
},
83+
calendar: mockCalendar,
84+
} as unknown as Awaited<ReturnType<typeof getOrgDashboardData>>);
6285
// Fixed values so Cache-Control assertions don't depend on the real clock.
6386
vi.mocked(getSecondsUntilUTCMidnight).mockReturnValue(3600);
6487
vi.mocked(getSecondsUntilMidnightInTimezone).mockReturnValue(7200);
@@ -138,6 +161,17 @@ describe('GET /api/streak', () => {
138161
const textOutput = await response.text();
139162
expect(textOutput).toContain('<svg');
140163
});
164+
165+
it('should return 200 OK and valid SVG when the optional org query parameter is provided', async () => {
166+
// 1. Make request with both parameters present
167+
const response = await GET(makeRequest({ user: 'octocat', org: 'vercel' }));
168+
169+
// 2. Assert definitions of done
170+
expect(response.status).toBe(200);
171+
172+
const textOutput = await response.text();
173+
expect(textOutput).toContain('<svg');
174+
});
141175
});
142176

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

0 commit comments

Comments
 (0)