Skip to content

Commit 8604adf

Browse files
test(displayName): add unit tests for displayName helper (JhaSourav07#1164)
## Description Fixes JhaSourav07#1057 Added focused unit tests for the `displayName` helper in `lib/github.ts`. ### Test Coverage Added * Returns the user's name when present. * Falls back to login when name is `null`. * Falls back to login when name is an empty string. * Falls back to login when name contains only whitespace. ## Pillar * [ ] 🎨 Pillar 1 — New Theme Design * [ ] 📐 Pillar 2 — Geometric SVG Improvement * [ ] 🕐 Pillar 3 — Timezone Logic Optimization * [x] 🛠️ Other (Bug fix, refactoring, docs) ## Visual Preview Not applicable — test-only change. ## Checklist before requesting a review: * [x] I have read the `CONTRIBUTING.md` file. * [x] I have tested these changes locally (`localhost:3000/api/streak?user=YOUR_USERNAME`). * [x] I have run `npm run format` and `npm run lint` locally and resolved all errors (CI will fail otherwise). * [x] My commits follow the Conventional Commits format (e.g., `feat(themes): ...`, `fix(calculate): ...`). * [ ] I have updated `README.md` if I added a new theme or URL parameter. * [x] I have starred the repo. * [x] I have made sure that I have only one commit to merge in this PR. * [x] The SVG output matches the CommitPulse "premium quality" aesthetic standard (no raw elements, smooth animations, correct fonts). * [x] (Recommended) I joined the CommitPulse Discord community for contributor discussions, mentorship, and faster PR support.
1 parent b7cebef commit 8604adf

1 file changed

Lines changed: 32 additions & 1 deletion

File tree

lib/github.test.ts

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
validateGitHubUsername,
1313
cacheKey,
1414
buildInsights,
15+
displayName,
1516
fetchOrgMembers,
1617
getOrgDashboardData,
1718
getWrappedData,
@@ -805,13 +806,13 @@ describe('generateAchievements', () => {
805806
const achievements = generateAchievements(600, 10, 0, 0);
806807

807808
const unlocked = achievements.filter((a) => a.isUnlocked);
809+
808810
expect(unlocked.some((a) => a.title === '500 Contributions')).toBe(true);
809811
expect(unlocked.some((a) => a.title === 'Consistency King')).toBe(true);
810812
expect(unlocked.some((a) => a.title === '1000 Contributions')).toBe(false);
811813
});
812814

813815
it('unlocks all achievements for max contribution and streak values', () => {
814-
// Consistency King III requires 2000, streak needs 100, weekend needs 10, polyglot needs 5
815816
const achievements = generateAchievements(2001, 101, 11, 6);
816817

817818
expect(achievements.every((achievement) => achievement.isUnlocked === true)).toBe(true);
@@ -846,6 +847,36 @@ describe('generateAchievements', () => {
846847
});
847848
});
848849

850+
describe('displayName', () => {
851+
const makeProfile = (name: string | null) => ({
852+
login: 'octocat',
853+
name,
854+
avatar_url: 'avatar.png',
855+
public_repos: 0,
856+
followers: 0,
857+
following: 0,
858+
created_at: '2020-01-01T00:00:00Z',
859+
bio: null,
860+
location: null,
861+
});
862+
863+
it('returns the name when present', () => {
864+
expect(displayName(makeProfile('The Octocat'))).toBe('The Octocat');
865+
});
866+
867+
it('falls back to login when name is null', () => {
868+
expect(displayName(makeProfile(null))).toBe('octocat');
869+
});
870+
871+
it('falls back to login when name is empty', () => {
872+
expect(displayName(makeProfile(''))).toBe('octocat');
873+
});
874+
875+
it('falls back to login when name contains only whitespace', () => {
876+
expect(displayName(makeProfile(' '))).toBe('octocat');
877+
});
878+
});
879+
849880
describe('validateGitHubUsername', () => {
850881
it('returns true for a valid username', () => {
851882
expect(validateGitHubUsername('valid-username-123')).toBe(true);

0 commit comments

Comments
 (0)