The export routes wait up to 120 s as the design says, instead of the 30 s default. Event names and updatedAt can be null, and a history card for a removed event shows no empty name line. Notes on export paging and on url-less folder modules in the ACL menu. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
46 lines
2.3 KiB
TypeScript
46 lines
2.3 KiB
TypeScript
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
|
|
const mocks = vi.hoisted(() => ({ callMobileApiBinary: vi.fn(), getToken: vi.fn() }));
|
|
vi.mock("@/app/lib/server/mobileApi", () => ({ callMobileApiBinary: mocks.callMobileApiBinary }));
|
|
vi.mock("@/app/lib/server/session", () => ({ getToken: mocks.getToken }));
|
|
|
|
import { GET } from "./route";
|
|
|
|
type Req = Parameters<typeof GET>[0];
|
|
const req = (url: string) => new Request(`http://localhost${url}`) as unknown as Req;
|
|
const ctx = (eventUuid: string) => ({ params: Promise.resolve({ eventUuid }) });
|
|
|
|
beforeEach(() => {
|
|
mocks.callMobileApiBinary.mockReset();
|
|
mocks.getToken.mockReset().mockResolvedValue("jwt-abc");
|
|
});
|
|
|
|
describe("/api/event-leads/[eventUuid]/export", () => {
|
|
it("returns 401 without a session", async () => {
|
|
mocks.getToken.mockResolvedValue(null);
|
|
expect((await GET(req("/x"), ctx("e-1"))).status).toBe(401);
|
|
expect(mocks.callMobileApiBinary).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("forwards the query string and passes bytes and headers through", async () => {
|
|
mocks.callMobileApiBinary.mockResolvedValue({ ok: true, data: { body: new Uint8Array([9]).buffer, contentType: "application/x-xlsx", contentDisposition: 'attachment; filename="e.xlsx"' } });
|
|
const res = await GET(req("/x?status=OPEN&leadType=NEW"), ctx("e-1"));
|
|
expect(mocks.callMobileApiBinary).toHaveBeenCalledWith("/api/admin/event-leads/e-1/export?status=OPEN&leadType=NEW", { token: "jwt-abc", timeoutMs: 120_000 }); // design: the export route waits up to 120 s
|
|
expect(res.headers.get("content-type")).toBe("application/x-xlsx");
|
|
expect(res.headers.get("content-disposition")).toBe('attachment; filename="e.xlsx"');
|
|
expect(new Uint8Array(await res.arrayBuffer())).toEqual(new Uint8Array([9]));
|
|
});
|
|
|
|
it("maps a failure through errorResponse, keeping code and details", async () => {
|
|
mocks.callMobileApiBinary.mockResolvedValue({ ok: false, error: "Too many", status: 422, code: "EXPORT_TOO_LARGE", details: { limit: 20000 } });
|
|
const res = await GET(req("/x"), ctx("e-1"));
|
|
expect(res.status).toBe(422);
|
|
expect(await res.json()).toMatchObject({ code: "EXPORT_TOO_LARGE", details: { limit: 20000 } });
|
|
});
|
|
|
|
it("rejects dot segments", async () => {
|
|
expect((await GET(req("/x"), ctx(".."))).status).toBe(400);
|
|
expect(mocks.callMobileApiBinary).not.toHaveBeenCalled();
|
|
});
|
|
});
|