[Bug 44270] New: Add Cypress helpers to create a staff member and log in as them
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44270 Bug ID: 44270 Summary: Add Cypress helpers to create a staff member and log in as them Initiative type: --- Sponsorship --- status: Product: Koha Version: Main Hardware: All OS: All Status: NEW Severity: enhancement Priority: P5 - low Component: Test Suite Assignee: chris@bigballofwax.co.nz Reporter: nick@bywatersolutions.com QA Contact: testopia@bugs.koha-community.org Target Milestone: --- Several Cypress specs need a staff member with specific permissions, and each builds one by hand, we should centralize this routine -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44270 Nick Clemens (kidclamp) <nick@bywatersolutions.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Blocks| |44271 -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44270 Nick Clemens (kidclamp) <nick@bywatersolutions.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Assignee|chris@bigballofwax.co.nz |nick@bywatersolutions.com Status|NEW |Needs Signoff -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44270 --- Comment #1 from Nick Clemens (kidclamp) <nick@bywatersolutions.com> --- Created attachment 212569 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=212569&action=edit Bug 44270: Add Cypress helpers to create a staff member and log in as them Several Cypress specs need a staff member with specific permissions, and each builds one by hand: insertSamplePatron, then SQL for borrowers.flags and user_permissions, then the password through the API, then their own login and cleanup code. This adds: - the insertSampleStaff task, which creates a staff member who can log in to the staff interface (catalogue is always given) with the requested permissions, written as "module" or "module:subpermission": cy.task("insertSampleStaff", { permissions: ["tools:upload_general_files"], library: { library_id: "CPL" }, }) It returns { patron, password } (and the generated library and patron category, if any), which can be passed to deleteSampleObjects. The permissions are deleted with the patron by the database. - the cy.loginAs(staff) command, which clears the cookies and logs in as that staff member borrowers.flags is computed with 2 ** bit: some permission modules have a bit above 30 (sip2 is 31, item_lists 33), which 1 << bit gets wrong in JavaScript. Test plan: npx cypress run --spec t/cypress/integration/t/insertData.ts The insertSampleStaff tests pass. (insertSampleHold needs circulation rules that allow holds.) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44270 --- Comment #2 from Nick Clemens (kidclamp) <nick@bywatersolutions.com> --- Created attachment 212570 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=212570&action=edit Bug 44270: Use insertSampleStaff and cy.loginAs in the notices tests The notices management tests built their staff members by hand. They now use the shared insertSampleStaff task and cy.loginAs command. The permissions are written as names ("tools:view_generated_notices") rather than module bits. Test plan: npx cypress run --spec t/cypress/integration/Tools/NoticesManagement_spec.ts All pass, as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44270 David Nind <david@davidnind.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|Needs Signoff |Signed Off -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44270 David Nind <david@davidnind.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #212569|0 |1 is obsolete| | Attachment #212570|0 |1 is obsolete| | -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44270 --- Comment #3 from David Nind <david@davidnind.com> --- Created attachment 212585 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=212585&action=edit Bug 44270: Add Cypress helpers to create a staff member and log in as them Several Cypress specs need a staff member with specific permissions, and each builds one by hand: insertSamplePatron, then SQL for borrowers.flags and user_permissions, then the password through the API, then their own login and cleanup code. This adds: - the insertSampleStaff task, which creates a staff member who can log in to the staff interface (catalogue is always given) with the requested permissions, written as "module" or "module:subpermission": cy.task("insertSampleStaff", { permissions: ["tools:upload_general_files"], library: { library_id: "CPL" }, }) It returns { patron, password } (and the generated library and patron category, if any), which can be passed to deleteSampleObjects. The permissions are deleted with the patron by the database. - the cy.loginAs(staff) command, which clears the cookies and logs in as that staff member borrowers.flags is computed with 2 ** bit: some permission modules have a bit above 30 (sip2 is 31, item_lists 33), which 1 << bit gets wrong in JavaScript. Test plan: npx cypress run --spec t/cypress/integration/t/insertData.ts The insertSampleStaff tests pass. (insertSampleHold needs circulation rules that allow holds.) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: David Nind <david@davidnind.com> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44270 --- Comment #4 from David Nind <david@davidnind.com> --- Created attachment 212586 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=212586&action=edit Bug 44270: Use insertSampleStaff and cy.loginAs in the notices tests The notices management tests built their staff members by hand. They now use the shared insertSampleStaff task and cy.loginAs command. The permissions are written as names ("tools:view_generated_notices") rather than module bits. Test plan: npx cypress run --spec t/cypress/integration/Tools/NoticesManagement_spec.ts All pass, as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: David Nind <david@davidnind.com> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44270 Jonathan Druart <jonathan.druart@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |jonathan.druart@gmail.com Status|Signed Off |Failed QA --- Comment #5 from Jonathan Druart <jonathan.druart@gmail.com> --- I think insertSampleStaff should accept the same values as C4::Auth::haspermission, don't you? -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44270 Nick Clemens (kidclamp) <nick@bywatersolutions.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|Failed QA |Signed Off -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44270 --- Comment #6 from Nick Clemens (kidclamp) <nick@bywatersolutions.com> --- Created attachment 212710 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=212710&action=edit Bug 44270: (QA follow-up) Accept the permissions as C4::Auth::haspermission does insertSampleStaff now takes its permissions as the flagsrequired parameter of C4::Auth::haspermission, rather than "module" and "module:subpermission" strings, so that haspermission( userid, permissions ) is true for the created staff member: "tools" or { tools: 1 } the whole module { superlibrarian: 1 } superlibrarian { tools: "upload_manage" } a subpermission { borrowers: { edit_borrowers: 1, list_borrowers: 1 } } { tools: ["upload_manage", "export_catalog"] } ["circulate", { tools: "upload_manage" }] Where haspermission accepts any of a list (arrays), all of them are given. "*" (any module, or any subpermission of a module) does not say which permission to give, and is rejected. The notices management tests are adjusted. Test plan: npx cypress run --spec t/cypress/integration/t/insertData.ts,t/cypress/integration/Tools/NoticesManagement_spec.ts All pass. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> -- You are receiving this mail because: You are watching all bug changes.
participants (1)
-
bugzilla-daemon@bugs.koha-community.org