Bugzilla – Attachment 183975 Details for
Bug 40345
Missing Cypress tests for checkout history - OPAC
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 40345: Add insertSamplePatron
Bug-40345-Add-insertSamplePatron.patch (text/plain), 10.62 KB, created by
Jonathan Druart
on 2025-07-11 07:22:31 UTC
(
hide
)
Description:
Bug 40345: Add insertSamplePatron
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2025-07-11 07:22:31 UTC
Size:
10.62 KB
patch
obsolete
>From 44908554b82bf59efe4c3d1ecde45e3e79eecab0 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Thu, 10 Jul 2025 16:42:30 +0200 >Subject: [PATCH] Bug 40345: Add insertSamplePatron > >So it's easier to build and insert a new patron >--- > t/cypress/integration/t/insertData.ts | 49 +++----- > t/cypress/plugins/index.js | 4 + > t/cypress/plugins/insertData.js | 164 +++++++++++++++----------- > 3 files changed, 117 insertions(+), 100 deletions(-) > >diff --git a/t/cypress/integration/t/insertData.ts b/t/cypress/integration/t/insertData.ts >index 8eb4e26235b..aff5e3b6e24 100644 >--- a/t/cypress/integration/t/insertData.ts >+++ b/t/cypress/integration/t/insertData.ts >@@ -232,36 +232,25 @@ describe("insertData", () => { > }); > > it("insertSampleCheckout - pass an already generated patron", () => { >- cy.task("buildSampleObject", { >- object: "patron", >- values: { >- incorrect_address: null, >- patron_card_lost: null, >- }, >- }).then(generatedPatron => { >- cy.task("insertObject", { >- type: "patron", >- object: generatedPatron, >- }).then(patron => { >- cy.task("insertSampleCheckout", { patron }).then( >- objects_checkout => { >- expect(objects_checkout.patron).to.not.exists; >- cy.task("apiGet", { >- endpoint: `/api/v1/checkouts/${objects_checkout.checkout.checkout_id}`, >- }).then(checkout => { >- expect(checkout.item_id).to.be.equal( >- objects_checkout.items[0].item_id >- ); >- expect(checkout.patron_id).to.be.equal( >- generatedPatron.patron_id >- ); >- }); >- cy.task("deleteSampleObjects", [ >- objects_checkout, >- { patron }, >- ]); >- } >- ); >+ cy.task("insertSamplePatron").then(objects_patron => { >+ cy.task("insertSampleCheckout", { >+ patron: objects_patron.patron, >+ }).then(objects_checkout => { >+ expect(objects_checkout.patron).to.not.exist; >+ cy.task("apiGet", { >+ endpoint: `/api/v1/checkouts/${objects_checkout.checkout.checkout_id}`, >+ }).then(checkout => { >+ expect(checkout.item_id).to.be.equal( >+ objects_checkout.items[0].item_id >+ ); >+ expect(checkout.patron_id).to.be.equal( >+ objects_patron.patron.patron_id >+ ); >+ }); >+ cy.task("deleteSampleObjects", [ >+ objects_checkout, >+ objects_patron, >+ ]); > }); > }); > }); >diff --git a/t/cypress/plugins/index.js b/t/cypress/plugins/index.js >index 77ae3098980..2f919b78b2f 100644 >--- a/t/cypress/plugins/index.js >+++ b/t/cypress/plugins/index.js >@@ -6,6 +6,7 @@ const { > insertSampleBiblio, > insertSampleHold, > insertSampleCheckout, >+ insertSamplePatron, > insertObject, > deleteSampleObjects, > } = require("./insertData.js"); >@@ -47,6 +48,9 @@ module.exports = (on, config) => { > insertSampleCheckout(args) { > return insertSampleCheckout({ ...args, baseUrl, authHeader }); > }, >+ insertSamplePatron(args) { >+ return insertSamplePatron({ ...args, baseUrl, authHeader }); >+ }, > insertObject(args) { > return insertObject({ ...args, baseUrl, authHeader }); > }, >diff --git a/t/cypress/plugins/insertData.js b/t/cypress/plugins/insertData.js >index c92aded59cd..482de34cbd0 100644 >--- a/t/cypress/plugins/insertData.js >+++ b/t/cypress/plugins/insertData.js >@@ -175,14 +175,8 @@ const insertSampleHold = async ({ > ); > } > >- const generatedPatron = await buildSampleObject({ >- object: "patron", >- values: { library_id, incorrect_address: null, patron_card_lost: null }, >- }); >- >- const patron = await insertObject({ >- type: "patron", >- object: generatedPatron, >+ const { patron, patron_category } = await insertSamplePatron({ >+ library: { library_id }, > baseUrl, > authHeader, > }); >@@ -202,7 +196,7 @@ const insertSampleHold = async ({ > baseUrl, > authHeader, > }); >- return { hold, patron }; >+ return { hold, patron, patron_category }; > }; > > const insertSampleCheckout = async ({ patron, baseUrl, authHeader }) => { >@@ -213,22 +207,16 @@ const insertSampleCheckout = async ({ patron, baseUrl, authHeader }) => { > }); > > let generatedPatron; >+ let patronCategory; > if (!patron) { >- generatedPatron = await buildSampleObject({ >- object: "patron", >- values: { >- library_id: libraries[0].library_id, >- incorrect_address: null, >- patron_card_lost: null, >- }, >- }); >- >- patron = await insertObject({ >- type: "patron", >- object: generatedPatron, >+ generatedPatron = true; >+ const patron_objects = await insertSamplePatron({ >+ library: { library_id: libraries[0].library_id }, > baseUrl, > authHeader, > }); >+ generatedCategory = patron_objects.category; >+ patron = patron_objects.patron; > } > > const generatedCheckout = buildSampleObject({ >@@ -250,9 +238,89 @@ const insertSampleCheckout = async ({ patron, baseUrl, authHeader }) => { > items, > libraries, > item_type, >- patron, > checkout, >- ...(generatedPatron ? { patron: generatedPatron } : {}), >+ ...(generatedPatron >+ ? { >+ patron, >+ patron_category: generatedCategory, >+ } >+ : {}), >+ }; >+}; >+ >+const insertSamplePatron = async ({ >+ library, >+ patron_category, >+ baseUrl, >+ authHeader, >+}) => { >+ let generatedLibrary; >+ let generatedCategory; >+ if (!library) { >+ generatedLibrary = await buildSampleObject({ object: "library" }); >+ library = await insertLibrary({ >+ library: generatedLibrary, >+ baseUrl, >+ authHeader, >+ }); >+ } >+ if (!patron_category) { >+ generatedCategory = await buildSampleObject({ >+ object: "patron_category", >+ }); >+ query({ >+ sql: "INSERT INTO categories(categorycode, description) VALUES (?, ?)", >+ values: [ >+ generatedCategory.patron_category_id, >+ `description for ${generatedCategory.patron_category_id}`, >+ ], >+ }); >+ // FIXME We need /patron_categories/:patron_category_id >+ await apiGet({ >+ endpoint: `/api/v1/patron_categories?q={"me.patron_category_id":"${generatedCategory.patron_category_id}"}`, >+ baseUrl, >+ authHeader, >+ }).then(categories => (patron_category = categories[0])); >+ } >+ >+ let generatedPatron = await buildSampleObject({ >+ object: "patron", >+ values: { >+ library_id: library.library_id, >+ category_id: patron_category.patron_category_id, >+ incorrect_address: null, >+ patron_card_lost: null, >+ }, >+ }); >+ >+ let { >+ patron_id, >+ _strings, >+ anonymized, >+ restricted, >+ expired, >+ extended_attributes, >+ checkouts_count, >+ overdues_count, >+ account_balance, >+ lang, >+ login_attempts, >+ sms_provider_id, >+ ...patron >+ } = generatedPatron; >+ delete patron.library; >+ >+ patron = await apiPost({ >+ endpoint: `/api/v1/patrons`, >+ body: patron, >+ baseUrl, >+ authHeader, >+ }); >+ >+ return { >+ patron, >+ ...(generatedLibrary ? { library } : {}), >+ ...(generatedCategory ? { patron_category } : {}), > }; > }; > >@@ -363,7 +431,7 @@ const deleteSampleObjects = async allObjects => { > return true; > }; > >-const insertLibrary = async (library, baseUrl, authHeader) => { >+const insertLibrary = async ({ library, baseUrl, authHeader }) => { > const { > pickup_items, > smtp_server, >@@ -382,52 +450,7 @@ const insertLibrary = async (library, baseUrl, authHeader) => { > }; > > const insertObject = async ({ type, object, baseUrl, authHeader }) => { >- if (type == "patron") { >- await query({ >- sql: "SELECT COUNT(*) AS count FROM branches WHERE branchcode = ?", >- values: [object.library_id], >- }).then(result => { >- if (!result[0].count) { >- insertLibrary(object.library, baseUrl, authHeader); >- } >- }); >- await query({ >- sql: "SELECT COUNT(*) AS count FROM categories WHERE categorycode= ?", >- values: [object.category_id], >- }).then(result => { >- if (!result[0].count) { >- query({ >- sql: "INSERT INTO categories(categorycode, description) VALUES (?, ?)", >- values: [ >- object.category_id, >- `description for ${object.category_id}`, >- ], >- }); >- } >- }); >- const { >- _strings, >- anonymized, >- restricted, >- expired, >- extended_attributes, >- library, >- checkouts_count, >- overdues_count, >- account_balance, >- lang, >- login_attempts, >- sms_provider_id, >- ...patron >- } = object; >- >- return apiPost({ >- endpoint: `/api/v1/patrons`, >- body: patron, >- baseUrl, >- authHeader, >- }); >- } else if (type == "library") { >+ if (type == "library") { > const keysToKeep = ["library_id", "name"]; > const library = Object.fromEntries( > Object.entries(object).filter(([key]) => keysToKeep.includes(key)) >@@ -511,6 +534,7 @@ module.exports = { > insertSampleBiblio, > insertSampleHold, > insertSampleCheckout, >+ insertSamplePatron, > insertObject, > deleteSampleObjects, > }; >-- >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 40345
:
183974
|
183975
|
183976
|
183977
|
183979
|
183983
|
183984
|
183985
|
183986
|
183987
|
183988