pokerogue/test/plugins/api/pokerogue-savedata-api.test.ts
Sirz Benjie 51d4c33de0
[Misc] Standardize-file-names (#6137)
* 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>
2025-07-24 16:38:31 -04:00

53 lines
1.8 KiB
TypeScript

import { PokerogueSavedataApi } from "#api/pokerogue-savedata-api";
import { initServerForApiTests } from "#test/test-utils/test-file-initialization";
import { getApiBaseUrl } from "#test/test-utils/test-utils";
import type { UpdateAllSavedataRequest } from "#types/api/pokerogue-save-data-api";
import { HttpResponse, http } from "msw";
import type { SetupServerApi } from "msw/node";
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
const apiBase = getApiBaseUrl();
const savedataApi = new PokerogueSavedataApi(apiBase);
let server: SetupServerApi;
beforeAll(async () => {
server = await initServerForApiTests();
});
afterEach(() => {
server.resetHandlers();
});
describe("Pokerogue Savedata API", () => {
beforeEach(() => {
vi.spyOn(console, "warn");
});
describe("Update All", () => {
it("should return an empty string on SUCCESS", async () => {
server.use(http.post(`${apiBase}/savedata/updateall`, () => HttpResponse.text(null)));
const error = await savedataApi.updateAll({} as UpdateAllSavedataRequest);
expect(error).toBe("");
});
it("should return an error message on FAILURE", async () => {
server.use(http.post(`${apiBase}/savedata/updateall`, () => HttpResponse.text("Failed to update all!")));
const error = await savedataApi.updateAll({} as UpdateAllSavedataRequest);
expect(error).toBe("Failed to update all!");
});
it("should return 'Unknown error' and report a warning on ERROR", async () => {
server.use(http.post(`${apiBase}/savedata/updateall`, () => HttpResponse.error()));
const error = await savedataApi.updateAll({} as UpdateAllSavedataRequest);
expect(error).toBe("Unknown error");
expect(console.warn).toHaveBeenCalledWith("Could not update all savedata!", expect.any(Error));
});
});
});