|
| 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 { getGameProgression } from "./getGameProgression"; |
| 9 | +import type { GetGameProgressionResponse } from "./models"; |
| 10 | + |
| 11 | +const server = setupServer(); |
| 12 | + |
| 13 | +describe("Function: getGameProgression", () => { |
| 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(getGameProgression).toBeDefined(); |
| 22 | + }); |
| 23 | + |
| 24 | + it("given a game ID, retrieves information about the average time to unlock achievements in a game", async () => { |
| 25 | + // ARRANGE |
| 26 | + const authorization = buildAuthorization({ |
| 27 | + username: "mockUserName", |
| 28 | + webApiKey: "mockWebApiKey", |
| 29 | + }); |
| 30 | + |
| 31 | + const mockResponse: GetGameProgressionResponse = { |
| 32 | + ID: 228, |
| 33 | + Title: "Super Mario World", |
| 34 | + ConsoleID: 3, |
| 35 | + ConsoleName: "SNES/Super Famicom", |
| 36 | + ImageIcon: "/Images/112443.png", |
| 37 | + NumDistinctPlayers: 79_281, |
| 38 | + TimesUsedInBeatMedian: 4493, |
| 39 | + TimesUsedInHardcoreBeatMedian: 8249, |
| 40 | + MedianTimeToBeat: 17_878, |
| 41 | + MedianTimeToBeatHardcore: 19_224, |
| 42 | + TimesUsedInCompletionMedian: 155, |
| 43 | + TimesUsedInMasteryMedian: 1091, |
| 44 | + MedianTimeToComplete: 67_017, |
| 45 | + MedianTimeToMaster: 79_744, |
| 46 | + NumAchievements: 89, |
| 47 | + Achievements: [ |
| 48 | + { |
| 49 | + ID: 342, |
| 50 | + Title: "Giddy Up!", |
| 51 | + Description: "Catch a ride with a friend", |
| 52 | + Points: 1, |
| 53 | + TrueRatio: 1, |
| 54 | + Type: null, |
| 55 | + BadgeName: "46580", |
| 56 | + NumAwarded: 75_168, |
| 57 | + NumAwardedHardcore: 37_024, |
| 58 | + TimesUsedInUnlockMedian: 63, |
| 59 | + TimesUsedInHardcoreUnlockMedian: 69, |
| 60 | + MedianTimeToUnlock: 274, |
| 61 | + MedianTimeToUnlockHardcore: 323, |
| 62 | + }, |
| 63 | + ], |
| 64 | + }; |
| 65 | + |
| 66 | + server.use( |
| 67 | + http.get(`${apiBaseUrl}/API_GetGameProgression.php`, () => |
| 68 | + HttpResponse.json(mockResponse) |
| 69 | + ) |
| 70 | + ); |
| 71 | + |
| 72 | + // ACT |
| 73 | + const response = await getGameProgression(authorization, { |
| 74 | + gameId: 104_370, |
| 75 | + hardcore: true, |
| 76 | + }); |
| 77 | + |
| 78 | + // ASSERT |
| 79 | + expect(response).toEqual({ |
| 80 | + id: 228, |
| 81 | + title: "Super Mario World", |
| 82 | + consoleId: 3, |
| 83 | + consoleName: "SNES/Super Famicom", |
| 84 | + imageIcon: "/Images/112443.png", |
| 85 | + numDistinctPlayers: 79_281, |
| 86 | + timesUsedInBeatMedian: 4493, |
| 87 | + timesUsedInHardcoreBeatMedian: 8249, |
| 88 | + medianTimeToBeat: 17_878, |
| 89 | + medianTimeToBeatHardcore: 19_224, |
| 90 | + timesUsedInCompletionMedian: 155, |
| 91 | + timesUsedInMasteryMedian: 1091, |
| 92 | + medianTimeToComplete: 67_017, |
| 93 | + medianTimeToMaster: 79_744, |
| 94 | + numAchievements: 89, |
| 95 | + achievements: [ |
| 96 | + { |
| 97 | + id: 342, |
| 98 | + title: "Giddy Up!", |
| 99 | + description: "Catch a ride with a friend", |
| 100 | + points: 1, |
| 101 | + trueRatio: 1, |
| 102 | + type: null, |
| 103 | + badgeName: "46580", |
| 104 | + numAwarded: 75_168, |
| 105 | + numAwardedHardcore: 37_024, |
| 106 | + timesUsedInUnlockMedian: 63, |
| 107 | + timesUsedInHardcoreUnlockMedian: 69, |
| 108 | + medianTimeToUnlock: 274, |
| 109 | + medianTimeToUnlockHardcore: 323, |
| 110 | + }, |
| 111 | + ], |
| 112 | + }); |
| 113 | + }); |
| 114 | +}); |
0 commit comments