Bugzilla – Attachment 179203 Details for
Bug 39315
Missing tests for KohaTable search on coded value's description
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 39315: MockData - generate full objects for libraries and item types
Bug-39315-MockData---generate-full-objects-for-lib.patch (text/plain), 4.09 KB, created by
Jonathan Druart
on 2025-03-12 12:24:38 UTC
(
hide
)
Description:
Bug 39315: MockData - generate full objects for libraries and item types
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2025-03-12 12:24:38 UTC
Size:
4.09 KB
patch
obsolete
>From cb95ba97158fcd4fba333eb0e33af7f372088742 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Wed, 12 Mar 2025 13:17:35 +0100 >Subject: [PATCH] Bug 39315: MockData - generate full objects for libraries and > item types > >--- > t/cypress/integration/t/mockData.ts | 22 +++++++++++++++ > t/cypress/plugins/mockData.js | 44 +++++++++++++++++++++++++---- > 2 files changed, 60 insertions(+), 6 deletions(-) > >diff --git a/t/cypress/integration/t/mockData.ts b/t/cypress/integration/t/mockData.ts >index 60c1c2118d7..8c63fb75f72 100644 >--- a/t/cypress/integration/t/mockData.ts >+++ b/t/cypress/integration/t/mockData.ts >@@ -53,3 +53,25 @@ describe("Generate Random Libraries", () => { > ); > }); > }); >+ >+describe("Generate objects", () => { >+ it("should generate an object for library", () => { >+ cy.task("buildSampleObject", { object: "item" }).then(mockItem => { >+ expect(mockItem.home_library).to.have.property("library_id"); >+ expect(mockItem.home_library).to.have.property("name"); >+ expect(mockItem.home_library_id).to.equal( >+ mockItem.home_library.library_id >+ ); >+ expect(mockItem.holding_library).to.have.property("library_id"); >+ expect(mockItem.holding_library).to.have.property("name"); >+ expect(mockItem.holding_library_id).to.equal( >+ mockItem.holding_library.library_id >+ ); >+ expect(mockItem.item_type).to.have.property("item_type_id"); >+ expect(mockItem.item_type).to.have.property("description"); >+ expect(mockItem.item_type_id).to.equal( >+ mockItem.item_type.item_type_id >+ ); >+ }); >+ }); >+}); >diff --git a/t/cypress/plugins/mockData.js b/t/cypress/plugins/mockData.js >index 48219e62579..0f9c292df81 100644 >--- a/t/cypress/plugins/mockData.js >+++ b/t/cypress/plugins/mockData.js >@@ -3,9 +3,6 @@ const { readYamlFile } = require("./../plugins/readYamlFile.js"); > const fs = require("fs"); > > const generateMockData = (type, properties) => { >- if (Array.isArray(type)) { >- type = type.filter(t => t != '"null"')[0]; >- } > switch (type) { > case "string": > if (properties?.maxLength) { >@@ -36,17 +33,52 @@ const generateMockData = (type, properties) => { > > const generateDataFromSchema = (properties, values = {}) => { > const mockData = {}; >+ const ids = {}; > Object.entries(properties).forEach(([key, value]) => { > if (values.hasOwnProperty(key)) { > mockData[key] = values[key]; > } else { >- let type = >+ let data; >+ let type = value.type; >+ if (Array.isArray(type)) { >+ type = type.filter(t => t != '"null"')[0]; >+ } >+ >+ type = > value?.format == "date" || value?.format == "date-time" > ? value.format >- : value.type; >- mockData[key] = generateMockData(type, value); >+ : type; >+ let fk_name; >+ if (type == "object") { >+ switch (key) { >+ case "home_library": >+ case "holding_library": >+ data = buildSampleObject({ object: "library" }); >+ fk_name = "library_id"; >+ break; >+ case "item_type": >+ data = buildSampleObject({ object: "item_type" }); >+ fk_name = "item_type_id"; >+ break; >+ default: >+ data = generateMockData(type, value); >+ } >+ if (typeof data === "object") { >+ ids[key] = data[fk_name]; >+ } >+ } else { >+ data = generateMockData(type, value); >+ } >+ mockData[key] = data; > } > }); >+ >+ Object.keys(ids).forEach(k => { >+ if (mockData.hasOwnProperty(k + "_id")) { >+ mockData[k + "_id"] = ids[k]; >+ } >+ }); >+ > return mockData; > }; > >-- >2.34.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 39315
:
179201
|
179202
|
179203
|
179204
|
179365
|
179366
|
179367
|
179368
|
180285
|
180317
|
180318
|
180319
|
180320
|
180371
|
180372
|
180373
|
180374
|
180386
|
180387
|
180388
|
180389