From 131bdb1725e454e2f709cc18cf97c140222fe75c Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Fri, 11 Jul 2025 14:08:02 +0200 Subject: [PATCH] Bug 40345: Use then to prevent async issues --- .../KohaTable/OPACCirculationHistory_spec.ts | 50 +++++++++++-------- 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/t/cypress/integration/KohaTable/OPACCirculationHistory_spec.ts b/t/cypress/integration/KohaTable/OPACCirculationHistory_spec.ts index 56f0c43c95f..4e6786ca4fe 100644 --- a/t/cypress/integration/KohaTable/OPACCirculationHistory_spec.ts +++ b/t/cypress/integration/KohaTable/OPACCirculationHistory_spec.ts @@ -1,35 +1,43 @@ describe("opac-readingrecord", () => { beforeEach(() => { + cy.loginOpac(); let objects_to_cleanup = []; cy.task("apiGet", { endpoint: "/api/v1/patrons/51", - }).then(patron => { - [...Array(51)].forEach(() => { - cy.task("insertSampleCheckout", { - patron: patron, - }).then(objects_checkout => { - cy.task("query", { - sql: "INSERT INTO old_issues SELECT * FROM issues WHERE issue_id=?", - values: [objects_checkout.checkout.checkout_id], - }); - cy.task("query", { - sql: "DELETE FROM issues WHERE issue_id=?", - values: [objects_checkout.checkout.checkout_id], + }) + .then(patron => { + [...Array(51)].forEach(() => { + cy.task("insertSampleCheckout", { + patron: patron, + }).then(objects_checkout => { + cy.task("query", { + sql: "INSERT INTO old_issues SELECT * FROM issues WHERE issue_id=?", + values: [objects_checkout.checkout.checkout_id], + }) + .then(() => { + cy.task("query", { + sql: "DELETE FROM issues WHERE issue_id=?", + values: [ + objects_checkout.checkout.checkout_id, + ], + }); + }) + .then(() => { + objects_checkout.old_checkout = + objects_checkout.checkout; + delete objects_checkout.checkout; + objects_to_cleanup.push(objects_checkout); + }); }); - objects_checkout.old_checkout = objects_checkout.checkout; - delete objects_checkout.checkout; - objects_to_cleanup.push(objects_checkout); }); + }) + .then(() => { + cy.wrap(objects_to_cleanup).as("objects_to_cleanup"); }); - - cy.wrap(objects_to_cleanup).as("objects_to_cleanup"); - }); - - cy.loginOpac(); }); afterEach(function () { - cy.task("deleteSampleObjects", [this.objects_to_cleanup]); + cy.task("deleteSampleObjects", this.objects_to_cleanup); }); it("50 items should be displayed by default", function () { -- 2.34.1