|
1
|
import { Modules } from "@medusajs/utils" |
|
2
|
import { moduleIntegrationTestRunner } from "@medusajs/test-utils" |
|
3
|
import { SettingsTypes } from "@medusajs/types" |
|
4
|
import { getTestJoinerConfigs } from "../__fixtures__/joiner-configs" |
|
5
|
import { |
|
6
|
getEntityOverrideRegistry, |
|
7
|
resetEntityOverrideRegistry, |
|
8
|
EntityOverride, |
|
9
|
BUILTIN_ENTITY_OVERRIDES, |
|
10
|
} from "../../src/utils" |
|
11
|
|
|
12
|
jest.setTimeout(30000) |
|
13
|
|
|
14
|
moduleIntegrationTestRunner<SettingsTypes.ISettingsModuleService>({ |
|
15
|
moduleName: Modules.SETTINGS, |
|
16
|
hooks: { |
|
17
|
beforeModuleInit: async () => { |
|
18
|
const { MedusaModule } = await import("@medusajs/framework/modules-sdk") |
|
19
|
|
|
20
|
for (const config of getTestJoinerConfigs()) { |
|
21
|
if (config.serviceName && !config.isReadOnlyLink) { |
|
22
|
MedusaModule.setJoinerConfig(config.serviceName, config) |
|
23
|
} |
|
24
|
} |
|
25
|
}, |
|
26
|
}, |
|
27
|
testSuite: ({ service }) => { |
|
28
|
describe("EntityDiscovery", function () { |
|
29
|
describe("listDiscoverableEntities", function () { |
|
30
|
it("should return list of discoverable entities", async () => { |
|
31
|
const entities = await service.listDiscoverableEntities() |
|
32
|
|
|
33
|
expect(Array.isArray(entities)).toBe(true) |
|
34
|
expect(entities.length).toBeGreaterThan(0) |
|
35
|
}) |
|
36
|
|
|
37
|
it("should return entities with correct AdminEntityInfo shape", async () => { |
|
38
|
const entities = await service.listDiscoverableEntities() |
|
39
|
|
|
40
|
const entity = entities[0] |
|
41
|
|
|
42
|
// Validate AdminEntityInfo shape |
|
43
|
expect(entity).toHaveProperty("name") |
|
44
|
expect(entity).toHaveProperty("pluralName") |
|
45
|
expect(entity).toHaveProperty("module") |
|
46
|
expect(entity).toHaveProperty("propertyCount") |
|
47
|
expect(entity).toHaveProperty("hasOverrides") |
|
48
|
|
|
49
|
// Validate types |
|
50
|
expect(typeof entity.name).toBe("string") |
|
51
|
expect(typeof entity.pluralName).toBe("string") |
|
52
|
expect(typeof entity.module).toBe("string") |
|
53
|
expect(typeof entity.propertyCount).toBe("number") |
|
54
|
expect(typeof entity.hasOverrides).toBe("boolean") |
|
55
|
}) |
|
56
|
|
|
57
|
it("should include Product entity from fixture", async () => { |
|
58
|
const entities = await service.listDiscoverableEntities() |
|
59
|
const productEntity = entities.find((e) => e.name === "Product") |
|
60
|
|
|
61
|
expect(productEntity).toBeDefined() |
|
62
|
expect(productEntity?.name).toBe("Product") |
|
63
|
expect(productEntity?.propertyCount).toBeGreaterThan(0) |
|
64
|
}) |
|
65
|
|
|
66
|
it("should include Order entity from fixture", async () => { |
|
67
|
const entities = await service.listDiscoverableEntities() |
|
68
|
const orderEntity = entities.find((e) => e.name === "Order") |
|
69
|
|
|
70
|
expect(orderEntity).toBeDefined() |
|
71
|
expect(orderEntity?.name).toBe("Order") |
|
72
|
expect(orderEntity?.propertyCount).toBeGreaterThan(0) |
|
73
|
}) |
|
74
|
|
|
75
|
it("should include Customer entity from fixture", async () => { |
|
76
|
const entities = await service.listDiscoverableEntities() |
|
77
|
const customerEntity = entities.find((e) => e.name === "Customer") |
|
78
|
|
|
79
|
expect(customerEntity).toBeDefined() |
|
80
|
expect(customerEntity?.name).toBe("Customer") |
|
81
|
expect(customerEntity?.propertyCount).toBeGreaterThan(0) |
|
82
|
}) |
|
83
|
}) |
|
84
|
|
|
85
|
describe("hasEntity", function () { |
|
86
|
it("should return true for existing entities", async () => { |
|
87
|
expect(service.hasEntity("Product")).toBe(true) |
|
88
|
expect(service.hasEntity("Order")).toBe(true) |
|
89
|
expect(service.hasEntity("Customer")).toBe(true) |
|
90
|
}) |
|
91
|
|
|
92
|
it("should return false for non-existing entities", async () => { |
|
93
|
expect(service.hasEntity("NonExistentEntity")).toBe(false) |
|
94
|
expect(service.hasEntity("Foo")).toBe(false) |
|
95
|
}) |
|
96
|
|
|
97
|
it("should handle different case variations", async () => { |
|
98
|
expect(service.hasEntity("product")).toBe(true) |
|
99
|
expect(service.hasEntity("PRODUCT")).toBe(true) |
|
100
|
expect(service.hasEntity("Product")).toBe(true) |
|
101
|
}) |
|
102
|
|
|
103
|
it("should handle plural forms", async () => { |
|
104
|
expect(service.hasEntity("products")).toBe(true) |
|
105
|
expect(service.hasEntity("orders")).toBe(true) |
|
106
|
expect(service.hasEntity("customers")).toBe(true) |
|
107
|
}) |
|
108
|
}) |
|
109
|
|
|
110
|
describe("generateEntityColumns", function () { |
|
111
|
it("should generate columns for Product entity", async () => { |
|
112
|
const columns = await service.generateEntityColumns("Product") |
|
113
|
|
|
114
|
expect(columns).not.toBeNull() |
|
115
|
expect(Array.isArray(columns)).toBe(true) |
|
116
|
expect(columns!.length).toBeGreaterThan(0) |
|
117
|
}) |
|
118
|
|
|
119
|
it("should generate columns for Order entity", async () => { |
|
120
|
const columns = await service.generateEntityColumns("Order") |
|
121
|
|
|
122
|
expect(columns).not.toBeNull() |
|
123
|
expect(Array.isArray(columns)).toBe(true) |
|
124
|
expect(columns!.length).toBeGreaterThan(0) |
|
125
|
}) |
|
126
|
|
|
127
|
it("should return null for non-existing entity", async () => { |
|
128
|
const columns = await service.generateEntityColumns("NonExistent") |
|
129
|
|
|
130
|
expect(columns).toBeNull() |
|
131
|
}) |
|
132
|
|
|
133
|
it("should return columns with correct AdminColumn shape", async () => { |
|
134
|
const columns = await service.generateEntityColumns("Product") |
|
135
|
|
|
136
|
expect(columns).not.toBeNull() |
|
137
|
const column = columns![0] |
|
138
|
|
|
139
|
// Required fields |
|
140
|
expect(column).toHaveProperty("id") |
|
141
|
expect(column).toHaveProperty("name") |
|
142
|
expect(column).toHaveProperty("field") |
|
143
|
expect(column).toHaveProperty("sortable") |
|
144
|
expect(column).toHaveProperty("hideable") |
|
145
|
expect(column).toHaveProperty("default_visible") |
|
146
|
expect(column).toHaveProperty("data_type") |
|
147
|
|
|
148
|
// Validate types |
|
149
|
expect(typeof column.id).toBe("string") |
|
150
|
expect(typeof column.name).toBe("string") |
|
151
|
expect(typeof column.field).toBe("string") |
|
152
|
expect(typeof column.sortable).toBe("boolean") |
|
153
|
expect(typeof column.hideable).toBe("boolean") |
|
154
|
expect(typeof column.default_visible).toBe("boolean") |
|
155
|
expect(typeof column.data_type).toBe("string") |
|
156
|
|
|
157
|
// Validate data_type is one of the allowed values |
|
158
|
expect([ |
|
159
|
"string", |
|
160
|
"number", |
|
161
|
"boolean", |
|
162
|
"date", |
|
163
|
"currency", |
|
164
|
"enum", |
|
165
|
"object", |
|
166
|
]).toContain(column.data_type) |
|
167
|
}) |
|
168
|
|
|
169
|
it("should include common Product fields", async () => { |
|
170
|
const columns = await service.generateEntityColumns("Product") |
|
171
|
|
|
172
|
expect(columns).not.toBeNull() |
|
173
|
const columnIds = columns!.map((c) => c.id) |
|
174
|
|
|
175
|
// Check for common Product fields from fixture schema |
|
176
|
expect(columnIds).toContain("id") |
|
177
|
expect(columnIds).toContain("title") |
|
178
|
expect(columnIds).toContain("handle") |
|
179
|
expect(columnIds).toContain("status") |
|
180
|
}) |
|
181
|
|
|
182
|
it("should include common Order fields", async () => { |
|
183
|
const columns = await service.generateEntityColumns("Order") |
|
184
|
|
|
185
|
expect(columns).not.toBeNull() |
|
186
|
const columnIds = columns!.map((c) => c.id) |
|
187
|
|
|
188
|
// Check for common Order fields from fixture schema |
|
189
|
expect(columnIds).toContain("id") |
|
190
|
expect(columnIds).toContain("status") |
|
191
|
expect(columnIds).toContain("currency_code") |
|
192
|
}) |
|
193
|
|
|
194
|
it("should handle entity lookup with different cases", async () => { |
|
195
|
const columns1 = await service.generateEntityColumns("product") |
|
196
|
const columns2 = await service.generateEntityColumns("Product") |
|
197
|
const columns3 = await service.generateEntityColumns("products") |
|
198
|
|
|
199
|
expect(columns1).not.toBeNull() |
|
200
|
expect(columns2).not.toBeNull() |
|
201
|
expect(columns3).not.toBeNull() |
|
202
|
|
|
203
|
// All should return the same columns |
|
204
|
expect(columns1!.length).toBe(columns2!.length) |
|
205
|
expect(columns2!.length).toBe(columns3!.length) |
|
206
|
}) |
|
207
|
|
|
208
|
it("should include render_mode in columns", async () => { |
|
209
|
const columns = await service.generateEntityColumns("Order") |
|
210
|
|
|
211
|
expect(columns).not.toBeNull() |
|
212
|
|
|
213
|
// Find timestamp columns which should have datetime render_mode |
|
214
|
const createdAt = columns!.find((c) => c.id === "created_at")! |
|
215
|
expect(createdAt.render_mode).toBe("datetime") |
|
216
|
|
|
217
|
// Find status column which should have status render_mode |
|
218
|
const status = columns!.find((c) => c.id === "status")! |
|
219
|
expect(status.render_mode).toBe("status") |
|
220
|
}) |
|
221
|
|
|
222
|
it("should include filter configuration in columns", async () => { |
|
223
|
const columns = await service.generateEntityColumns("Product") |
|
224
|
|
|
225
|
expect(columns).not.toBeNull() |
|
226
|
|
|
227
|
// Find a filterable column |
|
228
|
const statusColumn = columns!.find((c) => c.id === "status")! |
|
229
|
expect(statusColumn.filter).toHaveProperty("enabled") |
|
230
|
expect(typeof statusColumn.filter!.enabled).toBe("boolean") |
|
231
|
}) |
|
232
|
|
|
233
|
it("should include source information in columns", async () => { |
|
234
|
const columns = await service.generateEntityColumns("Product") |
|
235
|
|
|
236
|
expect(columns).not.toBeNull() |
|
237
|
const columnWithSource = columns!.find((c) => c.source)! |
|
238
|
expect(columnWithSource.source).toHaveProperty("module") |
|
239
|
expect(columnWithSource.source).toHaveProperty("entity") |
|
240
|
}) |
|
241
|
|
|
242
|
it("should apply custom property labels to columns", async () => { |
|
243
|
await service.createPropertyLabels({ |
|
244
|
entity: "Product", |
|
245
|
property: "title", |
|
246
|
label: "Product Name", |
|
247
|
}) |
|
248
|
|
|
249
|
const columns = await service.generateEntityColumns("Product") |
|
250
|
|
|
251
|
expect(columns).not.toBeNull() |
|
252
|
const titleColumn = columns!.find((c) => c.id === "title") |
|
253
|
|
|
254
|
expect(titleColumn).toBeDefined() |
|
255
|
expect(titleColumn?.name).toBe("Product Name") |
|
256
|
expect(titleColumn?.custom_label).toBe(true) |
|
257
|
}) |
|
258
|
}) |
|
259
|
|
|
260
|
describe("relationship filters", function () { |
|
261
|
it("should include sales_channels relationship filter for Product", async () => { |
|
262
|
const columns = await service.generateEntityColumns("Product") |
|
263
|
|
|
264
|
expect(columns).not.toBeNull() |
|
265
|
|
|
266
|
// Find the sales_channels filter column |
|
267
|
const salesChannelsFilter = columns!.find( |
|
268
|
(c) => c.id === "sales_channels_filter" |
|
269
|
) |
|
270
|
|
|
271
|
expect(salesChannelsFilter).toBeDefined() |
|
272
|
expect(salesChannelsFilter?.filter).toBeDefined() |
|
273
|
expect(salesChannelsFilter?.filter?.enabled).toBe(true) |
|
274
|
expect(salesChannelsFilter?.filter?.relationship).toBeDefined() |
|
275
|
expect(salesChannelsFilter?.filter?.relationship?.entity).toBe( |
|
276
|
"SalesChannel" |
|
277
|
) |
|
278
|
expect(salesChannelsFilter?.filter?.relationship?.value_field).toBe( |
|
279
|
"id" |
|
280
|
) |
|
281
|
expect(salesChannelsFilter?.filter?.relationship?.display_field).toBe( |
|
282
|
"name" |
|
283
|
) |
|
284
|
expect(salesChannelsFilter?.filter?.relationship?.multiple).toBe(true) |
|
285
|
expect(salesChannelsFilter?.filter?.relationship?.endpoint).toBe( |
|
286
|
"/admin/sales-channels" |
|
287
|
) |
|
288
|
}) |
|
289
|
|
|
290
|
it("should include tags relationship filter for Product", async () => { |
|
291
|
const columns = await service.generateEntityColumns("Product") |
|
292
|
|
|
293
|
expect(columns).not.toBeNull() |
|
294
|
|
|
295
|
// Find the tags filter column |
|
296
|
const tagsFilter = columns!.find((c) => c.id === "tags_filter") |
|
297
|
|
|
298
|
expect(tagsFilter).toBeDefined() |
|
299
|
expect(tagsFilter?.filter?.enabled).toBe(true) |
|
300
|
expect(tagsFilter?.filter?.relationship).toBeDefined() |
|
301
|
expect(tagsFilter?.filter?.relationship?.entity).toBe("ProductTag") |
|
302
|
expect(tagsFilter?.filter?.relationship?.multiple).toBe(true) |
|
303
|
}) |
|
304
|
|
|
305
|
it("should include collection relationship for Product", async () => { |
|
306
|
const columns = await service.generateEntityColumns("Product") |
|
307
|
|
|
308
|
expect(columns).not.toBeNull() |
|
309
|
|
|
310
|
// Find the collection.title column (single relationship) |
|
311
|
const collectionColumn = columns!.find( |
|
312
|
(c) => c.id === "collection.title" |
|
313
|
) |
|
314
|
|
|
315
|
expect(collectionColumn).toBeDefined() |
|
316
|
expect(collectionColumn?.category).toBe("relationship") |
|
317
|
}) |
|
318
|
|
|
319
|
it("should include region relationship for Order", async () => { |
|
320
|
const columns = await service.generateEntityColumns("Order") |
|
321
|
|
|
322
|
expect(columns).not.toBeNull() |
|
323
|
|
|
324
|
// Find the region.name column (single relationship) |
|
325
|
const regionColumn = columns!.find((c) => c.id === "region.name") |
|
326
|
|
|
327
|
expect(regionColumn).toBeDefined() |
|
328
|
expect(regionColumn?.category).toBe("relationship") |
|
329
|
}) |
|
330
|
|
|
331
|
it("should have correct RelationshipFilterConfig shape", async () => { |
|
332
|
const columns = await service.generateEntityColumns("Product") |
|
333
|
|
|
334
|
expect(columns).not.toBeNull() |
|
335
|
|
|
336
|
const salesChannelsFilter = columns!.find( |
|
337
|
(c) => c.id === "sales_channels_filter" |
|
338
|
) |
|
339
|
|
|
340
|
expect(salesChannelsFilter?.filter?.relationship).toBeDefined() |
|
341
|
|
|
342
|
const relationshipConfig = salesChannelsFilter!.filter!.relationship! |
|
343
|
|
|
344
|
expect(relationshipConfig).toHaveProperty("entity") |
|
345
|
expect(relationshipConfig).toHaveProperty("value_field") |
|
346
|
expect(relationshipConfig).toHaveProperty("display_field") |
|
347
|
expect(relationshipConfig).toHaveProperty("multiple") |
|
348
|
expect(relationshipConfig).toHaveProperty("endpoint") |
|
349
|
|
|
350
|
expect(typeof relationshipConfig.entity).toBe("string") |
|
351
|
expect(typeof relationshipConfig.value_field).toBe("string") |
|
352
|
expect(typeof relationshipConfig.display_field).toBe("string") |
|
353
|
expect(typeof relationshipConfig.multiple).toBe("boolean") |
|
354
|
expect(typeof relationshipConfig.endpoint).toBe("string") |
|
355
|
}) |
|
356
|
|
|
357
|
it("should include groups relationship filter for Customer", async () => { |
|
358
|
const columns = await service.generateEntityColumns("Customer") |
|
359
|
|
|
360
|
expect(columns).not.toBeNull() |
|
361
|
|
|
362
|
// Find the groups filter column |
|
363
|
const groupsFilter = columns!.find((c) => c.id === "groups_filter") |
|
364
|
|
|
365
|
expect(groupsFilter).toBeDefined() |
|
366
|
expect(groupsFilter?.filter?.enabled).toBe(true) |
|
367
|
expect(groupsFilter?.filter?.relationship).toBeDefined() |
|
368
|
expect(groupsFilter?.filter?.relationship?.entity).toBe( |
|
369
|
"CustomerGroup" |
|
370
|
) |
|
371
|
expect(groupsFilter?.filter?.relationship?.multiple).toBe(true) |
|
372
|
}) |
|
373
|
}) |
|
374
|
|
|
375
|
describe("isEntityDiscoveryInitialized", function () { |
|
376
|
it("should return true when entity discovery is initialized", async () => { |
|
377
|
const initialized = service.isEntityDiscoveryInitialized() |
|
378
|
|
|
379
|
expect(typeof initialized).toBe("boolean") |
|
380
|
expect(initialized).toBe(true) |
|
381
|
}) |
|
382
|
}) |
|
383
|
|
|
384
|
describe("category mapping", function () { |
|
385
|
it("should map identifier semantic type to identifier category", async () => { |
|
386
|
const columns = await service.generateEntityColumns("Order") |
|
387
|
|
|
388
|
expect(columns).not.toBeNull() |
|
389
|
|
|
390
|
// display_id should have identifier category |
|
391
|
const displayIdColumn = columns!.find((c) => c.id === "display_id") |
|
392
|
expect(displayIdColumn).toBeDefined() |
|
393
|
expect(displayIdColumn?.semantic_type).toBe("identifier") |
|
394
|
expect(displayIdColumn?.category).toBe("identifier") |
|
395
|
}) |
|
396
|
|
|
397
|
it("should map timestamp semantic type to timestamp category", async () => { |
|
398
|
const columns = await service.generateEntityColumns("Order") |
|
399
|
|
|
400
|
expect(columns).not.toBeNull() |
|
401
|
|
|
402
|
// created_at should have timestamp category |
|
403
|
const createdAtColumn = columns!.find((c) => c.id === "created_at") |
|
404
|
expect(createdAtColumn).toBeDefined() |
|
405
|
expect(createdAtColumn?.semantic_type).toBe("timestamp") |
|
406
|
expect(createdAtColumn?.category).toBe("timestamp") |
|
407
|
}) |
|
408
|
|
|
409
|
it("should map status semantic type to status category", async () => { |
|
410
|
const columns = await service.generateEntityColumns("Order") |
|
411
|
|
|
412
|
expect(columns).not.toBeNull() |
|
413
|
|
|
414
|
// status should have status category |
|
415
|
const statusColumn = columns!.find((c) => c.id === "status") |
|
416
|
expect(statusColumn).toBeDefined() |
|
417
|
expect(statusColumn?.semantic_type).toBe("status") |
|
418
|
expect(statusColumn?.category).toBe("status") |
|
419
|
}) |
|
420
|
|
|
421
|
it("should map currency semantic type to metric category", async () => { |
|
422
|
const columns = await service.generateEntityColumns("Order") |
|
423
|
|
|
424
|
expect(columns).not.toBeNull() |
|
425
|
|
|
426
|
// total should have metric category (mapped from currency semantic type) |
|
427
|
const totalColumn = columns!.find((c) => c.id === "total") |
|
428
|
expect(totalColumn).toBeDefined() |
|
429
|
expect(totalColumn?.semantic_type).toBe("currency") |
|
430
|
expect(totalColumn?.category).toBe("metric") |
|
431
|
}) |
|
432
|
|
|
433
|
it("should use field category for other semantic types", async () => { |
|
434
|
const columns = await service.generateEntityColumns("Order") |
|
435
|
|
|
436
|
expect(columns).not.toBeNull() |
|
437
|
|
|
438
|
// currency_code should have field category |
|
439
|
const currencyCodeColumn = columns!.find( |
|
440
|
(c) => c.id === "currency_code" |
|
441
|
) |
|
442
|
expect(currencyCodeColumn).toBeDefined() |
|
443
|
expect(currencyCodeColumn?.category).toBe("field") |
|
444
|
}) |
|
445
|
}) |
|
446
|
|
|
447
|
describe("single relationship columns", function () { |
|
448
|
it("should generate multiple columns for single relationships", async () => { |
|
449
|
const columns = await service.generateEntityColumns("Order") |
|
450
|
|
|
451
|
expect(columns).not.toBeNull() |
|
452
|
const columnIds = columns!.map((c) => c.id) |
|
453
|
|
|
454
|
// Region is a single relationship - should have multiple nested columns |
|
455
|
const regionColumns = columnIds.filter((id) => |
|
456
|
id.startsWith("region.") |
|
457
|
) |
|
458
|
expect(regionColumns.length).toBeGreaterThan(1) |
|
459
|
|
|
460
|
// Should include both id and name |
|
461
|
expect(columnIds).toContain("region.id") |
|
462
|
expect(columnIds).toContain("region.name") |
|
463
|
}) |
|
464
|
|
|
465
|
it("should generate columns for all scalar fields of relationships", async () => { |
|
466
|
const columns = await service.generateEntityColumns("Product") |
|
467
|
|
|
468
|
expect(columns).not.toBeNull() |
|
469
|
const columnIds = columns!.map((c) => c.id) |
|
470
|
|
|
471
|
// Collection is a single relationship - should have multiple nested columns |
|
472
|
const collectionColumns = columnIds.filter((id) => |
|
473
|
id.startsWith("collection.") |
|
474
|
) |
|
475
|
expect(collectionColumns.length).toBeGreaterThan(1) |
|
476
|
|
|
477
|
// Should include id, title, handle |
|
478
|
expect(columnIds).toContain("collection.id") |
|
479
|
expect(columnIds).toContain("collection.title") |
|
480
|
expect(columnIds).toContain("collection.handle") |
|
481
|
}) |
|
482
|
|
|
483
|
it("should mark all relationship columns with relationship category", async () => { |
|
484
|
const columns = await service.generateEntityColumns("Order") |
|
485
|
|
|
486
|
expect(columns).not.toBeNull() |
|
487
|
|
|
488
|
// All region.* columns should have relationship category |
|
489
|
const regionColumns = columns!.filter((c) => |
|
490
|
c.id.startsWith("region.") |
|
491
|
) |
|
492
|
for (const col of regionColumns) { |
|
493
|
expect(col.category).toBe("relationship") |
|
494
|
} |
|
495
|
}) |
|
496
|
}) |
|
497
|
|
|
498
|
describe("endpoint inference", function () { |
|
499
|
it("should infer endpoint following kebab-case plural convention", async () => { |
|
500
|
const columns = await service.generateEntityColumns("Product") |
|
501
|
|
|
502
|
expect(columns).not.toBeNull() |
|
503
|
|
|
504
|
// sales_channels filter should have inferred endpoint |
|
505
|
const salesChannelsFilter = columns!.find( |
|
506
|
(c) => c.id === "sales_channels_filter" |
|
507
|
) |
|
508
|
expect(salesChannelsFilter?.filter?.relationship?.endpoint).toBe( |
|
509
|
"/admin/sales-channels" |
|
510
|
) |
|
511
|
}) |
|
512
|
|
|
513
|
it("should use custom endpoint for ProductCollection", async () => { |
|
514
|
const columns = await service.generateEntityColumns("Product") |
|
515
|
|
|
516
|
expect(columns).not.toBeNull() |
|
517
|
|
|
518
|
// collection.id should have relationship filter with custom endpoint |
|
519
|
const collectionIdColumn = columns!.find( |
|
520
|
(c) => c.id === "collection.id" |
|
521
|
) |
|
522
|
expect(collectionIdColumn?.filter?.relationship?.endpoint).toBe( |
|
523
|
"/admin/collections" |
|
524
|
) |
|
525
|
}) |
|
526
|
|
|
527
|
it("should infer endpoint for CustomerGroup", async () => { |
|
528
|
const columns = await service.generateEntityColumns("Customer") |
|
529
|
|
|
530
|
expect(columns).not.toBeNull() |
|
531
|
|
|
532
|
// groups filter should have inferred endpoint |
|
533
|
const groupsFilter = columns!.find((c) => c.id === "groups_filter") |
|
534
|
expect(groupsFilter?.filter?.relationship?.endpoint).toBe( |
|
535
|
"/admin/customer-groups" |
|
536
|
) |
|
537
|
}) |
|
538
|
}) |
|
539
|
|
|
540
|
describe("display field inference", function () { |
|
541
|
it("should use name as display field when available", async () => { |
|
542
|
const columns = await service.generateEntityColumns("Product") |
|
543
|
|
|
544
|
expect(columns).not.toBeNull() |
|
545
|
|
|
546
|
// SalesChannel has name field, should use it as display_field |
|
547
|
const salesChannelsFilter = columns!.find( |
|
548
|
(c) => c.id === "sales_channels_filter" |
|
549
|
) |
|
550
|
expect(salesChannelsFilter?.filter?.relationship?.display_field).toBe( |
|
551
|
"name" |
|
552
|
) |
|
553
|
}) |
|
554
|
|
|
555
|
it("should use title as display field for ProductCollection", async () => { |
|
556
|
const columns = await service.generateEntityColumns("Product") |
|
557
|
|
|
558
|
expect(columns).not.toBeNull() |
|
559
|
|
|
560
|
// ProductCollection uses title (from override) |
|
561
|
const collectionIdColumn = columns!.find( |
|
562
|
(c) => c.id === "collection.id" |
|
563
|
) |
|
564
|
expect(collectionIdColumn?.filter?.relationship?.display_field).toBe( |
|
565
|
"title" |
|
566
|
) |
|
567
|
}) |
|
568
|
|
|
569
|
it("should use value as display field for ProductTag", async () => { |
|
570
|
const columns = await service.generateEntityColumns("Product") |
|
571
|
|
|
572
|
expect(columns).not.toBeNull() |
|
573
|
|
|
574
|
// ProductTag uses value (from override) |
|
575
|
const tagsFilter = columns!.find((c) => c.id === "tags_filter") |
|
576
|
expect(tagsFilter?.filter?.relationship?.display_field).toBe("value") |
|
577
|
}) |
|
578
|
}) |
|
579
|
|
|
580
|
describe("entity overrides", function () { |
|
581
|
describe("excludePrefixes", function () { |
|
582
|
it("should exclude fields with raw_ prefix for Order", async () => { |
|
583
|
const columns = await service.generateEntityColumns("Order") |
|
584
|
|
|
585
|
expect(columns).not.toBeNull() |
|
586
|
const columnIds = columns!.map((c) => c.id) |
|
587
|
|
|
588
|
// raw_total and raw_subtotal should be excluded |
|
589
|
expect(columnIds).not.toContain("raw_total") |
|
590
|
expect(columnIds).not.toContain("raw_subtotal") |
|
591
|
}) |
|
592
|
|
|
593
|
it("should exclude fields with raw_ prefix for Product", async () => { |
|
594
|
const columns = await service.generateEntityColumns("Product") |
|
595
|
|
|
596
|
expect(columns).not.toBeNull() |
|
597
|
const columnIds = columns!.map((c) => c.id) |
|
598
|
|
|
599
|
// raw_price and raw_compare_at_price should be excluded |
|
600
|
expect(columnIds).not.toContain("raw_price") |
|
601
|
expect(columnIds).not.toContain("raw_compare_at_price") |
|
602
|
}) |
|
603
|
}) |
|
604
|
|
|
605
|
describe("excludeSuffixes", function () { |
|
606
|
it("should exclude fields with _link suffix for Order", async () => { |
|
607
|
const columns = await service.generateEntityColumns("Order") |
|
608
|
|
|
609
|
expect(columns).not.toBeNull() |
|
610
|
const columnIds = columns!.map((c) => c.id) |
|
611
|
|
|
612
|
// customer_link should be excluded |
|
613
|
expect(columnIds).not.toContain("customer_link") |
|
614
|
}) |
|
615
|
|
|
616
|
it("should exclude fields with _link suffix for Product", async () => { |
|
617
|
const columns = await service.generateEntityColumns("Product") |
|
618
|
|
|
619
|
expect(columns).not.toBeNull() |
|
620
|
const columnIds = columns!.map((c) => c.id) |
|
621
|
|
|
622
|
// category_link should be excluded |
|
623
|
expect(columnIds).not.toContain("category_link") |
|
624
|
}) |
|
625
|
}) |
|
626
|
|
|
627
|
describe("excludeFields", function () { |
|
628
|
it("should exclude specific fields for Order", async () => { |
|
629
|
const columns = await service.generateEntityColumns("Order") |
|
630
|
|
|
631
|
expect(columns).not.toBeNull() |
|
632
|
const columnIds = columns!.map((c) => c.id) |
|
633
|
|
|
634
|
// order_change is specifically excluded in Order override |
|
635
|
expect(columnIds).not.toContain("order_change") |
|
636
|
}) |
|
637
|
}) |
|
638
|
|
|
639
|
describe("defaultVisibleFields", function () { |
|
640
|
it("should set default_visible for Order configured fields", async () => { |
|
641
|
const columns = await service.generateEntityColumns("Order") |
|
642
|
|
|
643
|
expect(columns).not.toBeNull() |
|
644
|
|
|
645
|
// display_id should be default visible for Order |
|
646
|
const displayIdColumn = columns!.find((c) => c.id === "display_id") |
|
647
|
expect(displayIdColumn).toBeDefined() |
|
648
|
expect(displayIdColumn?.default_visible).toBe(true) |
|
649
|
|
|
650
|
// created_at should be default visible for Order |
|
651
|
const createdAtColumn = columns!.find((c) => c.id === "created_at") |
|
652
|
expect(createdAtColumn).toBeDefined() |
|
653
|
expect(createdAtColumn?.default_visible).toBe(true) |
|
654
|
|
|
655
|
// payment_status should be default visible for Order |
|
656
|
const paymentStatusColumn = columns!.find( |
|
657
|
(c) => c.id === "payment_status" |
|
658
|
) |
|
659
|
expect(paymentStatusColumn).toBeDefined() |
|
660
|
expect(paymentStatusColumn?.default_visible).toBe(true) |
|
661
|
|
|
662
|
// fulfillment_status should be default visible for Order |
|
663
|
const fulfillmentStatusColumn = columns!.find( |
|
664
|
(c) => c.id === "fulfillment_status" |
|
665
|
) |
|
666
|
expect(fulfillmentStatusColumn).toBeDefined() |
|
667
|
expect(fulfillmentStatusColumn?.default_visible).toBe(true) |
|
668
|
}) |
|
669
|
|
|
670
|
it("should set default_visible for Product configured fields", async () => { |
|
671
|
const columns = await service.generateEntityColumns("Product") |
|
672
|
|
|
673
|
expect(columns).not.toBeNull() |
|
674
|
|
|
675
|
// status should be default visible for Product |
|
676
|
const statusColumn = columns!.find((c) => c.id === "status") |
|
677
|
expect(statusColumn).toBeDefined() |
|
678
|
expect(statusColumn?.default_visible).toBe(true) |
|
679
|
}) |
|
680
|
|
|
681
|
it("should not set default_visible for non-configured fields", async () => { |
|
682
|
const columns = await service.generateEntityColumns("Order") |
|
683
|
|
|
684
|
expect(columns).not.toBeNull() |
|
685
|
|
|
686
|
// version should not be default visible for Order |
|
687
|
const versionColumn = columns!.find((c) => c.id === "version") |
|
688
|
expect(versionColumn).toBeDefined() |
|
689
|
expect(versionColumn?.default_visible).toBe(false) |
|
690
|
|
|
691
|
// metadata should not be default visible |
|
692
|
const metadataColumn = columns!.find((c) => c.id === "metadata") |
|
693
|
if (metadataColumn) { |
|
694
|
expect(metadataColumn.default_visible).toBe(false) |
|
695
|
} |
|
696
|
}) |
|
697
|
}) |
|
698
|
|
|
699
|
describe("defaultFieldOrdering", function () { |
|
700
|
it("should order Order fields according to defaultFieldOrdering", async () => { |
|
701
|
const columns = await service.generateEntityColumns("Order") |
|
702
|
|
|
703
|
expect(columns).not.toBeNull() |
|
704
|
|
|
705
|
// Get columns with their default_order |
|
706
|
const displayId = columns!.find((c) => c.id === "display_id") |
|
707
|
const createdAt = columns!.find((c) => c.id === "created_at") |
|
708
|
const paymentStatus = columns!.find( |
|
709
|
(c) => c.id === "payment_status" |
|
710
|
) |
|
711
|
const fulfillmentStatus = columns!.find( |
|
712
|
(c) => c.id === "fulfillment_status" |
|
713
|
) |
|
714
|
const total = columns!.find((c) => c.id === "total") |
|
715
|
|
|
716
|
// Verify defaultFieldOrdering is applied (lower number = earlier in list) |
|
717
|
expect(displayId?.default_order).toBeLessThan( |
|
718
|
createdAt?.default_order || Infinity |
|
719
|
) |
|
720
|
expect(createdAt?.default_order).toBeLessThan( |
|
721
|
fulfillmentStatus?.default_order || Infinity |
|
722
|
) |
|
723
|
expect(paymentStatus?.default_order).toBeLessThan( |
|
724
|
fulfillmentStatus?.default_order || Infinity |
|
725
|
) |
|
726
|
expect(fulfillmentStatus?.default_order).toBeLessThan( |
|
727
|
total?.default_order || Infinity |
|
728
|
) |
|
729
|
}) |
|
730
|
|
|
731
|
it("should sort columns by default_order", async () => { |
|
732
|
const columns = await service.generateEntityColumns("Order") |
|
733
|
|
|
734
|
expect(columns).not.toBeNull() |
|
735
|
|
|
736
|
// Verify columns are sorted by default_order |
|
737
|
for (let i = 1; i < columns!.length; i++) { |
|
738
|
const prevOrder = columns![i - 1].default_order || 0 |
|
739
|
const currentOrder = columns![i].default_order || 0 |
|
740
|
expect(prevOrder).toBeLessThanOrEqual(currentOrder) |
|
741
|
} |
|
742
|
}) |
|
743
|
}) |
|
744
|
|
|
745
|
describe("nonFilterableFields", function () { |
|
746
|
it("should disable filtering on Order's payment_status and fulfillment_status", async () => { |
|
747
|
const columns = await service.generateEntityColumns("Order") |
|
748
|
|
|
749
|
expect(columns).not.toBeNull() |
|
750
|
|
|
751
|
const paymentStatus = columns!.find( |
|
752
|
(c) => c.id === "payment_status" |
|
753
|
) |
|
754
|
expect(paymentStatus).toBeDefined() |
|
755
|
expect(paymentStatus?.filter?.enabled).toBe(false) |
|
756
|
expect(paymentStatus?.filter?.operators).toBeUndefined() |
|
757
|
|
|
758
|
const fulfillmentStatus = columns!.find( |
|
759
|
(c) => c.id === "fulfillment_status" |
|
760
|
) |
|
761
|
expect(fulfillmentStatus).toBeDefined() |
|
762
|
expect(fulfillmentStatus?.filter?.enabled).toBe(false) |
|
763
|
expect(fulfillmentStatus?.filter?.operators).toBeUndefined() |
|
764
|
}) |
|
765
|
|
|
766
|
it("should keep the column itself visible and sortable when filtering is disabled", async () => { |
|
767
|
const columns = await service.generateEntityColumns("Order") |
|
768
|
|
|
769
|
expect(columns).not.toBeNull() |
|
770
|
|
|
771
|
const paymentStatus = columns!.find( |
|
772
|
(c) => c.id === "payment_status" |
|
773
|
) |
|
774
|
expect(paymentStatus?.default_visible).toBe(true) |
|
775
|
expect(paymentStatus?.sortable).toBe(true) |
|
776
|
|
|
777
|
const fulfillmentStatus = columns!.find( |
|
778
|
(c) => c.id === "fulfillment_status" |
|
779
|
) |
|
780
|
expect(fulfillmentStatus?.default_visible).toBe(true) |
|
781
|
expect(fulfillmentStatus?.sortable).toBe(true) |
|
782
|
}) |
|
783
|
|
|
784
|
it("should keep filtering enabled on other Order scalar fields", async () => { |
|
785
|
const columns = await service.generateEntityColumns("Order") |
|
786
|
|
|
787
|
expect(columns).not.toBeNull() |
|
788
|
|
|
789
|
const status = columns!.find((c) => c.id === "status") |
|
790
|
expect(status?.filter?.enabled).toBe(true) |
|
791
|
|
|
792
|
const total = columns!.find((c) => c.id === "total") |
|
793
|
expect(total?.filter?.enabled).toBe(true) |
|
794
|
}) |
|
795
|
}) |
|
796
|
|
|
797
|
describe("Customer entity overrides", function () { |
|
798
|
it("should generate columns for Customer entity", async () => { |
|
799
|
const columns = await service.generateEntityColumns("Customer") |
|
800
|
|
|
801
|
expect(columns).not.toBeNull() |
|
802
|
expect(Array.isArray(columns)).toBe(true) |
|
803
|
expect(columns!.length).toBeGreaterThan(0) |
|
804
|
|
|
805
|
// Should include basic fields |
|
806
|
const columnIds = columns!.map((c) => c.id) |
|
807
|
expect(columnIds).toContain("id") |
|
808
|
expect(columnIds).toContain("email") |
|
809
|
}) |
|
810
|
|
|
811
|
it("should set default_visible for Customer configured fields", async () => { |
|
812
|
const columns = await service.generateEntityColumns("Customer") |
|
813
|
|
|
814
|
expect(columns).not.toBeNull() |
|
815
|
|
|
816
|
// email should be default visible for Customer |
|
817
|
const emailColumn = columns!.find((c) => c.id === "email") |
|
818
|
expect(emailColumn).toBeDefined() |
|
819
|
expect(emailColumn?.default_visible).toBe(true) |
|
820
|
|
|
821
|
// customer_name should be default visible for Customer |
|
822
|
const customerNameColumn = columns!.find( |
|
823
|
(c) => c.id === "customer_name" |
|
824
|
) |
|
825
|
expect(customerNameColumn).toBeDefined() |
|
826
|
expect(customerNameColumn?.default_visible).toBe(true) |
|
827
|
}) |
|
828
|
|
|
829
|
it("should apply filter rules for Customer", async () => { |
|
830
|
const columns = await service.generateEntityColumns("Customer") |
|
831
|
|
|
832
|
expect(columns).not.toBeNull() |
|
833
|
const columnIds = columns!.map((c) => c.id) |
|
834
|
|
|
835
|
// _link suffix fields should be excluded |
|
836
|
const linkColumns = columnIds.filter((id) => id.endsWith("_link")) |
|
837
|
expect(linkColumns.length).toBe(0) |
|
838
|
|
|
839
|
// raw_ prefix fields should be excluded |
|
840
|
const rawColumns = columnIds.filter((id) => id.startsWith("raw_")) |
|
841
|
expect(rawColumns.length).toBe(0) |
|
842
|
}) |
|
843
|
}) |
|
844
|
|
|
845
|
describe("hasOverrides in entity info", function () { |
|
846
|
it("should report hasOverrides=true only for entities with at least one property label", async () => { |
|
847
|
await service.createPropertyLabels([ |
|
848
|
{ entity: "Product", property: "title", label: "Title" }, |
|
849
|
]) |
|
850
|
|
|
851
|
const entities = await service.listDiscoverableEntities() |
|
852
|
|
|
853
|
const productEntity = entities.find((e) => e.name === "Product") |
|
854
|
const orderEntity = entities.find((e) => e.name === "Order") |
|
855
|
|
|
856
|
// Product has a property label; Order does not. |
|
857
|
expect(productEntity?.hasOverrides).toBe(true) |
|
858
|
expect(orderEntity?.hasOverrides).toBe(false) |
|
859
|
}) |
|
860
|
|
|
861
|
it("should report hasOverrides accurately for all entities", async () => { |
|
862
|
const entities = await service.listDiscoverableEntities() |
|
863
|
|
|
864
|
for (const entity of entities) { |
|
865
|
expect(typeof entity.hasOverrides).toBe("boolean") |
|
866
|
} |
|
867
|
}) |
|
868
|
}) |
|
869
|
}) |
|
870
|
|
|
871
|
describe("EntityOverrideRegistry", function () { |
|
872
|
beforeEach(() => { |
|
873
|
resetEntityOverrideRegistry() |
|
874
|
}) |
|
875
|
|
|
876
|
afterAll(() => { |
|
877
|
resetEntityOverrideRegistry() |
|
878
|
}) |
|
879
|
|
|
880
|
describe("initialization", function () { |
|
881
|
it("should initialize with built-in overrides", () => { |
|
882
|
const registry = getEntityOverrideRegistry() |
|
883
|
const entityNames = registry.getEntityNames() |
|
884
|
|
|
885
|
// Should include all built-in entities |
|
886
|
expect(entityNames).toContain("Order") |
|
887
|
expect(entityNames).toContain("Product") |
|
888
|
expect(entityNames).toContain("Customer") |
|
889
|
expect(entityNames).toContain("User") |
|
890
|
expect(entityNames).toContain("Region") |
|
891
|
expect(entityNames).toContain("SalesChannel") |
|
892
|
}) |
|
893
|
|
|
894
|
it("should return same instance on multiple calls (singleton)", () => { |
|
895
|
const registry1 = getEntityOverrideRegistry() |
|
896
|
const registry2 = getEntityOverrideRegistry() |
|
897
|
|
|
898
|
expect(registry1).toBe(registry2) |
|
899
|
}) |
|
900
|
|
|
901
|
it("should reset correctly for testing", () => { |
|
902
|
const registry1 = getEntityOverrideRegistry() |
|
903
|
registry1.register("TestEntity", { excludeFields: ["test"] }) |
|
904
|
|
|
905
|
resetEntityOverrideRegistry() |
|
906
|
|
|
907
|
const registry2 = getEntityOverrideRegistry() |
|
908
|
expect(registry2.has("TestEntity")).toBe(false) |
|
909
|
}) |
|
910
|
}) |
|
911
|
|
|
912
|
describe("register", function () { |
|
913
|
it("should register a new entity override", () => { |
|
914
|
const registry = getEntityOverrideRegistry() |
|
915
|
|
|
916
|
const customOverride: EntityOverride = { |
|
917
|
excludeFields: ["internal_field"], |
|
918
|
excludePrefixes: ["_"], |
|
919
|
defaultVisibleFields: ["name", "status"], |
|
920
|
defaultFieldOrdering: { name: 100, status: 200 }, |
|
921
|
} |
|
922
|
|
|
923
|
registry.register("CustomEntity", customOverride) |
|
924
|
|
|
925
|
expect(registry.has("CustomEntity")).toBe(true) |
|
926
|
const retrieved = registry.get("CustomEntity") |
|
927
|
expect(retrieved?.excludeFields).toContain("internal_field") |
|
928
|
expect(retrieved?.excludePrefixes).toContain("_") |
|
929
|
expect(retrieved?.defaultVisibleFields).toEqual(["name", "status"]) |
|
930
|
}) |
|
931
|
|
|
932
|
it("should merge overrides for existing entity", () => { |
|
933
|
const registry = getEntityOverrideRegistry() |
|
934
|
|
|
935
|
registry.register("Order", { |
|
936
|
excludeFields: ["new_excluded_field"], |
|
937
|
defaultFieldOrdering: { new_field: 50 }, |
|
938
|
}) |
|
939
|
|
|
940
|
const merged = registry.get("Order") |
|
941
|
|
|
942
|
expect(merged?.excludeFields).toContain("order_change") |
|
943
|
expect(merged?.excludeFields).toContain("new_excluded_field") |
|
944
|
expect(merged?.defaultFieldOrdering?.display_id).toBe(100) |
|
945
|
expect(merged?.defaultFieldOrdering?.new_field).toBe(50) |
|
946
|
}) |
|
947
|
|
|
948
|
it("should prefer new values for non-array fields", () => { |
|
949
|
const registry = getEntityOverrideRegistry() |
|
950
|
|
|
951
|
registry.register("Order", { |
|
952
|
excludePrefixes: ["custom_"], |
|
953
|
}) |
|
954
|
|
|
955
|
const merged = registry.get("Order") |
|
956
|
|
|
957
|
expect(merged?.excludePrefixes).toEqual(["custom_"]) |
|
958
|
}) |
|
959
|
|
|
960
|
it("should concatenate array fields (excludeFields, additionalTypes)", () => { |
|
961
|
const registry = getEntityOverrideRegistry() |
|
962
|
|
|
963
|
registry.register("Order", { |
|
964
|
additionalTypes: ["OrderSummary"], |
|
965
|
}) |
|
966
|
|
|
967
|
const merged = registry.get("Order") |
|
968
|
|
|
969
|
expect(merged?.additionalTypes).toContain("OrderDetail") |
|
970
|
expect(merged?.additionalTypes).toContain("OrderSummary") |
|
971
|
}) |
|
972
|
|
|
973
|
it("should concatenate nonFilterableFields when extending an existing override", () => { |
|
974
|
const registry = getEntityOverrideRegistry() |
|
975
|
|
|
976
|
registry.register("Order", { |
|
977
|
nonFilterableFields: ["custom_computed_field"], |
|
978
|
}) |
|
979
|
|
|
980
|
const merged = registry.get("Order") |
|
981
|
|
|
982
|
expect(merged?.nonFilterableFields).toContain("payment_status") |
|
983
|
expect(merged?.nonFilterableFields).toContain("fulfillment_status") |
|
984
|
expect(merged?.nonFilterableFields).toContain( |
|
985
|
"custom_computed_field" |
|
986
|
) |
|
987
|
}) |
|
988
|
}) |
|
989
|
|
|
990
|
describe("get", function () { |
|
991
|
it("should return override for existing entity", () => { |
|
992
|
const registry = getEntityOverrideRegistry() |
|
993
|
const orderOverride = registry.get("Order") |
|
994
|
|
|
995
|
expect(orderOverride).toBeDefined() |
|
996
|
expect(orderOverride?.excludeFields).toContain("order_change") |
|
997
|
}) |
|
998
|
|
|
999
|
it("should return undefined for non-existing entity", () => { |
|
1000
|
const registry = getEntityOverrideRegistry() |
|
1001
|
const nonExistent = registry.get("NonExistentEntity") |
|
1002
|
|
|
1003
|
expect(nonExistent).toBeUndefined() |
|
1004
|
}) |
|
1005
|
}) |
|
1006
|
|
|
1007
|
describe("has", function () { |
|
1008
|
it("should return true for entities with overrides", () => { |
|
1009
|
const registry = getEntityOverrideRegistry() |
|
1010
|
|
|
1011
|
expect(registry.has("Order")).toBe(true) |
|
1012
|
expect(registry.has("Product")).toBe(true) |
|
1013
|
}) |
|
1014
|
|
|
1015
|
it("should return false for entities without overrides", () => { |
|
1016
|
const registry = getEntityOverrideRegistry() |
|
1017
|
|
|
1018
|
expect(registry.has("NonExistentEntity")).toBe(false) |
|
1019
|
}) |
|
1020
|
}) |
|
1021
|
|
|
1022
|
describe("getEntityNames", function () { |
|
1023
|
it("should return all registered entity names", () => { |
|
1024
|
const registry = getEntityOverrideRegistry() |
|
1025
|
const names = registry.getEntityNames() |
|
1026
|
|
|
1027
|
expect(Array.isArray(names)).toBe(true) |
|
1028
|
expect(names.length).toBeGreaterThan(0) |
|
1029
|
|
|
1030
|
for (const builtIn of Object.keys(BUILTIN_ENTITY_OVERRIDES)) { |
|
1031
|
expect(names).toContain(builtIn) |
|
1032
|
} |
|
1033
|
}) |
|
1034
|
|
|
1035
|
it("should include newly registered entities", () => { |
|
1036
|
const registry = getEntityOverrideRegistry() |
|
1037
|
|
|
1038
|
registry.register("NewCustomEntity", { |
|
1039
|
defaultVisibleFields: ["field1"], |
|
1040
|
}) |
|
1041
|
|
|
1042
|
const names = registry.getEntityNames() |
|
1043
|
expect(names).toContain("NewCustomEntity") |
|
1044
|
}) |
|
1045
|
}) |
|
1046
|
|
|
1047
|
describe("getAll", function () { |
|
1048
|
it("should return all overrides as a record", () => { |
|
1049
|
const registry = getEntityOverrideRegistry() |
|
1050
|
const all = registry.getAll() |
|
1051
|
|
|
1052
|
expect(typeof all).toBe("object") |
|
1053
|
expect(all).toHaveProperty("Order") |
|
1054
|
expect(all).toHaveProperty("Product") |
|
1055
|
}) |
|
1056
|
|
|
1057
|
it("should include registered custom entities", () => { |
|
1058
|
const registry = getEntityOverrideRegistry() |
|
1059
|
|
|
1060
|
registry.register("AnotherCustomEntity", { |
|
1061
|
excludeFields: ["secret"], |
|
1062
|
}) |
|
1063
|
|
|
1064
|
const all = registry.getAll() |
|
1065
|
expect(all).toHaveProperty("AnotherCustomEntity") |
|
1066
|
expect(all.AnotherCustomEntity.excludeFields).toContain("secret") |
|
1067
|
}) |
|
1068
|
}) |
|
1069
|
|
|
1070
|
describe("column generation helper functions", function () { |
|
1071
|
it("should use registry overrides in getFieldFilterRules", () => { |
|
1072
|
// Import the helper function for direct testing |
|
1073
|
const { |
|
1074
|
getFieldFilterRules, |
|
1075
|
} = require("../../src/utils/entity-overrides") |
|
1076
|
|
|
1077
|
const registry = getEntityOverrideRegistry() |
|
1078
|
|
|
1079
|
registry.register("TestEntity", { |
|
1080
|
excludeFields: ["secret_field"], |
|
1081
|
excludePrefixes: ["internal_"], |
|
1082
|
}) |
|
1083
|
|
|
1084
|
const filterRules = getFieldFilterRules("TestEntity") |
|
1085
|
|
|
1086
|
expect(filterRules.excludeFields).toContain("secret_field") |
|
1087
|
expect(filterRules.excludePrefixes).toContain("internal_") |
|
1088
|
}) |
|
1089
|
|
|
1090
|
it("should use registry overrides in getDefaultVisibleFields", () => { |
|
1091
|
const { |
|
1092
|
getDefaultVisibleFields, |
|
1093
|
} = require("../../src/utils/entity-overrides") |
|
1094
|
|
|
1095
|
const registry = getEntityOverrideRegistry() |
|
1096
|
|
|
1097
|
registry.register("VisibilityTestEntity", { |
|
1098
|
defaultVisibleFields: ["name", "status", "created_at"], |
|
1099
|
}) |
|
1100
|
|
|
1101
|
const visibleFields = getDefaultVisibleFields( |
|
1102
|
"VisibilityTestEntity" |
|
1103
|
) |
|
1104
|
|
|
1105
|
expect(visibleFields).toEqual(["name", "status", "created_at"]) |
|
1106
|
}) |
|
1107
|
|
|
1108
|
it("should use registry overrides in getFieldOrdering", () => { |
|
1109
|
const { |
|
1110
|
getFieldOrdering, |
|
1111
|
} = require("../../src/utils/entity-overrides") |
|
1112
|
|
|
1113
|
const registry = getEntityOverrideRegistry() |
|
1114
|
|
|
1115
|
registry.register("OrderingTestEntity", { |
|
1116
|
defaultFieldOrdering: { name: 100, status: 200, created_at: 300 }, |
|
1117
|
}) |
|
1118
|
|
|
1119
|
const ordering = getFieldOrdering("OrderingTestEntity") |
|
1120
|
|
|
1121
|
expect(ordering.name).toBe(100) |
|
1122
|
expect(ordering.status).toBe(200) |
|
1123
|
expect(ordering.created_at).toBe(300) |
|
1124
|
}) |
|
1125
|
|
|
1126
|
it("should use registry overrides in getAdditionalTypes", () => { |
|
1127
|
const { |
|
1128
|
getAdditionalTypes, |
|
1129
|
} = require("../../src/utils/entity-overrides") |
|
1130
|
|
|
1131
|
const registry = getEntityOverrideRegistry() |
|
1132
|
|
|
1133
|
registry.register("TypesTestEntity", { |
|
1134
|
additionalTypes: [ |
|
1135
|
"TypesTestEntityDetail", |
|
1136
|
"TypesTestEntitySummary", |
|
1137
|
], |
|
1138
|
}) |
|
1139
|
|
|
1140
|
const additionalTypes = getAdditionalTypes("TypesTestEntity") |
|
1141
|
|
|
1142
|
expect(additionalTypes).toContain("TypesTestEntityDetail") |
|
1143
|
expect(additionalTypes).toContain("TypesTestEntitySummary") |
|
1144
|
}) |
|
1145
|
}) |
|
1146
|
}) |
|
1147
|
}) |
|
1148
|
}, |
|
1149
|
}) |