2024-09-26 15:55:08 -05:00
|
|
|
import * as BattleScene from "#app/battle-scene";
|
2024-11-04 12:57:21 -08:00
|
|
|
import { pokerogueApi } from "#app/plugins/api/pokerogue-api";
|
2025-01-12 15:33:05 -08:00
|
|
|
import type { SessionSaveData } from "#app/system/game-data";
|
2024-09-26 15:55:08 -05:00
|
|
|
import { Abilities } from "#enums/abilities";
|
|
|
|
import { Moves } from "#enums/moves";
|
2025-02-22 22:52:07 -06:00
|
|
|
import GameManager from "#test/testUtils/gameManager";
|
2024-09-26 15:55:08 -05:00
|
|
|
import Phaser from "phaser";
|
2024-11-04 12:57:21 -08:00
|
|
|
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
2025-02-22 22:52:07 -06:00
|
|
|
import * as account from "#app/account";
|
2024-09-26 15:55:08 -05:00
|
|
|
|
|
|
|
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
|
2024-10-04 13:08:31 +08:00
|
|
|
.moveset([ Moves.SPLASH ])
|
2024-09-26 15:55:08 -05:00
|
|
|
.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);
|
2024-10-04 13:08:31 +08:00
|
|
|
vi.spyOn(account, "updateUserInfo").mockImplementation(async () => [ true, 1 ]);
|
2024-09-26 15:55:08 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it("should return [true, true] if bypassLogin is true", async () => {
|
|
|
|
vi.spyOn(BattleScene, "bypassLogin", "get").mockReturnValue(true);
|
|
|
|
|
2025-01-12 15:33:05 -08:00
|
|
|
const result = await game.scene.gameData.tryClearSession(0);
|
2024-09-26 15:55:08 -05:00
|
|
|
|
2024-10-04 13:08:31 +08:00
|
|
|
expect(result).toEqual([ true, true ]);
|
2024-09-26 15:55:08 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it("should return [true, true] if successful", async () => {
|
2024-11-04 12:57:21 -08:00
|
|
|
vi.spyOn(pokerogueApi.savedata.session, "clear").mockResolvedValue({ success: true });
|
2024-09-26 15:55:08 -05:00
|
|
|
|
2025-01-12 15:33:05 -08:00
|
|
|
const result = await game.scene.gameData.tryClearSession(0);
|
2024-09-26 15:55:08 -05:00
|
|
|
|
2024-10-04 13:08:31 +08:00
|
|
|
expect(result).toEqual([ true, true ]);
|
2024-09-26 15:55:08 -05:00
|
|
|
expect(account.updateUserInfo).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should return [true, false] if not successful", async () => {
|
2024-11-04 12:57:21 -08:00
|
|
|
vi.spyOn(pokerogueApi.savedata.session, "clear").mockResolvedValue({ success: false });
|
2024-09-26 15:55:08 -05:00
|
|
|
|
2025-01-12 15:33:05 -08:00
|
|
|
const result = await game.scene.gameData.tryClearSession(0);
|
2024-09-26 15:55:08 -05:00
|
|
|
|
2024-10-04 13:08:31 +08:00
|
|
|
expect(result).toEqual([ true, false ]);
|
2024-09-26 15:55:08 -05:00
|
|
|
expect(account.updateUserInfo).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should return [false, false] session is out of date", async () => {
|
2024-11-04 12:57:21 -08:00
|
|
|
vi.spyOn(pokerogueApi.savedata.session, "clear").mockResolvedValue({ error: "session out of date" });
|
2024-09-26 15:55:08 -05:00
|
|
|
|
2025-01-12 15:33:05 -08:00
|
|
|
const result = await game.scene.gameData.tryClearSession(0);
|
2024-09-26 15:55:08 -05:00
|
|
|
|
2024-10-04 13:08:31 +08:00
|
|
|
expect(result).toEqual([ false, false ]);
|
2024-09-26 15:55:08 -05:00
|
|
|
expect(account.updateUserInfo).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|