From 17134bd7156ea2a793e3bf488b4c315d905fa510 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 21 Nov 2024 14:06:41 +0100 Subject: [PATCH] Bug 38503: Same for libraries --- t/cypress/integration/t/mockData.ts | 17 +++++++++++++++++ t/cypress/plugins/index.js | 9 ++++++++- t/cypress/plugins/mockData.js | 14 ++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/t/cypress/integration/t/mockData.ts b/t/cypress/integration/t/mockData.ts index 22379c3ff0d..3ca84da9208 100644 --- a/t/cypress/integration/t/mockData.ts +++ b/t/cypress/integration/t/mockData.ts @@ -16,3 +16,20 @@ describe("Generate Random Patrons", () => { }); }); }); + +describe("Generate Random Library", () => { + it("should generate a random library from the schema", () => { + cy.task("buildSampleLibrary").then(mockLibrary => { + expect(mockLibrary).to.have.property("library_id"); + }); + }); +}); + +describe("Generate Random Libraries", () => { + it("should generate 42 random library from the schema", () => { + cy.task("buildSampleLibraries", 42).then(mockLibraries => { + expect(mockLibraries.length).to.equal(42); + expect(mockLibraries[0]).to.have.property("library_id"); + }); + }); +}); diff --git a/t/cypress/plugins/index.js b/t/cypress/plugins/index.js index be07e4fe8ed..990b98bc174 100644 --- a/t/cypress/plugins/index.js +++ b/t/cypress/plugins/index.js @@ -18,12 +18,19 @@ module.exports = (on, config) => { mysql.configurePlugin(on); }; -const { buildSamplePatron, buildSamplePatrons } = require("./mockData.js"); +const { + buildSamplePatron, + buildSamplePatrons, + buildSampleLibrary, + buildSampleLibraries, +} = require("./mockData.js"); module.exports = (on, config) => { on("task", { buildSamplePatron, buildSamplePatrons, + buildSampleLibrary, + buildSampleLibraries, }); return config; }; diff --git a/t/cypress/plugins/mockData.js b/t/cypress/plugins/mockData.js index abcf0adc03e..a0b2d56a118 100644 --- a/t/cypress/plugins/mockData.js +++ b/t/cypress/plugins/mockData.js @@ -38,9 +38,23 @@ const buildSamplePatron = () => { return buildSamplePatrons()[0]; }; +const buildSampleLibraries = (count = 1) => { + const yamlPath = "api/v1/swagger/definitions/library.yaml"; + const schema = readYamlFile(yamlPath); + return Array.from({ length: count }, () => + generateDataFromSchema(schema.properties) + ); +}; + +const buildSampleLibrary = () => { + return buildSampleLibraries()[0]; +}; + module.exports = { generateMockData, generateDataFromSchema, buildSamplePatron, buildSamplePatrons, + buildSampleLibrary, + buildSampleLibraries, }; -- 2.34.1