Files
joshuaandClaude Opus 5.5 53797e4447 Feedback Send now and Remind run in the background (2.1.1)
- Send now and Remind answer straight away with who they're going to and
  queue the feedback-send task; the Feedback page refreshes to show progress.
- One-off background tasks (enqueueTask in src/jobs/index.js): pg-boss with
  retries, or in-process after the response when the queue is off.
- Reminders are claimed with the 24-hour rule, so two tasks at once never
  remind the same person twice.
- Tests: tests/tasks.test.js, tests/feedbackPage.test.ts, e2e/feedback.spec.ts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-03 14:11:44 +02:00

62 lines
3.4 KiB
TypeScript

import { test, expect, loginAs, api, v2, seed, API } from "./fixtures";
// 2.1.0: Supervisor → Feedback. The seed puts a named feedback form on "E2E Last Sunday", sent
// two days ago to Thandi (who answers here) and Lerato (who doesn't).
type PublicForm = { fields: { id: string; type: string }[] };
type AccessLog = { rows: { action: string; what: string; records: number | null; actor: string }[] };
test.describe("feedback page", () => {
test("see the answers, who hasn't answered, and remind them", async ({ page }) => {
const token = seed().feedback.tokens.user;
const form = await (await page.request.get(`${API}/api/v2/feedback-forms/${token}`)).json() as { data: PublicForm };
const [rating, text] = form.data.fields;
const sent = await page.request.post(`${API}/api/v2/feedback-forms/${token}`, {
headers: { "Content-Type": "application/json" },
data: JSON.stringify({ answers: { [rating.id]: 5, [text.id]: "Loved the worship" } }),
});
expect(sent.ok()).toBe(true);
await loginAs(page, "supervisor");
await page.goto("/dashboard/supervisor/feedback");
const row = page.getByRole("row", { name: /E2E Last Sunday/ });
await expect(row).toContainText("1 of 2");
await expect(row).toContainText("5.0");
await row.getByRole("button", { name: "E2E Last Sunday" }).click();
await expect(page.getByRole("heading", { name: "E2E Last Sunday" })).toBeVisible();
await expect(page.getByText("Loved the worship")).toBeVisible();
await expect(page.getByText("— Thandi Test")).toBeVisible();
await page.getByRole("tab", { name: /Responses/ }).click();
await expect(page.getByRole("article").filter({ hasText: "Thandi Test" })).toContainText("★★★★★");
await page.getByRole("tab", { name: /People/ }).click();
const lerato = page.getByRole("row", { name: /Lerato Late/ });
await expect(lerato).toContainText("Not yet");
await expect(page.getByRole("row", { name: /Thandi Test/ }).getByRole("button", { name: "Remind" })).toHaveCount(0);
page.once("dialog", d => d.accept());
await lerato.getByRole("button", { name: "Remind" }).click();
// 2.1.1: it answers straight away; the reminder goes out in the background and the page refreshes.
await expect(page.getByRole("status")).toHaveText("Reminding 1 person. It carries on in the background.");
await expect(lerato).toContainText("1 · last");
await expect(lerato.getByRole("button", { name: "Remind" })).toBeDisabled();
await expect(page.getByRole("button", { name: /Remind those who haven't answered/ })).toBeDisabled();
// Reminding again the same day sends nothing.
const again = await api<{ data: { reminded: number; message: string } }>(page, "supervisor", "POST", `/api/v2/events/${seed().events.past}/feedback/remind`, {});
expect(again.data.reminded).toBe(0);
expect(again.data.message).toMatch(/last 24 hours/);
// Opening a named form's answers is in the access log.
const log = await v2<AccessLog>(page, "admin", "GET", "/api/v2/privacy/access-log");
expect(log.rows.find(r => r.action === "feedback_responses")).toMatchObject({ what: "Feedback answers: E2E Last Sunday", records: 1, actor: "Sam Supervisor" });
});
test("staff can't see feedback", async ({ page }) => {
const res = await page.request.get(`${API}/api/v2/feedback`, { headers: { Authorization: `Bearer ${seed().users.staff.token}` } });
expect(res.status()).toBe(403);
});
});