mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-04-24 06:17:40 -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
69 lines
2.3 KiB
TypeScript
69 lines
2.3 KiB
TypeScript
import * as bypassLogin from "#app/global-vars/bypass-login";
|
|
import { pokerogueApi } from "#app/plugins/api/pokerogue-api";
|
|
import { describe, expect, it, vi } from "vitest";
|
|
import { initLoggedInUser, loggedInUser, updateUserInfo } from "#app/account";
|
|
|
|
describe("account", () => {
|
|
describe("initLoggedInUser", () => {
|
|
it("should set loggedInUser to Guest and lastSessionSlot to -1", () => {
|
|
initLoggedInUser();
|
|
|
|
expect(loggedInUser!.username).toBe("Guest");
|
|
expect(loggedInUser!.lastSessionSlot).toBe(-1);
|
|
});
|
|
});
|
|
|
|
describe("updateUserInfo", () => {
|
|
it("should set loggedInUser! to Guest if bypassLogin is true", async () => {
|
|
vi.spyOn(bypassLogin, "bypassLogin", "get").mockReturnValue(true);
|
|
|
|
const [success, status] = await updateUserInfo();
|
|
|
|
expect(success).toBe(true);
|
|
expect(status).toBe(200);
|
|
expect(loggedInUser!.username).toBe("Guest");
|
|
expect(loggedInUser!.lastSessionSlot).toBe(-1);
|
|
});
|
|
|
|
it("should fetch user info from the API if bypassLogin is false", async () => {
|
|
vi.spyOn(bypassLogin, "bypassLogin", "get").mockReturnValue(false);
|
|
vi.spyOn(pokerogueApi.account, "getInfo").mockResolvedValue([
|
|
{
|
|
username: "test",
|
|
lastSessionSlot: 99,
|
|
discordId: "",
|
|
googleId: "",
|
|
hasAdminRole: false,
|
|
},
|
|
200,
|
|
]);
|
|
|
|
const [success, status] = await updateUserInfo();
|
|
|
|
expect(success).toBe(true);
|
|
expect(status).toBe(200);
|
|
expect(loggedInUser!.username).toBe("test");
|
|
expect(loggedInUser!.lastSessionSlot).toBe(99);
|
|
});
|
|
|
|
it("should handle resolved API errors", async () => {
|
|
vi.spyOn(bypassLogin, "bypassLogin", "get").mockReturnValue(false);
|
|
vi.spyOn(pokerogueApi.account, "getInfo").mockResolvedValue([null, 401]);
|
|
|
|
const [success, status] = await updateUserInfo();
|
|
|
|
expect(success).toBe(false);
|
|
expect(status).toBe(401);
|
|
});
|
|
|
|
it("should handle 500 API errors", async () => {
|
|
vi.spyOn(bypassLogin, "bypassLogin", "get").mockReturnValue(false);
|
|
vi.spyOn(pokerogueApi.account, "getInfo").mockResolvedValue([null, 500]);
|
|
|
|
const [success, status] = await updateUserInfo();
|
|
|
|
expect(success).toBe(false);
|
|
expect(status).toBe(500);
|
|
});
|
|
});
|
|
});
|