Bugzilla – Attachment 184329 Details for
Bug 40174
Add a way to cleanly insert data in DB from Cypress tests
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 40174: Use api-client
Bug-40174-Use-api-client.patch (text/plain), 5.30 KB, created by
Martin Renvoize (ashimema)
on 2025-07-18 11:21:51 UTC
(
hide
)
Description:
Bug 40174: Use api-client
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2025-07-18 11:21:51 UTC
Size:
5.30 KB
patch
obsolete
>From 188d245e1af61550d823c02b6e74cf19acf34ca0 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Thu, 19 Jun 2025 11:40:12 +0200 >Subject: [PATCH] Bug 40174: Use api-client > >Signed-off-by: Matt Blenkinsop <matt.blenkinsop@openfifth.co.uk> >Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk> >--- > t/cypress/plugins/insertData.js | 68 +++++++++++++-------------------- > 1 file changed, 27 insertions(+), 41 deletions(-) > >diff --git a/t/cypress/plugins/insertData.js b/t/cypress/plugins/insertData.js >index e4fb6b484e7..3063679d177 100644 >--- a/t/cypress/plugins/insertData.js >+++ b/t/cypress/plugins/insertData.js >@@ -1,10 +1,9 @@ > const { buildSampleObject, buildSampleObjects } = require("./mockData.js"); > const { query } = require("./db.js"); > >-const { APIClient } = require("./dist/api-client.cjs.js"); >+const { apiGet, apiPost } = require("./api-client.js"); > > const insertSampleBiblio = async (item_count, baseUrl, authHeader) => { >- let client = APIClient.default; > let generated_objects = {}; > const objects = [{ object: "library" }, { object: "item_type" }]; > for (const { object } of objects) { >@@ -52,14 +51,15 @@ const insertSampleBiblio = async (item_count, baseUrl, authHeader) => { > }, > ], > }; >- let result = await client.koha.post({ >- endpoint: `${baseUrl}/api/v1/biblios`, >+ let result = await apiPost({ >+ endpoint: "/api/v1/biblios", > headers: { > "Content-Type": "application/marc-in-json", > "x-confirm-not-duplicate": 1, >- Authorization: authHeader, > }, > body: biblio, >+ baseUrl, >+ authHeader, > }); > const biblio_id = result.id; > // We do not have a route to get a biblio as it is stored in DB >@@ -124,16 +124,12 @@ const insertSampleBiblio = async (item_count, baseUrl, authHeader) => { > ); > let createdItems = []; > for (const item of items) { >- await client.koha >- .post({ >- endpoint: `${baseUrl}/api/v1/biblios/${biblio_id}/items`, >- body: item, >- headers: { >- "Content-Type": "application/json", >- Authorization: authHeader, >- }, >- }) >- .then(i => createdItems.push(i)); >+ await apiPost({ >+ endpoint: `/api/v1/biblios/${biblio_id}/items`, >+ body: item, >+ baseUrl, >+ authHeader, >+ }).then(i => createdItems.push(i)); > } > return { biblio, items: createdItems, library, item_type }; > }; >@@ -195,19 +191,15 @@ const insertLibrary = async (library, baseUrl, authHeader) => { > needs_override, > ...new_library > } = library; >- let client = APIClient.default; >- return client.koha.post({ >- endpoint: `${baseUrl}/api/v1/libraries`, >+ return apiPost({ >+ endpoint: "/api/v1/libraries", > body: new_library, >- headers: { >- "Content-Type": "application/json", >- Authorization: authHeader, >- }, >+ baseUrl, >+ authHeader, > }); > }; > > const insertObject = async (type, object, baseUrl, authHeader) => { >- let client = APIClient.default; > if (type == "patron") { > await query({ > sql: "SELECT COUNT(*) AS count FROM branches WHERE branchcode = ?", >@@ -247,26 +239,22 @@ const insertObject = async (type, object, baseUrl, authHeader) => { > ...patron > } = object; > >- return client.koha.post({ >- endpoint: `${baseUrl}/api/v1/patrons`, >+ return apiPost({ >+ endpoint: `/api/v1/patrons`, > body: patron, >- headers: { >- "Content-Type": "application/json", >- Authorization: authHeader, >- }, >+ baseUrl, >+ authHeader, > }); > } else if (type == "library") { > const keysToKeep = ["library_id", "name"]; > const library = Object.fromEntries( > Object.entries(object).filter(([key]) => keysToKeep.includes(key)) > ); >- return client.koha.post({ >- endpoint: `${baseUrl}/api/v1/libraries`, >- headers: { >- "Content-Type": "application/json", >- Authorization: authHeader, >- }, >+ return apiPost({ >+ endpoint: "/api/v1/libraries", > body: library, >+ baseUrl, >+ authHeader, > }); > } else if (type == "item_type") { > const keysToKeep = ["item_type_id", "description"]; >@@ -279,12 +267,10 @@ const insertObject = async (type, object, baseUrl, authHeader) => { > }) > .then(result => { > // FIXME We need /item_types/:item_type_id >- return client.koha.get({ >- endpoint: `${baseUrl}/api/v1/item_types?q={"item_type_id":"${item_type.item_type_id}"}`, >- headers: { >- "Content-Type": "application/json", >- Authorization: authHeader, >- }, >+ return apiGet({ >+ endpoint: `/api/v1/item_types?q={"item_type_id":"${item_type.item_type_id}"}`, >+ baseUrl, >+ authHeader, > }); > }) > .then(item_types => item_types[0]); >-- >2.50.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 40174
:
183372
|
183373
|
183374
|
183851
|
183929
|
183978
|
183980
|
183981
|
184103
|
184104
|
184105
|
184106
|
184107
|
184108
|
184195
|
184327
|
184328
| 184329 |
184330
|
184331
|
184332
|
184333