Bugzilla – Attachment 175215 Details for
Bug 38503
Add a Cypress task to generate objects based on its swagger def spec
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 38503: Have a generic buildSampleObject[s]
Bug-38503-Have-a-generic-buildSampleObjects.patch (text/plain), 5.37 KB, created by
Victor Grousset/tuxayo
on 2024-12-05 05:53:24 UTC
(
hide
)
Description:
Bug 38503: Have a generic buildSampleObject[s]
Filename:
MIME Type:
Creator:
Victor Grousset/tuxayo
Created:
2024-12-05 05:53:24 UTC
Size:
5.37 KB
patch
obsolete
>From 9b229c053dedf1e979d3f432e6ed884c1392e12e Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Thu, 21 Nov 2024 14:07:31 +0100 >Subject: [PATCH] Bug 38503: Have a generic buildSampleObject[s] > >Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net> >--- > t/cypress/integration/t/mockData.ts | 30 +++++++++++++---------- > t/cypress/plugins/index.js | 13 +++------- > t/cypress/plugins/mockData.js | 37 +++++++++++++---------------- > 3 files changed, 38 insertions(+), 42 deletions(-) > >diff --git a/t/cypress/integration/t/mockData.ts b/t/cypress/integration/t/mockData.ts >index 3ca84da920..6624909173 100644 >--- a/t/cypress/integration/t/mockData.ts >+++ b/t/cypress/integration/t/mockData.ts >@@ -2,7 +2,7 @@ import { mount } from "@cypress/vue"; > > describe("Generate Random Patron", () => { > it("should generate a random patron from the schema", () => { >- cy.task("buildSamplePatron").then(mockPatron => { >+ cy.task("buildSampleObject", { object: "patron" }).then(mockPatron => { > expect(mockPatron).to.have.property("patron_id"); > }); > }); >@@ -10,26 +10,32 @@ describe("Generate Random Patron", () => { > > describe("Generate Random Patrons", () => { > it("should generate 42 random patron from the schema", () => { >- cy.task("buildSamplePatrons", 42).then(mockPatrons => { >- expect(mockPatrons.length).to.equal(42); >- expect(mockPatrons[0]).to.have.property("patron_id"); >- }); >+ cy.task("buildSampleObjects", { object: "patron", count: 42 }).then( >+ mockPatrons => { >+ expect(mockPatrons.length).to.equal(42); >+ expect(mockPatrons[0]).to.have.property("patron_id"); >+ } >+ ); > }); > }); > > 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"); >- }); >+ cy.task("buildSampleObject", { object: "library" }).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"); >- }); >+ cy.task("buildSampleObjects", { object: "library", count: 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 990b98bc17..6a5e123a86 100644 >--- a/t/cypress/plugins/index.js >+++ b/t/cypress/plugins/index.js >@@ -18,19 +18,12 @@ module.exports = (on, config) => { > mysql.configurePlugin(on); > }; > >-const { >- buildSamplePatron, >- buildSamplePatrons, >- buildSampleLibrary, >- buildSampleLibraries, >-} = require("./mockData.js"); >+const { buildSampleObject, buildSampleObjects } = require("./mockData.js"); > > module.exports = (on, config) => { > on("task", { >- buildSamplePatron, >- buildSamplePatrons, >- buildSampleLibrary, >- buildSampleLibraries, >+ buildSampleObject, >+ buildSampleObjects, > }); > return config; > }; >diff --git a/t/cypress/plugins/mockData.js b/t/cypress/plugins/mockData.js >index a0b2d56a11..5bb9bb75b2 100644 >--- a/t/cypress/plugins/mockData.js >+++ b/t/cypress/plugins/mockData.js >@@ -1,6 +1,14 @@ > const { faker } = require("@faker-js/faker"); > const { readYamlFile } = require("./../plugins/readYamlFile.js"); > >+const objects = { >+ patron: { >+ spec: "patron", >+ }, >+ library: { >+ spec: "library", >+ }, >+}; > const generateMockData = type => { > switch (type) { > case "string": >@@ -26,35 +34,24 @@ const generateDataFromSchema = properties => { > return mockData; > }; > >-const buildSamplePatrons = (count = 1) => { >- const yamlPath = "api/v1/swagger/definitions/patron.yaml"; >- const schema = readYamlFile(yamlPath); >- return Array.from({ length: count }, () => >- generateDataFromSchema(schema.properties) >- ); >-}; >- >-const buildSamplePatron = () => { >- return buildSamplePatrons()[0]; >-}; >- >-const buildSampleLibraries = (count = 1) => { >- const yamlPath = "api/v1/swagger/definitions/library.yaml"; >+const buildSampleObjects = ({ object, count = 1 }) => { >+ if (!objects.hasOwnProperty(object)) { >+ throw new Error(`Object type not supported: ${object}`); >+ } >+ const yamlPath = `api/v1/swagger/definitions/${objects[object].spec}.yaml`; > const schema = readYamlFile(yamlPath); > return Array.from({ length: count }, () => > generateDataFromSchema(schema.properties) > ); > }; > >-const buildSampleLibrary = () => { >- return buildSampleLibraries()[0]; >+const buildSampleObject = object => { >+ return buildSampleObjects({ object })[0]; > }; > > module.exports = { > generateMockData, > generateDataFromSchema, >- buildSamplePatron, >- buildSamplePatrons, >- buildSampleLibrary, >- buildSampleLibraries, >+ buildSampleObject, >+ buildSampleObjects, > }; >-- >2.47.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 38503
:
174872
|
174873
|
174874
|
174875
|
174876
|
174884
|
174885
|
174921
|
174922
|
175173
|
175175
|
175212
|
175213
|
175214
|
175215
|
175216
|
175217
|
175218
|
175219
|
175220
|
175221
|
175222
|
175888
|
175889
|
175890
|
175891
|
175892
|
175893
|
175894
|
175895
|
175896
|
176073
|
176074
|
176075
|
176076
|
176077
|
176078
|
176079
|
176080
|
176081
|
176775
|
176776
|
176792