Refresh HiveGrid Cloud reference snapshot
This commit is contained in:
1 parent
5e99e14772
commit
7f88026f79
5955 files changed
+1177325
-188362
No files matched your search
+662
@@ -0,0 +1,662 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
import {
|
||||
assertKwpReadOperationAllowed,
|
||||
buildKwpSemanticContract,
|
||||
createKwpResourceTransport,
|
||||
KWP_ADDRESS_DETAILS_PATH,
|
||||
KWP_PROJECT_CATALOG_PATH,
|
||||
KWP_PROJECT_DETAILS_PATH,
|
||||
KWP_PROJECT_SEARCH_PATH,
|
||||
} from "./resource-client.js";
|
||||
import { KWP_OIDC_ISSUER, KWP_REQUIRED_OAUTH_SCOPES, type KwpCredentials, type KwpOutboundRequestOptions } from "./client.js";
|
||||
import { KWP_SCOPED_OPERATIONS } from "./scoped-contract.js";
|
||||
|
||||
const CREDENTIALS: KwpCredentials = {
|
||||
accessToken: "access-secret",
|
||||
refreshToken: "refresh-secret",
|
||||
expiresAt: "2026-07-23T12:00:00.000Z",
|
||||
issuer: KWP_OIDC_ISSUER,
|
||||
clientId: "_extern-geerkens2",
|
||||
clientSecret: "client-secret",
|
||||
customerCode: "geerkens2",
|
||||
scopes: [...KWP_REQUIRED_OAUTH_SCOPES],
|
||||
mandantBinding: { kind: "selected", code: "mandant1" },
|
||||
};
|
||||
|
||||
const PUBLIC_ADDRESS_RESOLVER = async (): Promise<readonly string[]> => ["93.184.216.34"];
|
||||
|
||||
describe("KWP project resource transport", () => {
|
||||
it("executes only targeted search and normalizes the consumed fields", async () => {
|
||||
const fetchMock = vi
|
||||
.fn()
|
||||
.mockResolvedValueOnce(new Response("https://geerkens2.app04.kwp-online.de"))
|
||||
.mockResolvedValueOnce(
|
||||
jsonResponse([
|
||||
{
|
||||
projNr: " P-100 ",
|
||||
projBezeichnung: " Heizung Schule ",
|
||||
projAdr: "ADR-1",
|
||||
rechAdr: "ADR-2",
|
||||
bauHrAdr: "ADR-3",
|
||||
auftragStatus: 8,
|
||||
},
|
||||
])
|
||||
);
|
||||
const consumeBudget = vi.fn().mockResolvedValue(undefined);
|
||||
const resource = createKwpResourceTransport(CREDENTIALS, {
|
||||
consumeBudget,
|
||||
outboundOptions: outboundOptions(fetchMock),
|
||||
});
|
||||
|
||||
await expect(resource.searchProjects(" Schule ")).resolves.toEqual([
|
||||
{
|
||||
externalProjectNumber: "P-100",
|
||||
name: "Heizung Schule",
|
||||
projectAddressCode: "ADR-1",
|
||||
invoiceAddressCode: "ADR-2",
|
||||
clientAddressCode: "ADR-3",
|
||||
status: 8,
|
||||
statusLabel: "Erhalten",
|
||||
},
|
||||
]);
|
||||
|
||||
expect(consumeBudget).toHaveBeenCalledTimes(2);
|
||||
const [url, init] = fetchMock.mock.calls[1] as [string, RequestInit];
|
||||
expect(new URL(url).pathname).toBe(`/relay/geerkens2/pwa${KWP_PROJECT_SEARCH_PATH}`);
|
||||
expect(new URL(url).searchParams.get("mandant")).toBe("mandant1");
|
||||
expect(init.method).toBe("POST");
|
||||
expect(JSON.parse(String(init.body))).toEqual({ value: "Schule" });
|
||||
});
|
||||
|
||||
it("skips search rows without the optional routing status while keeping routable results available", async () => {
|
||||
const fetchMock = vi
|
||||
.fn()
|
||||
.mockResolvedValueOnce(new Response("https://geerkens2.app04.kwp-online.de"))
|
||||
.mockResolvedValueOnce(
|
||||
jsonResponse([
|
||||
{
|
||||
projNr: "P-NO-STATUS",
|
||||
projBezeichnung: "Noch nicht routbar",
|
||||
},
|
||||
{
|
||||
projNr: "P-ROUTABLE",
|
||||
projBezeichnung: "Routbares Projekt",
|
||||
auftragStatus: 7,
|
||||
},
|
||||
])
|
||||
);
|
||||
const resource = createKwpResourceTransport(CREDENTIALS, {
|
||||
consumeBudget: async () => undefined,
|
||||
outboundOptions: outboundOptions(fetchMock),
|
||||
});
|
||||
|
||||
await expect(resource.searchProjects("Projekt")).resolves.toEqual([
|
||||
{
|
||||
externalProjectNumber: "P-ROUTABLE",
|
||||
name: "Routbares Projekt",
|
||||
projectAddressCode: null,
|
||||
invoiceAddressCode: null,
|
||||
clientAddressCode: null,
|
||||
status: 7,
|
||||
statusLabel: "Zugesagt",
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it("discovers the setting-visible project catalog without an empty search", async () => {
|
||||
const fetchMock = vi
|
||||
.fn()
|
||||
.mockResolvedValueOnce(new Response("https://geerkens2.app04.kwp-online.de"))
|
||||
.mockResolvedValueOnce(
|
||||
jsonResponse([
|
||||
{ projNr: " P-100 ", anzahlAktivitaeten: 3 },
|
||||
{ projNr: "P-200", anzahlAktivitaeten: 0 },
|
||||
{ projNr: "P-100", anzahlAktivitaeten: 4 },
|
||||
{ projNr: null, anzahlAktivitaeten: 0 },
|
||||
])
|
||||
);
|
||||
const resource = createKwpResourceTransport(CREDENTIALS, {
|
||||
consumeBudget: async () => undefined,
|
||||
outboundOptions: outboundOptions(fetchMock),
|
||||
});
|
||||
|
||||
await expect(resource.listProjectNumbers()).resolves.toEqual(["P-100", "P-200"]);
|
||||
const [url, init] = fetchMock.mock.calls[1] as [string, RequestInit];
|
||||
expect(new URL(url).pathname).toBe(`/relay/geerkens2/pwa${KWP_PROJECT_CATALOG_PATH}`);
|
||||
expect(new URL(url).searchParams.get("mandant")).toBe("mandant1");
|
||||
expect(init.method).toBe("GET");
|
||||
expect(init.body).toBeUndefined();
|
||||
});
|
||||
|
||||
it("still rejects a present search status outside the consumed KWP enum", async () => {
|
||||
const fetchMock = vi
|
||||
.fn()
|
||||
.mockResolvedValueOnce(new Response("https://geerkens2.app04.kwp-online.de"))
|
||||
.mockResolvedValueOnce(
|
||||
jsonResponse([
|
||||
{
|
||||
projNr: "P-INVALID-STATUS",
|
||||
projBezeichnung: "Ungültiger Status",
|
||||
auftragStatus: 10,
|
||||
},
|
||||
])
|
||||
);
|
||||
const resource = createKwpResourceTransport(CREDENTIALS, {
|
||||
consumeBudget: async () => undefined,
|
||||
outboundOptions: outboundOptions(fetchMock),
|
||||
});
|
||||
|
||||
await expect(resource.searchProjects("Projekt")).rejects.toMatchObject({
|
||||
code: "contract_drift",
|
||||
});
|
||||
});
|
||||
|
||||
it("accepts omitted optional fields from live project and address responses", async () => {
|
||||
const detailsFetch = vi
|
||||
.fn()
|
||||
.mockResolvedValueOnce(new Response("https://geerkens2.app04.kwp-online.de"))
|
||||
.mockResolvedValueOnce(
|
||||
jsonResponse({
|
||||
projNr: "P-100",
|
||||
projBezeichnung: "Heizung Schule",
|
||||
adresse: {
|
||||
adrNrGes: "ADR-1",
|
||||
name: "Schule",
|
||||
zusatz: "Altbau",
|
||||
strasse: "Dorfstraße 1",
|
||||
ort: { ortId: 1, plz: "12345", ort: "Berlin" },
|
||||
},
|
||||
auftragssumme: 42_500,
|
||||
})
|
||||
);
|
||||
const detailsResource = createKwpResourceTransport(CREDENTIALS, {
|
||||
consumeBudget: async () => undefined,
|
||||
outboundOptions: outboundOptions(detailsFetch),
|
||||
});
|
||||
|
||||
await expect(detailsResource.loadProjectDetails("P-100")).resolves.toEqual({
|
||||
externalProjectNumber: "P-100",
|
||||
name: "Heizung Schule",
|
||||
startDate: null,
|
||||
orderValue: 42_500,
|
||||
addressCode: "ADR-1",
|
||||
addressName: "Schule",
|
||||
});
|
||||
|
||||
const addressFetch = vi
|
||||
.fn()
|
||||
.mockResolvedValueOnce(new Response("https://geerkens2.app04.kwp-online.de"))
|
||||
.mockResolvedValueOnce(
|
||||
jsonResponse({
|
||||
adrNrGes: "ADR-1",
|
||||
name: "Schule",
|
||||
zusatz: "Altbau",
|
||||
strasse: "Dorfstraße 1",
|
||||
ort: { ortId: 1, plz: "12345", ort: "Berlin" },
|
||||
// Real KWP tenants return null for these documented object fields.
|
||||
// They are not consumed by project import and must not create a
|
||||
// capability-wide false-positive contract pause.
|
||||
ortPstf: null,
|
||||
briefanrede: null,
|
||||
selekt1: null,
|
||||
selekt2: null,
|
||||
bank: null,
|
||||
kontakte: [
|
||||
{
|
||||
kontaktId: 1,
|
||||
kontaktart: 2,
|
||||
kontakt: "info@example.test",
|
||||
kontaktartTyp: 0,
|
||||
kontaktName: "E-Mail",
|
||||
ansprechpartnerId: null,
|
||||
},
|
||||
],
|
||||
ansprechpartner: [],
|
||||
})
|
||||
);
|
||||
const addressResource = createKwpResourceTransport(CREDENTIALS, {
|
||||
consumeBudget: async () => undefined,
|
||||
outboundOptions: outboundOptions(addressFetch),
|
||||
});
|
||||
|
||||
await expect(addressResource.loadAddressDetails("ADR-1")).resolves.toMatchObject({
|
||||
externalAddressCode: "ADR-1",
|
||||
firstName: null,
|
||||
country: null,
|
||||
invoiceEmail: null,
|
||||
email: "info@example.test",
|
||||
contactPeople: [],
|
||||
});
|
||||
});
|
||||
|
||||
it("still rejects an invalid consumed address field while ignoring unconsumed nullable drift", async () => {
|
||||
const fetchMock = vi
|
||||
.fn()
|
||||
.mockResolvedValueOnce(new Response("https://geerkens2.app04.kwp-online.de"))
|
||||
.mockResolvedValueOnce(
|
||||
jsonResponse({
|
||||
adrNrGes: "ADR-1",
|
||||
name: "Schule",
|
||||
ortPstf: null,
|
||||
briefanrede: null,
|
||||
selekt1: null,
|
||||
selekt2: null,
|
||||
bank: null,
|
||||
kontakte: [{ kontaktart: 99, kontakt: "invalid@example.test", ansprechpartnerId: null }],
|
||||
})
|
||||
);
|
||||
const resource = createKwpResourceTransport(CREDENTIALS, {
|
||||
consumeBudget: async () => undefined,
|
||||
outboundOptions: outboundOptions(fetchMock),
|
||||
});
|
||||
|
||||
await expect(resource.loadAddressDetails("ADR-1")).rejects.toMatchObject({
|
||||
code: "contract_drift",
|
||||
});
|
||||
});
|
||||
|
||||
it("rejects empty or one-character search without provider I/O", async () => {
|
||||
const fetchMock = vi.fn();
|
||||
const consumeBudget = vi.fn();
|
||||
const resource = createKwpResourceTransport(CREDENTIALS, {
|
||||
consumeBudget,
|
||||
outboundOptions: outboundOptions(fetchMock),
|
||||
});
|
||||
|
||||
await expect(resource.searchProjects(" ")).rejects.toMatchObject({ code: "invalid_credentials" });
|
||||
await expect(resource.searchProjects("x")).rejects.toMatchObject({ code: "invalid_credentials" });
|
||||
expect(consumeBudget).not.toHaveBeenCalled();
|
||||
expect(fetchMock).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("loads project details by GET and detects a renamed consumed field", async () => {
|
||||
const validFetch = vi
|
||||
.fn()
|
||||
.mockResolvedValueOnce(new Response("https://geerkens2.app04.kwp-online.de"))
|
||||
.mockResolvedValueOnce(
|
||||
jsonResponse({
|
||||
projNr: "P-100",
|
||||
projBezeichnung: "Heizung Schule",
|
||||
beginn: "2026-07-01T00:00:00+02:00",
|
||||
adresse: {
|
||||
adrNrGes: "ADR-1",
|
||||
name: "Schule",
|
||||
vorname: null,
|
||||
zusatz: null,
|
||||
strasse: "Dorfstraße 1",
|
||||
ort: { ortId: 1, land: "DE", plz: "12345", ort: "Berlin" },
|
||||
debitKreditNr: 987654,
|
||||
},
|
||||
sachBearb: null,
|
||||
vertrieb: null,
|
||||
auftragssumme: 42_500,
|
||||
})
|
||||
);
|
||||
const validResource = createKwpResourceTransport(CREDENTIALS, {
|
||||
consumeBudget: async () => undefined,
|
||||
outboundOptions: outboundOptions(validFetch),
|
||||
});
|
||||
|
||||
await expect(validResource.loadProjectDetails("P-100")).resolves.toEqual({
|
||||
externalProjectNumber: "P-100",
|
||||
name: "Heizung Schule",
|
||||
startDate: "2026-06-30T22:00:00.000Z",
|
||||
orderValue: 42_500,
|
||||
addressCode: "ADR-1",
|
||||
addressName: "Schule",
|
||||
});
|
||||
const [url, init] = validFetch.mock.calls[1] as [string, RequestInit];
|
||||
expect(new URL(url).pathname).toBe(`/relay/geerkens2/pwa${KWP_PROJECT_DETAILS_PATH}`);
|
||||
expect(new URL(url).searchParams.get("projNr")).toBe("P-100");
|
||||
expect(init.method).toBe("GET");
|
||||
expect(init.body).toBeUndefined();
|
||||
|
||||
const driftFetch = vi
|
||||
.fn()
|
||||
.mockResolvedValueOnce(new Response("https://geerkens2.app04.kwp-online.de"))
|
||||
.mockResolvedValueOnce(
|
||||
jsonResponse({
|
||||
projektNummer: "P-100",
|
||||
projBezeichnung: "Heizung Schule",
|
||||
beginn: null,
|
||||
adresse: { adrNrGes: null, name: null, vorname: null, zusatz: null, strasse: null, ort: { ortId: 1, land: null, plz: null, ort: null } },
|
||||
sachBearb: null,
|
||||
vertrieb: null,
|
||||
auftragssumme: null,
|
||||
})
|
||||
);
|
||||
const driftResource = createKwpResourceTransport(CREDENTIALS, {
|
||||
consumeBudget: async () => undefined,
|
||||
outboundOptions: outboundOptions(driftFetch),
|
||||
});
|
||||
await expect(driftResource.loadProjectDetails("P-100")).rejects.toMatchObject({ code: "contract_drift" });
|
||||
});
|
||||
|
||||
it("discards prohibited financial, tax, birthday, note and user fields", async () => {
|
||||
const fetchMock = vi
|
||||
.fn()
|
||||
.mockResolvedValueOnce(new Response("https://geerkens2.app04.kwp-online.de"))
|
||||
.mockResolvedValueOnce(
|
||||
jsonResponse({
|
||||
adrNrGes: "ADR-1",
|
||||
name: "Geerkens GmbH",
|
||||
vorname: null,
|
||||
zusatz: "Niederlassung",
|
||||
strasse: "Werkstraße 7",
|
||||
ort: { ortId: 1, land: "DE", plz: "52511", ort: "Geilenkirchen" },
|
||||
rechnungsmailadresse: "rechnung@example.test",
|
||||
kontakte: [
|
||||
{ kontaktId: 1, kontaktart: 2, kontakt: "info@example.test", kontaktName: "E-Mail", bemerkung: "secret", ansprechpartnerId: null },
|
||||
{ kontaktId: 2, kontaktart: 0, kontakt: "+49 123", kontaktName: "Telefon", bemerkung: null, ansprechpartnerId: null },
|
||||
],
|
||||
ansprechpartner: [
|
||||
{
|
||||
nachname: "Muster",
|
||||
vorname: "Maria",
|
||||
ansprechpartnerId: 99,
|
||||
zusatz: null,
|
||||
geburtstag: "1980-01-01T00:00:00Z",
|
||||
benutzerFeld1: "never-store",
|
||||
bemerkung: "internal",
|
||||
kontakte: [{ kontaktId: 3, kontaktart: 2, kontakt: "maria@example.test", kontaktName: "E-Mail", bemerkung: null, ansprechpartnerId: 99 }],
|
||||
},
|
||||
],
|
||||
iban: "DE001234",
|
||||
bank: { bezeichnung: "Secret Bank" },
|
||||
kreditLimit: 100_000,
|
||||
ustId: "DE123",
|
||||
hinweis: "internal",
|
||||
benutzerFeld1: "never-store",
|
||||
})
|
||||
);
|
||||
const resource = createKwpResourceTransport(CREDENTIALS, {
|
||||
consumeBudget: async () => undefined,
|
||||
outboundOptions: outboundOptions(fetchMock),
|
||||
});
|
||||
|
||||
const address = await resource.loadAddressDetails("ADR-1");
|
||||
expect(address).toMatchObject({
|
||||
externalAddressCode: "ADR-1",
|
||||
name: "Geerkens GmbH",
|
||||
invoiceEmail: "rechnung@example.test",
|
||||
email: "info@example.test",
|
||||
phone: "+49 123",
|
||||
contactPeople: [
|
||||
{
|
||||
externalContactId: "99",
|
||||
firstName: "Maria",
|
||||
lastName: "Muster",
|
||||
email: "maria@example.test",
|
||||
},
|
||||
],
|
||||
});
|
||||
const persisted = JSON.stringify(address).toLowerCase();
|
||||
for (const prohibited of [
|
||||
'"iban"',
|
||||
'"bank"',
|
||||
'"kreditlimit"',
|
||||
'"ustid"',
|
||||
'"geburtstag"',
|
||||
'"hinweis"',
|
||||
'"benutzerfeld1"',
|
||||
'"bemerkung"',
|
||||
"de001234",
|
||||
"never-store",
|
||||
]) {
|
||||
expect(persisted).not.toContain(prohibited.toLowerCase());
|
||||
}
|
||||
expect(new URL(String(fetchMock.mock.calls[1]?.[0])).pathname).toBe(`/relay/geerkens2/pwa${KWP_ADDRESS_DETAILS_PATH}`);
|
||||
});
|
||||
|
||||
it("blocks every KWP write or non-allowlisted read before transport", () => {
|
||||
for (const operation of KWP_SCOPED_OPERATIONS) {
|
||||
const assertion = () => assertKwpReadOperationAllowed(operation.method, operation.path);
|
||||
if (operation.mode === "read") expect(assertion).not.toThrow();
|
||||
else expect(assertion).toThrow();
|
||||
}
|
||||
expect(() => assertKwpReadOperationAllowed("GET", "/api/Core/GetApiVersion")).toThrow();
|
||||
expect(() => assertKwpReadOperationAllowed("GET", KWP_PROJECT_DETAILS_PATH)).not.toThrow();
|
||||
});
|
||||
|
||||
it("executes exact generic GET and read-POST operation ids without exposing a free path", async () => {
|
||||
const fetchMock = vi
|
||||
.fn()
|
||||
.mockResolvedValueOnce(new Response("https://geerkens2.app04.kwp-online.de"))
|
||||
.mockResolvedValueOnce(jsonResponse({}))
|
||||
.mockResolvedValueOnce(new Response("https://geerkens2.app04.kwp-online.de"))
|
||||
.mockResolvedValueOnce(jsonResponse([]));
|
||||
const resource = createKwpResourceTransport(CREDENTIALS, {
|
||||
consumeBudget: async () => undefined,
|
||||
outboundOptions: outboundOptions(fetchMock),
|
||||
});
|
||||
|
||||
await expect(resource.executeReadOperation("monteursteuerungGetSetup")).resolves.toEqual({});
|
||||
await expect(resource.executeReadOperation("vorgangAnzeigeLoadPositionen", { body: {} })).resolves.toEqual([]);
|
||||
|
||||
const getUrl = new URL(String(fetchMock.mock.calls[1]?.[0]));
|
||||
expect(getUrl.pathname).toBe("/relay/geerkens2/pwa/api/Monteursteuerung/GetSetup");
|
||||
expect(getUrl.searchParams.get("mandant")).toBe("mandant1");
|
||||
expect((fetchMock.mock.calls[1]?.[1] as RequestInit).method).toBe("GET");
|
||||
const postUrl = new URL(String(fetchMock.mock.calls[3]?.[0]));
|
||||
expect(postUrl.pathname).toBe("/relay/geerkens2/pwa/api/VorgangAnzeige/LoadPositionen");
|
||||
expect(postUrl.searchParams.get("mandant")).toBe("mandant1");
|
||||
expect((fetchMock.mock.calls[3]?.[1] as RequestInit).method).toBe("POST");
|
||||
expect(JSON.parse(String((fetchMock.mock.calls[3]?.[1] as RequestInit).body))).toEqual({});
|
||||
});
|
||||
|
||||
it("fails closed for an unconfirmed mandant and classifies 403 without exposing the provider body", async () => {
|
||||
const { mandantBinding: _binding, ...unconfirmed } = CREDENTIALS;
|
||||
expect(() =>
|
||||
createKwpResourceTransport(unconfirmed, {
|
||||
consumeBudget: async () => undefined,
|
||||
})
|
||||
).toThrowError(expect.objectContaining({ code: "mandant_unconfirmed" }));
|
||||
|
||||
const fetchMock = vi
|
||||
.fn()
|
||||
.mockResolvedValueOnce(new Response("https://geerkens2.app04.kwp-online.de"))
|
||||
.mockResolvedValueOnce(jsonResponse({ token: CREDENTIALS.accessToken }, 403));
|
||||
const resource = createKwpResourceTransport(CREDENTIALS, {
|
||||
consumeBudget: async () => undefined,
|
||||
outboundOptions: outboundOptions(fetchMock),
|
||||
});
|
||||
const error = await resource.searchProjects("Projekt").catch((caught: unknown) => caught);
|
||||
expect(error).toMatchObject({ code: "auth_scope_missing", httpStatus: 403 });
|
||||
expect(JSON.stringify(error)).not.toContain(CREDENTIALS.accessToken);
|
||||
});
|
||||
|
||||
it.each([
|
||||
[401, "auth_token_invalid"],
|
||||
[429, "rate_limit_exceeded"],
|
||||
[503, "provider_outage"],
|
||||
])("classifies HTTP %i without hidden refresh or request retry", async (status, code) => {
|
||||
const fetchMock = vi
|
||||
.fn()
|
||||
.mockResolvedValueOnce(new Response("https://geerkens2.app04.kwp-online.de"))
|
||||
.mockResolvedValueOnce(jsonResponse({ token: CREDENTIALS.accessToken }, status));
|
||||
const resource = createKwpResourceTransport(CREDENTIALS, {
|
||||
consumeBudget: async () => undefined,
|
||||
outboundOptions: outboundOptions(fetchMock),
|
||||
});
|
||||
|
||||
await expect(resource.searchProjects("Projekt")).rejects.toMatchObject({
|
||||
code,
|
||||
httpStatus: status,
|
||||
});
|
||||
expect(fetchMock).toHaveBeenCalledTimes(2);
|
||||
expect(JSON.stringify(fetchMock.mock.results)).not.toContain(CREDENTIALS.refreshToken);
|
||||
});
|
||||
|
||||
it("fingerprints only the consumed semantic OpenAPI slice", () => {
|
||||
const base = openApiFixture();
|
||||
const first = buildKwpSemanticContract(base);
|
||||
const unrelated = structuredClone(base);
|
||||
unrelated.paths["/api/Unrelated/Save"] = { post: { responses: { 200: {} } } };
|
||||
unrelated.components.schemas.Unrelated = { type: "object", properties: { value: { type: "string" } } };
|
||||
expect(buildKwpSemanticContract(unrelated).semanticFingerprint).toBe(first.semanticFingerprint);
|
||||
|
||||
const architectOnly = structuredClone(base);
|
||||
architectOnly.components.schemas["Kwp.Api.Service.Dto.Projekte.DtoSearchResultProjekt"].properties.archAdr = {
|
||||
type: "integer",
|
||||
};
|
||||
expect(buildKwpSemanticContract(architectOnly).semanticFingerprint).toBe(first.semanticFingerprint);
|
||||
|
||||
const changed = structuredClone(base);
|
||||
changed.components.schemas["Kwp.Api.Model.Values.ProjektHauptstatus"].enum.push(10);
|
||||
expect(buildKwpSemanticContract(changed).semanticFingerprint).not.toBe(first.semanticFingerprint);
|
||||
|
||||
const renamed = structuredClone(base);
|
||||
delete renamed.components.schemas["Kwp.Api.Service.Dto.Projekte.DtoSearchResultProjekt"].properties.projNr;
|
||||
expect(() => buildKwpSemanticContract(renamed)).toThrowError(expect.objectContaining({ code: "contract_drift" }));
|
||||
});
|
||||
|
||||
it("accepts the larger tenant OpenAPI while keeping business responses capped at one MiB", async () => {
|
||||
const openApi = openApiFixture();
|
||||
openApi.paths["/api/Unrelated/Large"] = {
|
||||
get: {
|
||||
description: "x".repeat(2 * 1024 * 1024),
|
||||
responses: { 200: {} },
|
||||
},
|
||||
};
|
||||
const openApiFetch = vi.fn().mockResolvedValueOnce(new Response("https://geerkens2.app04.kwp-online.de")).mockResolvedValueOnce(jsonResponse(openApi));
|
||||
const openApiResource = createKwpResourceTransport(CREDENTIALS, {
|
||||
consumeBudget: async () => undefined,
|
||||
outboundOptions: outboundOptions(openApiFetch),
|
||||
});
|
||||
|
||||
await expect(openApiResource.loadSemanticContract()).resolves.toMatchObject({
|
||||
apiVersion: "v1",
|
||||
});
|
||||
|
||||
const oversizedBusinessResponse = [
|
||||
{
|
||||
projNr: "P-100",
|
||||
projBezeichnung: "Heizung Schule",
|
||||
auftragStatus: 8,
|
||||
ignored: "x".repeat(1024 * 1024),
|
||||
},
|
||||
];
|
||||
const searchFetch = vi
|
||||
.fn()
|
||||
.mockResolvedValueOnce(new Response("https://geerkens2.app04.kwp-online.de"))
|
||||
.mockResolvedValueOnce(jsonResponse(oversizedBusinessResponse));
|
||||
const searchResource = createKwpResourceTransport(CREDENTIALS, {
|
||||
consumeBudget: async () => undefined,
|
||||
outboundOptions: outboundOptions(searchFetch),
|
||||
});
|
||||
|
||||
await expect(searchResource.searchProjects("Projekt")).rejects.toMatchObject({
|
||||
code: "contract_drift",
|
||||
});
|
||||
});
|
||||
|
||||
it("rejects an OpenAPI response above the dedicated eight MiB ceiling", async () => {
|
||||
const openApi = openApiFixture();
|
||||
openApi.paths["/api/Unrelated/Oversized"] = {
|
||||
get: {
|
||||
description: "x".repeat(8 * 1024 * 1024),
|
||||
responses: { 200: {} },
|
||||
},
|
||||
};
|
||||
const fetchMock = vi.fn().mockResolvedValueOnce(new Response("https://geerkens2.app04.kwp-online.de")).mockResolvedValueOnce(jsonResponse(openApi));
|
||||
const resource = createKwpResourceTransport(CREDENTIALS, {
|
||||
consumeBudget: async () => undefined,
|
||||
outboundOptions: outboundOptions(fetchMock),
|
||||
});
|
||||
|
||||
await expect(resource.loadSemanticContract()).rejects.toMatchObject({
|
||||
code: "contract_drift",
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
function outboundOptions(fetchImpl: typeof fetch): KwpOutboundRequestOptions {
|
||||
return { fetchImpl, addressResolver: PUBLIC_ADDRESS_RESOLVER };
|
||||
}
|
||||
|
||||
function jsonResponse(body: unknown, status = 200): Response {
|
||||
return new Response(JSON.stringify(body), { status, headers: { "content-type": "application/json" } });
|
||||
}
|
||||
|
||||
function openApiFixture(): {
|
||||
info: { version: string };
|
||||
paths: Record<string, any>;
|
||||
components: { schemas: Record<string, any> };
|
||||
} {
|
||||
const response = (schema: string) => ({
|
||||
"200": { content: { "application/json": { schema: { $ref: `#/components/schemas/${schema}` } } } },
|
||||
});
|
||||
const property = (type: string) => ({ type, nullable: true });
|
||||
return {
|
||||
info: { version: "v1" },
|
||||
paths: {
|
||||
[KWP_PROJECT_SEARCH_PATH]: {
|
||||
post: {
|
||||
parameters: [{ name: "mandant", in: "query", schema: { type: "string" } }],
|
||||
requestBody: { content: { "application/json": { schema: { $ref: "#/components/schemas/Kwp.Api.Service.Dto.DtoValue" } } } },
|
||||
responses: response("Kwp.Api.Service.Dto.Projekte.DtoSearchResultProjekt"),
|
||||
},
|
||||
},
|
||||
[KWP_PROJECT_DETAILS_PATH]: {
|
||||
get: {
|
||||
parameters: [{ name: "projNr", in: "query", schema: { type: "string" } }],
|
||||
responses: response("Kwp.Api.Service.Dto.Projektampel.DtoProjektampelProjekt"),
|
||||
},
|
||||
},
|
||||
[KWP_ADDRESS_DETAILS_PATH]: {
|
||||
get: {
|
||||
parameters: [{ name: "adresskuerzel", in: "query", schema: { type: "string" } }],
|
||||
responses: response("Kwp.Api.Service.Dto.Adressen.DtoAdresseKomplett"),
|
||||
},
|
||||
},
|
||||
},
|
||||
components: {
|
||||
schemas: {
|
||||
"Kwp.Api.Service.Dto.DtoValue": { type: "object", properties: { value: property("string") } },
|
||||
"Kwp.Api.Service.Dto.Projekte.DtoSearchResultProjekt": {
|
||||
type: "object",
|
||||
properties: Object.fromEntries(
|
||||
["projNr", "projBezeichnung", "projAdr", "rechAdr", "archAdr", "bauHrAdr", "auftragStatus"].map((name) => [
|
||||
name,
|
||||
property(name === "auftragStatus" ? "integer" : "string"),
|
||||
])
|
||||
),
|
||||
},
|
||||
"Kwp.Api.Model.Values.ProjektHauptstatus": { type: "integer", format: "int32", enum: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] },
|
||||
"Kwp.Api.Service.Dto.Projektampel.DtoProjektampelProjekt": {
|
||||
type: "object",
|
||||
properties: Object.fromEntries(
|
||||
["projNr", "projBezeichnung", "beginn", "adresse", "sachBearb", "vertrieb", "auftragssumme"].map((name) => [name, property("string")])
|
||||
),
|
||||
},
|
||||
"Kwp.Api.Service.Dto.Adressen.DtoAdresse": {
|
||||
type: "object",
|
||||
properties: Object.fromEntries(["adrNrGes", "name", "vorname", "zusatz", "strasse", "ort"].map((name) => [name, property("string")])),
|
||||
},
|
||||
"Kwp.Api.Service.Dto.Adressen.DtoAdresseKomplett": {
|
||||
type: "object",
|
||||
properties: Object.fromEntries(
|
||||
["adrNrGes", "name", "vorname", "zusatz", "strasse", "ort", "rechnungsmailadresse", "kontakte", "ansprechpartner"].map((name) => [
|
||||
name,
|
||||
property("string"),
|
||||
])
|
||||
),
|
||||
},
|
||||
"Kwp.Api.Service.Dto.Adressen.DtoOrt": {
|
||||
type: "object",
|
||||
properties: Object.fromEntries(["ortId", "land", "plz", "ort"].map((name) => [name, property("string")])),
|
||||
},
|
||||
"Kwp.Api.Service.Dto.Adressen.DtoKontakt": {
|
||||
type: "object",
|
||||
properties: Object.fromEntries(["kontaktId", "kontaktart", "kontakt", "kontaktName", "ansprechpartnerId"].map((name) => [name, property("string")])),
|
||||
},
|
||||
"Kwp.Api.Service.Dto.Adressen.DtoAnsprechpartner": {
|
||||
type: "object",
|
||||
properties: Object.fromEntries(["nachname", "vorname", "ansprechpartnerId", "zusatz", "kontakte"].map((name) => [name, property("string")])),
|
||||
},
|
||||
"Kwp.Api.Model.Values.Adresse.Kontaktart": { type: "integer", format: "int32", enum: [0, 1, 2, 3, 4, 5] },
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user