fac9b96cca
CI / build (push) Has been cancelled
Folders were an implementation detail leaking into the event workflow: every upload needed a folder first and photos were split across pages. Uploads now land in a single implicit "Photos" folder and the event page renders one gallery with the uploader and an edited-only download. 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
208 lines
8.1 KiB
TypeScript
208 lines
8.1 KiB
TypeScript
import { test, expect } from "@playwright/test";
|
|
import { signInAs, resetDb, BASE } from "./dev";
|
|
|
|
/**
|
|
* Growth goals, the mentor queue, retention, and the server-rendered booth
|
|
* sheet. These surfaces turn existing rules/data into screens, so the point of
|
|
* this suite is that a volunteer can ask, a coordinator can resolve, and the
|
|
* derived artifacts (sweep report, PDF) are really produced.
|
|
*/
|
|
test.describe("growth goals and maintenance", () => {
|
|
test.beforeAll(async ({ browser }) => {
|
|
const context = await browser.newContext();
|
|
const page = await context.newPage();
|
|
await resetDb(page);
|
|
await context.close();
|
|
});
|
|
|
|
test("volunteer requests a goal and admin resolves it in the mentor queue", async ({
|
|
page,
|
|
}) => {
|
|
await page.setViewportSize({ width: 1280, height: 1000 });
|
|
await signInAs(page, "jordan@glenloch.local");
|
|
await page.goto(`${BASE}/profile`);
|
|
|
|
await expect(page.getByText("Growth goals", { exact: true })).toBeVisible();
|
|
|
|
const skillSelect = page.getByLabel("Skill", { exact: true });
|
|
const audio = skillSelect
|
|
.locator("option")
|
|
.filter({ hasText: /^Audio/ })
|
|
.first();
|
|
const audioValue = await audio.getAttribute("value");
|
|
expect(audioValue, "the seed should include an Audio skill").toBeTruthy();
|
|
await skillSelect.selectOption(audioValue!);
|
|
await page.getByLabel("Target level").selectOption("expert");
|
|
await page.getByRole("button", { name: "Request goal" }).click();
|
|
|
|
await expect(
|
|
page.getByText("Goal requested. A coordinator will pair you with a mentor."),
|
|
).toBeVisible();
|
|
await expect(page.getByText("Waiting for a mentor")).toBeVisible();
|
|
|
|
// The coordinator sees the same goal and can act on it.
|
|
await signInAs(page, "admin@glenloch.local");
|
|
await page.goto(`${BASE}/admin`);
|
|
await expect(page.getByText("Mentor queue", { exact: true })).toBeVisible();
|
|
await expect(
|
|
page.getByText(/Jordan.*Audio/).first(),
|
|
).toBeVisible();
|
|
|
|
await page.getByRole("button", { name: "Decline" }).first().click();
|
|
// The confirmation toast is transient (the page refreshes immediately), so
|
|
// assert the durable outcome instead.
|
|
await expect(page.getByText("No open growth goals.")).toBeVisible();
|
|
|
|
// Persisted: the volunteer now sees the declined state, not a pending goal.
|
|
await signInAs(page, "jordan@glenloch.local");
|
|
await page.goto(`${BASE}/profile`);
|
|
await expect(page.getByText("Declined", { exact: true })).toBeVisible();
|
|
});
|
|
|
|
test("admin sees retention counts and can run the sweep", async ({ page }) => {
|
|
await page.setViewportSize({ width: 1280, height: 1000 });
|
|
await signInAs(page, "admin@glenloch.local");
|
|
await page.goto(`${BASE}/admin`);
|
|
|
|
await expect(page.getByText("Retention & storage", { exact: true })).toBeVisible();
|
|
await expect(page.getByText("Upload volume", { exact: true })).toBeVisible();
|
|
|
|
const before = await page.request.get(`${BASE}/api/dev/retention`);
|
|
expect(before.ok(), "retention summary should require and accept an admin").toBe(true);
|
|
const summary = (await before.json()) as {
|
|
summary: { notifications: { total: number }; thresholds: { notificationDays: number } };
|
|
};
|
|
expect(summary.summary.thresholds.notificationDays).toBeGreaterThan(0);
|
|
|
|
await page.getByRole("button", { name: "Prune now" }).click();
|
|
await expect(
|
|
page.getByText(/Removed \d+ notification rows|Sweep complete/),
|
|
).toBeVisible();
|
|
});
|
|
|
|
test("booth sheet downloads as a real PDF", async ({ page }) => {
|
|
await signInAs(page, "admin@glenloch.local");
|
|
|
|
const res = await page.request.get(`${BASE}/api/dev/schedule/instances`);
|
|
expect(res.ok()).toBe(true);
|
|
const body = (await res.json()) as { instances: { id: string }[] };
|
|
const instance = body.instances[0];
|
|
expect(instance, "the seed should include a service instance").toBeTruthy();
|
|
|
|
const pdf = await page.request.get(
|
|
`${BASE}/api/run-sheet/${instance.id}/pdf`,
|
|
);
|
|
expect(pdf.status()).toBe(200);
|
|
expect(pdf.headers()["content-type"]).toContain("application/pdf");
|
|
expect(pdf.headers()["content-disposition"]).toContain("booth-sheet");
|
|
const bytes = await pdf.body();
|
|
expect(bytes.subarray(0, 5).toString()).toBe("%PDF-");
|
|
expect(bytes.length).toBeGreaterThan(1000);
|
|
});
|
|
|
|
test("media uploads and editing stay blocked until media storage is set", async ({
|
|
page,
|
|
}) => {
|
|
await page.setViewportSize({ width: 1280, height: 1000 });
|
|
await signInAs(page, "admin@glenloch.local");
|
|
|
|
const archiveRoot = process.env.ARCHIVE_DIR ?? "/tmp/glenloch-e2e-archive";
|
|
// A writable path with no named share is not enough: the app must never
|
|
// fall back to storing event media inside the container.
|
|
const cleared = await page.request.put(`${BASE}/api/dev/storage`, {
|
|
data: { nfsShare: "", archivePath: archiveRoot, archiveFolder: "E2E Gate" },
|
|
});
|
|
expect(cleared.ok()).toBe(true);
|
|
|
|
const eventResponse = await page.request.post(`${BASE}/api/events`, {
|
|
data: {
|
|
title: "E2E storage gate",
|
|
eventType: "photoshoot",
|
|
startsAtLocal: "2026-11-22T10:00",
|
|
location: "Main campus",
|
|
},
|
|
});
|
|
expect(eventResponse.ok()).toBe(true);
|
|
const eventId = ((await eventResponse.json()) as { event: { id: string } })
|
|
.event.id;
|
|
const folderResponse = await page.request.post(
|
|
`${BASE}/api/events/${eventId}/folders`,
|
|
{ data: { name: "Originals", kind: "originals" } },
|
|
);
|
|
expect(folderResponse.ok()).toBe(true);
|
|
const folderId = (
|
|
(await folderResponse.json()) as { folder: { id: string } }
|
|
).folder.id;
|
|
|
|
const photo = await page.request.post(
|
|
`${BASE}/api/events/${eventId}/folders/${folderId}/photos?name=blocked.jpg`,
|
|
{
|
|
headers: { "content-type": "image/jpeg" },
|
|
data: Buffer.from([0xff, 0xd8, 0xff, 0xd9]),
|
|
},
|
|
);
|
|
expect(photo.status()).toBe(503);
|
|
expect(((await photo.json()) as { error: string }).error).toContain(
|
|
"No media storage share",
|
|
);
|
|
|
|
const video = await page.request.post(
|
|
`${BASE}/api/events/${eventId}/videos?name=blocked.mp4`,
|
|
{
|
|
headers: { "content-type": "video/mp4" },
|
|
data: Buffer.from("not-a-video"),
|
|
},
|
|
);
|
|
expect(video.status()).toBe(409);
|
|
expect(((await video.json()) as { error: string }).error).toContain(
|
|
"No media storage share",
|
|
);
|
|
|
|
await page.goto(`${BASE}/events/${eventId}`);
|
|
await expect(
|
|
page.getByText("Photo uploads and editing are disabled"),
|
|
).toBeVisible();
|
|
await expect(page.getByText("Photo and video uploads are disabled")).toBeVisible();
|
|
|
|
// A share name that reads like `host:/export` while the path is a local
|
|
// directory must block writes: media would silently land on local disk.
|
|
const mismatched = await page.request.put(`${BASE}/api/dev/storage`, {
|
|
data: {
|
|
nfsShare: "e2e-nas:/export/church",
|
|
archivePath: archiveRoot,
|
|
archiveFolder: "E2E Gate",
|
|
},
|
|
});
|
|
expect(mismatched.ok()).toBe(true);
|
|
const blockedAgain = await page.request.post(
|
|
`${BASE}/api/events/${eventId}/folders/${folderId}/photos?name=still-blocked.jpg`,
|
|
{
|
|
headers: { "content-type": "image/jpeg" },
|
|
data: Buffer.from([0xff, 0xd8, 0xff, 0xd9]),
|
|
},
|
|
);
|
|
expect(blockedAgain.status()).toBe(503);
|
|
expect(((await blockedAgain.json()) as { error: string }).error).toContain(
|
|
"not a network mount",
|
|
);
|
|
|
|
// Leave a working local-path destination behind for the specs that upload
|
|
// media; a path-style share is allowed to live on local disk.
|
|
const restored = await page.request.put(`${BASE}/api/dev/storage`, {
|
|
data: {
|
|
nfsShare: archiveRoot,
|
|
archivePath: archiveRoot,
|
|
archiveFolder: "E2E Archive",
|
|
},
|
|
});
|
|
expect(restored.ok()).toBe(true);
|
|
|
|
// With a usable local path the Media page reports the storage usage.
|
|
await page.goto(`${BASE}/media`);
|
|
await expect(
|
|
page.getByText("Original media storage", { exact: true }),
|
|
).toBeVisible();
|
|
await expect(page.getByText(/\bused of\b.*\bfree$/)).toBeVisible();
|
|
});
|
|
});
|