Bug 40169

Summary: Cypress tests - mockData should not replace "_id" fields if passed
Product: Koha Reporter: Jonathan Druart <jonathan.druart>
Component: Test SuiteAssignee: Jonathan Druart <jonathan.druart>
Status: Signed Off --- QA Contact: Testopia <testopia>
Severity: normal    
Priority: P5 - low CC: david
Version: unspecified   
Hardware: All   
OS: All   
GIT URL: Change sponsored?: ---
Patch complexity: --- Documentation contact:
Documentation submission: Text to go in the release notes:
Version(s) released in:
Circulation function:
Bug Depends on: 38503    
Bug Blocks:    
Attachments: Bug 40169: Add a test
Bug 40169: mockData - Do not replace _id if passed
Bug 40169: Add a test
Bug 40169: mockData - Do not replace _id if passed

Description Jonathan Druart 2025-06-18 20:18:27 UTC

    
Comment 1 Jonathan Druart 2025-06-18 20:24:19 UTC
Created attachment 183350 [details] [review]
Bug 40169: Add a test
Comment 2 Jonathan Druart 2025-06-18 20:24:21 UTC
Created attachment 183351 [details] [review]
Bug 40169: mockData - Do not replace _id if passed

If we build an object and pass a primary key (ie. suffixed by _id) we
should not replace it.

Test plan:
The test highlights the problem, it won't affect existing tests.
0. Apply only the first patch (Cypress tests)
1. Run yarn cypress run t/cypress/integration/t/mockData.ts
=> It fails
2. Apply this patch
=> It passes
Comment 3 David Nind 2025-06-18 23:34:17 UTC
I had failed tests before and after the patches were applied:

1. Failed tests before the patches were applied:
   - ERM/DataProviders_spec.ts
   - ERM/UsageReports_spec.ts

2. Failed tests with both the patches applied:
   - ERM/DataProviders_spec.ts 
   - ERM/UsageReports_spec.ts
   - KohaTable/Holdings_spec.ts
Comment 4 Jonathan Druart 2025-06-19 07:14:39 UTC
(In reply to David Nind from comment #3)
> I had failed tests before and after the patches were applied:
> 
> 1. Failed tests before the patches were applied:
>    - ERM/DataProviders_spec.ts
>    - ERM/UsageReports_spec.ts
> 
> 2. Failed tests with both the patches applied:
>    - ERM/DataProviders_spec.ts 
>    - ERM/UsageReports_spec.ts
>    - KohaTable/Holdings_spec.ts

Can you try again after a reset_all please? They all pass for me.

If still failing, could you paste the output?
Comment 5 Jonathan Druart 2025-06-19 07:16:29 UTC
(In reply to Jonathan Druart from comment #4)
> (In reply to David Nind from comment #3)
> > I had failed tests before and after the patches were applied:
> > 
> > 1. Failed tests before the patches were applied:
> >    - ERM/DataProviders_spec.ts
> >    - ERM/UsageReports_spec.ts
> > 
> > 2. Failed tests with both the patches applied:
> >    - ERM/DataProviders_spec.ts 
> >    - ERM/UsageReports_spec.ts
> >    - KohaTable/Holdings_spec.ts
> 
> Can you try again after a reset_all please? They all pass for me.
> 
> If still failing, could you paste the output?

Hum, the 2 ERM tests are indeed failing on main, and with this patch (so not related).
Comment 6 David Nind 2025-06-19 11:17:42 UTC
Created attachment 183378 [details] [review]
Bug 40169: Add a test

Signed-off-by: David Nind <david@davidnind.com>
Comment 7 David Nind 2025-06-19 11:17:45 UTC
Created attachment 183379 [details] [review]
Bug 40169: mockData - Do not replace _id if passed

If we build an object and pass a primary key (ie. suffixed by _id) we
should not replace it.

Test plan:
The test highlights the problem, it won't affect existing tests.
0. Apply only the first patch (Cypress tests)
1. Run yarn cypress run t/cypress/integration/t/mockData.ts
=> It fails
2. Apply this patch
=> It passes

Signed-off-by: David Nind <david@davidnind.com>
Comment 8 David Nind 2025-06-19 11:18:43 UTC
The tests (excluding the ERM ones) now pass.

Doing a reset_all seems to have done the trick.