mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-07-27 02:32:21 +02:00
Add function to initialize server for API tests
This commit is contained in:
parent
6154306f80
commit
791bcf32ab
@ -4,11 +4,16 @@ import { PokerogueAccountApi } from "#app/plugins/api/pokerogue-account-api";
|
||||
import { getApiBaseUrl } from "#test/utils/testUtils";
|
||||
import * as Utils from "#app/utils";
|
||||
import { http, HttpResponse } from "msw";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { initServerForApiTests } from "#test/utils/testFileInitialization";
|
||||
|
||||
const apiBase = getApiBaseUrl();
|
||||
const accountApi = new PokerogueAccountApi(apiBase);
|
||||
const { server } = global;
|
||||
|
||||
let server;
|
||||
beforeAll(async () => {
|
||||
server = await initServerForApiTests();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
server.resetHandlers();
|
||||
|
@ -7,13 +7,18 @@ import type {
|
||||
UnlinkAccountFromGoogledIdRequest,
|
||||
} from "#app/@types/PokerogueAdminApi";
|
||||
import { PokerogueAdminApi } from "#app/plugins/api/pokerogue-admin-api";
|
||||
import { initServerForApiTests } from "#test/utils/testFileInitialization";
|
||||
import { getApiBaseUrl } from "#test/utils/testUtils";
|
||||
import { http, HttpResponse } from "msw";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
const apiBase = getApiBaseUrl();
|
||||
const adminApi = new PokerogueAdminApi(apiBase);
|
||||
const { server } = global;
|
||||
|
||||
let server;
|
||||
beforeAll(async () => {
|
||||
server = await initServerForApiTests();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
server.resetHandlers();
|
||||
|
@ -1,11 +1,16 @@
|
||||
import type { TitleStatsResponse } from "#app/@types/PokerogueApi";
|
||||
import { pokerogueApi } from "#app/plugins/api/pokerogue-api";
|
||||
import { initServerForApiTests } from "#test/utils/testFileInitialization";
|
||||
import { getApiBaseUrl } from "#test/utils/testUtils";
|
||||
import { http, HttpResponse } from "msw";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
const apiBase = getApiBaseUrl();
|
||||
const { server } = global;
|
||||
|
||||
let server;
|
||||
beforeAll(async () => {
|
||||
server = await initServerForApiTests();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
server.resetHandlers();
|
||||
|
@ -3,11 +3,16 @@ import { PokerogueDailyApi } from "#app/plugins/api/pokerogue-daily-api";
|
||||
import { getApiBaseUrl } from "#test/utils/testUtils";
|
||||
import { ScoreboardCategory, type RankingEntry } from "#app/ui/daily-run-scoreboard";
|
||||
import { http, HttpResponse } from "msw";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { initServerForApiTests } from "#test/testUtils/testFileInitialization";
|
||||
|
||||
const apiBase = getApiBaseUrl();
|
||||
const dailyApi = new PokerogueDailyApi(apiBase);
|
||||
const { server } = global;
|
||||
|
||||
let server;
|
||||
beforeAll(async () => {
|
||||
server = await initServerForApiTests();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
server.resetHandlers();
|
||||
|
@ -1,12 +1,17 @@
|
||||
import type { UpdateAllSavedataRequest } from "#app/@types/PokerogueSavedataApi";
|
||||
import { PokerogueSavedataApi } from "#app/plugins/api/pokerogue-savedata-api";
|
||||
import { initServerForApiTests } from "#test/utils/testFileInitialization";
|
||||
import { getApiBaseUrl } from "#test/utils/testUtils";
|
||||
import { http, HttpResponse } from "msw";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
const apiBase = getApiBaseUrl();
|
||||
const savedataApi = new PokerogueSavedataApi(apiBase);
|
||||
const { server } = global;
|
||||
|
||||
let server;
|
||||
beforeAll(async () => {
|
||||
server = await initServerForApiTests();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
server.resetHandlers();
|
||||
|
@ -10,11 +10,16 @@ import { PokerogueSessionSavedataApi } from "#app/plugins/api/pokerogue-session-
|
||||
import type { SessionSaveData } from "#app/system/game-data";
|
||||
import { getApiBaseUrl } from "#test/utils/testUtils";
|
||||
import { http, HttpResponse } from "msw";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { initServerForApiTests } from "#test/testUtils/testFileInitialization";
|
||||
|
||||
const apiBase = getApiBaseUrl();
|
||||
const sessionSavedataApi = new PokerogueSessionSavedataApi(apiBase);
|
||||
const { server } = global;
|
||||
|
||||
let server;
|
||||
beforeAll(async () => {
|
||||
server = await initServerForApiTests();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
server.resetHandlers();
|
||||
|
@ -8,11 +8,16 @@ import { PokerogueSystemSavedataApi } from "#app/plugins/api/pokerogue-system-sa
|
||||
import type { SystemSaveData } from "#app/system/game-data";
|
||||
import { getApiBaseUrl } from "#test/utils/testUtils";
|
||||
import { http, HttpResponse } from "msw";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { initServerForApiTests } from "#test/utils/testFileInitialization";
|
||||
|
||||
const apiBase = getApiBaseUrl();
|
||||
const systemSavedataApi = new PokerogueSystemSavedataApi(getApiBaseUrl());
|
||||
const { server } = global;
|
||||
|
||||
let server;
|
||||
beforeAll(async () => {
|
||||
server = await initServerForApiTests();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
server.resetHandlers();
|
||||
|
@ -57,6 +57,7 @@ import fs from "fs";
|
||||
import { expect, vi } from "vitest";
|
||||
import { globalScene } from "#app/global-scene";
|
||||
import type StarterSelectUiHandler from "#app/ui/starter-select-ui-handler";
|
||||
import { MockFetch } from "./mocks/mockFetch";
|
||||
|
||||
/**
|
||||
* Class to manage the game state and transitions between phases.
|
||||
@ -122,6 +123,8 @@ export default class GameManager {
|
||||
|
||||
// Sanitize overrides for each test
|
||||
this.override.mysteryEncounterChance(0).moveset([]).enemyMoveset([]).startingHeldItems([]).enemyHeldItems([]);
|
||||
|
||||
global.fetch = vi.fn(MockFetch) as any;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -15,12 +15,10 @@ import { setCookie } from "#app/utils";
|
||||
import { blobToString } from "#test/utils/gameManagerUtils";
|
||||
import { MockConsoleLog } from "#test/utils/mocks/mockConsoleLog";
|
||||
import { mockContext } from "#test/utils/mocks/mockContext";
|
||||
import { MockFetch } from "#test/utils/mocks/mockFetch";
|
||||
import mockLocalStorage from "#test/utils/mocks/mockLocalStorage";
|
||||
import MockImage from "#test/utils/mocks/mocksContainer/mockImage";
|
||||
import Phaser from "phaser";
|
||||
import InputText from "phaser3-rex-plugins/plugins/inputtext";
|
||||
import { vi } from "vitest";
|
||||
import { manageListeners } from "./listenersManager";
|
||||
|
||||
/**
|
||||
@ -53,7 +51,6 @@ export function initTestFile() {
|
||||
return null as any;
|
||||
};
|
||||
navigator.getGamepads = () => [];
|
||||
global.fetch = vi.fn(MockFetch) as any;
|
||||
setCookie(SESSION_ID_COOKIE_NAME, "fake_token");
|
||||
|
||||
window.matchMedia = () =>
|
||||
@ -99,3 +96,15 @@ export function initTestFile() {
|
||||
|
||||
manageListeners();
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the current mock server and initializes a new mock server.
|
||||
* This is run at the beginning of every API test file.
|
||||
*/
|
||||
export async function initServerForApiTests() {
|
||||
global.server?.close();
|
||||
const { setupServer } = await import("msw/node");
|
||||
global.server = setupServer();
|
||||
global.server.listen({ onUnhandledRequest: "error" });
|
||||
return global.server;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user