mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-12-11 20:35:18 +01:00
* add: i18n backend support the backend is being supported by using msw which will import the correct file from the local locales folder * fix: tests to no longer rely on static i18n keys * Update src/test/mystery-encounter/encounters/teleporting-hijinks-encounter.test.ts Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com> * Update src/test/mystery-encounter/encounters/teleporting-hijinks-encounter.test.ts Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com> * Update src/test/ui/type-hints.test.ts Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com> * Update src/test/mystery-encounter/encounters/a-trainers-test-encounter.test.ts Co-authored-by: MokaStitcher <54149968+MokaStitcher@users.noreply.github.com> * Fix typos Co-authored-by: Adrian T. <68144167+torranx@users.noreply.github.com> * Fix linting * update locales submodule update reference to `56eeb809eb5a2de40cfc5bc6128a78bef14deea9` (from `3ccef8472dd7cc7c362538489954cb8fdad27e5f`) --------- Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com> Co-authored-by: MokaStitcher <54149968+MokaStitcher@users.noreply.github.com> Co-authored-by: Adrian T. <68144167+torranx@users.noreply.github.com>
93 lines
3.1 KiB
TypeScript
93 lines
3.1 KiB
TypeScript
import * as BattleScene from "#app/battle-scene";
|
|
import { SessionSaveData } from "#app/system/game-data";
|
|
import { Abilities } from "#enums/abilities";
|
|
import { Moves } from "#enums/moves";
|
|
import GameManager from "#test/utils/gameManager";
|
|
import { http, HttpResponse } from "msw";
|
|
import { setupServer } from "msw/node";
|
|
import Phaser from "phaser";
|
|
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
|
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", () => {
|
|
let phaserGame: Phaser.Game;
|
|
let game: GameManager;
|
|
|
|
beforeAll(() => {
|
|
global.i18nServer.close();
|
|
server.listen();
|
|
phaserGame = new Phaser.Game({
|
|
type: Phaser.HEADLESS,
|
|
});
|
|
});
|
|
|
|
afterAll(() => {
|
|
server.close();
|
|
global.i18nServer.listen();
|
|
});
|
|
|
|
beforeEach(() => {
|
|
game = new GameManager(phaserGame);
|
|
game.override
|
|
.moveset([ Moves.SPLASH ])
|
|
.battleType("single")
|
|
.enemyAbility(Abilities.BALL_FETCH)
|
|
.enemyMoveset(Moves.SPLASH);
|
|
});
|
|
|
|
afterEach(() => {
|
|
server.resetHandlers();
|
|
game.phaseInterceptor.restoreOg();
|
|
});
|
|
|
|
describe("tryClearSession", () => {
|
|
beforeEach(() => {
|
|
vi.spyOn(BattleScene, "bypassLogin", "get").mockReturnValue(false);
|
|
vi.spyOn(game.scene.gameData, "getSessionSaveData").mockReturnValue({} as SessionSaveData);
|
|
vi.spyOn(account, "updateUserInfo").mockImplementation(async () => [ true, 1 ]);
|
|
});
|
|
|
|
it("should return [true, true] if bypassLogin is true", async () => {
|
|
vi.spyOn(BattleScene, "bypassLogin", "get").mockReturnValue(true);
|
|
|
|
const result = await game.scene.gameData.tryClearSession(game.scene, 0);
|
|
|
|
expect(result).toEqual([ true, true ]);
|
|
});
|
|
|
|
it("should return [true, true] if successful", async () => {
|
|
server.use(http.post(`${apiBase}/savedata/session/clear`, () => HttpResponse.json({ success: true })));
|
|
|
|
const result = await game.scene.gameData.tryClearSession(game.scene, 0);
|
|
|
|
expect(result).toEqual([ true, true ]);
|
|
expect(account.updateUserInfo).toHaveBeenCalled();
|
|
});
|
|
|
|
it("should return [true, false] if not successful", async () => {
|
|
server.use(http.post(`${apiBase}/savedata/session/clear`, () => HttpResponse.json({ success: false })));
|
|
|
|
const result = await game.scene.gameData.tryClearSession(game.scene, 0);
|
|
|
|
expect(result).toEqual([ true, false ]);
|
|
expect(account.updateUserInfo).toHaveBeenCalled();
|
|
});
|
|
|
|
it("should return [false, false] session is out of date", async () => {
|
|
server.use(
|
|
http.post(`${apiBase}/savedata/session/clear`, () => HttpResponse.json({ error: "session out of date" }))
|
|
);
|
|
|
|
const result = await game.scene.gameData.tryClearSession(game.scene, 0);
|
|
|
|
expect(result).toEqual([ false, false ]);
|
|
expect(account.updateUserInfo).toHaveBeenCalled();
|
|
});
|
|
});
|
|
});
|