- scripts/products/events.sh: packages/auth-client is installed and built (after contracts) when Events uses it, as 3.0.0 does; without it a 3.0 deploy would fail at the first sign-in through Accounts. bats test. - test:accounts runs on real Postgres for both apps with EVENTS_TEST_DATABASE_URL and ACCOUNTS_TEST_DATABASE_URL (14/14); the Accounts test harness takes a real Prisma client. - e2e/excel.spec.ts resolves excelts from the backend (hoisted in the monorepo), so the e2e suite loads again. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
49 lines
2.2 KiB
TypeScript
49 lines
2.2 KiB
TypeScript
import path from "path";
|
||
import { test, expect, seed, API } from "./fixtures";
|
||
|
||
// Excel exports (ExcelTS since 1.51.6): a styled report and the attendance register come back as
|
||
// real workbooks that open and hold what was asked for.
|
||
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
||
const { Workbook } = require(require.resolve("@cj-tech-master/excelts", { paths: [path.join(__dirname, "..", "backend")] }));
|
||
|
||
const XLSX = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
|
||
|
||
async function open(body: Buffer) {
|
||
const wb = new Workbook();
|
||
await wb.xlsx.load(body);
|
||
return wb;
|
||
}
|
||
|
||
test.describe("Excel exports", () => {
|
||
test("a report with stats, a chart and a table", async ({ request }) => {
|
||
const res = await request.post(`${API}/api/v2/reports/excel`, {
|
||
headers: { Authorization: `Bearer ${seed().users.supervisor.token}` },
|
||
data: {
|
||
title: "E2E Payments",
|
||
kind: "table",
|
||
subtitle: "1–31 October",
|
||
stats: [{ label: "Total", value: "R 1 200.00" }],
|
||
chart: { title: "By method", data: [{ label: "Card", value: 900 }, { label: "Cash", value: 300 }] },
|
||
table: { columns: ["Name", "Amount"], rows: [["Thandi", "R 600.00"], ["Sipho", "R 600.00"]] },
|
||
},
|
||
});
|
||
expect(res.status()).toBe(200);
|
||
expect(res.headers()["content-type"]).toContain(XLSX);
|
||
const ws = (await open(await res.body())).worksheets[0];
|
||
const values: string[] = [];
|
||
ws.eachRow((row: { values: unknown[] }) => values.push(...row.values.filter(Boolean).map(String)));
|
||
expect(values).toEqual(expect.arrayContaining(["E2E Payments", "Total", "Card", "Thandi", "Sipho"]));
|
||
});
|
||
|
||
test("the attendance register", async ({ request }) => {
|
||
const res = await request.get(`${API}/api/v2/events/${seed().events.course}/attendance/export?format=xlsx`, {
|
||
headers: { Authorization: `Bearer ${seed().users.supervisor.token}` },
|
||
});
|
||
expect(res.status()).toBe(200);
|
||
expect(res.headers()["content-type"]).toContain(XLSX);
|
||
const ws = (await open(await res.body())).getWorksheet("Attendance");
|
||
expect(ws.getRow(1).getCell(1).value).toBe("Name");
|
||
expect(ws.rowCount).toBeGreaterThan(1);
|
||
});
|
||
});
|