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: Pedro Amorim <pedro.amorim@openfifth.co.uk>
This commit is contained in:
Pedro Amorim 2026-06-01 10:43:49 +00:00
parent bdd552a05d
commit d5ae629d8c
No known key found for this signature in database
GPG Key ID: 06B75BA7F3894D55
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");
});
});