From ab5f6908bead7e322f05f8d3e14e88d570fdb2bd Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 18 Jun 2025 14:20:29 +0200 Subject: [PATCH] Bug 40181: Make sure data won't be added by insertData We are here testing that data inserted by insertData tasks can be easily removed from the DB using deleteSampleObjects Test plan: Cypress test t/cypress/integration/t/insertData.ts must pass Signed-off-by: Owen Leonard --- t/cypress/integration/t/insertData.ts | 45 +++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/t/cypress/integration/t/insertData.ts b/t/cypress/integration/t/insertData.ts index 41f8f1a686d..00c651a6d05 100644 --- a/t/cypress/integration/t/insertData.ts +++ b/t/cypress/integration/t/insertData.ts @@ -2,6 +2,31 @@ const { query } = require("./../../plugins/db.js"); const { getBasicAuthHeader } = require("./../../plugins/auth.js"); describe("insertData", () => { + let tablesToCheck = [ + "borrowers", + "branches", + "items", + "biblio", + "reserves", + ]; + beforeEach(() => { + const counts = {}; + + const queries = tablesToCheck.map(table => { + return cy + .task("query", { + sql: `SELECT COUNT(*) as count FROM ${table}`, + }) + .then(result => { + counts[table] = result[0].count; + }); + }); + + cy.wrap(Promise.all(queries)).then(() => { + cy.wrap(counts).as("initialCounts"); + }); + }); + describe("deleteSampleObjects", () => { it("should delete everything from Object", () => { cy.task("insertSampleBiblio", { item_count: 2 }).then(objects => { @@ -189,4 +214,24 @@ describe("insertData", () => { ); }); }); + + afterEach(function () { + cy.get("@initialCounts").then(initialCounts => { + const queries = tablesToCheck.map(table => { + return cy + .task("query", { + sql: `SELECT COUNT(*) as count FROM ${table}`, + }) + .then(result => { + const finalCount = result[0].count; + expect( + finalCount, + `Row count for ${table} should match` + ).to.eq(initialCounts[table]); + }); + }); + + return Promise.all(queries); + }); + }); }); -- 2.39.5