fix tests
This commit is contained in:
parent
1154d797bf
commit
aafbd00fbd
|
@ -10,5 +10,5 @@ declare global {
|
||||||
*
|
*
|
||||||
* To set up your own server in a test see `game_data.test.ts`
|
* To set up your own server in a test see `game_data.test.ts`
|
||||||
*/
|
*/
|
||||||
var i18nServer: SetupServerApi;
|
var server: SetupServerApi;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,22 +2,13 @@ import type { AccountInfoResponse } from "#app/@types/PokerogueAccountApi";
|
||||||
import { SESSION_ID_COOKIE_NAME } from "#app/constants";
|
import { SESSION_ID_COOKIE_NAME } from "#app/constants";
|
||||||
import { PokerogueAccountApi } from "#app/plugins/api/pokerogue-account-api";
|
import { PokerogueAccountApi } from "#app/plugins/api/pokerogue-account-api";
|
||||||
import { getApiBaseUrl } from "#app/test/utils/testUtils";
|
import { getApiBaseUrl } from "#app/test/utils/testUtils";
|
||||||
import { http, HttpResponse } from "msw";
|
|
||||||
import { setupServer } from "msw/node";
|
|
||||||
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
|
||||||
import * as Utils from "#app/utils";
|
import * as Utils from "#app/utils";
|
||||||
|
import { http, HttpResponse } from "msw";
|
||||||
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||||
|
|
||||||
const apiBase = getApiBaseUrl();
|
const apiBase = getApiBaseUrl();
|
||||||
const accountApi = new PokerogueAccountApi(apiBase);
|
const accountApi = new PokerogueAccountApi(apiBase);
|
||||||
const server = setupServer();
|
const { server } = global;
|
||||||
|
|
||||||
beforeAll(() => {
|
|
||||||
server.listen({ onUnhandledRequest: "error" });
|
|
||||||
});
|
|
||||||
|
|
||||||
afterAll(() => {
|
|
||||||
server.close();
|
|
||||||
});
|
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
server.resetHandlers();
|
server.resetHandlers();
|
||||||
|
|
|
@ -2,20 +2,11 @@ import type { LinkAccountToDiscordIdRequest } from "#app/@types/PokerogueAdminAp
|
||||||
import { PokerogueAdminApi } from "#app/plugins/api/pokerogue-admin-api";
|
import { PokerogueAdminApi } from "#app/plugins/api/pokerogue-admin-api";
|
||||||
import { getApiBaseUrl } from "#app/test/utils/testUtils";
|
import { getApiBaseUrl } from "#app/test/utils/testUtils";
|
||||||
import { http, HttpResponse } from "msw";
|
import { http, HttpResponse } from "msw";
|
||||||
import { setupServer } from "msw/node";
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||||
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
|
||||||
|
|
||||||
const apiBase = getApiBaseUrl();
|
const apiBase = getApiBaseUrl();
|
||||||
const adminApi = new PokerogueAdminApi(apiBase);
|
const adminApi = new PokerogueAdminApi(apiBase);
|
||||||
const server = setupServer();
|
const { server } = global;
|
||||||
|
|
||||||
beforeAll(() => {
|
|
||||||
server.listen({ onUnhandledRequest: "error" });
|
|
||||||
});
|
|
||||||
|
|
||||||
afterAll(() => {
|
|
||||||
server.close();
|
|
||||||
});
|
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
server.resetHandlers();
|
server.resetHandlers();
|
||||||
|
|
|
@ -2,19 +2,10 @@ import type { TitleStatsResponse } from "#app/@types/PokerogueApi";
|
||||||
import { pokerogueApi } from "#app/plugins/api/pokerogue-api";
|
import { pokerogueApi } from "#app/plugins/api/pokerogue-api";
|
||||||
import { getApiBaseUrl } from "#app/test/utils/testUtils";
|
import { getApiBaseUrl } from "#app/test/utils/testUtils";
|
||||||
import { http, HttpResponse } from "msw";
|
import { http, HttpResponse } from "msw";
|
||||||
import { setupServer } from "msw/node";
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||||
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
|
||||||
|
|
||||||
const apiBase = getApiBaseUrl();
|
const apiBase = getApiBaseUrl();
|
||||||
const server = setupServer();
|
const { server } = global;
|
||||||
|
|
||||||
beforeAll(() => {
|
|
||||||
server.listen({ onUnhandledRequest: "error" });
|
|
||||||
});
|
|
||||||
|
|
||||||
afterAll(() => {
|
|
||||||
server.close();
|
|
||||||
});
|
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
server.resetHandlers();
|
server.resetHandlers();
|
||||||
|
|
|
@ -3,20 +3,11 @@ import { PokerogueDailyApi } from "#app/plugins/api/pokerogue-daily-api";
|
||||||
import { getApiBaseUrl } from "#app/test/utils/testUtils";
|
import { getApiBaseUrl } from "#app/test/utils/testUtils";
|
||||||
import { ScoreboardCategory, type RankingEntry } from "#app/ui/daily-run-scoreboard";
|
import { ScoreboardCategory, type RankingEntry } from "#app/ui/daily-run-scoreboard";
|
||||||
import { http, HttpResponse } from "msw";
|
import { http, HttpResponse } from "msw";
|
||||||
import { setupServer } from "msw/node";
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||||
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
|
||||||
|
|
||||||
const apiBase = getApiBaseUrl();
|
const apiBase = getApiBaseUrl();
|
||||||
const dailyApi = new PokerogueDailyApi(apiBase);
|
const dailyApi = new PokerogueDailyApi(apiBase);
|
||||||
const server = setupServer();
|
const { server } = global;
|
||||||
|
|
||||||
beforeAll(() => {
|
|
||||||
server.listen({ onUnhandledRequest: "error" });
|
|
||||||
});
|
|
||||||
|
|
||||||
afterAll(() => {
|
|
||||||
server.close();
|
|
||||||
});
|
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
server.resetHandlers();
|
server.resetHandlers();
|
||||||
|
|
|
@ -2,20 +2,11 @@ import type { UpdateAllSavedataRequest } from "#app/@types/PokerogueSavedataApi"
|
||||||
import { PokerogueSavedataApi } from "#app/plugins/api/pokerogue-savedata-api";
|
import { PokerogueSavedataApi } from "#app/plugins/api/pokerogue-savedata-api";
|
||||||
import { getApiBaseUrl } from "#app/test/utils/testUtils";
|
import { getApiBaseUrl } from "#app/test/utils/testUtils";
|
||||||
import { http, HttpResponse } from "msw";
|
import { http, HttpResponse } from "msw";
|
||||||
import { setupServer } from "msw/node";
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||||
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
|
||||||
|
|
||||||
const apiBase = getApiBaseUrl();
|
const apiBase = getApiBaseUrl();
|
||||||
const savedataApi = new PokerogueSavedataApi(apiBase);
|
const savedataApi = new PokerogueSavedataApi(apiBase);
|
||||||
const server = setupServer();
|
const { server } = global;
|
||||||
|
|
||||||
beforeAll(() => {
|
|
||||||
server.listen({ onUnhandledRequest: "error" });
|
|
||||||
});
|
|
||||||
|
|
||||||
afterAll(() => {
|
|
||||||
server.close();
|
|
||||||
});
|
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
server.resetHandlers();
|
server.resetHandlers();
|
||||||
|
|
|
@ -10,20 +10,11 @@ import { PokerogueSessionSavedataApi } from "#app/plugins/api/pokerogue-session-
|
||||||
import type { SessionSaveData } from "#app/system/game-data";
|
import type { SessionSaveData } from "#app/system/game-data";
|
||||||
import { getApiBaseUrl } from "#app/test/utils/testUtils";
|
import { getApiBaseUrl } from "#app/test/utils/testUtils";
|
||||||
import { http, HttpResponse } from "msw";
|
import { http, HttpResponse } from "msw";
|
||||||
import { setupServer } from "msw/node";
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||||
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
|
||||||
|
|
||||||
const apiBase = getApiBaseUrl();
|
const apiBase = getApiBaseUrl();
|
||||||
const sessionSavedataApi = new PokerogueSessionSavedataApi(apiBase);
|
const sessionSavedataApi = new PokerogueSessionSavedataApi(apiBase);
|
||||||
const server = setupServer();
|
const { server } = global;
|
||||||
|
|
||||||
beforeAll(() => {
|
|
||||||
server.listen({ onUnhandledRequest: "error" });
|
|
||||||
});
|
|
||||||
|
|
||||||
afterAll(() => {
|
|
||||||
server.close();
|
|
||||||
});
|
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
server.resetHandlers();
|
server.resetHandlers();
|
||||||
|
|
|
@ -8,20 +8,11 @@ import { PokerogueSystemSavedataApi } from "#app/plugins/api/pokerogue-system-sa
|
||||||
import type { SystemSaveData } from "#app/system/game-data";
|
import type { SystemSaveData } from "#app/system/game-data";
|
||||||
import { getApiBaseUrl } from "#app/test/utils/testUtils";
|
import { getApiBaseUrl } from "#app/test/utils/testUtils";
|
||||||
import { http, HttpResponse } from "msw";
|
import { http, HttpResponse } from "msw";
|
||||||
import { setupServer } from "msw/node";
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||||
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
|
||||||
|
|
||||||
const apiBase = getApiBaseUrl();
|
const apiBase = getApiBaseUrl();
|
||||||
const systemSavedataApi = new PokerogueSystemSavedataApi(apiBase);
|
const systemSavedataApi = new PokerogueSystemSavedataApi(getApiBaseUrl());
|
||||||
const server = setupServer();
|
const { server } = global;
|
||||||
|
|
||||||
beforeAll(() => {
|
|
||||||
server.listen({ onUnhandledRequest: "error" });
|
|
||||||
});
|
|
||||||
|
|
||||||
afterAll(() => {
|
|
||||||
server.close();
|
|
||||||
});
|
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
server.resetHandlers();
|
server.resetHandlers();
|
||||||
|
|
|
@ -1,36 +1,23 @@
|
||||||
import * as BattleScene from "#app/battle-scene";
|
import * as BattleScene from "#app/battle-scene";
|
||||||
|
import { pokerogueApi } from "#app/plugins/api/pokerogue-api";
|
||||||
import { SessionSaveData } from "#app/system/game-data";
|
import { SessionSaveData } from "#app/system/game-data";
|
||||||
import { Abilities } from "#enums/abilities";
|
import { Abilities } from "#enums/abilities";
|
||||||
import { Moves } from "#enums/moves";
|
import { Moves } from "#enums/moves";
|
||||||
import GameManager from "#test/utils/gameManager";
|
import GameManager from "#test/utils/gameManager";
|
||||||
import { http, HttpResponse } from "msw";
|
|
||||||
import { setupServer } from "msw/node";
|
|
||||||
import Phaser from "phaser";
|
import Phaser from "phaser";
|
||||||
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||||
import * as account from "../../account";
|
import * as account from "../../account";
|
||||||
|
|
||||||
const apiBase = import.meta.env.VITE_API_BASE_URL ?? "http://localhost:8001";
|
|
||||||
|
|
||||||
/** We need a custom server. For some reasons I can't extend the listeners of {@linkcode global.i18nServer} with {@linkcode global.i18nServer.use} */
|
|
||||||
const server = setupServer();
|
|
||||||
|
|
||||||
describe("System - Game Data", () => {
|
describe("System - Game Data", () => {
|
||||||
let phaserGame: Phaser.Game;
|
let phaserGame: Phaser.Game;
|
||||||
let game: GameManager;
|
let game: GameManager;
|
||||||
|
|
||||||
beforeAll(() => {
|
beforeAll(() => {
|
||||||
global.i18nServer.close();
|
|
||||||
server.listen();
|
|
||||||
phaserGame = new Phaser.Game({
|
phaserGame = new Phaser.Game({
|
||||||
type: Phaser.HEADLESS,
|
type: Phaser.HEADLESS,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
afterAll(() => {
|
|
||||||
server.close();
|
|
||||||
global.i18nServer.listen();
|
|
||||||
});
|
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
game = new GameManager(phaserGame);
|
game = new GameManager(phaserGame);
|
||||||
game.override
|
game.override
|
||||||
|
@ -41,7 +28,6 @@ describe("System - Game Data", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
server.resetHandlers();
|
|
||||||
game.phaseInterceptor.restoreOg();
|
game.phaseInterceptor.restoreOg();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -61,7 +47,7 @@ describe("System - Game Data", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should return [true, true] if successful", async () => {
|
it("should return [true, true] if successful", async () => {
|
||||||
server.use(http.post(`${apiBase}/savedata/session/clear`, () => HttpResponse.json({ success: true })));
|
vi.spyOn(pokerogueApi.savedata.session, "clear").mockResolvedValue({ success: true });
|
||||||
|
|
||||||
const result = await game.scene.gameData.tryClearSession(game.scene, 0);
|
const result = await game.scene.gameData.tryClearSession(game.scene, 0);
|
||||||
|
|
||||||
|
@ -70,7 +56,7 @@ describe("System - Game Data", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should return [true, false] if not successful", async () => {
|
it("should return [true, false] if not successful", async () => {
|
||||||
server.use(http.post(`${apiBase}/savedata/session/clear`, () => HttpResponse.json({ success: false })));
|
vi.spyOn(pokerogueApi.savedata.session, "clear").mockResolvedValue({ success: false });
|
||||||
|
|
||||||
const result = await game.scene.gameData.tryClearSession(game.scene, 0);
|
const result = await game.scene.gameData.tryClearSession(game.scene, 0);
|
||||||
|
|
||||||
|
@ -79,9 +65,7 @@ describe("System - Game Data", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should return [false, false] session is out of date", async () => {
|
it("should return [false, false] session is out of date", async () => {
|
||||||
server.use(
|
vi.spyOn(pokerogueApi.savedata.session, "clear").mockResolvedValue({ error: "session out of date" });
|
||||||
http.post(`${apiBase}/savedata/session/clear`, () => HttpResponse.json({ error: "session out of date" }))
|
|
||||||
);
|
|
||||||
|
|
||||||
const result = await game.scene.gameData.tryClearSession(game.scene, 0);
|
const result = await game.scene.gameData.tryClearSession(game.scene, 0);
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,7 @@ vi.mock("i18next", async (importOriginal) => {
|
||||||
const { setupServer } = await import("msw/node");
|
const { setupServer } = await import("msw/node");
|
||||||
const { http, HttpResponse } = await import("msw");
|
const { http, HttpResponse } = await import("msw");
|
||||||
|
|
||||||
global.i18nServer = setupServer(
|
global.server = setupServer(
|
||||||
http.get("/locales/en/*", async (req) => {
|
http.get("/locales/en/*", async (req) => {
|
||||||
const filename = req.params[0];
|
const filename = req.params[0];
|
||||||
|
|
||||||
|
@ -50,9 +50,12 @@ vi.mock("i18next", async (importOriginal) => {
|
||||||
console.log(`Failed to load locale ${filename}!`, err);
|
console.log(`Failed to load locale ${filename}!`, err);
|
||||||
return HttpResponse.json({});
|
return HttpResponse.json({});
|
||||||
}
|
}
|
||||||
})
|
}),
|
||||||
|
http.get("https://fonts.googleapis.com/*", () => {
|
||||||
|
return HttpResponse.text("");
|
||||||
|
}),
|
||||||
);
|
);
|
||||||
global.i18nServer.listen({ onUnhandledRequest: "error" });
|
global.server.listen({ onUnhandledRequest: "error" });
|
||||||
console.log("i18n MSW server listening!");
|
console.log("i18n MSW server listening!");
|
||||||
|
|
||||||
return await importOriginal();
|
return await importOriginal();
|
||||||
|
@ -83,6 +86,6 @@ beforeAll(() => {
|
||||||
});
|
});
|
||||||
|
|
||||||
afterAll(() => {
|
afterAll(() => {
|
||||||
global.i18nServer.close();
|
global.server.close();
|
||||||
console.log("Closing i18n MSW server!");
|
console.log("Closing i18n MSW server!");
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue