Bugzilla – Attachment 183356 Details for
Bug 40173
Reuse http-client from Cypress tests - preparation steps
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 40173: Add test for the api-client Cypress plugin
Bug-40173-Add-test-for-the-api-client-Cypress-plug.patch (text/plain), 4.11 KB, created by
Jonathan Druart
on 2025-06-18 21:05:54 UTC
(
hide
)
Description:
Bug 40173: Add test for the api-client Cypress plugin
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2025-06-18 21:05:54 UTC
Size:
4.11 KB
patch
obsolete
>From 79b52ba5f52da616ef64250f06a70fd62ef97ed5 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Mon, 16 Jun 2025 11:10:07 +0200 >Subject: [PATCH] Bug 40173: Add test for the api-client Cypress plugin > >--- > t/cypress/integration/t/api-client.ts | 28 ++++++++++++++ > t/cypress/plugins/api-client.js | 56 +++++++++++++++++++++++++++ > t/cypress/plugins/index.js | 15 +++++++ > 3 files changed, 99 insertions(+) > create mode 100644 t/cypress/integration/t/api-client.ts > create mode 100644 t/cypress/plugins/api-client.js > >diff --git a/t/cypress/integration/t/api-client.ts b/t/cypress/integration/t/api-client.ts >new file mode 100644 >index 00000000000..7fb60112272 >--- /dev/null >+++ b/t/cypress/integration/t/api-client.ts >@@ -0,0 +1,28 @@ >+const { APIClient } = require("./../../plugins/dist/api-client.cjs.js"); >+ >+describe("Using APIClient", () => { >+ let client = APIClient.default; >+ it("should 404 for non-existent biblio", async () => { >+ try { >+ await client.koha.get({ >+ endpoint: "/api/v1/public/biblios/99999", >+ return_response: true, >+ }); >+ } catch (error) { >+ expect(error.response.status).to.equal(404); >+ } >+ }); >+}); >+ >+describe("Using the api-client plugin", () => { >+ it("should 404 for non-existent biblio", async () => { >+ try { >+ await cy.task("apiGet", { >+ endpoint: "/api/v1/public/biblios/99999", >+ return_response: true, >+ }); >+ } catch (error) { >+ expect(error.response.status).to.equal(404); >+ } >+ }); >+}); >diff --git a/t/cypress/plugins/api-client.js b/t/cypress/plugins/api-client.js >new file mode 100644 >index 00000000000..db246e419e4 >--- /dev/null >+++ b/t/cypress/plugins/api-client.js >@@ -0,0 +1,56 @@ >+const { APIClient } = require("./dist/api-client.cjs.js"); >+ >+const client = APIClient.default.koha; >+ >+const prepareRequest = params => { >+ const { baseUrl, endpoint, authHeader, headers = {}, ...rest } = params; >+ const url = baseUrl + endpoint; >+ const finalHeaders = { >+ ...headers, >+ ...(authHeader ? { Authorization: authHeader } : {}), >+ }; >+ return { url, headers: finalHeaders, rest }; >+}; >+ >+const apiGet = params => { >+ const { url, headers, rest } = prepareRequest(params); >+ return client.get({ >+ endpoint: url, >+ headers, >+ ...rest, >+ }); >+}; >+ >+const apiPost = params => { >+ const { url, headers, rest } = prepareRequest(params); >+ return client.post({ >+ endpoint: url, >+ headers, >+ ...rest, >+ }); >+}; >+ >+const apiPut = params => { >+ const { url, headers, rest } = prepareRequest(params); >+ return client.put({ >+ endpoint: url, >+ headers, >+ ...rest, >+ }); >+}; >+ >+const apiDelete = params => { >+ const { url, headers, rest } = prepareRequest(params); >+ return client.delete({ >+ endpoint: url, >+ headers, >+ ...rest, >+ }); >+}; >+ >+module.exports = { >+ apiGet, >+ apiPost, >+ apiPut, >+ apiDelete, >+}; >diff --git a/t/cypress/plugins/index.js b/t/cypress/plugins/index.js >index 837e6d747cb..4f961d2caeb 100644 >--- a/t/cypress/plugins/index.js >+++ b/t/cypress/plugins/index.js >@@ -4,6 +4,8 @@ const mysql = require("cypress-mysql"); > > const { buildSampleObject, buildSampleObjects } = require("./mockData.js"); > >+const { apiGet, apiPost, apiPut, apiDelete } = require("./api-client.js"); >+ > module.exports = (on, config) => { > on("dev-server:start", options => > startDevServer({ >@@ -16,6 +18,19 @@ module.exports = (on, config) => { > on("task", { > buildSampleObject, > buildSampleObjects, >+ >+ apiGet(args) { >+ return apiGet({ ...args, baseUrl, authHeader }); >+ }, >+ apiPost(args) { >+ return apiPost({ ...args, baseUrl, authHeader }); >+ }, >+ apiPut(args) { >+ return apiPut({ ...args, baseUrl, authHeader }); >+ }, >+ apiDelete(args) { >+ return apiDelete({ ...args, baseUrl, authHeader }); >+ }, > }); > return config; > }; >-- >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 40173
:
183354
|
183355
| 183356