|
| 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 { getLeaderboardEntries } from "./getLeaderboardEntries"; |
| 9 | +import type { GetLeaderboardEntriesResponse } from "./models"; |
| 10 | + |
| 11 | +const server = setupServer(); |
| 12 | + |
| 13 | +describe("Function: getLeaderboardEntries", () => { |
| 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(getLeaderboardEntries).toBeDefined(); |
| 22 | + }); |
| 23 | + |
| 24 | + it("given a leaderboard ID, retrieves the entries in that leaderboard", async () => { |
| 25 | + // ARRANGE |
| 26 | + const authorization = buildAuthorization({ |
| 27 | + username: "mockUserName", |
| 28 | + webApiKey: "mockWebApiKey", |
| 29 | + }); |
| 30 | + |
| 31 | + const mockResponse: GetLeaderboardEntriesResponse = { |
| 32 | + Count: 100, |
| 33 | + Total: 1287, |
| 34 | + Results: [ |
| 35 | + { |
| 36 | + Rank: 1, |
| 37 | + User: "vani11a", |
| 38 | + ULID: "00003EMFWR7XB8SDPEHB3K56ZQ", |
| 39 | + Score: 390_490, |
| 40 | + FormattedScore: "390,490", |
| 41 | + DateSubmitted: "2024-07-25T15:51:00+00:00", |
| 42 | + }, |
| 43 | + ], |
| 44 | + }; |
| 45 | + |
| 46 | + server.use( |
| 47 | + http.get(`${apiBaseUrl}/API_GetLeaderboardEntries.php`, () => |
| 48 | + HttpResponse.json(mockResponse) |
| 49 | + ) |
| 50 | + ); |
| 51 | + |
| 52 | + // ACT |
| 53 | + const response = await getLeaderboardEntries(authorization, { |
| 54 | + leaderboardId: 104_370, |
| 55 | + }); |
| 56 | + |
| 57 | + // ASSERT |
| 58 | + expect(response).toEqual({ |
| 59 | + count: 100, |
| 60 | + total: 1287, |
| 61 | + results: [ |
| 62 | + { |
| 63 | + rank: 1, |
| 64 | + user: "vani11a", |
| 65 | + ulid: "00003EMFWR7XB8SDPEHB3K56ZQ", |
| 66 | + score: 390_490, |
| 67 | + formattedScore: "390,490", |
| 68 | + dateSubmitted: "2024-07-25T15:51:00+00:00", |
| 69 | + }, |
| 70 | + ], |
| 71 | + }); |
| 72 | + }); |
| 73 | +}); |
0 commit comments