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 <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
(cherry picked from commit 5baf1ce6e0)
Signed-off-by: Baptiste Wojtkowski <baptiste.wojtkowski@biblibre.com>
This commit is contained in:
Pedro Amorim 2026-06-01 10:43:49 +00:00 committed by Baptiste Wojtkowski
parent 66fc0daf4a
commit 8527fdf29f
No known key found for this signature in database
GPG Key ID: 47A8A13E10BC0D40
1 changed files with 29 additions and 0 deletions

View File

@ -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");
});
});