Skip to content

Commit 39ed6cb

Browse files
authored
test(github): add cache hit tests for profile and repos (JhaSourav07#576)
2 parents 9cb8bc0 + 3e9cbcd commit 39ed6cb

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
@@ -424,6 +424,66 @@ describe('GitHub API cache behavior', () => {
424424

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

0 commit comments

Comments
 (0)