add pokerogue-savedata-api test coverage
This commit is contained in:
parent
bf4f79379d
commit
087bedd47e
|
@ -35,7 +35,7 @@ export class PokerogueSavedataApi extends ApiBase {
|
|||
return await response.text();
|
||||
} catch (err) {
|
||||
console.warn("Could not update all savedata!", err);
|
||||
return null;
|
||||
return "Unknown error";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
import type { UpdateAllSavedataRequest } from "#app/@types/PokerogueSavedataApi";
|
||||
import { PokerogueSavedataApi } from "#app/plugins/api/pokerogue-savedata-api";
|
||||
import { getApiBaseUrl } from "#app/test/utils/testUtils";
|
||||
import { http, HttpResponse } from "msw";
|
||||
import { setupServer } from "msw/node";
|
||||
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
const apiBase = getApiBaseUrl();
|
||||
const savedataApi = new PokerogueSavedataApi(apiBase);
|
||||
const server = setupServer();
|
||||
|
||||
beforeAll(() => {
|
||||
server.listen({ onUnhandledRequest: "error" });
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
server.close();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
server.resetHandlers();
|
||||
});
|
||||
|
||||
describe("Pokerogue Admin 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));
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue