Files
co-lite/solvway-admin-portal/app/api/registrationAdminRoutes.test.ts
T
ngqileandClaude Opus 5.5 08c45e9109 feat(portal): QR self-registration page, event QR card, My QR codes, privacy notice editor
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
2026-12-01 12:57:18 +08:00

44 lines
2.1 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 { GET as getLinks } from "./events/[uuid]/registration-links/route";
import { PUT as putLink } from "./events/[uuid]/registration-links/[token]/route";
import { GET as getMine } from "./my-registration-links/route";
import { GET as getNotice, PUT as putNotice } from "./companies/[id]/privacy-notice/route";
const req = (init?: RequestInit) => new Request("http://localhost/x", init) as never;
const p = <T,>(v: T) => ({ params: Promise.resolve(v) });
beforeEach(() => {
mocks.callMobileApi.mockReset().mockResolvedValue({ ok: true, data: { ok: 1 } });
mocks.getToken.mockReset().mockResolvedValue("jwt");
});
describe("registration admin proxies", () => {
it("require a session", async () => {
mocks.getToken.mockResolvedValue(null);
for (const res of [await getLinks(req(), p({ uuid: "e" })), await getMine(), await getNotice(req(), p({ id: "1" }))]) {
expect(res.status).toBe(401);
}
expect(mocks.callMobileApi).not.toHaveBeenCalled();
});
it("forward to the admin endpoints with the token", async () => {
await getLinks(req(), p({ uuid: "e1" }));
await putLink(req({ method: "PUT", body: '{"enabled":false}' }), p({ uuid: "e1", token: "t1" }));
await getMine();
await getNotice(req(), p({ id: "2" }));
await putNotice(req({ method: "PUT", body: '{"textEn":"a","textMs":"b"}' }), p({ id: "2" }));
expect(mocks.callMobileApi.mock.calls).toEqual([
["/api/admin/events/e1/registration-links", { token: "jwt" }],
["/api/admin/events/e1/registration-links/t1", { method: "PUT", body: { enabled: false }, token: "jwt" }],
["/api/admin/my-registration-links", { token: "jwt" }],
["/api/admin/companies/2/privacy-notice", { token: "jwt" }],
["/api/admin/companies/2/privacy-notice", { method: "PUT", body: { textEn: "a", textMs: "b" }, token: "jwt" }],
]);
});
});