Skip to content

Commit 3e9cbcd

Browse files
committed
test(github): add cache hit tests for profile and repos
1 parent e15a46a commit 3e9cbcd

1 file changed

Lines changed: 60 additions & 0 deletions

File tree

lib/github.test.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,66 @@ describe('GitHub API cache behavior', () => {
423423

424424
expect(fetch).toHaveBeenCalledTimes(2);
425425
});
426+
427+
it('cache hit: second profile call uses cached value', async () => {
428+
vi.mocked(fetch).mockResolvedValue(
429+
mockResponse({
430+
login: 'octocat',
431+
name: 'The Octocat',
432+
})
433+
);
434+
435+
await fetchUserProfile('octocat');
436+
await fetchUserProfile('octocat');
437+
438+
expect(fetch).toHaveBeenCalledTimes(1);
439+
});
440+
441+
it('refresh bypass: bypassCache=true forces fresh profile fetch', async () => {
442+
vi.mocked(fetch).mockImplementation(async () =>
443+
mockResponse({
444+
login: 'octocat',
445+
name: 'The Octocat',
446+
})
447+
);
448+
449+
await fetchUserProfile('octocat');
450+
await fetchUserProfile('octocat', { bypassCache: true });
451+
452+
expect(fetch).toHaveBeenCalledTimes(2);
453+
});
454+
455+
it('cache hit: second repos call uses cached value', async () => {
456+
vi.mocked(fetch).mockResolvedValue(
457+
mockResponse([
458+
{
459+
stargazers_count: 1,
460+
language: 'TypeScript',
461+
},
462+
])
463+
);
464+
465+
await fetchUserRepos('octocat');
466+
await fetchUserRepos('octocat');
467+
468+
expect(fetch).toHaveBeenCalledTimes(1);
469+
});
470+
471+
it('refresh bypass: bypassCache=true forces fresh repos fetch', async () => {
472+
vi.mocked(fetch).mockImplementation(async () =>
473+
mockResponse([
474+
{
475+
stargazers_count: 1,
476+
language: 'TypeScript',
477+
},
478+
])
479+
);
480+
481+
await fetchUserRepos('octocat');
482+
await fetchUserRepos('octocat', { bypassCache: true });
483+
484+
expect(fetch).toHaveBeenCalledTimes(2);
485+
});
426486
});
427487
describe('generateAchievements', () => {
428488
it('marks contribution milestones correctly', () => {

0 commit comments

Comments
 (0)