forked from jappel/leistungsbilanz-ts
40 lines
1.4 KiB
TypeScript
40 lines
1.4 KiB
TypeScript
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
|
|
);
|
|
}
|
|
});
|
|
});
|