pokerogue/test/system/game_data.test.ts
Sirz Benjie 408b66f913
[Misc][Refactor][GitHub] Ditch eslint for biome, and add a formatter (#5495)
Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com>
2025-03-09 14:13:25 -07:00

83 lines
2.6 KiB
TypeScript

import * as BattleScene from "#app/battle-scene";
import { pokerogueApi } from "#app/plugins/api/pokerogue-api";
import type { SessionSaveData } from "#app/system/game-data";
import { Abilities } from "#enums/abilities";
import { Moves } from "#enums/moves";
import GameManager from "#test/testUtils/gameManager";
import Phaser from "phaser";
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
import * as account from "#app/account";
describe("System - Game Data", () => {
let phaserGame: Phaser.Game;
let game: GameManager;
beforeAll(() => {
phaserGame = new Phaser.Game({
type: Phaser.HEADLESS,
});
});
beforeEach(() => {
game = new GameManager(phaserGame);
game.override
.moveset([Moves.SPLASH])
.battleType("single")
.enemyAbility(Abilities.BALL_FETCH)
.enemyMoveset(Moves.SPLASH);
});
afterEach(() => {
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(0);
expect(result).toEqual([true, true]);
});
it("should return [true, true] if successful", async () => {
vi.spyOn(pokerogueApi.savedata.session, "clear").mockResolvedValue({
success: true,
});
const result = await game.scene.gameData.tryClearSession(0);
expect(result).toEqual([true, true]);
expect(account.updateUserInfo).toHaveBeenCalled();
});
it("should return [true, false] if not successful", async () => {
vi.spyOn(pokerogueApi.savedata.session, "clear").mockResolvedValue({
success: false,
});
const result = await game.scene.gameData.tryClearSession(0);
expect(result).toEqual([true, false]);
expect(account.updateUserInfo).toHaveBeenCalled();
});
it("should return [false, false] session is out of date", async () => {
vi.spyOn(pokerogueApi.savedata.session, "clear").mockResolvedValue({
error: "session out of date",
});
const result = await game.scene.gameData.tryClearSession(0);
expect(result).toEqual([false, false]);
expect(account.updateUserInfo).toHaveBeenCalled();
});
});
});