From bb2e88a1e3ebbed3d291cdf7450933aca0ff88ec Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 20 Jan 2025 13:38:46 +0100 Subject: [PATCH] Bug 38461: Do not rely on biblio_id=1 It might not exist! This code is not trivial and should ideally be moved to somewhere it could be reused easily. But good enough for now to fix the failing tests. Signed-off-by: Katrin Fischer --- api/v1/swagger/definitions/item_type.yaml | 2 + t/cypress/integration/KohaTable_spec.ts | 125 +++++++++++++++++++++- 2 files changed, 123 insertions(+), 4 deletions(-) diff --git a/api/v1/swagger/definitions/item_type.yaml b/api/v1/swagger/definitions/item_type.yaml index 274c393b83..ec9f1781c6 100644 --- a/api/v1/swagger/definitions/item_type.yaml +++ b/api/v1/swagger/definitions/item_type.yaml @@ -5,6 +5,8 @@ properties: type: string description: Unique key, a code associated with the item type readOnly: true + maxLength: 10 + minLength: 1 parent_type: description: Unique key, a code associated with the parent item type type: diff --git a/t/cypress/integration/KohaTable_spec.ts b/t/cypress/integration/KohaTable_spec.ts index 7eacab0824..f5f10146db 100644 --- a/t/cypress/integration/KohaTable_spec.ts +++ b/t/cypress/integration/KohaTable_spec.ts @@ -488,8 +488,124 @@ describe("Hit all tables", () => { describe("catalogue/detail/holdings_table", () => { const table_id = "holdings_table"; - it("correctly init", () => { - const biblio_id = 1; + beforeEach(() => { + // FIXME All the following code should not be reused as it + // It must be moved to a Cypress command or task "buildSampleBiblio" or even "insertSampleBiblio" + let generated_objects = {}; + const objects = [{ object: "library" }, { object: "item_type" }]; + cy.wrap(Promise.resolve()) + .then(() => { + return objects.reduce((chain, { object }) => { + return chain.then(() => { + return cy + .task("buildSampleObject", { object }) + .then(attributes => { + generated_objects[object] = attributes; + }); + }); + }, Promise.resolve()); + }) + .then(() => { + const library = generated_objects["library"]; + const item_type = generated_objects["item_type"]; + const queries = [ + { + query: "INSERT INTO branches(branchcode, branchname) VALUES (?, ?)", + values: [library.library_id, library.name], + }, + { + query: "INSERT INTO itemtypes(itemtype, description) VALUES (?, ?)", + values: [ + item_type.item_type_id, + item_type.description, + ], + }, + ]; + cy.wrap(Promise.resolve()) + .then(() => { + return queries.reduce( + (chain, { query, values }) => { + return chain.then(() => + cy.query(query, values) + ); + }, + Promise.resolve() + ); + }) + .then(() => { + let biblio = { + leader: " nam a22 7a 4500", + fields: [ + { "005": "20250120101920.0" }, + { + "245": { + ind1: "", + ind2: "", + subfields: [ + { a: "Some boring read" }, + ], + }, + }, + { + "100": { + ind1: "", + ind2: "", + subfields: [ + { c: "Some boring author" }, + ], + }, + }, + { + "942": { + ind1: "", + ind2: "", + subfields: [ + { c: item_type.item_type_id }, + ], + }, + }, + ], + }; + cy.request({ + method: "POST", + url: "/api/v1/biblios", + auth: { + username: "koha", + password: "koha", + }, + headers: { + "Content-Type": "application/marc-in-json", + "x-confirm-not-duplicate": 1, + }, + body: biblio, + }).then(response => { + const biblio_id = response.body.id; + cy.wrap(biblio_id).as("biblio_id"); + cy.request({ + method: "POST", + url: `/api/v1/biblios/${biblio_id}/items`, + auth: { + username: "koha", + password: "koha", + }, + headers: { + "Content-Type": "application/json", + }, + body: { + home_library_id: library.library_id, + holding_library_id: library.library_id, + }, + }); + }); + }); + }); + }); + + afterEach(() => {}); + + it("Correctly init the table", function () { + // Do not use `() => {` or this.biblio_id won't be retrieved + const biblio_id = this.biblio_id; cy.task("buildSampleObjects", { object: "item", count: RESTdefaultPageSize, @@ -537,8 +653,9 @@ describe("Hit all tables", () => { }); }); - it("Show filters", () => { - const biblio_id = 1; + it("Show filters", function () { + // Do not use `() => {` or this.biblio_id won't be retrieved + const biblio_id = this.biblio_id; cy.task("buildSampleObjects", { object: "item", count: RESTdefaultPageSize,