Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfiCVCgCVJZq4NDEqZs
49 lines
3.0 KiB
TypeScript
49 lines
3.0 KiB
TypeScript
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
|
|
const mocks = vi.hoisted(() => ({ callMobileApi: vi.fn(), getToken: vi.fn() }));
|
|
vi.mock("@/app/lib/server/mobileApi", () => ({ callMobileApi: mocks.callMobileApi }));
|
|
vi.mock("@/app/lib/server/session", () => ({ getToken: mocks.getToken }));
|
|
|
|
import { DELETE, GET, POST, PUT } from "./events/[uuid]/[...path]/route";
|
|
|
|
// add-event-ticket-orders: the event proxy forwards the ticket settings, ticket types and order endpoints.
|
|
const req = (url = "http://localhost/x", init?: RequestInit) => new Request(url, init) as never;
|
|
const p = (uuid: string, ...path: string[]) => ({ params: Promise.resolve({ uuid, path }) });
|
|
|
|
beforeEach(() => {
|
|
mocks.callMobileApi.mockReset().mockResolvedValue({ ok: true, data: {} });
|
|
mocks.getToken.mockReset().mockResolvedValue("jwt");
|
|
});
|
|
|
|
describe("event ticket proxies", () => {
|
|
it("forward settings, types and order actions with the token", async () => {
|
|
await GET(req(), p("e1", "tickets", "settings"));
|
|
await PUT(req("http://localhost/x", { method: "PUT", body: '{"holdDays":3}' }), p("e1", "tickets", "settings"));
|
|
await POST(req("http://localhost/x", { method: "POST", body: '{"name":"General"}' }), p("e1", "ticket-types"));
|
|
await PUT(req("http://localhost/x", { method: "PUT", body: '{"name":"General"}' }), p("e1", "ticket-types", "2"));
|
|
await DELETE(req(), p("e1", "ticket-types", "2"));
|
|
await GET(req("http://localhost/x?status=PAID&q=ais&page=1&evil=1"), p("e1", "orders"));
|
|
await GET(req("http://localhost/x?status=PAID"), p("e1", "orders", "300"));
|
|
await POST(req("http://localhost/x", { method: "POST", body: '{"paymentRef":"MBB"}' }), p("e1", "orders", "300", "paid"));
|
|
await POST(req("http://localhost/x", { method: "POST" }), p("e1", "orders", "300", "tickets", "7", "cancel"));
|
|
expect(mocks.callMobileApi.mock.calls).toEqual([
|
|
["/api/admin/events/e1/tickets/settings", { token: "jwt" }],
|
|
["/api/admin/events/e1/tickets/settings", { method: "PUT", body: { holdDays: 3 }, token: "jwt" }],
|
|
["/api/admin/events/e1/ticket-types", { method: "POST", body: { name: "General" }, token: "jwt" }],
|
|
["/api/admin/events/e1/ticket-types/2", { method: "PUT", body: { name: "General" }, token: "jwt" }],
|
|
["/api/admin/events/e1/ticket-types/2", { method: "DELETE", token: "jwt" }],
|
|
["/api/admin/events/e1/orders?status=PAID&q=ais&page=1", { token: "jwt" }],
|
|
["/api/admin/events/e1/orders/300", { token: "jwt" }],
|
|
["/api/admin/events/e1/orders/300/paid", { method: "POST", body: { paymentRef: "MBB" }, token: "jwt" }],
|
|
["/api/admin/events/e1/orders/300/tickets/7/cancel", { method: "POST", body: {}, token: "jwt" }],
|
|
]);
|
|
});
|
|
|
|
it("refuse other ticket paths", async () => {
|
|
for (const path of [["tickets"], ["ticket-types", "x"], ["orders", "300", "refund"], ["orders", "x"]]) {
|
|
expect((await GET(req(), p("e1", ...path))).status).toBe(400);
|
|
}
|
|
expect(mocks.callMobileApi).not.toHaveBeenCalled();
|
|
});
|
|
});
|