|
| 1 | +/* eslint-disable sonarjs/no-duplicate-string */ |
| 2 | + |
| 3 | +import { http, HttpResponse } from "msw"; |
| 4 | +import { setupServer } from "msw/node"; |
| 5 | + |
| 6 | +import { apiBaseUrl } from "../utils/internal"; |
| 7 | +import { buildAuthorization } from "../utils/public"; |
| 8 | +import { getUserWantToPlayList } from "./getUserWantToPlayList"; |
| 9 | +import type { GetUserWantToPlayListResponse } from "./models"; |
| 10 | + |
| 11 | +const server = setupServer(); |
| 12 | + |
| 13 | +describe("Function: getUserWantToPlayList", () => { |
| 14 | + // MSW Setup |
| 15 | + beforeAll(() => server.listen()); |
| 16 | + afterEach(() => server.resetHandlers()); |
| 17 | + afterAll(() => server.close()); |
| 18 | + |
| 19 | + it("is defined #sanity", () => { |
| 20 | + // ASSERT |
| 21 | + expect(getUserWantToPlayList).toBeDefined(); |
| 22 | + }); |
| 23 | + |
| 24 | + it('given a username, retrieves that users "Want To Play Games"', async () => { |
| 25 | + // ARRANGE |
| 26 | + const authorization = buildAuthorization({ |
| 27 | + username: "mockUserName", |
| 28 | + webApiKey: "mockWebApiKey", |
| 29 | + }); |
| 30 | + |
| 31 | + const mockResponse: GetUserWantToPlayListResponse = { |
| 32 | + Count: 100, |
| 33 | + Total: 1287, |
| 34 | + Results: [ |
| 35 | + { |
| 36 | + ID: 20_246, |
| 37 | + Title: "~Hack~ Knuckles the Echidna in Sonic the Hedgehog", |
| 38 | + ImageIcon: "/Images/074560.png", |
| 39 | + ConsoleID: 1, |
| 40 | + ConsoleName: "Genesis/Mega Drive", |
| 41 | + PointsTotal: 1500, |
| 42 | + AchievementsPublished: 50, |
| 43 | + }, |
| 44 | + ], |
| 45 | + }; |
| 46 | + |
| 47 | + server.use( |
| 48 | + http.get(`${apiBaseUrl}/API_GetUserWantToPlayList.php`, () => |
| 49 | + HttpResponse.json(mockResponse) |
| 50 | + ) |
| 51 | + ); |
| 52 | + |
| 53 | + // ACT |
| 54 | + const response = await getUserWantToPlayList(authorization, { |
| 55 | + username: "xelnia", |
| 56 | + }); |
| 57 | + |
| 58 | + // ASSERT |
| 59 | + expect(response).toEqual({ |
| 60 | + count: 100, |
| 61 | + total: 1287, |
| 62 | + results: [ |
| 63 | + { |
| 64 | + id: 20_246, |
| 65 | + title: "~Hack~ Knuckles the Echidna in Sonic the Hedgehog", |
| 66 | + imageIcon: "/Images/074560.png", |
| 67 | + consoleId: 1, |
| 68 | + consoleName: "Genesis/Mega Drive", |
| 69 | + pointsTotal: 1500, |
| 70 | + achievementsPublished: 50, |
| 71 | + }, |
| 72 | + ], |
| 73 | + }); |
| 74 | + }); |
| 75 | +}); |
0 commit comments