Skip to content

Commit bae8288

Browse files
authored
test(compareclient-type-compiler): add type validation coverage (JhaSourav07#3305)
## Description Fixes JhaSourav07#2792 ## Summary Added TypeScript compiler validation coverage for `CompareClient` interfaces and schema structures. ## Changes Made * Exported CompareClient interfaces for external type validation * Added type compiler test coverage using `expectTypeOf` * Verified: * `UserProfile` structure * `UserStats` optional fields * `LanguageData` schema * `ActivityData` optional properties * `CompareResponse` structure consistency ## Validation ```bash id="pl3k7m" npx vitest ./app/compare/CompareClient.type-compiler.test.tsx npm run lint npm run format ``` ## Pillar - [ ] 🎨 Pillar 1 — New Theme Design - [ ] 📐 Pillar 2 — Geometric SVG Improvement - [ ] 🕐 Pillar 3 — Timezone Logic Optimization - [x] 🛠️ Other (Bug fix, refactoring, docs) ## Visual Preview ## 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 started 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.
2 parents 7624de5 + fba36e8 commit bae8288

2 files changed

Lines changed: 74 additions & 6 deletions

File tree

app/compare/CompareClient.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import {
3737

3838
/* ── types ────────────────────────────────────────────────────────────── */
3939

40-
interface UserProfile {
40+
export interface UserProfile {
4141
username: string;
4242
name: string;
4343
avatarUrl: string;
@@ -54,7 +54,7 @@ interface UserProfile {
5454
};
5555
}
5656

57-
interface UserStats {
57+
export interface UserStats {
5858
currentStreak: number;
5959
peakStreak: number;
6060
totalContributions: number;
@@ -63,28 +63,28 @@ interface UserStats {
6363
totalIssues?: number;
6464
}
6565

66-
interface LanguageData {
66+
export interface LanguageData {
6767
name: string;
6868
color: string;
6969
percentage: number;
7070
}
7171

72-
interface ActivityData {
72+
export interface ActivityData {
7373
date: string;
7474
count: number;
7575
intensity: 0 | 1 | 2 | 3 | 4;
7676
locAdditions?: number;
7777
locDeletions?: number;
7878
}
7979

80-
interface CompareUserData {
80+
export interface CompareUserData {
8181
profile: UserProfile;
8282
stats: UserStats;
8383
languages: LanguageData[];
8484
activity: ActivityData[];
8585
}
8686

87-
interface CompareResponse {
87+
export interface CompareResponse {
8888
user1: CompareUserData;
8989
user2: CompareUserData;
9090
error?: string;
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import { describe, expectTypeOf, it } from 'vitest';
2+
3+
import type {
4+
ActivityData,
5+
CompareResponse,
6+
CompareUserData,
7+
LanguageData,
8+
UserProfile,
9+
UserStats,
10+
} from './CompareClient';
11+
12+
describe('CompareClient Type Compiler Validation', () => {
13+
it('validates UserProfile structure', () => {
14+
expectTypeOf<UserProfile>().toEqualTypeOf<{
15+
username: string;
16+
name: string;
17+
avatarUrl: string;
18+
isPro: boolean;
19+
bio: string;
20+
location: string;
21+
joinedDate: string;
22+
developerScore: number;
23+
stats: {
24+
repositories: number;
25+
followers: number;
26+
following: number;
27+
stars: number;
28+
};
29+
}>();
30+
});
31+
32+
it('validates UserStats numeric and optional fields', () => {
33+
expectTypeOf<UserStats>().toEqualTypeOf<{
34+
currentStreak: number;
35+
peakStreak: number;
36+
totalContributions: number;
37+
codingHabit?: string;
38+
totalPRs?: number;
39+
totalIssues?: number;
40+
}>();
41+
});
42+
43+
it('validates LanguageData structure', () => {
44+
expectTypeOf<LanguageData>().toEqualTypeOf<{
45+
name: string;
46+
color: string;
47+
percentage: number;
48+
}>();
49+
});
50+
51+
it('accepts optional fields in ActivityData without compile errors', () => {
52+
expectTypeOf<ActivityData>().toEqualTypeOf<{
53+
date: string;
54+
count: number;
55+
intensity: 0 | 1 | 2 | 3 | 4;
56+
locAdditions?: number;
57+
locDeletions?: number;
58+
}>();
59+
});
60+
61+
it('validates CompareResponse structure', () => {
62+
expectTypeOf<CompareResponse>().toEqualTypeOf<{
63+
user1: CompareUserData;
64+
user2: CompareUserData;
65+
error?: string;
66+
}>();
67+
});
68+
});

0 commit comments

Comments
 (0)