From 401abad48be31330a09872e907dc4924f6a821e3 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 21 Nov 2024 15:13:10 +0100 Subject: [PATCH] Bug 38503: Generate correct values for date and date-time --- t/cypress/integration/t/mockData.ts | 5 +++++ t/cypress/plugins/mockData.js | 10 +++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/t/cypress/integration/t/mockData.ts b/t/cypress/integration/t/mockData.ts index 5ca38a99998..60c1c2118d7 100644 --- a/t/cypress/integration/t/mockData.ts +++ b/t/cypress/integration/t/mockData.ts @@ -13,6 +13,11 @@ describe("Generate Random Patron", () => { }).then(mockPatron => { expect(mockPatron.surname).to.equal("test_surname"); expect(mockPatron.overdues_count).to.be.a("number"); + expect(mockPatron.date_of_birth).to.match(/^\d{4}-\d{2}-\d{2}$/); + // TODO We are not testing for timezone part + expect(mockPatron.updated_on).to.match( + /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/ + ); }); }); }); diff --git a/t/cypress/plugins/mockData.js b/t/cypress/plugins/mockData.js index 855a55ba692..0f41eaef2a7 100644 --- a/t/cypress/plugins/mockData.js +++ b/t/cypress/plugins/mockData.js @@ -24,6 +24,10 @@ const generateMockData = type => { return [faker.lorem.word(), faker.lorem.word()]; case "number": return faker.number.float(); + case "date": + return new Date().toISOString().split("T")[0]; + case "date-time": + return new Date().toISOString(); default: return faker.lorem.word(); } @@ -35,7 +39,11 @@ const generateDataFromSchema = (properties, values = {}) => { if (values.hasOwnProperty(key)) { mockData[key] = values[key]; } else { - mockData[key] = generateMockData(value.type); + let type = + value?.format == "date" || value?.format == "date-time" + ? value.format + : value.type; + mockData[key] = generateMockData(type); } }); return mockData; -- 2.34.1