We have TestBuilder for the Perl tests. However for the Cypress tests we have to: 1. either mock all the routes (which is painful and time-consuming), 2. or rely on the existing data in DB (which will produce failures if data has been inserted, and tests will have to cleanup before/after, which is painful, time-consuming and not robust) We should have a way to generate objects easily, in order to mock the response of a GET route easily. We can actually rely on the swagger spec files (the definition file) to generate random data and mock the response of routes. The first intended goal is to provide tests for the tables (bug 38461) and allow future enhancements in this area (see dependent bugs of bug 36640).
Created attachment 174872 [details] [review] Bug 38503: Read patron swagger spec file and implement buildSamplePatron
Created attachment 174873 [details] [review] Bug 38503: Implement a plural form - buildSamplePatrons
Created attachment 174874 [details] [review] Bug 38503: Same for libraries
Created attachment 174875 [details] [review] Bug 38503: Have a generic buildSampleObject[s]
Created attachment 174876 [details] [review] Bug 38503: Allow to pass values
Created attachment 174884 [details] [review] Bug 38503: Deal with types that can be "null"
Created attachment 174885 [details] [review] Bug 38503: Generate correct values for date and date-time
Created attachment 174921 [details] [review] Bug 38503: [DO NOT PUSH] (follow-up) Generate correct values for date and date-time
Created attachment 174922 [details] [review] Bug 38503: [DO NOT PUSH] (follow-up) Upgrade @vue/cli-service for compat with node v22
Sorry, forgot to edit the commit message the first time. So for compatibility with node v22, I just upgraded @vue/cli-service to its latest version. To reproduce: 1) Make sure you are on node v22 2) Apply the patch interactively without the updated lockfile 3) Run `yarn install` 4) Observe error: kohadev-koha@kohadevbox:koha(bug_38503)$ yarn install yarn install v1.22.22 [1/4] Resolving packages... [2/4] Fetching packages... error @achrinza/node-ipc@9.2.5: The engine "node" is incompatible with this module. Expected version "8 || 9 || 10 || 11 || 12 || 13 || 14 || 15 || 16 || 17 || 18". Got "22.11.0" error Found incompatible module. info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command. 5) Apply the last patch as well 6) Observe success kohadev-koha@kohadevbox:koha(bug_38503)$ yarn install yarn install v1.22.22 [1/4] Resolving packages... [2/4] Fetching packages... [3/4] Linking dependencies... warning "@redocly/cli > redoc > @cfaester/enzyme-adapter-react-18@0.8.0" has unmet peer dependency "enzyme@^3.11.0". warning " > eslint-config-prettier@9.1.0" has unmet peer dependency "eslint@>=7.0.0". warning " > eslint-plugin-prettier@5.1.3" has unmet peer dependency "eslint@>=8.0.0". warning " > eslint-plugin-prettier@5.1.3" has unmet peer dependency "prettier@>=3.0.0". warning "swagger-cli > @apidevtools/swagger-cli > @apidevtools/swagger-parser@10.1.0" has unmet peer dependency "openapi-types@>=7". [4/4] Building fresh packages... Done in 303.71s.
Does this really depend on vue-cli? - I upgraded node to v22 - applied all patches - removed vue-cli and babel deps - sudo yarn install --modules-folder /kohadevbox/node_modules and t/cypress/integration/t/mockData.ts ran after doing the same removals as: https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=174858&action=diff cypress output confirms it's using node 22 Is there anything else to test?
Created attachment 175173 [details] [review] Bug 38503: Do not list the objects No need to list all the objects, just retrieve the spec depending on the "object" var we pass.
Created attachment 175175 [details] [review] Bug 38503: Do not list the objects No need to list all the objects, just retrieve the spec depending on the "object" var we pass.
Ready to go as a first step.
Created attachment 175212 [details] [review] Bug 38503: Read patron swagger spec file and implement buildSamplePatron Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net>
Created attachment 175213 [details] [review] Bug 38503: Implement a plural form - buildSamplePatrons Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net>
Created attachment 175214 [details] [review] Bug 38503: Same for libraries Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net>
Created attachment 175215 [details] [review] Bug 38503: Have a generic buildSampleObject[s] Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net>
Created attachment 175216 [details] [review] Bug 38503: Allow to pass values Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net>
Created attachment 175217 [details] [review] Bug 38503: Deal with types that can be "null" Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net>
Created attachment 175218 [details] [review] Bug 38503: Generate correct values for date and date-time Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net>
Created attachment 175219 [details] [review] Bug 38503: [DO NOT PUSH] (follow-up) Upgrade @vue/cli-service for compat with node v22 Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net>
Created attachment 175220 [details] [review] Bug 38503: Do not list the objects No need to list all the objects, just retrieve the spec depending on the "object" var we pass. Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net>
Created attachment 175221 [details] [review] Bug 38503: [PROPOSAL] deps: remove @vue/cli-service & babel They really don't seem needed
Created attachment 175222 [details] [review] Bug 38503: [DO NOT PUSH] Update yarn.lock for the previous [PROPOSAL]
It works! :) 150 runs done. Without @vue/cli-service and babel. I'm also hammering bug 38461 tests. So it really really looks like cli-service isn't a dependency. Hence the two last commits added to remove them. It also works with @vue/cli-service and babel not removed. ----- > Bug 38503: [DO NOT PUSH] (follow-up) Upgrade @vue/cli-service for compat with node v22 Assuming it's confirmed we don't need vue/cli-service & babel: The commit above would not be needed. But it worth mentioning that it had an issue for future node package stuff: It's a [DO NOT PUSH] commit that had the task of updating deps. So that update will be lost. We can't have anything meaningful in yarn.lock with the current workflow. (which seems to be good btw) If only an RM/RMaint touches yark.lock then dependency updates need to be done in package.json. Not only to work in our workflow but also to document accurately that we need more recent deps.
additional info: still works if forgetting to upgrade node from 18 to 22. That's still a good opportunity to upgrade though. (to test, edit version in /etc/apt/sources.list.d/nodesource.list and then `sudo apt update;sudo install nodejs`)
This patch should be moved to its own bug report. "Bug 38503: [PROPOSAL] deps: remove @vue/cli-service & babel"
Created attachment 175888 [details] [review] Bug 38503: Read patron swagger spec file and implement buildSamplePatron Test plan: 1. Install deps sudo yarn install --modules-folder /kohadevbox/node_modules 2. Run tests cypress run --config video=false --spec t/cypress/integration/t/mockData.ts Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net>
Created attachment 175889 [details] [review] Bug 38503: Implement a plural form - buildSamplePatrons Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net>
Created attachment 175890 [details] [review] Bug 38503: Same for libraries Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net>
Created attachment 175891 [details] [review] Bug 38503: Have a generic buildSampleObject[s] Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net>
Created attachment 175892 [details] [review] Bug 38503: Allow to pass values Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net>
Created attachment 175893 [details] [review] Bug 38503: Deal with types that can be "null" Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net>
Created attachment 175894 [details] [review] Bug 38503: Generate correct values for date and date-time Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net>
Created attachment 175895 [details] [review] Bug 38503: Do not list the objects No need to list all the objects, just retrieve the spec depending on the "object" var we pass. Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net>
Created attachment 175896 [details] [review] Bug 38503: [DO NOT PUSH] yarn.lock changes
(In reply to Jonathan Druart from comment #28) > This patch should be moved to its own bug report. > "Bug 38503: [PROPOSAL] deps: remove @vue/cli-service & babel" Moved to Bug 38770. And not added as a dependency because there is no sign it's needed for the test plan to work (unless steps were missing?) ---- test plan added in 1st commit ---- yarn.lock changes commit added
Created attachment 176073 [details] [review] Bug 38503: Read patron swagger spec file and implement buildSamplePatron Test plan: 1. Install deps sudo yarn install --modules-folder /kohadevbox/node_modules 2. Run tests cypress run --config video=false --spec t/cypress/integration/t/mockData.ts Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net> Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Created attachment 176074 [details] [review] Bug 38503: Implement a plural form - buildSamplePatrons Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net> Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Created attachment 176075 [details] [review] Bug 38503: Same for libraries Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net> Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Created attachment 176076 [details] [review] Bug 38503: Have a generic buildSampleObject[s] Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net> Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Created attachment 176077 [details] [review] Bug 38503: Allow to pass values Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net> Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Created attachment 176078 [details] [review] Bug 38503: Deal with types that can be "null" Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net> Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Created attachment 176079 [details] [review] Bug 38503: Generate correct values for date and date-time Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net> Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Created attachment 176080 [details] [review] Bug 38503: Do not list the objects No need to list all the objects, just retrieve the spec depending on the "object" var we pass. Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net> Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Created attachment 176081 [details] [review] Bug 38503: [DO NOT PUSH] yarn.lock changes Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
This is a great step forward, nice approach. All works as expected, mocking endpoints is easy now :) Passing QA Minor niggle.. we need some good release notes for this one and good developer documentation somewhere to encourage it's adoption.
> Minor niggle.. we need some good release notes for this one Here is a first try. > and good developer documentation somewhere to encourage it's adoption. There doesn't seem to be documentation for Cypress tests for now ^^" . Much less for mocking API responses where this would fit well.
Thanks :)
*** Bug 36607 has been marked as a duplicate of this bug. ***
Pushed for 25.05! Well done everyone, thank you!
Created attachment 176775 [details] [review] Bug 38503: Merge the module.exports We redefine it and so the query/mysql plugin is not available It fixes csrf.ts 14:36:17 koha_1 | The task 'query' was not handled in the setupNodeEvents method. The following tasks are registered: buildSampleObject, buildSampleObjects
Created attachment 176776 [details] [review] Bug 38503: Merge the module.exports We redefine it and so the query/mysql plugin is not available It fixes csrf.ts 14:36:17 koha_1 | The task 'query' was not handled in the setupNodeEvents method. The following tasks are registered: buildSampleObject, buildSampleObjects
Created attachment 176792 [details] [review] Bug 38503: Do not generate too long strings
Please set status to PQA when you attach follow-ups for me to push. Helps me keep on top of things. Last 2 patches picked for main.