mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-03-28 12:38:43 +00:00
* start migrating Utils.apiFetch to api class * move dailyranking to api * use api in title-ui-handler * remove: Utils.apiFetch * migrate `updateSystemSavedata` to api * migrate clear session savedata to api * migrate updateAllSavedata to api * migrate `updateSessionSavedata` to api * rename `api` to `pokerogue-api` * migrate unlink discord to pokerogue-api * migrate unlink google to pokerogue-api * update pokerogue-api login * migrate register account to pokerogue-api * remove Utils.apiPost * reset overrides.ts * chore: cleanup * fix env.development * fix circular dependencies with api * fix gamedata verify missing await * fix daily api calls in daily-run-scorebard * fix discord-link request body being empty there was a double `toUrlSearchParams()` call involved * add pokerogue-api test coverge * add test-utils `getApiBaseUrl()` method * add pokerogue-admin-api test coverage * add pokerogue-account-api test coverage * add pokerogue-daily-api test coverage * add pokerogue-savedata-api test coverage * fix some test describes * add pokerogue-session-savedata-api test coverage * add pokerogue-system-savedata-api test coverage * fix tests * fix tryExportData thanks @MokaStitcher * chore: fix menu-ui-handlers.ts * fix admin-ui-handler (types) * extend test-coverage for admin-api * remove outdated code * skip some clowning-around-encounter tests if events are active this is not a permanent solution * Update src/system/game-data.ts Co-authored-by: PigeonBar <56974298+PigeonBar@users.noreply.github.com> * Revert "skip some clowning-around-encounter tests if events are active" This reverts commit a97dafe8b2479e9b2ddd49d4dc9710814d7c7b67. * mark `localServerUrl` and `apiUrl` as deprecated in `utils.ts` --------- Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com> Co-authored-by: PigeonBar <56974298+PigeonBar@users.noreply.github.com>
70 lines
2.3 KiB
TypeScript
70 lines
2.3 KiB
TypeScript
import * as battleScene from "#app/battle-scene";
|
|
import { pokerogueApi } from "#app/plugins/api/pokerogue-api";
|
|
import { describe, expect, it, vi } from "vitest";
|
|
import { initLoggedInUser, loggedInUser, updateUserInfo } from "../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(battleScene, "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(battleScene, "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(battleScene, "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(battleScene, "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);
|
|
});
|
|
});
|
|
});
|