mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-08-07 07:59:26 +02:00
* Standardize filenames to kebab-case Co-authored-by: pymilkmaiden <cassiopeiamahler56@gmail.com> * Move script outside of public folder * Move update_exp_sprites to scripts * Add ls-lint to lint file and directory names * Update lefthook.yml to skip merge / rebase on all pre-commit commands --------- Co-authored-by: pymilkmaiden <cassiopeiamahler56@gmail.com>
83 lines
2.6 KiB
TypeScript
83 lines
2.6 KiB
TypeScript
import { pokerogueApi } from "#api/pokerogue-api";
|
|
import * as account from "#app/account";
|
|
import * as bypassLoginModule from "#app/global-vars/bypass-login";
|
|
import { AbilityId } from "#enums/ability-id";
|
|
import { MoveId } from "#enums/move-id";
|
|
import type { SessionSaveData } from "#system/game-data";
|
|
import { GameManager } from "#test/test-utils/game-manager";
|
|
import Phaser from "phaser";
|
|
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
|
|
|
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();
|
|
});
|
|
});
|
|
});
|