47 lines
1.2 KiB
TypeScript
47 lines
1.2 KiB
TypeScript
import { describe, expect, it, vi } from "vitest";
|
|
import {
|
|
RECENT_FURNI_RESYNC_URL,
|
|
requestRecentFurniResync,
|
|
} from "./recent-furni-resync";
|
|
|
|
describe("requestRecentFurniResync", () => {
|
|
it("posts to the fixed seven-day resync endpoint and normalizes the result", async () => {
|
|
const fetcher = vi.fn(async () =>
|
|
Response.json({
|
|
ok: true,
|
|
mode: "days",
|
|
days: 7,
|
|
examined: 4,
|
|
resynced: 3,
|
|
failed: 1,
|
|
rconOk: false,
|
|
errors: [{ classname: "chair", message: "invalid entry" }],
|
|
}),
|
|
);
|
|
|
|
await expect(requestRecentFurniResync(fetcher)).resolves.toEqual({
|
|
examined: 4,
|
|
resynced: 3,
|
|
failed: 1,
|
|
rconOk: false,
|
|
errors: [{ classname: "chair", message: "invalid entry" }],
|
|
});
|
|
expect(RECENT_FURNI_RESYNC_URL).toBe(
|
|
"/api/admin/import/furni/resync?days=7",
|
|
);
|
|
expect(fetcher).toHaveBeenCalledWith(RECENT_FURNI_RESYNC_URL, {
|
|
method: "POST",
|
|
});
|
|
});
|
|
|
|
it("throws the API error when the request fails", async () => {
|
|
const fetcher = vi.fn(async () =>
|
|
Response.json({ error: "Forbidden" }, { status: 403 }),
|
|
);
|
|
|
|
await expect(requestRecentFurniResync(fetcher)).rejects.toThrow(
|
|
"Forbidden",
|
|
);
|
|
});
|
|
});
|