From c7893fda314c5927ac64fca26f9c0169890cef0f Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 16 Jun 2025 14:05:57 +0200 Subject: [PATCH] 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 --- t/cypress/integration/t/mockData.ts | 8 ++++++++ t/cypress/plugins/mockData.js | 5 ++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/t/cypress/integration/t/mockData.ts b/t/cypress/integration/t/mockData.ts index 1c586fac76..29aa1f28eb 100644 --- a/t/cypress/integration/t/mockData.ts +++ b/t/cypress/integration/t/mockData.ts @@ -20,6 +20,14 @@ describe("Generate Random Patron", () => { ); }); }); + + it.only("should not overwrite _id if passed", () => { + const home_library_id = "LIB4TEST"; + cy.task("buildSampleObject", {object: "item", values: {home_library_id}}).then(mockItem => { + expect(mockItem.home_library_id).to.equal(home_library_id); + }); + }); + }); describe("Generate Random Patrons", () => { diff --git a/t/cypress/plugins/mockData.js b/t/cypress/plugins/mockData.js index 0f9c292df8..c2025abeeb 100644 --- a/t/cypress/plugins/mockData.js +++ b/t/cypress/plugins/mockData.js @@ -74,7 +74,10 @@ const generateDataFromSchema = (properties, values = {}) => { }); Object.keys(ids).forEach(k => { - if (mockData.hasOwnProperty(k + "_id")) { + if ( + mockData.hasOwnProperty(k + "_id") && + !values.hasOwnProperty(k + "_id") + ) { mockData[k + "_id"] = ids[k]; } }); -- 2.39.5