mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-04-24 14:27:37 -04:00
* Extract Mode enum out of UI and into its own file Reduces circular imports from 909 to 773 * Move around utility files Reduces cyclical dependencies from 773 to 765 * Remove starterColors and bypassLogin from battle-scene Reduces cyclical dependencies from 765 to 623 * Fix test runner error * Update import for bypassLogin in test * Update mocks for utils in tests * Fix broken tests * Update selectWithTera override * Update path for utils in ab-attr.ts * Update path for utils in ability-class.ts * Fix utils import path in healer.test.ts
82 lines
2.6 KiB
TypeScript
82 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 { 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])
|
|
.battleStyle("single")
|
|
.enemyAbility(Abilities.BALL_FETCH)
|
|
.enemyMoveset(Moves.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();
|
|
});
|
|
});
|
|
});
|