feat(results): save results as PDF automatically on the server and ask to print when the finals are done (1.89.28)

This commit is contained in:
larssand committed 2026-11-14 15:58:23 +01:00
1 parent ae829123cc
commit e98abd92d9
16 files changed
+253 -6

No files matched your search

@@ -567,6 +567,35 @@ test("PDF export renders Swedish åäö/ÅÄÖ correctly instead of mojibake", {
}
});
test("autopilot print: a result PDF is saved on the server, listed and served, a newer one overwrites it", { timeout: 20000 }, async () => {
const dataDir = mkdtempSync(join(tmpdir(), "live-rc-test-autosave-"));
const port = await reservePort();
const baseUrl = `http://127.0.0.1:${port}`;
const child = spawn(process.execPath, [join(projectRoot, "server.js")], {
cwd: projectRoot,
env: { ...process.env, HOST: "127.0.0.1", PORT: String(port), RC_TIMING_DATA_DIR: dataDir, RC_TIMING_PID_FILE: "" },
stdio: ["ignore", "pipe", "pipe"],
});
try {
await waitForServer(child);
const save = (rows) => fetch(`${baseUrl}/api/results/autosave`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ date: "2026-11-14", title: "Klubbrace", filename: "Klubbrace_åäö_A_final_1.pdf", sections: [{ title: "A final 1", headers: ["Pos", "Förare"], rows }] }) });
const first = await (await save([["1", "Roy"]])).json();
assert.deepEqual(first, { ok: true, date: "2026-11-14", name: "Klubbrace_aao_A_final_1.pdf" });
await save([["1", "Anders"]]);
const { files } = await (await fetch(`${baseUrl}/api/results/saved`)).json();
assert.equal(files.length, 1, "the newer version overwrote the old one");
const pdf = await fetch(`${baseUrl}/api/results/saved/2026-11-14/Klubbrace_aao_A_final_1.pdf`);
assert.equal(pdf.headers.get("content-type"), "application/pdf");
assert.ok(Buffer.from(await pdf.arrayBuffer()).toString("latin1").includes("Anders"));
assert.ok(existsSync(join(dataDir, "results", "2026-11-14", "Klubbrace_aao_A_final_1.pdf")));
assert.equal((await fetch(`${baseUrl}/api/results/saved/2026-11-14/..%2F..%2Frc_timing.sqlite`)).status, 404, "no way out of the results folder");
assert.equal((await fetch(`${baseUrl}/api/results/saved/x/a.pdf`)).status, 404);
} finally {
await stopServer(child);
rmSync(dataDir, { recursive: true, force: true });
}
});
test("an admin PIN blocks unauthenticated writes, and the login cookie lets them through", { timeout: 20000 }, async () => {
const dataDir = mkdtempSync(join(tmpdir(), "live-rc-test-auth-"));
const port = await reservePort();