Skip to content

Commit 111c5b6

Browse files
authored
Merge pull request #61 from DaleStudy/fix/count-catalogued-solutions
fix: ํ•™์Šต ํ˜„ํ™ฉ ํ•ด๊ฒฐ ์ˆ˜๋ฅผ ๋“ฑ๋ก๋œ ๋ฌธ์ œ ๊ธฐ์ค€์œผ๋กœ ์ง‘๊ณ„
2 parents 282c484 + 52ed6bb commit 111c5b6

2 files changed

Lines changed: 98 additions & 1 deletion

File tree

โ€Žhandlers/learning-status.jsโ€Ž

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,10 @@ export async function postLearningStatus(
112112
}
113113

114114
// 2. ์ด๋ฒˆ ๊ธฐ์ˆ˜์—์„œ ์‚ฌ์šฉ์ž๊ฐ€ ์ œ์ถœํ•œ ํ’€์ด ๋ชฉ๋ก ์กฐํšŒ
115-
const solvedProblems = await fetchCohortUserSolutions(repoOwner, repoName, username, appToken);
115+
const cohortSolutions = await fetchCohortUserSolutions(repoOwner, repoName, username, appToken);
116+
const solvedProblems = cohortSolutions.filter((problemName) =>
117+
Object.hasOwn(categories, problemName)
118+
);
116119
console.log(
117120
`[learningStatus] PR #${prNumber}: ${username} has ${solvedProblems.length} solutions in current cohort`
118121
);
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
2+
3+
vi.mock("../utils/learningData.js", () => ({
4+
fetchProblemCategories: vi.fn(),
5+
fetchCohortUserSolutions: vi.fn(),
6+
fetchPRSubmissions: vi.fn(),
7+
}));
8+
9+
vi.mock("../utils/openai.js", () => ({
10+
generateApproachAnalysis: vi.fn(),
11+
}));
12+
13+
import { postLearningStatus } from "./learning-status.js";
14+
import {
15+
fetchProblemCategories,
16+
fetchCohortUserSolutions,
17+
fetchPRSubmissions,
18+
} from "../utils/learningData.js";
19+
import { generateApproachAnalysis } from "../utils/openai.js";
20+
21+
describe("postLearningStatus โ€” ๋ˆ„์  ํ’€์ด ์ง‘๊ณ„", () => {
22+
let originalFetch;
23+
24+
beforeEach(() => {
25+
vi.clearAllMocks();
26+
originalFetch = globalThis.fetch;
27+
fetchProblemCategories.mockResolvedValue({
28+
"two-sum": {
29+
difficulty: "Easy",
30+
blindCategories: ["Array"],
31+
intended_approach: "Hash Table",
32+
},
33+
});
34+
fetchPRSubmissions.mockResolvedValue([
35+
{ problemName: "two-sum", rawUrl: "https://example.com/solution.py" },
36+
]);
37+
generateApproachAnalysis.mockResolvedValue({
38+
matches: true,
39+
explanation: "Uses a hash table",
40+
});
41+
globalThis.fetch = vi
42+
.fn()
43+
.mockResolvedValueOnce({
44+
ok: true,
45+
text: () => Promise.resolve("class Solution: pass"),
46+
})
47+
.mockResolvedValueOnce({
48+
ok: true,
49+
json: () => Promise.resolve([]),
50+
})
51+
.mockResolvedValueOnce({ ok: true });
52+
});
53+
54+
afterEach(() => {
55+
globalThis.fetch = originalFetch;
56+
});
57+
58+
it.each([
59+
{
60+
name: "๋“ฑ๋ก๋œ ๋ฌธ์ œ์˜ ํ’€์ด ์ˆ˜๋ฅผ ์œ ์ง€ํ•œ๋‹ค",
61+
solved: ["two-sum"],
62+
expected: 1,
63+
},
64+
{
65+
name: "๋ฏธ๋“ฑ๋ก ๋ฌธ์ œ๊ฐ€ ์„ž์—ฌ ์žˆ์œผ๋ฉด ๋“ฑ๋ก๋œ ๋ฌธ์ œ๋งŒ ์ง‘๊ณ„ํ•œ๋‹ค",
66+
solved: ["to-lower-case", "two-sum"],
67+
expected: 1,
68+
},
69+
{
70+
name: "๋ฏธ๋“ฑ๋ก ๋ฌธ์ œ๋งŒ ํ’€์—ˆ์œผ๋ฉด ํ’€์ด ์ˆ˜๋Š” 0์ด๋‹ค",
71+
solved: ["to-lower-case"],
72+
expected: 0,
73+
},
74+
])("$name", async ({ solved, expected }) => {
75+
fetchCohortUserSolutions.mockResolvedValue(solved);
76+
77+
await postLearningStatus(
78+
"DaleStudy",
79+
"leetcode-study",
80+
42,
81+
"learner",
82+
"token",
83+
{}
84+
);
85+
86+
const post = globalThis.fetch.mock.calls.find(
87+
([, options]) => options?.method === "POST"
88+
);
89+
expect(post).toBeDefined();
90+
91+
const body = JSON.parse(post[1].body).body;
92+
expect(body).toContain(`ํ’€์ดํ•œ ๋ฌธ์ œ: ${expected} / 1๊ฐœ`);
93+
});
94+
});

0 commit comments

Comments
ย (0)