- /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>
65 lines
3.9 KiB
TypeScript
65 lines
3.9 KiB
TypeScript
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 };
|
|
type Readiness = { score: number; checks: { key: string; ok: boolean; applies: boolean }[] };
|
|
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 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 v2<UserRow>(page, "admin", "GET", `/api/v2/users/${seed().retention.toWarn}`);
|
|
expect(warned.email).toBe("dormant@e2e.test");
|
|
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 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 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 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",
|
|
});
|
|
expect(breach.status).toBe("open");
|
|
|
|
await loginAs(page, "admin");
|
|
await page.goto("/dashboard/admin/privacy?tab=breaches");
|
|
await page.getByRole("button", { name: /Phone with the attendee list lost/ }).click();
|
|
await expect(page.getByText("Draft message to the people affected")).toBeVisible();
|
|
await expect(page.getByText("Personal information affected: Names and phone numbers of 40 campers")).toBeVisible();
|
|
await page.getByRole("button", { name: "Regulator told today" }).click();
|
|
await expect(page.getByRole("button", { name: "Regulator told today" })).toHaveCount(0);
|
|
|
|
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 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
|
|
|
|
await loginAs(page, "admin");
|
|
await page.goto("/dashboard/admin/privacy");
|
|
await expect(page.getByText("POPIA readiness")).toBeVisible();
|
|
await expect(page.getByText(`${r.score}%`)).toBeVisible();
|
|
});
|
|
});
|