diff --git a/src/tests/user/getUserProfile.test.ts b/src/tests/user/getUserProfile.test.ts index 1d7d0489..3f1888fb 100644 --- a/src/tests/user/getUserProfile.test.ts +++ b/src/tests/user/getUserProfile.test.ts @@ -23,53 +23,55 @@ describe("getUserProfile", () => { jest.spyOn(console, "error").mockImplementation(() => {}); }); - describe("프로필 조회 성공", () => { - it("유저 프로필을 성공적으로 가져온다", async () => { - (fetcher as jest.Mock).mockResolvedValue({ - ok: true, - json: () => Promise.resolve({ data: mockUserProfile }), - }); - - const userId = "1"; - const data = await getUserProfile(userId); - - expect(fetcher).toHaveBeenCalledWith(`/user/profile/${userId}`, "", {}); - expect(data).toEqual(mockUserProfile); + it("Next.js fetch 옵션을 전달할 수 있다", async () => { + (fetcher as jest.Mock).mockResolvedValue({ + ok: true, + json: () => Promise.resolve({ data: mockUserProfile }), }); - it("추가 옵션을 전달할 수 있다", async () => { - (fetcher as jest.Mock).mockResolvedValue({ - ok: true, - json: () => Promise.resolve({ data: mockUserProfile }), - }); + const options = { + cache: "no-store" as const, + next: { revalidate: 60 }, + }; - const options = { headers: { "Cache-Control": "no-cache" } }; - await getUserProfile("1", options); + await getUserProfile("1", options); - expect(fetcher).toHaveBeenCalledWith(`/user/profile/1`, "", { - ...options, - }); - }); + expect(fetcher).toHaveBeenCalledWith( + `/user/profile/1`, + "", + expect.objectContaining(options), + ); }); - describe("프로필 조회 실패", () => { - it("API 요청이 실패하면 에러를 던진다", async () => { - const errorResponse = { - status: "error", - data: null, - message: "해당 유저는 존재하지 않습니다.", - additionalData: null, - }; + it("유저 프로필을 성공적으로 가져온다", async () => { + (fetcher as jest.Mock).mockResolvedValue({ + ok: true, + json: () => Promise.resolve({ data: mockUserProfile }), + }); + + const userId = "1"; + const data = await getUserProfile(userId); + + expect(fetcher).toHaveBeenCalledWith(`/user/profile/${userId}`, "", {}); + expect(data).toEqual(mockUserProfile); + }); - (fetcher as jest.Mock).mockResolvedValue({ - ok: false, - status: 400, - json: () => Promise.resolve(errorResponse), - }); + it("API 요청이 실패하면 에러를 던진다", async () => { + const errorResponse = { + status: "error", + data: null, + message: "해당 유저는 존재하지 않습니다.", + additionalData: null, + }; - await expect(getUserProfile("999")).rejects.toThrow( - "해당 유저는 존재하지 않습니다.", - ); + (fetcher as jest.Mock).mockResolvedValue({ + ok: false, + status: 400, + json: () => Promise.resolve(errorResponse), }); + + await expect(getUserProfile("999")).rejects.toThrow( + "해당 유저는 존재하지 않습니다.", + ); }); });