|
| 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 { getGameHashes } from "./getGameHashes"; |
| 9 | +import type { GetGameHashesResponse } from "./models"; |
| 10 | + |
| 11 | +const server = setupServer(); |
| 12 | + |
| 13 | +describe("Function: getGameExtended", () => { |
| 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(getGameHashes).toBeDefined(); |
| 22 | + }); |
| 23 | + |
| 24 | + it("given a game ID, retrieves extended metadata about the game", async () => { |
| 25 | + // ARRANGE |
| 26 | + const authorization = buildAuthorization({ |
| 27 | + username: "mockUserName", |
| 28 | + webApiKey: "mockWebApiKey", |
| 29 | + }); |
| 30 | + |
| 31 | + const mockResponse: GetGameHashesResponse = { |
| 32 | + Results: [ |
| 33 | + { |
| 34 | + Name: "Sonic The Hedgehog (USA, Europe) (Ru) (NewGame).md", |
| 35 | + MD5: "1b1d9ac862c387367e904036114c4825", |
| 36 | + Labels: ["nointro", "rapatches"], |
| 37 | + PatchUrl: |
| 38 | + "https://github.com/RetroAchievements/RAPatches/raw/main/MD/Translation/Russian/1-Sonic1-Russian.zip", |
| 39 | + }, |
| 40 | + { |
| 41 | + Name: "Sonic The Hedgehog (USA, Europe).md", |
| 42 | + MD5: "1bc674be034e43c96b86487ac69d9293", |
| 43 | + Labels: ["nointro"], |
| 44 | + PatchUrl: null, |
| 45 | + }, |
| 46 | + ], |
| 47 | + }; |
| 48 | + |
| 49 | + server.use( |
| 50 | + http.get(`${apiBaseUrl}/API_GetGameHashes.php`, () => |
| 51 | + HttpResponse.json(mockResponse) |
| 52 | + ) |
| 53 | + ); |
| 54 | + |
| 55 | + // ACT |
| 56 | + const response = await getGameHashes(authorization, { gameId: 1 }); |
| 57 | + |
| 58 | + // ASSERT |
| 59 | + expect(response).toEqual({ |
| 60 | + results: [ |
| 61 | + { |
| 62 | + name: "Sonic The Hedgehog (USA, Europe) (Ru) (NewGame).md", |
| 63 | + md5: "1b1d9ac862c387367e904036114c4825", |
| 64 | + labels: ["nointro", "rapatches"], |
| 65 | + patchUrl: |
| 66 | + "https://github.com/RetroAchievements/RAPatches/raw/main/MD/Translation/Russian/1-Sonic1-Russian.zip", |
| 67 | + }, |
| 68 | + { |
| 69 | + name: "Sonic The Hedgehog (USA, Europe).md", |
| 70 | + md5: "1bc674be034e43c96b86487ac69d9293", |
| 71 | + labels: ["nointro"], |
| 72 | + patchUrl: null, |
| 73 | + }, |
| 74 | + ], |
| 75 | + }); |
| 76 | + }); |
| 77 | +}); |
0 commit comments