From 5baf1ce6e07faf7ecdadeb74b96185f6a6acf627 Mon Sep 17 00:00:00 2001 From: Pedro Amorim Date: Mon, 1 Jun 2026 10:43:49 +0000 Subject: [PATCH] Bug 42705: Add HttpClient_spec.ts This fails without the fix patch in this set: cypress run --spec t/cypress/integration/HttpClient_spec.ts It passes with the fix Signed-off-by: Jonathan Druart Signed-off-by: Lucas Gass --- t/cypress/integration/HttpClient_spec.ts | 29 ++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 t/cypress/integration/HttpClient_spec.ts diff --git a/t/cypress/integration/HttpClient_spec.ts b/t/cypress/integration/HttpClient_spec.ts new file mode 100644 index 0000000000..f76d01e449 --- /dev/null +++ b/t/cypress/integration/HttpClient_spec.ts @@ -0,0 +1,29 @@ +describe("HttpClient", () => { + beforeEach(() => { + cy.login(); + cy.title().should("eq", "Koha staff interface"); + }); + + it("handles C4::Service error format without crashing", () => { + // C4::Service returns { type, message } on failure — not the OpenAPI + // { error } or { errors: [...] } shape that http-client.js was written for. + // Without the fix, accessing json.errors.map(...) throws: + // TypeError: Cannot read properties of undefined (reading 'map') + cy.intercept("POST", "/cgi-bin/koha/svc/config/systempreferences", { + statusCode: 400, + headers: { "content-type": "application/json" }, + body: { type: "auth", message: "expired" }, + }).as("sysprefUpdate"); + + cy.window().then(win => { + const client = win.APIClient.sysprefs; + return client.sysprefs + .update("WebBasedSelfCheck", "1") + .catch(err => { + expect(err.message).to.include("expired"); + }); + }); + + cy.wait("@sysprefUpdate"); + }); +});