Bug 40174 - Add a way to cleanly insert data in DB from Cypress tests
Summary: Add a way to cleanly insert data in DB from Cypress tests
Status: Needs Signoff
Alias: None
Product: Koha
Classification: Unclassified
Component: Test Suite (show other bugs)
Version: unspecified
Hardware: All All
: P5 - low enhancement
Assignee: Jonathan Druart
QA Contact: Testopia
URL:
Keywords:
Depends on: 40170 40173 40179
Blocks: 40180
  Show dependency treegraph
 
Reported: 2025-06-18 21:10 UTC by Jonathan Druart
Modified: 2025-06-19 10:51 UTC (History)
0 users

See Also:
GIT URL:
Change sponsored?: ---
Patch complexity: ---
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:
Circulation function:


Attachments
Bug 40174: Allow proper E2E testing with Cypress (49.30 KB, patch)
2025-06-19 10:50 UTC, Jonathan Druart
Details | Diff | Splinter Review
Bug 40174: Introduce Cypress auth plugin (4.31 KB, patch)
2025-06-19 10:50 UTC, Jonathan Druart
Details | Diff | Splinter Review
Bug 40174: Use api-client (5.18 KB, patch)
2025-06-19 10:51 UTC, Jonathan Druart
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Jonathan Druart 2025-06-18 21:10:48 UTC
We need a way to insert into the DB the objects generated via mockData
Comment 1 Jonathan Druart 2025-06-19 10:50:58 UTC
Created attachment 183372 [details] [review]
Bug 40174: Allow proper E2E testing with Cypress

This is the first step toward implementing true end-to-end testing with
Cypress.

Until now, we have been mocking responses using cy.intercept(), but this
approach can lead to confusion. In some cases, we have even had to mock
global JavaScript variables, which makes the code unnecessarily complex
and unconventional (e.g. win.categories_map).

All the bug reports listed under this tree have helped lay the
groundwork for this patch. With it, we are able to build mock objects
(via plugin mockData) and insert them directly into the database
(insertData). Once the tests are complete, we’ll restore the database to
its previous state by removing any data generated during the tests.

The tests in KohaTable/Holdings_spec.ts have been updated to leverage
this new setup.

Additionally, a caching mechanism has been added to prevent _id
attributes from being generated with the same values (a rare issue we
occasionally encountered).

While this is still not a perfect solution, it introduces a solid
foundation for future improvements.

Test plan:
All Cypress tests must pass
Comment 2 Jonathan Druart 2025-06-19 10:50:59 UTC
Created attachment 183373 [details] [review]
Bug 40174: Introduce Cypress auth plugin

So we can easily retrieve the value for the Authorization header.
Comment 3 Jonathan Druart 2025-06-19 10:51:01 UTC
Created attachment 183374 [details] [review]
Bug 40174: Use api-client