WIP 2.0.0: v1 removed; Argon2id passwords; node-fetch gone
- /api (v1) answers 410 API_V1_REMOVED, except provider webhooks (/api/webhooks/*, /api/whatsapp/webhook) and links in sent messages (308s, one-click POST). 43 v1 route files and deprecation.ts removed; /docs redirects to /docs/v2; API_DOCUMENTATION.md points there. - Read-only and impersonation lists name v2 paths only. The campus scope route test now runs over v2 routes (v2CampusScope.test.ts). - Passwords hashed with Argon2id (@node-rs/argon2); bcrypt hashes still sign in and are re-hashed at the next sign-in. - e2e on /api/v2 only (v2() helper); Playwright waits on /api/v2. - MIGRATING-TO-2.md with the full v1 -> v2 table. - Two documented response shapes corrected. Backend 690 tests and e2e 102/102 (PayFast sandbox skipped) pass. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { test, expect, seed, loginAs, api } from "./fixtures";
|
||||
import { test, expect, seed, loginAs, api, v2 } from "./fixtures";
|
||||
|
||||
type RunResult = { result: Record<string, Record<string, number>> };
|
||||
type UserRow = { name: string; email: string; isActive: boolean };
|
||||
@@ -7,32 +7,32 @@ type Breach = { id: string; status: string; regulatorNotifiedAt: string | null }
|
||||
|
||||
test.describe("retention, breaches and readiness (POPIA)", () => {
|
||||
test("the retention job warns inactive accounts first, and anonymises them 30 days after the warning", async ({ page }) => {
|
||||
const { result } = await api<RunResult>(page, "admin", "POST", "/api/privacy/retention/run");
|
||||
const { result } = await v2<RunResult>(page, "admin", "POST", "/api/v2/privacy/retention/run");
|
||||
expect(result.inactive_accounts.warned).toBeGreaterThanOrEqual(1);
|
||||
expect(result.inactive_accounts.anonymised).toBeGreaterThanOrEqual(1);
|
||||
expect(result.login_history.deleted).toBeGreaterThanOrEqual(1);
|
||||
|
||||
const warned = await api<UserRow>(page, "admin", "GET", `/api/users/${seed().retention.toWarn}`);
|
||||
const warned = await v2<UserRow>(page, "admin", "GET", `/api/v2/users/${seed().retention.toWarn}`);
|
||||
expect(warned.email).toBe("dormant@e2e.test");
|
||||
const gone = await api<UserRow>(page, "admin", "GET", `/api/users/${seed().retention.toAnonymise}`);
|
||||
const gone = await v2<UserRow>(page, "admin", "GET", `/api/v2/users/${seed().retention.toAnonymise}`);
|
||||
expect(gone.name).toBe("Deleted User");
|
||||
expect(gone.email).toMatch(/@deleted\.invalid$/);
|
||||
|
||||
// Seeded accounts (staff roles, and the recently active user) are untouched.
|
||||
expect((await api<UserRow>(page, "admin", "GET", `/api/users/${seed().users.user.id}`)).email).toBe("user@e2e.test");
|
||||
expect((await v2<UserRow>(page, "admin", "GET", `/api/v2/users/${seed().users.user.id}`)).email).toBe("user@e2e.test");
|
||||
});
|
||||
|
||||
test("retention periods are validated and saved; the notice follows them", async ({ page }) => {
|
||||
const state = await api<{ policies: Record<string, { enabled: boolean; months: number }> }>(page, "admin", "GET", "/api/privacy/retention");
|
||||
await expect(api(page, "admin", "PUT", "/api/privacy/retention", { policies: { ...state.policies, inactive_accounts: { enabled: true, months: 3 } } })).rejects.toThrow(/400/);
|
||||
await api(page, "admin", "PUT", "/api/privacy/retention", { policies: { ...state.policies, form_answers: { enabled: true, months: 18 } } });
|
||||
const state = await v2<{ policies: Record<string, { enabled: boolean; months: number }> }>(page, "admin", "GET", "/api/v2/privacy/retention");
|
||||
await expect(v2(page, "admin", "PUT", "/api/v2/privacy/retention", { policies: { ...state.policies, inactive_accounts: { enabled: true, months: 3 } } })).rejects.toThrow(/400/);
|
||||
await v2(page, "admin", "PUT", "/api/v2/privacy/retention", { policies: { ...state.policies, form_answers: { enabled: true, months: 18 } } });
|
||||
|
||||
await page.goto("/legal/privacy");
|
||||
await expect(page.getByText("Answers to event forms are deleted 18 months after the event.", { exact: false })).toBeVisible();
|
||||
});
|
||||
|
||||
test("a breach is recorded, reported, and drafts are ready to copy", async ({ page }) => {
|
||||
const breach = await api<Breach>(page, "admin", "POST", "/api/privacy/breaches", {
|
||||
const breach = await v2<Breach>(page, "admin", "POST", "/api/v2/privacy/breaches", {
|
||||
title: "Phone with the attendee list lost", discoveredAt: new Date().toISOString(),
|
||||
description: "A leader's phone was stolen at the camp site.", dataAffected: "Names and phone numbers of 40 campers",
|
||||
});
|
||||
@@ -46,12 +46,12 @@ test.describe("retention, breaches and readiness (POPIA)", () => {
|
||||
await page.getByRole("button", { name: "Regulator told today" }).click();
|
||||
await expect(page.getByRole("button", { name: "Regulator told today" })).toHaveCount(0);
|
||||
|
||||
const list = await api<Breach[]>(page, "admin", "GET", "/api/privacy/breaches");
|
||||
const list = await v2<Breach[]>(page, "admin", "GET", "/api/v2/privacy/breaches");
|
||||
expect(list.find(b => b.id === breach.id)?.regulatorNotifiedAt).toBeTruthy();
|
||||
});
|
||||
|
||||
test("the readiness page scores the install", async ({ page }) => {
|
||||
const r = await api<Readiness>(page, "admin", "GET", "/api/privacy/readiness");
|
||||
const r = await v2<Readiness>(page, "admin", "GET", "/api/v2/privacy/readiness");
|
||||
expect(r.score).toBeGreaterThan(0);
|
||||
expect(r.checks.find(c => c.key === "retention_reviewed")?.ok).toBe(true);
|
||||
expect(r.checks.find(c => c.key === "retention_running")?.ok).toBe(false); // jobs are off in e2e
|
||||
|
||||
Reference in New Issue
Block a user