Bugzilla – Attachment 183932 Details for
Bug 40180
Missing Cypress tests for 'Holds to pull' library filters
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 40180: Improve deleteSampleObjects
Bug-40180-Improve-deleteSampleObjects.patch (text/plain), 8.15 KB, created by
Jonathan Druart
on 2025-07-10 12:21:33 UTC
(
hide
)
Description:
Bug 40180: Improve deleteSampleObjects
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2025-07-10 12:21:33 UTC
Size:
8.15 KB
patch
obsolete
>From 7bf6b1bebfc272256e273133ba0c8be6fd97ba11 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Thu, 10 Jul 2025 14:09:12 +0200 >Subject: [PATCH] Bug 40180: Improve deleteSampleObjects > >We want the task to accept an Object or an Array of Objects >--- > t/cypress/integration/t/insertData.ts | 19 ++++ > t/cypress/plugins/insertData.js | 154 ++++++++++++++------------ > 2 files changed, 102 insertions(+), 71 deletions(-) > >diff --git a/t/cypress/integration/t/insertData.ts b/t/cypress/integration/t/insertData.ts >index bb721d021d3..41f8f1a686d 100644 >--- a/t/cypress/integration/t/insertData.ts >+++ b/t/cypress/integration/t/insertData.ts >@@ -2,6 +2,25 @@ const { query } = require("./../../plugins/db.js"); > const { getBasicAuthHeader } = require("./../../plugins/auth.js"); > > describe("insertData", () => { >+ describe("deleteSampleObjects", () => { >+ it("should delete everything from Object", () => { >+ cy.task("insertSampleBiblio", { item_count: 2 }).then(objects => { >+ cy.task("deleteSampleObjects", objects); >+ }); >+ }); >+ it("should delete everything from Array", () => { >+ cy.task("insertSampleBiblio", { item_count: 2 }).then(objects => { >+ cy.task("deleteSampleObjects", [ >+ { biblio: objects.biblio }, >+ { item_type: objects.item_type }, >+ { item: objects.items[0] }, >+ { item: objects.items[1] }, >+ { library: objects.libraries[0] }, >+ ]); >+ }); >+ }); >+ }); >+ > describe("insertSampleBiblio", () => { > it("should generate library and item type", () => { > cy.task("insertSampleBiblio", { item_count: 3 }).then(objects => { >diff --git a/t/cypress/plugins/insertData.js b/t/cypress/plugins/insertData.js >index a00327388c9..06077a00811 100644 >--- a/t/cypress/plugins/insertData.js >+++ b/t/cypress/plugins/insertData.js >@@ -210,82 +210,94 @@ const deleteSampleObjects = async allObjects => { > allObjects = [allObjects]; > } > >+ const pluralMap = { >+ hold: "holds", >+ patron: "patrons", >+ item: "items", >+ biblio: "biblios", >+ library: "libraries", >+ item_type: "item_types", >+ }; >+ // Merge by type >+ const mergedObjects = {}; >+ for (const objects of allObjects) { >+ for (const [type, value] of Object.entries(objects)) { >+ let plural = pluralMap?.[type] || type; >+ if (!mergedObjects[plural]) { >+ mergedObjects[plural] = []; >+ } >+ >+ if (Array.isArray(value)) { >+ mergedObjects[plural].push(...value); >+ } else { >+ mergedObjects[plural].push(value); >+ } >+ } >+ } >+ > const deletionOrder = [ >- "hold", >- "patron", >- "item", >+ "holds", >+ "patrons", > "items", >- "biblio", >- "library", >+ "biblios", > "libraries", >- "item_type", >+ "item_types", > ]; > > for (const type of deletionOrder) { >- for (const objects of allObjects) { >- if (!objects.hasOwnProperty(type)) { >- continue; >- } >- if (Array.isArray(objects[type]) && objects[type].length == 0) { >- // Empty array >- continue; >- } >- switch (type) { >- case "biblio": >- await query({ >- sql: "DELETE FROM biblio WHERE biblionumber=?", >- values: [objects[type].biblio_id], >- }); >- break; >- case "items": >- let item_ids = objects[type].map(i => i.item_id); >- await query({ >- sql: `DELETE FROM items WHERE itemnumber IN (${item_ids.map(() => "?").join(",")})`, >- values: item_ids, >- }); >- break; >- case "item": >- await query({ >- sql: "DELETE FROM items WHERE itemnumber = ?", >- values: [objects[type].item_id], >- }); >- break; >- case "library": >- await query({ >- sql: "DELETE FROM branches WHERE branchcode = ?", >- values: [objects[type].library_id], >- }); >- break; >- case "libraries": >- let library_ids = objects[type].map(i => i.library_id); >- await query({ >- sql: `DELETE FROM branches WHERE branchcode IN (${library_ids.map(() => "?").join(",")})`, >- values: library_ids, >- }); >- break; >- case "hold": >- await query({ >- sql: "DELETE FROM reserves WHERE reserve_id = ?", >- values: [objects[type].hold_id], >- }); >- break; >- case "item_type": >- await query({ >- sql: "DELETE FROM itemtypes WHERE itemtype = ?", >- values: [objects[type].item_type_id], >- }); >- break; >- case "patron": >- await query({ >- sql: "DELETE FROM borrowers WHERE borrowernumber = ?", >- values: [objects[type].patron_id], >- }); >- break; >- default: >- console.log( >- `Not implemented yet: cannot deleted object '${type}'` >- ); >- } >+ if (!mergedObjects[type] || mergedObjects[type].length === 0) { >+ continue; >+ } >+ >+ const objects = mergedObjects[type]; >+ let ids = []; >+ switch (type) { >+ case "biblios": >+ ids = objects.map(i => i.biblio_id); >+ await query({ >+ sql: `DELETE FROM biblio WHERE biblionumber IN (${ids.map(() => "?").join(",")})`, >+ values: ids, >+ }); >+ break; >+ case "items": >+ ids = objects.map(i => i.item_id); >+ await query({ >+ sql: `DELETE FROM items WHERE itemnumber IN (${ids.map(() => "?").join(",")})`, >+ values: ids, >+ }); >+ break; >+ case "libraries": >+ ids = objects.map(i => i.library_id); >+ await query({ >+ sql: `DELETE FROM branches WHERE branchcode IN (${ids.map(() => "?").join(",")})`, >+ values: ids, >+ }); >+ break; >+ case "holds": >+ ids = objects.map(i => i.hold_id); >+ await query({ >+ sql: `DELETE FROM reserves WHERE reserve_id IN (${ids.map(() => "?").join(",")})`, >+ values: ids, >+ }); >+ break; >+ case "item_types": >+ ids = objects.map(i => i.item_type_id); >+ await query({ >+ sql: `DELETE FROM itemtypes WHERE itemtype IN (${ids.map(() => "?").join(",")})`, >+ values: ids, >+ }); >+ break; >+ case "patrons": >+ ids = objects.map(i => i.patron_id); >+ await query({ >+ sql: `DELETE FROM borrowers WHERE borrowernumber IN (${ids.map(() => "?").join(",")})`, >+ values: ids, >+ }); >+ break; >+ default: >+ throw Error( >+ `Not implemented yet: cannot deleted object '${type}'` >+ ); > } > } > return true; >@@ -420,7 +432,7 @@ const insertObject = async ({ type, object, baseUrl, authHeader }) => { > authHeader, > }); > } else { >- return false; >+ throw Error(`Unsupported object type '${type}' to insert`); > } > > return true; >-- >2.34.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 40180
:
183375
|
183376
|
183930
|
183931
|
183932
|
183933
|
183934
|
183935
|
184221
|
184222
|
184223
|
184227
|
184228
|
184229
|
184334
|
184335
|
184336
|
184532