From 786eaeb7e94a54e26c6c89d0080dc3db103c978a Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 4 Dec 2024 14:05:51 +0100 Subject: [PATCH] Bug 38503: Do not list the objects No need to list all the objects, just retrieve the spec depending on the "object" var we pass. Signed-off-by: Victor Grousset/tuxayo --- t/cypress/plugins/mockData.js | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/t/cypress/plugins/mockData.js b/t/cypress/plugins/mockData.js index 0f41eaef2a..6cd20ed108 100644 --- a/t/cypress/plugins/mockData.js +++ b/t/cypress/plugins/mockData.js @@ -1,14 +1,7 @@ const { faker } = require("@faker-js/faker"); const { readYamlFile } = require("./../plugins/readYamlFile.js"); +const fs = require('fs'); -const objects = { - patron: { - spec: "patron", - }, - library: { - spec: "library", - }, -}; const generateMockData = type => { if (Array.isArray(type)) { type = type.filter(t => t != '"null"')[0]; @@ -50,10 +43,12 @@ const generateDataFromSchema = (properties, values = {}) => { }; const buildSampleObjects = ({ object, values, count = 1 }) => { - if (!objects.hasOwnProperty(object)) { - throw new Error(`Object type not supported: ${object}`); + const yamlPath = `api/v1/swagger/definitions/${object}.yaml`; + if (!fs.existsSync(yamlPath)) { + throw new Error( + `Object type not supported: '${object}'. No spec file.` + ); } - const yamlPath = `api/v1/swagger/definitions/${objects[object].spec}.yaml`; const schema = readYamlFile(yamlPath); return Array.from({ length: count }, () => generateDataFromSchema(schema.properties, values) -- 2.47.1