Bug 36493

Summary: Test for GET /api/v1/cash_registers/:cash_register_id/cashups is fragile
Product: Koha Reporter: Tomás Cohen Arazi (tcohen) <tomascohen>
Component: REST APIAssignee: Tomás Cohen Arazi (tcohen) <tomascohen>
Status: Pushed to oldstable --- QA Contact: Marcel de Rooy <m.de.rooy>
Severity: normal    
Priority: P5 - low CC: david, fridolin.somers, lucas, m.de.rooy, tomascohen
Version: Main   
Hardware: All   
OS: All   
Change sponsored?: --- Patch complexity: Trivial patch
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
24.05.00,23.11.06,23.05.12
Circulation function:
Bug Depends on: 26274    
Bug Blocks:    
Attachments: Bug 36493: Make cashups test more robust
Bug 36493: Make cashups test more robust
Bug 36493: Make cashups test more robust

Description Tomás Cohen Arazi (tcohen) 2024-04-02 15:36:55 UTC
This test fails if Koha has a cash register defined already, with ID=1.

To reproduce:
1. Fire up a fresh KTD
2. Add a cash register (needs UseCashRegisters enabled)
3. Run:
   $ ktd --shell
  k$ prove t/db_dependent/api/v1/cashups.t
=> FAIL: Expecting a 404 ("Register not found"), getting a 200.
Comment 1 Tomás Cohen Arazi (tcohen) 2024-04-02 15:42:29 UTC
Created attachment 164285 [details] [review]
Bug 36493: Make cashups test more robust

This patch makes the test independent from existing cash registers in
the system.

To test:
1. Enable UseCashRegisters on a fresh KTD
2. Add a cash register
3. Run:
   $ ktd --shell
  k$ prove t/db_dependent/api/v1/cashups.t
=> FAIL: Tests fail!
4. Apply this patch
5. Repeat 3
=> SUCCESS: Tests pass!
6. Sign off :-D

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Comment 2 David Nind 2024-04-02 17:44:53 UTC
Created attachment 164288 [details] [review]
Bug 36493: Make cashups test more robust

This patch makes the test independent from existing cash registers in
the system.

To test:
1. Enable UseCashRegisters on a fresh KTD
2. Add a cash register
3. Run:
   $ ktd --shell
  k$ prove t/db_dependent/api/v1/cashups.t
=> FAIL: Tests fail!
4. Apply this patch
5. Repeat 3
=> SUCCESS: Tests pass!
6. Sign off :-D

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: David Nind <david@davidnind.com>
Comment 3 David Nind 2024-04-02 17:49:39 UTC
Testing notes (using KTD):

1. The first cash register created doesn't always have an ID of 1.

2. I had to update the database manually to have one with an ID of 1:
   - Access the database: koha-mysql kohadev
   - Get a list of cash registers: select * from cash_registers;
   - Update the cash register ID (XXXXX = the name of the cash register from
     the first query): 
      update cash_registers set id=1 where name="XXXXX";
Comment 4 Marcel de Rooy 2024-04-12 06:26:50 UTC
Created attachment 164788 [details] [review]
Bug 36493: Make cashups test more robust

This patch makes the test independent from existing cash registers in
the system.

To test:
1. Enable UseCashRegisters on a fresh KTD
2. Add a cash register
3. Run:
   $ ktd --shell
  k$ prove t/db_dependent/api/v1/cashups.t
=> FAIL: Tests fail!
4. Apply this patch
5. Repeat 3
=> SUCCESS: Tests pass!
6. Sign off :-D

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: David Nind <david@davidnind.com>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Comment 5 Katrin Fischer 2024-04-12 09:28:23 UTC
Pushed for 24.05!

Well done everyone, thank you!
Comment 6 Fridolin Somers 2024-05-23 12:36:26 UTC
Pushed to 23.11.x for 23.11.06
Comment 7 Lucas Gass (lukeg) 2024-05-28 17:54:21 UTC
Backported to 23.05.x for upcoming 23.05.12