The public /r/<code> page (no admin shell, never redirects a visitor to the staff login), its proxy sending only the last X-Forwarded-For hop, the event page's Registration QR card, a My QR codes page in the user menu, and the super-admin privacy notice editor on Companies. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
33 lines
1.6 KiB
TypeScript
33 lines
1.6 KiB
TypeScript
// @vitest-environment jsdom
|
|
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
|
import { getRegistration, submitRegistration } from "./publicRegistration";
|
|
import { ApiError } from "@/app/lib/clientApi";
|
|
|
|
const body = { name: "A", mobile: "", email: "a@b.co", companyName: "", jobTitle: "", interestIds: [], consent: true, website: "" };
|
|
|
|
describe("publicRegistration service", () => {
|
|
const originalLocation = window.location;
|
|
beforeEach(() => {
|
|
Object.defineProperty(window, "location", { value: { ...window.location, assign: vi.fn() }, writable: true, configurable: true });
|
|
});
|
|
afterEach(() => {
|
|
Object.defineProperty(window, "location", { value: originalLocation, writable: true, configurable: true });
|
|
vi.unstubAllGlobals();
|
|
});
|
|
|
|
it("never sends a visitor to the admin login on a 401", async () => {
|
|
vi.stubGlobal("fetch", vi.fn().mockImplementation(async () => new Response(JSON.stringify({ error: "Unauthorized" }), { status: 401 })));
|
|
await expect(getRegistration("t")).rejects.toMatchObject({ status: 401 });
|
|
await expect(submitRegistration("t", body)).rejects.toBeInstanceOf(ApiError);
|
|
expect(window.location.assign).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("posts JSON and returns the parsed body", async () => {
|
|
const f = vi.fn().mockResolvedValue(new Response(JSON.stringify({ eventName: "Expo" }), { status: 200 }));
|
|
vi.stubGlobal("fetch", f);
|
|
expect(await submitRegistration("a/b", body)).toEqual({ eventName: "Expo" });
|
|
expect(f.mock.calls[0][0]).toBe("/api/public/registration/a%2Fb");
|
|
expect(f.mock.calls[0][1].method).toBe("POST");
|
|
});
|
|
});
|