From c1ebaee778177cccc2a11372ee5128df90aa18fc Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 3 Jul 2025 12:30:51 +0200 Subject: [PATCH] Bug 40301: Add insertSampleCheckout Signed-off-by: Owen Leonard --- t/cypress/integration/t/insertData.ts | 17 ++++++++ t/cypress/plugins/index.js | 4 ++ t/cypress/plugins/insertData.js | 60 +++++++++++++++++++++++++++ 3 files changed, 81 insertions(+) diff --git a/t/cypress/integration/t/insertData.ts b/t/cypress/integration/t/insertData.ts index 00c651a6d05..745137fee26 100644 --- a/t/cypress/integration/t/insertData.ts +++ b/t/cypress/integration/t/insertData.ts @@ -8,6 +8,7 @@ describe("insertData", () => { "items", "biblio", "reserves", + "issues", ]; beforeEach(() => { const counts = {}; @@ -215,6 +216,22 @@ describe("insertData", () => { }); }); + describe("insertSampleCheckout", () => { + it("insertSampleCheckout - without parameter", () => { + cy.task("insertSampleCheckout").then(objects_checkout => { + cy.task("apiGet", { + endpoint: `/api/v1/checkouts/${objects_checkout.checkout.checkout_id}`, + }).then(checkout => { + expect(checkout.item_id).to.be.equal( + objects_checkout.items[0].item_id + ); + }); + + cy.task("deleteSampleObjects", objects_checkout); + }); + }); + }); + afterEach(function () { cy.get("@initialCounts").then(initialCounts => { const queries = tablesToCheck.map(table => { diff --git a/t/cypress/plugins/index.js b/t/cypress/plugins/index.js index a3cbd0c908b..77ae3098980 100644 --- a/t/cypress/plugins/index.js +++ b/t/cypress/plugins/index.js @@ -5,6 +5,7 @@ const { buildSampleObject, buildSampleObjects } = require("./mockData.js"); const { insertSampleBiblio, insertSampleHold, + insertSampleCheckout, insertObject, deleteSampleObjects, } = require("./insertData.js"); @@ -43,6 +44,9 @@ module.exports = (on, config) => { insertSampleHold(args) { return insertSampleHold({ ...args, baseUrl, authHeader }); }, + insertSampleCheckout(args) { + return insertSampleCheckout({ ...args, baseUrl, authHeader }); + }, insertObject(args) { return insertObject({ ...args, baseUrl, authHeader }); }, diff --git a/t/cypress/plugins/insertData.js b/t/cypress/plugins/insertData.js index 06077a00811..61705a01f66 100644 --- a/t/cypress/plugins/insertData.js +++ b/t/cypress/plugins/insertData.js @@ -205,6 +205,47 @@ const insertSampleHold = async ({ return { hold, patron }; }; +const insertSampleCheckout = async ({ baseUrl, authHeader }) => { + const { biblio, items, libraries, item_type } = await insertSampleBiblio({ + item_count: 1, + baseUrl, + authHeader, + }); + const generatedPatron = await buildSampleObject({ + object: "patron", + values: { + library_id: libraries[0].library_id, + incorrect_address: null, + patron_card_lost: null, + }, + baseUrl, + authHeader, + }); + + const patron = await insertObject({ + type: "patron", + object: generatedPatron, + baseUrl, + authHeader, + }); + + const generatedCheckout = buildSampleObject({ + object: "checkout", + values: { + patron_id: patron.patron_id, + item_id: items[0].item_id, + }, + }); + delete generatedCheckout.external_id; + const checkout = await insertObject({ + type: "checkout", + object: generatedCheckout, + baseUrl, + authHeader, + }); + return { biblio, items, libraries, item_type, patron, checkout }; +}; + const deleteSampleObjects = async allObjects => { if (!Array.isArray(allObjects)) { allObjects = [allObjects]; @@ -212,6 +253,7 @@ const deleteSampleObjects = async allObjects => { const pluralMap = { hold: "holds", + checkout: "checkouts", patron: "patrons", item: "items", biblio: "biblios", @@ -237,6 +279,7 @@ const deleteSampleObjects = async allObjects => { const deletionOrder = [ "holds", + "checkouts", "patrons", "items", "biblios", @@ -280,6 +323,13 @@ const deleteSampleObjects = async allObjects => { values: ids, }); break; + case "checkouts": + ids = objects.map(i => i.checkout_id); + await query({ + sql: `DELETE FROM issues WHERE issue_id IN (${ids.map(() => "?").join(",")})`, + values: ids, + }); + break; case "item_types": ids = objects.map(i => i.item_type_id); await query({ @@ -431,6 +481,15 @@ const insertObject = async ({ type, object, baseUrl, authHeader }) => { baseUrl, authHeader, }); + } else if (type == "checkout") { + const { issuer, patron, ...checkout } = object; + + return apiPost({ + endpoint: "/api/v1/checkouts", + body: checkout, + baseUrl, + authHeader, + }); } else { throw Error(`Unsupported object type '${type}' to insert`); } @@ -441,6 +500,7 @@ const insertObject = async ({ type, object, baseUrl, authHeader }) => { module.exports = { insertSampleBiblio, insertSampleHold, + insertSampleCheckout, insertObject, deleteSampleObjects, }; -- 2.39.5