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 <katrin.fischer@bsz-bw.de>
This commit is contained in:
Jonathan Druart 2025-01-20 13:38:46 +01:00 committed by Katrin Fischer
parent 55c3840588
commit bb2e88a1e3
No known key found for this signature in database
GPG Key ID: 0EF6E2C03357A834
2 changed files with 123 additions and 4 deletions

View File

@ -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:

View File

@ -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,