Bugzilla – Attachment 183376 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: Add tests for insertSampleHold
Bug-40180-Add-tests-for-insertSampleHold.patch (text/plain), 11.75 KB, created by
Jonathan Druart
on 2025-06-19 10:53:08 UTC
(
hide
)
Description:
Bug 40180: Add tests for insertSampleHold
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2025-06-19 10:53:08 UTC
Size:
11.75 KB
patch
obsolete
>From 68153d19ac0968a23890adcbc28eec7184c0f7e3 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Wed, 18 Jun 2025 14:40:34 +0200 >Subject: [PATCH] Bug 40180: Add tests for insertSampleHold > >--- > t/cypress/integration/t/insertData.ts | 220 +++++++++++++++++++------- > t/cypress/plugins/insertData.js | 9 +- > 2 files changed, 168 insertions(+), 61 deletions(-) > >diff --git a/t/cypress/integration/t/insertData.ts b/t/cypress/integration/t/insertData.ts >index 9055067b541..b5ba8cae406 100644 >--- a/t/cypress/integration/t/insertData.ts >+++ b/t/cypress/integration/t/insertData.ts >@@ -1,78 +1,178 @@ > const { query } = require("./../../plugins/db.js"); >+const { APIClient } = require("./../../plugins/dist/api-client.cjs.js"); >+const { getBasicAuthHeader } = require("./../../plugins/auth.js"); > >-describe("insertSampleBiblio", () => { >- it("insertSampleBiblio - should generate library and item type", () => { >- cy.task("insertSampleBiblio", { item_count: 3 }).then(objects => { >- expect(typeof objects.biblio.biblio_id).to.be.equal("number"); >- expect(typeof objects.biblio.title).to.be.equal("string"); >- expect(typeof objects.biblio.author).to.be.equal("string"); >+const { APIClient } = require("./../../plugins/dist/api-client.cjs.js"); > >- const biblio_id = objects.biblio.biblio_id; >+let client = APIClient.default; > >- cy.task("query", { >- sql: "SELECT COUNT(*) as count FROM biblio WHERE biblionumber=?", >- values: [biblio_id], >- }).then(result => { >- expect(result[0].count).to.be.equal(1); >- }); >+describe("insertData", () => { >+ describe("insertSampleBiblio", () => { >+ it("should generate library and item type", () => { >+ cy.task("insertSampleBiblio", { item_count: 3 }).then(objects => { >+ expect(typeof objects.biblio.biblio_id).to.be.equal("number"); >+ expect(typeof objects.biblio.title).to.be.equal("string"); >+ expect(typeof objects.biblio.author).to.be.equal("string"); > >- cy.task("query", { >- sql: "SELECT COUNT(*) as count FROM items WHERE biblionumber=?", >- values: [biblio_id], >- }).then(result => { >- expect(result[0].count).to.be.equal(3); >- }); >+ const biblio_id = objects.biblio.biblio_id; > >- cy.task("query", { >- sql: "SELECT DISTINCT(itype) as count FROM items WHERE biblionumber=?", >- values: [biblio_id], >- }).then(result => { >- expect(result.length).to.be.equal(1); >- }); >+ cy.task("query", { >+ sql: "SELECT COUNT(*) as count FROM biblio WHERE biblionumber=?", >+ values: [biblio_id], >+ }).then(result => { >+ expect(result[0].count).to.be.equal(1); >+ }); > >- cy.task("query", { >- sql: "SELECT COUNT(*) as count FROM branches WHERE branchcode=?", >- values: [objects.libraries[0].library_id], >- }).then(result => { >- expect(result[0].count).to.be.equal(1); >- }); >+ cy.task("query", { >+ sql: "SELECT COUNT(*) as count FROM items WHERE biblionumber=?", >+ values: [biblio_id], >+ }).then(result => { >+ expect(result[0].count).to.be.equal(3); >+ }); > >- cy.task("query", { >- sql: "SELECT COUNT(*) as count FROM itemtypes WHERE itemtype=?", >- values: [objects.item_type.item_type_id], >- }).then(result => { >- expect(result[0].count).to.be.equal(1); >- }); >+ cy.task("query", { >+ sql: "SELECT DISTINCT(itype) as count FROM items WHERE biblionumber=?", >+ values: [biblio_id], >+ }).then(result => { >+ expect(result.length).to.be.equal(1); >+ }); > >- cy.task("deleteSampleObjects", objects); >+ cy.task("query", { >+ sql: "SELECT COUNT(*) as count FROM branches WHERE branchcode=?", >+ values: [objects.libraries[0].library_id], >+ }).then(result => { >+ expect(result[0].count).to.be.equal(1); >+ }); > >- cy.task("query", { >- sql: "SELECT COUNT(*) as count FROM biblio WHERE biblionumber=?", >- values: [biblio_id], >- }).then(result => { >- expect(result[0].count).to.be.equal(0); >- }); >+ cy.task("query", { >+ sql: "SELECT COUNT(*) as count FROM itemtypes WHERE itemtype=?", >+ values: [objects.item_type.item_type_id], >+ }).then(result => { >+ expect(result[0].count).to.be.equal(1); >+ }); > >- cy.task("query", { >- sql: "SELECT COUNT(*) as count FROM items WHERE biblionumber=?", >- values: [biblio_id], >- }).then(result => { >- expect(result[0].count).to.be.equal(0); >- }); >+ cy.task("deleteSampleObjects", objects); >+ >+ cy.task("query", { >+ sql: "SELECT COUNT(*) as count FROM biblio WHERE biblionumber=?", >+ values: [biblio_id], >+ }).then(result => { >+ expect(result[0].count).to.be.equal(0); >+ }); >+ >+ cy.task("query", { >+ sql: "SELECT COUNT(*) as count FROM items WHERE biblionumber=?", >+ values: [biblio_id], >+ }).then(result => { >+ expect(result[0].count).to.be.equal(0); >+ }); > >- cy.task("query", { >- sql: "SELECT COUNT(*) as count FROM branches WHERE branchcode=?", >- values: [objects.libraries[0].library_id], >- }).then(result => { >- expect(result[0].count).to.be.equal(0); >+ cy.task("query", { >+ sql: "SELECT COUNT(*) as count FROM branches WHERE branchcode=?", >+ values: [objects.libraries[0].library_id], >+ }).then(result => { >+ expect(result[0].count).to.be.equal(0); >+ }); >+ >+ cy.task("query", { >+ sql: "SELECT COUNT(*) as count FROM itemtypes WHERE itemtype=?", >+ values: [objects.item_type.item_type_id], >+ }).then(result => { >+ expect(result[0].count).to.be.equal(0); >+ }); > }); >+ }); >+ >+ it("insertSampleBiblio - options.different_libraries", () => { >+ cy.task("insertSampleBiblio", { >+ item_count: 3, >+ options: { different_libraries: true }, >+ }).then(objects => { >+ expect(objects.libraries.length).to.be.equal(3); >+ let libraries = objects.libraries >+ .map(library => library.library_id) >+ .sort(); >+ let itemsLibraries = objects.items >+ .map(item => item.home_library_id) >+ .sort(); >+ expect(libraries).deep.to.equal(itemsLibraries); > >- cy.task("query", { >- sql: "SELECT COUNT(*) as count FROM itemtypes WHERE itemtype=?", >- values: [objects.item_type.item_type_id], >- }).then(result => { >- expect(result[0].count).to.be.equal(0); >+ cy.task("deleteSampleObjects", objects); > }); > }); > }); >+ >+ describe("insertSampleHold", () => { >+ it("insertSampleHold - item/biblio", () => { >+ cy.task("insertSampleBiblio", { item_count: 2 }).then( >+ objects_biblio => { >+ cy.task("insertSampleHold", { >+ item: objects_biblio.items[0], >+ }).then(objects_hold_1 => { >+ cy.task("insertSampleHold", { >+ biblio: objects_biblio.biblio, >+ library_id: objects_biblio.items[0].home_library_id, >+ }).then(objects_hold_2 => { >+ cy.task("apiGet", { >+ // No /holds/:hold_id (yet) >+ // No q={} (yet) >+ endpoint: `/api/v1/holds?hold_id=${objects_hold_1.hold.hold_id}`, >+ headers: { >+ "Content-Type": "application/json", >+ }, >+ }).then(holds => { >+ expect(holds.length).to.be.equal(1); >+ expect(holds[0].biblio_id).to.be.equal( >+ objects_biblio.biblio.biblio_id >+ ); >+ expect(holds[0].item_id).to.be.equal( >+ objects_biblio.items[0].item_id >+ ); >+ }); >+ cy.task("apiGet", { >+ // No /holds/:hold_id (yet) >+ // No q={} (yet) >+ endpoint: `/api/v1/holds?hold_id=${objects_hold_2.hold.hold_id}`, >+ headers: { >+ "Content-Type": "application/json", >+ }, >+ }).then(holds => { >+ expect(holds.length).to.be.equal(1); >+ expect(holds[0].biblio_id).to.be.equal( >+ objects_biblio.biblio.biblio_id >+ ); >+ expect(holds[0].item_id).to.be.equal(null); >+ }); >+ >+ cy.task("deleteSampleObjects", [ >+ objects_biblio, >+ objects_hold_1, >+ objects_hold_2, >+ ]); >+ }); >+ }); >+ } >+ ); >+ }); >+ >+ // How to properly test for Error? >+ it.skip("insertSampleHold - missing library_id", () => { >+ cy.task("insertSampleBiblio", { item_count: 2 }).then( >+ objects_biblio => { >+ cy.task("insertSampleHold", { >+ biblio: objects_biblio.biblio, >+ }).then( >+ () => { >+ throw new Error("Task should have failed"); >+ }, >+ err => { >+ expect(err.message).to.include( >+ "Could not generate sample hold without library_id or item" >+ ); >+ } >+ ); >+ } >+ ); >+ }); >+ }); > }); >diff --git a/t/cypress/plugins/insertData.js b/t/cypress/plugins/insertData.js >index 954a86a8fa5..c8fdbdaea77 100644 >--- a/t/cypress/plugins/insertData.js >+++ b/t/cypress/plugins/insertData.js >@@ -170,7 +170,14 @@ const insertSampleHold = async ({ > authHeader, > }) => { > >- library_id ||= item.home_library_id; >+ library_id ||= item?.home_library_id; >+ >+ if (!library_id) { >+ throw new Error( >+ "Could not generate sample hold without library_id or item" >+ ); >+ } >+ > const generatedPatron = await buildSampleObject({ > object: "patron", > values: { library_id }, >-- >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