@@ -10,19 +10,13 @@ vi.mock("../utils/openai.js", () => ({
1010 generateApproachAnalysis : vi . fn ( ) ,
1111} ) ) ;
1212
13- vi . mock ( "../utils/learningComment.js" , async ( importOriginal ) => ( {
14- ...( await importOriginal ( ) ) ,
15- upsertLearningStatusComment : vi . fn ( ) ,
16- } ) ) ;
17-
1813import { postLearningStatus } from "./learning-status.js" ;
1914import {
2015 fetchProblemCategories ,
2116 fetchCohortUserSolutions ,
2217 fetchPRSubmissions ,
2318} from "../utils/learningData.js" ;
2419import { generateApproachAnalysis } from "../utils/openai.js" ;
25- import { upsertLearningStatusComment } from "../utils/learningComment.js" ;
2620
2721describe ( "postLearningStatus โ ๋์ ํ์ด ์ง๊ณ" , ( ) => {
2822 let originalFetch ;
@@ -44,10 +38,17 @@ describe("postLearningStatus โ ๋์ ํ์ด ์ง๊ณ", () => {
4438 matches : true ,
4539 explanation : "Uses a hash table" ,
4640 } ) ;
47- globalThis . fetch = vi . fn ( ) . mockResolvedValue ( {
48- ok : true ,
49- text : ( ) => Promise . resolve ( "class Solution: pass" ) ,
50- } ) ;
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 } ) ;
5152 } ) ;
5253
5354 afterEach ( ( ) => {
@@ -82,13 +83,12 @@ describe("postLearningStatus โ ๋์ ํ์ด ์ง๊ณ", () => {
8283 { }
8384 ) ;
8485
85- expect ( upsertLearningStatusComment ) . toHaveBeenCalledWith (
86- "DaleStudy" ,
87- "leetcode-study" ,
88- 42 ,
89- expect . stringContaining ( `ํ์ดํ ๋ฌธ์ : ${ expected } / 1๊ฐ` ) ,
90- "token" ,
91- null
86+ const post = globalThis . fetch . mock . calls . find (
87+ ( [ , options ] ) => options ?. method === "POST"
9288 ) ;
89+ expect ( post ) . toBeDefined ( ) ;
90+
91+ const body = JSON . parse ( post [ 1 ] . body ) . body ;
92+ expect ( body ) . toContain ( `ํ์ดํ ๋ฌธ์ : ${ expected } / 1๊ฐ` ) ;
9393 } ) ;
9494} ) ;
0 commit comments