pokerogue/test/system/game_data.test.ts
NightKev 9dcb904649
[Misc] Improve enum naming (#5933)
* Rename `Abilities` to `AbilityId`

* Rename `abilities.ts` to `ability-id.ts`

* Rename `Moves` to `MoveId`

* Rename `moves.ts` to `move-id.ts`

* Rename `Species` to `SpeciesId`

* Rename `species.ts` to `species-id.ts`

* Rename `Biome` to `BiomeId`

* Rename `biome.ts` to `biome-id.ts`

* Replace `Abilities` with `AbilityId` in comments

* Replace `Biome` with `BiomeId` in comments

* Replace `Moves` with `MoveId` in comments

* Replace `Species` with `SpeciesId` in comments
2025-06-04 14:54:27 -07:00

83 lines
2.6 KiB
TypeScript

import * as bypassLoginModule from "#app/global-vars/bypass-login";
import { pokerogueApi } from "#app/plugins/api/pokerogue-api";
import type { SessionSaveData } from "#app/system/game-data";
import { AbilityId } from "#enums/ability-id";
import { MoveId } from "#enums/move-id";
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([MoveId.SPLASH])
.battleStyle("single")
.enemyAbility(AbilityId.BALL_FETCH)
.enemyMoveset(MoveId.SPLASH);
});
afterEach(() => {
game.phaseInterceptor.restoreOg();
});
describe("tryClearSession", () => {
beforeEach(() => {
vi.spyOn(bypassLoginModule, "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(bypassLoginModule, "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();
});
});
});