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 <oleonard@myacpl.org>
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
(cherry picked from commit 34e4b19ff5)
Signed-off-by: Paul Derscheid <paul.derscheid@lmscloud.de>
This commit is contained in:
Jonathan Druart 2025-06-18 14:20:29 +02:00 committed by Paul Derscheid
parent 0810cc3b7a
commit f8e6f72f26
No known key found for this signature in database
GPG Key ID: C25F9FD44CED595B
1 changed files with 45 additions and 0 deletions

View File

@ -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);
});
});
});