Skip to content

Commit e9cfbf3

Browse files
committed
test: add dotenv configuration to test files and remove unused contributions mock
1 parent cfd921f commit e9cfbf3

7 files changed

Lines changed: 27 additions & 32 deletions

lib/github.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import "dotenv/config";
2+
3+
14
import {describe, expect, it} from "vitest";
25
import {parseCountEnv} from "./github";
36

test/github/github-cache.test.ts

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import "dotenv/config";
2+
13
import { afterEach, describe, expect, test, vi } from "vitest";
24
import {
35
createGitHubUserDataFetcher,
@@ -19,10 +21,7 @@ function makeExecutor(
1921
delayMs = 0,
2022
): GitHubFetcherDependencies["executor"] {
2123
return {
22-
async execute<
23-
TData,
24-
TVariables extends Record<string, unknown>,
25-
>(params: {
24+
async execute<TData, TVariables extends Record<string, unknown>>(params: {
2625
operationName: string;
2726
query: string;
2827
variables: TVariables;
@@ -174,8 +173,7 @@ function isGitHubUserData(value: unknown): value is GitHubUserData {
174173
value !== null &&
175174
"avatarUrl" in value &&
176175
"repos" in value &&
177-
"pullRequests" in value &&
178-
"contributions" in value
176+
"pullRequests" in value
179177
);
180178
}
181179

@@ -186,14 +184,11 @@ describe("GitHub user data caching", () => {
186184
test("cache hit skips GitHub calls", async () => {
187185
const cachedPayload: GitHubUserData = {
188186
name: "Cached",
187+
location: "any",
188+
login: "Cached",
189189
avatarUrl: "https://example.com/cached.png",
190190
repos: [],
191191
pullRequests: [],
192-
contributions: {
193-
totalCommitContributions: 0,
194-
totalPullRequestContributions: 0,
195-
totalIssueContributions: 0,
196-
},
197192
issues: [],
198193
discussions: [],
199194
};
@@ -266,10 +261,16 @@ describe("GitHub user data caching", () => {
266261
vi.stubEnv("GITHUB_ISSUE_COUNT", "2");
267262
vi.stubEnv("GITHUB_DISCUSSION_COUNT", "2");
268263

269-
const calls: Array<{ operationName: string; variables: Record<string, unknown> }> = [];
264+
const calls: Array<{
265+
operationName: string;
266+
variables: Record<string, unknown>;
267+
}> = [];
270268
const fetcher = createGitHubUserDataFetcher({
271269
executor: {
272-
async execute<TData, TVariables extends Record<string, unknown>>(params: {
270+
async execute<
271+
TData,
272+
TVariables extends Record<string, unknown>,
273+
>(params: {
273274
operationName: string;
274275
query: string;
275276
variables: TVariables;
@@ -416,8 +417,13 @@ describe("GitHub user data caching", () => {
416417
const result = await fetcher("testuser");
417418

418419
expect(result.pullRequests).toHaveLength(2);
419-
expect(calls.filter((call) => call.operationName === "FetchUserPullRequests")).toHaveLength(1);
420-
expect(calls.find((call) => call.operationName === "FetchUserPullRequests")?.variables.prCount).toBe(2);
420+
expect(
421+
calls.filter((call) => call.operationName === "FetchUserPullRequests"),
422+
).toHaveLength(1);
423+
expect(
424+
calls.find((call) => call.operationName === "FetchUserPullRequests")
425+
?.variables.prCount,
426+
).toBe(2);
421427
});
422428

423429
test("cache write failure does not fail request", async () => {

test/github/github-graphql-client.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import "dotenv/config";
2+
13
import { describe, expect, test } from "vitest";
24
import {
35
GitHubApiError,

test/scoring/calculateUserScore.contribution.test.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { describe, expect, test } from "vitest";
22

33
import { calculateUserScore } from "@/lib/score";
44
import {
5-
makeContributions,
65
makeDiscussion,
76
makeIssue,
87
makePullRequest,
@@ -17,11 +16,6 @@ describe("calculateUserScore - contribution scoring", () => {
1716
makeUserScoreInput({
1817
repos: [],
1918
pullRequests: [],
20-
contributions: makeContributions({
21-
totalCommitContributions: 10_000,
22-
totalPullRequestContributions: 0,
23-
totalIssueContributions: 0,
24-
}),
2519
}),
2620
"octocat",
2721
);
@@ -34,11 +28,6 @@ describe("calculateUserScore - contribution scoring", () => {
3428
makeUserScoreInput({
3529
repos: [],
3630
pullRequests: [],
37-
contributions: makeContributions({
38-
totalCommitContributions: 0,
39-
totalPullRequestContributions: 10_000,
40-
totalIssueContributions: 0,
41-
}),
4231
}),
4332
"octocat",
4433
);

test/scoring/calculateUserScore.language.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { describe, expect, test } from "vitest";
33
import { calculateUserScore } from "@/lib/score";
44
import { getLanguageFactor } from "@/lib/scoring/languageScoring";
55
import {
6-
makeContributions,
76
makePullRequest,
87
makeRepo,
98
makeRepoLanguages,
@@ -313,7 +312,6 @@ describe("calculateUserScore - language scoring", () => {
313312
},
314313
}),
315314
],
316-
contributions: makeContributions(),
317315
selectedLanguages: ["TypeScript"],
318316
}),
319317
"octocat",

test/scoring/calculateUserScore.repo.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { describe, expect, test } from "vitest";
22

33
import { calculateUserScore } from "@/lib/score";
4-
import { makeContributions, makeRepo, makeUserScoreInput } from "@/test/fixtures/github";
4+
import { makeRepo, makeUserScoreInput } from "@/test/fixtures/github";
55
import { expectedRepoScore, sumRepoScores } from "@/test/helpers/score";
66

77
describe("calculateUserScore - repository scoring", () => {
@@ -10,7 +10,6 @@ describe("calculateUserScore - repository scoring", () => {
1010
{
1111
repos: [],
1212
pullRequests: [],
13-
contributions: makeContributions(),
1413
},
1514
"octocat",
1615
);

test/scoring/calculateUserScore.scenario.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { describe, expect, test } from "vitest";
22

33
import { calculateUserScore } from "@/lib/score";
44
import {
5-
makeContributions,
65
makeIssue,
76
makePullRequest,
87
makeRepo,
@@ -95,7 +94,6 @@ describe("calculateUserScore - final score behavior", () => {
9594
{
9695
repos: [],
9796
pullRequests: [],
98-
contributions: makeContributions(),
9997
},
10098
"ghost",
10199
);

0 commit comments

Comments
 (0)