forked from jappel/leistungsbilanz-ts
Harden user management integration
This commit is contained in:
parent
73579d1e79
commit
847f4e9493
18 changed files with 394 additions and 111 deletions
40
tests/write-request-headers.test.ts
Normal file
40
tests/write-request-headers.test.ts
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
import assert from "node:assert/strict";
|
||||
import { describe, it } from "node:test";
|
||||
import { authApi } from "../src/frontend/utils/auth-api.js";
|
||||
import { createProject } from "../src/frontend/utils/api.js";
|
||||
import { calculateCableSizing } from "../src/frontend/components/cable-sizing-api.js";
|
||||
import type { CableSizingInput } from "../src/cable-sizing/domain/cable-sizing-calculation.js";
|
||||
import {
|
||||
WRITE_REQUEST_HEADER_NAME,
|
||||
WRITE_REQUEST_HEADER_VALUE,
|
||||
} from "../src/shared/constants/request-security.js";
|
||||
|
||||
describe("write request clients", () => {
|
||||
it("send the application header from every frontend API client", async () => {
|
||||
const originalFetch = globalThis.fetch;
|
||||
const requests: RequestInit[] = [];
|
||||
globalThis.fetch = async (_input, init) => {
|
||||
requests.push(init ?? {});
|
||||
return new Response(JSON.stringify({}), {
|
||||
status: 200,
|
||||
headers: { "Content-Type": "application/json" },
|
||||
});
|
||||
};
|
||||
|
||||
try {
|
||||
await authApi.login("admin", "start-passwort");
|
||||
await createProject("Testprojekt");
|
||||
await calculateCableSizing({} as CableSizingInput);
|
||||
} finally {
|
||||
globalThis.fetch = originalFetch;
|
||||
}
|
||||
|
||||
assert.equal(requests.length, 3);
|
||||
for (const request of requests) {
|
||||
assert.equal(
|
||||
new Headers(request.headers).get(WRITE_REQUEST_HEADER_NAME),
|
||||
WRITE_REQUEST_HEADER_VALUE
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue