mega-plant/lib/intake-retry.test.ts
Dave 2594dead84 feat: add user access and improve plant dashboard
Add PocketBase login, first-sign-in password changes, account settings,
and user activation, reactivation and deletion with self-removal guards.
Protect application pages and APIs and keep private pages out of PWA
caches.

Resolve plant locations from site assignments and improve map controls,
profit chart views, navigation and mobile table layouts.

Validation: production build and TypeScript passed; 28 unit tests passed.
Backend access integration tests and mobile verification are documented.
2026-10-06 04:02:08 +02:00

20 lines
1.2 KiB
TypeScript

import { test } from "node:test";
import assert from "node:assert/strict";
import { canReplaceRetrySource, intakeRetryHeaders } from "./intake-retry";
test("invoice retry retains source PDF after auth, duplicate, transport or malformed responses", () => {
for (const status of [400, 401, 403, 409, 500, 503]) assert.equal(canReplaceRetrySource(status, { ok: false }), false);
assert.equal(canReplaceRetrySource(422, { ok: false, status: "failed" }), false);
assert.equal(canReplaceRetrySource(422, { ok: false, status: "failed", intakeId: "bad" }), false);
assert.equal(canReplaceRetrySource(200, { ok: true }), true);
assert.equal(canReplaceRetrySource(422, { ok: false, status: "failed", intakeId: "abcdefghijklmno" }), true);
});
test("internal invoice retry forwards user session and origin to the intake endpoint", () => {
const request = new Request("http://localhost:6007/api/invoices/intake/source/retry", {
method: "POST", headers: { Cookie: "mega_session=temporary-test-token", Origin: "http://localhost:6007" },
});
const headers = intakeRetryHeaders(request);
assert.equal(headers.get("cookie"), "mega_session=temporary-test-token");
assert.equal(headers.get("origin"), "http://localhost:6007");
});