|
| 1 | +import { http, HttpResponse } from "msw"; |
| 2 | +import { setupServer } from "msw/node"; |
| 3 | + |
| 4 | +import { apiBaseUrl } from "../utils/internal"; |
| 5 | +import { buildAuthorization } from "../utils/public"; |
| 6 | +import { getUserCompletionProgress } from "./getUserCompletionProgress"; |
| 7 | +import type { GetUserCompletionProgressResponse } from "./models"; |
| 8 | + |
| 9 | +const server = setupServer(); |
| 10 | + |
| 11 | +describe("Function: getUserCompletionProgress", () => { |
| 12 | + // MSW Setup |
| 13 | + beforeAll(() => server.listen()); |
| 14 | + afterEach(() => server.resetHandlers()); |
| 15 | + afterAll(() => server.close()); |
| 16 | + |
| 17 | + it("is defined #sanity", () => { |
| 18 | + // ASSERT |
| 19 | + expect(getUserCompletionProgress).toBeDefined(); |
| 20 | + }); |
| 21 | + |
| 22 | + it("retrieves completion progress by username", async () => { |
| 23 | + // ARRANGE |
| 24 | + const authorization = buildAuthorization({ |
| 25 | + userName: "mockUserName", |
| 26 | + webApiKey: "mockWebApiKey" |
| 27 | + }); |
| 28 | + |
| 29 | + const mockResponse: GetUserCompletionProgressResponse = { |
| 30 | + Count: 1, |
| 31 | + Total: 1, |
| 32 | + Results: [ |
| 33 | + { |
| 34 | + GameID: 680, |
| 35 | + Title: "Game & Watch Gallery", |
| 36 | + ImageIcon: "/Images/042952.png", |
| 37 | + ConsoleID: 4, |
| 38 | + ConsoleName: "Game Boy", |
| 39 | + MaxPossible: 27, |
| 40 | + NumAwarded: 8, |
| 41 | + NumAwardedHardcore: 8, |
| 42 | + MostRecentAwardedDate: "2022-07-26T23:56:15+00:00", |
| 43 | + HighestAwardKind: null, |
| 44 | + HighestAwardDate: null |
| 45 | + } |
| 46 | + ] |
| 47 | + }; |
| 48 | + |
| 49 | + server.use( |
| 50 | + http.get(`${apiBaseUrl}/API_GetUserCompletionProgress.php`, () => |
| 51 | + HttpResponse.json(mockResponse) |
| 52 | + ) |
| 53 | + ); |
| 54 | + |
| 55 | + // ACT |
| 56 | + const response = await getUserCompletionProgress(authorization, { |
| 57 | + userName: "xelnia" |
| 58 | + }); |
| 59 | + |
| 60 | + // ASSERT |
| 61 | + expect(response).toEqual({ |
| 62 | + count: 1, |
| 63 | + total: 1, |
| 64 | + results: [ |
| 65 | + { |
| 66 | + gameId: 680, |
| 67 | + title: "Game & Watch Gallery", |
| 68 | + imageIcon: "/Images/042952.png", |
| 69 | + consoleId: 4, |
| 70 | + consoleName: "Game Boy", |
| 71 | + maxPossible: 27, |
| 72 | + numAwarded: 8, |
| 73 | + numAwardedHardcore: 8, |
| 74 | + mostRecentAwardedDate: "2022-07-26T23:56:15+00:00", |
| 75 | + highestAwardKind: null, |
| 76 | + highestAwardDate: null |
| 77 | + } |
| 78 | + ] |
| 79 | + }); |
| 80 | + }); |
| 81 | +}); |
0 commit comments