@contrail/flexplm 1.5.0-alpha.98b8b06 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (111) hide show
  1. package/.github/pull_request_template.md +31 -0
  2. package/.github/workflows/flexplm-lib.yml +27 -0
  3. package/.github/workflows/publish-to-npm.yml +121 -0
  4. package/CHANGELOG.md +45 -0
  5. package/lib/entity-processor/base-entity-processor.d.ts +0 -65
  6. package/lib/entity-processor/base-entity-processor.js +0 -71
  7. package/lib/entity-processor/base-entity-processor.spec.js +0 -1
  8. package/lib/index.d.ts +0 -1
  9. package/lib/index.js +0 -1
  10. package/lib/publish/base-process-publish-assortment.d.ts +0 -25
  11. package/lib/publish/base-process-publish-assortment.js +6 -60
  12. package/lib/publish/base-process-publish-assortment.spec.js +4 -22
  13. package/lib/publish/mockData.js +0 -5
  14. package/lib/transform/identifier-conversion-spec-mockData.js +6 -34
  15. package/lib/transform/identifier-conversion.d.ts +0 -36
  16. package/lib/transform/identifier-conversion.js +0 -36
  17. package/lib/transform/identifier-conversion.spec.js +0 -4
  18. package/lib/util/config-defaults.js +0 -3
  19. package/lib/util/config-defaults.spec.js +0 -9
  20. package/lib/util/data-converter-spec-mockData.js +3 -17
  21. package/lib/util/data-converter.d.ts +0 -97
  22. package/lib/util/data-converter.js +1 -127
  23. package/lib/util/data-converter.spec.js +0 -2
  24. package/lib/util/error-response-object.d.ts +0 -5
  25. package/lib/util/error-response-object.js +0 -7
  26. package/lib/util/event-short-message-status.js +0 -1
  27. package/lib/util/federation.js +0 -8
  28. package/lib/util/flexplm-connect.d.ts +0 -7
  29. package/lib/util/flexplm-connect.js +0 -14
  30. package/lib/util/logger-config.js +0 -1
  31. package/lib/util/map-util-spec-mockData.js +3 -17
  32. package/lib/util/map-utils.d.ts +0 -27
  33. package/lib/util/map-utils.js +0 -27
  34. package/lib/util/thumbnail-util.d.ts +0 -21
  35. package/lib/util/thumbnail-util.js +1 -28
  36. package/lib/util/thumbnail-util.spec.js +0 -6
  37. package/lib/util/type-conversion-utils-spec-mockData.js +3 -3
  38. package/lib/util/type-conversion-utils.d.ts +1 -152
  39. package/lib/util/type-conversion-utils.js +1 -155
  40. package/lib/util/type-defaults.d.ts +0 -66
  41. package/lib/util/type-defaults.js +0 -66
  42. package/lib/util/type-defaults.spec.js +5 -5
  43. package/lib/util/type-utils.d.ts +0 -21
  44. package/lib/util/type-utils.js +0 -23
  45. package/lib/util/type-utils.spec.js +0 -2
  46. package/package.json +6 -21
  47. package/publish.bat +5 -0
  48. package/publish.sh +5 -0
  49. package/src/entity-processor/base-entity-processor.spec.ts +689 -0
  50. package/src/entity-processor/base-entity-processor.ts +583 -0
  51. package/src/flexplm-request.ts +28 -0
  52. package/src/flexplm-utils.spec.ts +27 -0
  53. package/src/flexplm-utils.ts +29 -0
  54. package/src/index.ts +22 -0
  55. package/src/interfaces/interfaces.ts +122 -0
  56. package/src/interfaces/item-family-changes.ts +67 -0
  57. package/src/interfaces/publish-change-data.ts +43 -0
  58. package/src/publish/base-process-publish-assortment-callback.ts +50 -0
  59. package/src/publish/base-process-publish-assortment.spec.ts +1992 -0
  60. package/src/publish/base-process-publish-assortment.ts +1134 -0
  61. package/src/publish/mockData.ts +4561 -0
  62. package/src/transform/identifier-conversion-spec-mockData.ts +496 -0
  63. package/src/transform/identifier-conversion.spec.ts +386 -0
  64. package/src/transform/identifier-conversion.ts +282 -0
  65. package/src/util/config-defaults.spec.ts +445 -0
  66. package/src/util/config-defaults.ts +106 -0
  67. package/src/util/data-converter-spec-mockData.ts +231 -0
  68. package/src/util/data-converter.spec.ts +1622 -0
  69. package/src/util/data-converter.ts +819 -0
  70. package/src/util/error-response-object.spec.ts +116 -0
  71. package/src/util/error-response-object.ts +50 -0
  72. package/src/util/event-short-message-status.ts +22 -0
  73. package/src/util/federation.ts +172 -0
  74. package/src/util/flexplm-connect.spec.ts +132 -0
  75. package/src/util/flexplm-connect.ts +208 -0
  76. package/src/util/logger-config.ts +20 -0
  77. package/src/util/map-util-spec-mockData.ts +231 -0
  78. package/src/util/map-utils.spec.ts +103 -0
  79. package/src/util/map-utils.ts +41 -0
  80. package/src/util/mockData.ts +101 -0
  81. package/src/util/thumbnail-util.spec.ts +508 -0
  82. package/src/util/thumbnail-util.ts +272 -0
  83. package/src/util/type-conversion-utils-spec-mockData.ts +272 -0
  84. package/src/util/type-conversion-utils.spec.ts +1031 -0
  85. package/src/util/type-conversion-utils.ts +490 -0
  86. package/src/util/type-defaults.spec.ts +797 -0
  87. package/src/util/type-defaults.ts +320 -0
  88. package/src/util/type-utils.spec.ts +227 -0
  89. package/src/util/type-utils.ts +144 -0
  90. package/tsconfig.json +24 -0
  91. package/tslint.json +57 -0
  92. package/lib/cli/commands/compile.d.ts +0 -4
  93. package/lib/cli/commands/compile.js +0 -73
  94. package/lib/cli/commands/compile.spec.d.ts +0 -1
  95. package/lib/cli/commands/compile.spec.js +0 -80
  96. package/lib/cli/commands/create.d.ts +0 -5
  97. package/lib/cli/commands/create.js +0 -77
  98. package/lib/cli/commands/create.spec.d.ts +0 -1
  99. package/lib/cli/commands/create.spec.js +0 -78
  100. package/lib/cli/commands/upload.d.ts +0 -17
  101. package/lib/cli/commands/upload.js +0 -228
  102. package/lib/cli/commands/upload.spec.d.ts +0 -1
  103. package/lib/cli/commands/upload.spec.js +0 -88
  104. package/lib/cli/index.d.ts +0 -5
  105. package/lib/cli/index.js +0 -70
  106. package/lib/cli/index.spec.d.ts +0 -1
  107. package/lib/cli/index.spec.js +0 -85
  108. package/lib/cli/template/mapping-template.ts.template +0 -62
  109. package/lib/interfaces/mapping-file.d.ts +0 -460
  110. package/lib/interfaces/mapping-file.js +0 -2
  111. package/scripts/copy-template.js +0 -10
@@ -0,0 +1,1622 @@
1
+ const mockObj1234 = {
2
+ id: 1234,
3
+ typePath: 'color'
4
+ };
5
+ const mockObj2222 = {
6
+ id: 2222,
7
+ typePath: 'color'
8
+ };
9
+ const mockGetFunction = jest.fn((options) =>{
10
+ return (options?.criteria?.id === 1234)
11
+ ?[mockObj1234]
12
+ :[mockObj2222];
13
+ });
14
+ jest.mock('@contrail/sdk', () => {
15
+ const origModule = jest.requireActual('@contrail/sdk');
16
+ return {
17
+ __esModule: true,
18
+ ...origModule,
19
+ Entities: class {
20
+ get = mockGetFunction;
21
+ },
22
+ };
23
+ });
24
+
25
+ import { Entities } from '@contrail/sdk';
26
+ import { MapFileUtil } from '@contrail/transform-data';
27
+ import { DataConverter } from './data-converter';
28
+ import { FCConfig } from '../interfaces/interfaces';
29
+ import { TypeConversionUtils } from './type-conversion-utils';
30
+ import { MapUtil } from './map-utils';
31
+
32
+ describe('getFlexPLMValue multi_select', () => {
33
+ const config: FCConfig = {
34
+ apiHost: 'host',
35
+ userName: () => 'user',
36
+ password: () => 'pass',
37
+ urlContext: 'xxx',
38
+ vibeEventEndpoint: '/rfa/vibeiq/vibeEvents',
39
+ csrfEndpoint: '/servlet/rest/security/csrf',
40
+ itemPreDevelopmentLifecycleStages: ['concept']
41
+ };
42
+
43
+ const mapFileUtil = new MapFileUtil(new Entities());
44
+ const dc = new DataConverter(config, mapFileUtil);
45
+ const enumAtt = {
46
+ id: 'cJoZQvoj7dkfCBJq',
47
+ propertyType: 'multi_select',
48
+ slug: 'flexMultiSelect',
49
+ label: 'Flex Multi Select',
50
+ options: [
51
+ {
52
+ value: 'one',
53
+ display: 'One'
54
+ },
55
+ {
56
+ value: 'two',
57
+ display: 'Two'
58
+ },
59
+ {
60
+ value: 'three',
61
+ display: 'Three'
62
+ }
63
+ ],
64
+ };
65
+
66
+ it('multi_select_null', async () => {
67
+ const newData = {
68
+ flexMultiSelect: null
69
+ };
70
+ const returnValue = await dc.getFlexPLMValue(enumAtt, newData, true);
71
+ expect(returnValue).toEqual([]);
72
+ });
73
+
74
+ it('multi_select_no_values', async () => {
75
+ const newData = {
76
+ flexMultiSelect: []
77
+ };
78
+ const returnValue = await dc.getFlexPLMValue(enumAtt, newData, true);
79
+ expect(returnValue).toEqual(newData.flexMultiSelect);
80
+ });
81
+
82
+ it('multi_select_two_values', async () => {
83
+ const newData = {
84
+ flexMultiSelect: ['one', 'three']
85
+ };
86
+ const optionValues = [
87
+ { value: 'one', display: 'One' },
88
+ { value: 'three', display: 'Three' }
89
+ ];
90
+ const returnValue = await dc.getFlexPLMValue(enumAtt, newData, true);
91
+ expect(returnValue).toEqual(optionValues);
92
+ });
93
+ });
94
+
95
+ describe('getEnumerationValue', () =>{
96
+ const config: FCConfig = {
97
+ apiHost: 'host',
98
+ userName: () => 'user',
99
+ password: () => 'pass',
100
+ urlContext: 'xxx',
101
+ vibeEventEndpoint: '/rfa/vibeiq/vibeEvents',
102
+ csrfEndpoint: '/servlet/rest/security/csrf',
103
+ itemPreDevelopmentLifecycleStages: ['concept']
104
+ };
105
+
106
+ const mapFileUtil = new MapFileUtil(new Entities());
107
+ const dc = new DataConverter(config, mapFileUtil);
108
+ const enumProp = {
109
+ id: 'cJoZQvoj7dkfCBJq',
110
+ propertyType: 'choice',
111
+ slug: 'flexChoice',
112
+ label: 'Flex Choice',
113
+ options: [
114
+ {
115
+ value: 'one',
116
+ display: 'One'
117
+ },
118
+ {
119
+ value: 'two',
120
+ display: 'Two'
121
+ },
122
+ {
123
+ value: 'three',
124
+ display: 'Three'
125
+ }
126
+ ],
127
+ };
128
+
129
+ const enumPropNoList = {
130
+ id: 'cJoZQvoj7dkfCBJq',
131
+ propertyType: 'choice',
132
+ slug: 'flexChoice',
133
+ label: 'Flex Choice',
134
+ };
135
+
136
+ it('match 1 key', () =>{
137
+ const nd = 'one';
138
+ const expectedValue = {value: 'one', display: 'One'};
139
+
140
+ const returnValue = dc.getEnumerationValue(enumProp, nd);
141
+ expect(returnValue).toEqual(expectedValue);
142
+ });
143
+
144
+ it('wrong key', () =>{
145
+ const nd = 'one1';
146
+ const expectedValue = {};
147
+
148
+ const returnValue = dc.getEnumerationValue(enumProp, nd);
149
+ expect(returnValue).toEqual(expectedValue);
150
+ });
151
+
152
+ it('property no list', () =>{
153
+ const nd = 'one1';
154
+ const expectedValue = {};
155
+
156
+ const returnValue = dc.getEnumerationValue(enumPropNoList, nd);
157
+ expect(returnValue).toEqual(expectedValue);
158
+ });
159
+
160
+ });
161
+
162
+ describe('getEnumerationValue multi_select', () => {
163
+ const config: FCConfig = {
164
+ apiHost: 'host',
165
+ userName: () => 'user',
166
+ password: () => 'pass',
167
+ urlContext: 'xxx',
168
+ vibeEventEndpoint: '/rfa/vibeiq/vibeEvents',
169
+ csrfEndpoint: '/servlet/rest/security/csrf',
170
+ itemPreDevelopmentLifecycleStages: ['concept']
171
+ };
172
+
173
+ const mapFileUtil = new MapFileUtil(new Entities());
174
+ const dc = new DataConverter(config, mapFileUtil);
175
+ const enumAtt = {
176
+ id: 'cJoZQvoj7dkfCBJq',
177
+ propertyType: 'multi_select',
178
+ slug: 'flexMultiSelect',
179
+ label: 'Flex Multi Select',
180
+ options: [
181
+ {
182
+ value: 'one',
183
+ display: 'One'
184
+ },
185
+ {
186
+ value: 'two',
187
+ display: 'Two'
188
+ },
189
+ {
190
+ value: 'three',
191
+ display: 'Three'
192
+ }
193
+ ],
194
+ };
195
+
196
+
197
+ it('multi_select_null', async () => {
198
+ const nd = null;
199
+ const returnValue = await dc.getEnumerationValue(enumAtt, nd);
200
+ expect(returnValue).toEqual([]);
201
+ });
202
+
203
+ it('multi_select_no_values', async () => {
204
+ const nd = [];
205
+ const returnValue = await dc.getEnumerationValue(enumAtt, nd);
206
+ expect(returnValue).toEqual(nd);
207
+ });
208
+
209
+ it('multi select one string value', async () =>{
210
+ const nd = 'one';
211
+ const optionValues = [
212
+ { value: 'one', display: 'One' }
213
+ ];
214
+ const returnValue = await dc.getEnumerationValue(enumAtt, nd);
215
+ expect(returnValue).toEqual(optionValues);
216
+ });
217
+
218
+ it('multi_select_two_values', async () => {
219
+ const nd = ['one', 'three'];
220
+ const optionValues = [
221
+ { value: 'one', display: 'One' },
222
+ { value: 'three', display: 'Three' }
223
+ ];
224
+ const returnValue = await dc.getEnumerationValue(enumAtt, nd);
225
+ expect(returnValue).toEqual(optionValues);
226
+ });
227
+
228
+ });
229
+
230
+ describe('getPersistableChanges', () =>{
231
+ const config: FCConfig = {
232
+ apiHost: 'host',
233
+ userName: () => 'user',
234
+ password: () => 'pass',
235
+ urlContext: 'xxx',
236
+ vibeEventEndpoint: '/rfa/vibeiq/vibeEvents',
237
+ csrfEndpoint: '/servlet/rest/security/csrf',
238
+ itemPreDevelopmentLifecycleStages: ['concept']
239
+ };
240
+
241
+ const mapFileUtil = new MapFileUtil(new Entities());
242
+ const dc = new DataConverter(config, mapFileUtil);
243
+ it('no changes', () =>{
244
+ const entity = {
245
+ num: 1
246
+ };
247
+ const potentialChanges = {};
248
+
249
+ const diffs = dc.getPersistableChanges(entity, potentialChanges);
250
+ expect(Object.getOwnPropertyNames(diffs).length).toEqual(0);
251
+ });
252
+
253
+ it('same value', () =>{
254
+ const entity = {
255
+ str: 'test',
256
+ num: 1
257
+ };
258
+ const potentialChanges = {
259
+ str: 'test',
260
+ num: 1
261
+ };
262
+
263
+ const diffs = dc.getPersistableChanges(entity, potentialChanges);
264
+ expect(Object.getOwnPropertyNames(diffs).length).toEqual(0);
265
+ });
266
+
267
+ it('diff num value', () =>{
268
+ const entity = {
269
+ str: 'option 1 string-Changed',
270
+ num: 12
271
+ };
272
+ const potentialChanges = {
273
+ str: 'option 1 string-Changed',
274
+ num: 1
275
+ };
276
+
277
+ const diffs = dc.getPersistableChanges(entity, potentialChanges);
278
+ expect(Object.getOwnPropertyNames(diffs).length).toEqual(1);
279
+ expect(diffs['num']).toEqual(potentialChanges['num']);
280
+ });
281
+
282
+ it('zero num value', () =>{
283
+ const entity = {
284
+ str: 'option 1 string-Changed',
285
+ num: 12
286
+ };
287
+ const potentialChanges = {
288
+ str: 'option 1 string-Changed',
289
+ num: 0
290
+ };
291
+
292
+ const diffs = dc.getPersistableChanges(entity, potentialChanges);
293
+ expect(Object.getOwnPropertyNames(diffs).length).toEqual(1);
294
+ expect(diffs['num']).toEqual(potentialChanges['num']);
295
+ });
296
+
297
+ it('diff str value', () =>{
298
+ const entity = {
299
+ str: 'test',
300
+ num: 1
301
+ };
302
+ const potentialChanges = {
303
+ str: 'test-1',
304
+ num: 1
305
+ };
306
+
307
+ const diffs = dc.getPersistableChanges(entity, potentialChanges);
308
+ expect(Object.getOwnPropertyNames(diffs).length).toEqual(1);
309
+ expect(diffs['str']).toEqual(potentialChanges['str']);
310
+ });
311
+
312
+ it('empty str value', () =>{
313
+ const entity = {
314
+ str: 'test',
315
+ num: 1
316
+ };
317
+ const potentialChanges = {
318
+ str: '',
319
+ num: 1
320
+ };
321
+
322
+ const diffs = dc.getPersistableChanges(entity, potentialChanges);
323
+ expect(Object.getOwnPropertyNames(diffs).length).toEqual(1);
324
+ expect(diffs['str']).toBeNull();
325
+ });
326
+
327
+ });
328
+
329
+ describe('getObjectReferenceValue cache', () =>{
330
+ const config: FCConfig = {
331
+ apiHost: 'host',
332
+ userName: () => 'user',
333
+ password: () => 'pass',
334
+ urlContext: 'xxx',
335
+ vibeEventEndpoint: '/rfa/vibeiq/vibeEvents',
336
+ csrfEndpoint: '/servlet/rest/security/csrf',
337
+ itemPreDevelopmentLifecycleStages: ['concept']
338
+ };
339
+
340
+ const mapFileUtil = new MapFileUtil(new Entities());
341
+ const dc = new DataConverter(config, mapFileUtil);
342
+ const ref1Prop = {
343
+ id: 'cJoZQvoj7dkfCBJq',
344
+ propertyType: 'object_reference',
345
+ slug: 'ref1',
346
+ label: 'Object Ref#1',
347
+ referencedTypeRootSlug: 'color'
348
+
349
+ };
350
+ const ref2Prop = {
351
+ id: 'cJoZQvoj7dkfCBJq',
352
+ propertyType: 'object_reference',
353
+ slug: 'ref2',
354
+ label: 'Object Ref#2',
355
+ referencedTypeRootSlug: 'color'
356
+
357
+ };
358
+ const ref3Prop = {
359
+ id: 'cJoZQvoj7dkfCBJq',
360
+ propertyType: 'object_reference',
361
+ slug: 'ref3',
362
+ label: 'Object Ref#3',
363
+ referencedTypeRootSlug: 'color'
364
+
365
+ };
366
+ const newData = {
367
+ ref1Id: 1234,
368
+ ref2Id: 2222,
369
+ ref3Id: 1234
370
+ };
371
+
372
+ it('cache hit', async () =>{
373
+ const oobFunction = dc.getFlexPLMObjectData;
374
+ try {
375
+ dc.getFlexPLMObjectData = async (newData, /*dataToSkip: string[], inflateObjRef: boolean*/) => {
376
+ return newData;
377
+ };
378
+ mockGetFunction.mockClear();
379
+
380
+ const r1 = await dc.getObjectReferenceValue(ref1Prop, newData, true);
381
+ const r2 = await dc.getObjectReferenceValue(ref2Prop, newData, true);
382
+ const r3 = await dc.getObjectReferenceValue(ref3Prop, newData, true);
383
+
384
+ expect(mockGetFunction).toHaveBeenCalledTimes(2);
385
+ expect(r1).toEqual(mockObj1234);
386
+ expect(r2).toEqual(mockObj2222);
387
+ expect(r3).toEqual(mockObj1234);
388
+
389
+ } finally {
390
+ dc.getFlexPLMObjectData = oobFunction;
391
+ }
392
+ });
393
+ });
394
+ describe('getObjectReferenceValue bad value', () =>{
395
+ const config: FCConfig = {
396
+ apiHost: 'host',
397
+ userName: () => 'user',
398
+ password: () => 'pass',
399
+ urlContext: 'xxx',
400
+ vibeEventEndpoint: '/rfa/vibeiq/vibeEvents',
401
+ csrfEndpoint: '/servlet/rest/security/csrf',
402
+ itemPreDevelopmentLifecycleStages: ['concept']
403
+ };
404
+
405
+ const mapFileUtil = new MapFileUtil(new Entities());
406
+ const dc = new DataConverter(config, mapFileUtil);
407
+ const ref1Prop = {
408
+ id: 'cJoZQvoj7dkfCBJq',
409
+ propertyType: 'object_reference',
410
+ slug: 'ref1',
411
+ label: 'Object Ref#1',
412
+ referencedTypeRootSlug: 'color'
413
+
414
+ };
415
+ const ref2Prop = {
416
+ id: 'cJoZQvoj7dkfCBJq',
417
+ propertyType: 'object_reference',
418
+ slug: 'ref2',
419
+ label: 'Object Ref#2',
420
+ referencedTypeRootSlug: 'color'
421
+
422
+ };
423
+ const ref3Prop = {
424
+ id: 'cJoZQvoj7dkfCBJq',
425
+ propertyType: 'object_reference',
426
+ slug: 'ref3',
427
+ label: 'Object Ref#3',
428
+ referencedTypeRootSlug: 'color'
429
+
430
+ };
431
+ const newData = {
432
+ ref1Id: 1234,
433
+ ref2Id: 2222,
434
+ ref3Id: 1234,
435
+ ref3: 'old value'
436
+ };
437
+
438
+ it('old string value', async () =>{
439
+ const oobFunction = dc.getFlexPLMObjectData;
440
+ try {
441
+ dc.getFlexPLMObjectData = async (newData, /*dataToSkip: string[], inflateObjRef: boolean*/) => {
442
+ return newData;
443
+ };
444
+ mockGetFunction.mockClear();
445
+ const r3 = await dc.getObjectReferenceValue(ref3Prop, newData, true);
446
+ expect(r3).toEqual(mockObj1234);
447
+
448
+ } finally {
449
+ dc.getFlexPLMObjectData = oobFunction;
450
+ }
451
+ });
452
+
453
+ it('only id', async () =>{
454
+ const oobFunction = dc.getFlexPLMObjectData;
455
+ try {
456
+ dc.getFlexPLMObjectData = async (newData, /*dataToSkip: string[], inflateObjRef: boolean*/) => {
457
+ return newData;
458
+ };
459
+ mockGetFunction.mockClear();
460
+ const r2 = await dc.getObjectReferenceValue(ref2Prop, newData, true);
461
+ expect(r2).toEqual(mockObj2222);
462
+
463
+ } finally {
464
+ dc.getFlexPLMObjectData = oobFunction;
465
+ }
466
+ });
467
+
468
+ it('already references object', async () =>{
469
+ const testData = {
470
+ ref1Id: 1234,
471
+ ref1: mockObj1234,
472
+ ref2Id: 2222,
473
+ ref3Id: 1234,
474
+ ref3: 'old value'
475
+ };
476
+
477
+ const oobFunction = dc.getFlexPLMObjectData;
478
+ try {
479
+ dc.getFlexPLMObjectData = async (newData, /*dataToSkip: string[], inflateObjRef: boolean*/) => {
480
+ return newData;
481
+ };
482
+ mockGetFunction.mockClear();
483
+ const r1 = await dc.getObjectReferenceValue(ref1Prop, testData, true);
484
+ expect(r1).toEqual(mockObj1234);
485
+
486
+ } finally {
487
+ dc.getFlexPLMObjectData = oobFunction;
488
+ }
489
+ });
490
+
491
+ it('old string value, no refId', async () =>{
492
+ const testData = {
493
+ ref1: 'old value'
494
+ };
495
+
496
+ const oobFunction = dc.getFlexPLMObjectData;
497
+ try {
498
+ dc.getFlexPLMObjectData = async (newData, /*dataToSkip: string[], inflateObjRef: boolean*/) => {
499
+ return newData;
500
+ };
501
+ mockGetFunction.mockClear();
502
+ const r1 = await dc.getObjectReferenceValue(ref1Prop, testData, true);
503
+ expect(r1).toEqual({});
504
+
505
+ } finally {
506
+ dc.getFlexPLMObjectData = oobFunction;
507
+ }
508
+ });
509
+
510
+ });
511
+
512
+ describe('setObjectReferenceValue - identity service', () => {
513
+ const baseConfig = (): FCConfig => ({
514
+ apiHost: 'host',
515
+ userName: () => 'user',
516
+ password: () => 'pass',
517
+ urlContext: 'xxx',
518
+ vibeEventEndpoint: '/rfa/vibeiq/vibeEvents',
519
+ csrfEndpoint: '/servlet/rest/security/csrf',
520
+ itemPreDevelopmentLifecycleStages: ['concept']
521
+ });
522
+
523
+ const refProp = {
524
+ id: 'cJoZQvoj7dkfCBJq',
525
+ propertyType: 'object_reference',
526
+ slug: 'material',
527
+ label: 'Material',
528
+ referencedTypeRootSlug: 'item',
529
+ referencedTypePath: 'item:material'
530
+ };
531
+
532
+ let identifierSpy: jest.SpyInstance;
533
+ let poolKeySpy: jest.SpyInstance;
534
+ let getByRootAndPathSpy: jest.SpyInstance;
535
+ let filterTypePropertiesSpy: jest.SpyInstance;
536
+
537
+ const setupTypeUtilsSpies = (dc: DataConverter, rootPropSlugs: string[] = ['itemNumber']) => {
538
+ getByRootAndPathSpy = jest.spyOn(dc['typeUtils'], 'getByRootAndPath')
539
+ .mockImplementation(async () => ({ typePath: 'item', typeProperties: [] }) as any);
540
+ filterTypePropertiesSpy = jest.spyOn(dc['typeUtils'], 'filterTypeProperties')
541
+ .mockImplementation(() => rootPropSlugs.map(slug => ({ slug })) as any);
542
+ };
543
+
544
+ afterEach(() => {
545
+ identifierSpy?.mockRestore();
546
+ poolKeySpy?.mockRestore();
547
+ getByRootAndPathSpy?.mockRestore();
548
+ filterTypePropertiesSpy?.mockRestore();
549
+ mockGetFunction.mockReset();
550
+ mockGetFunction.mockImplementation((options) =>
551
+ ((options?.criteria?.id === 1234) ? [mockObj1234] : [mockObj2222]) as any
552
+ );
553
+ });
554
+
555
+ it('flag off - uses getAllObjectReferences path', async () => {
556
+ const dc = new DataConverter(baseConfig(), new MapFileUtil(new Entities()));
557
+ setupTypeUtilsSpies(dc, ['itemNumber', 'roles']);
558
+
559
+ identifierSpy = jest.spyOn(TypeConversionUtils, 'getIdentifierPropertiesFromObject')
560
+ .mockImplementation(async () => ['itemNumber', 'roles']);
561
+ poolKeySpy = jest.spyOn(TypeConversionUtils, 'getUniquenessPoolKeyFromObject')
562
+ .mockImplementation(async () => 'item:material');
563
+
564
+ mockGetFunction.mockClear();
565
+ mockGetFunction.mockImplementation(() => [{ id: 'abc123', typePath: 'item:material' }] as any);
566
+
567
+ const nd = { itemNumber: 'MAT-100', roles: ['family'] };
568
+ const result = await dc.setObjectReferenceValue(refProp, nd);
569
+
570
+ expect(mockGetFunction).toHaveBeenCalled();
571
+ const callArg = mockGetFunction.mock.calls[0][0];
572
+ expect(callArg.entityName).toEqual('item');
573
+ expect(callArg.entityName).not.toEqual('identity');
574
+ expect(result).toEqual('abc123');
575
+ expect(poolKeySpy).not.toHaveBeenCalled();
576
+ });
577
+
578
+ it('flag on, single identity match - returns parsed id', async () => {
579
+ const config = baseConfig();
580
+ config.search = { item: { useIdentityServiceForInboundData: true } };
581
+ const dc = new DataConverter(config, new MapFileUtil(new Entities()));
582
+ setupTypeUtilsSpies(dc);
583
+
584
+ identifierSpy = jest.spyOn(TypeConversionUtils, 'getIdentifierPropertiesFromObject')
585
+ .mockImplementation(async () => ['itemNumber', 'roles']);
586
+ poolKeySpy = jest.spyOn(TypeConversionUtils, 'getUniquenessPoolKeyFromObject')
587
+ .mockImplementation(async () => 'item:material');
588
+
589
+ mockGetFunction.mockClear();
590
+ mockGetFunction.mockImplementation(() => [{ entityReference: 'item:abc123' }] as any);
591
+
592
+ const nd = { itemNumber: 'MAT-100', roles: ['family'] };
593
+ const result = await dc.setObjectReferenceValue(refProp, nd);
594
+
595
+ expect(mockGetFunction).toHaveBeenCalledTimes(1);
596
+ const callArg = mockGetFunction.mock.calls[0][0];
597
+ expect(callArg.entityName).toEqual('identity');
598
+ expect(callArg.criteria).toEqual({
599
+ poolKey: 'item:material',
600
+ propertyName: 'itemNumber',
601
+ propertyValue: 'MAT-100'
602
+ });
603
+ expect(result).toEqual('abc123');
604
+ });
605
+
606
+ it('flag on, no identity match - returns empty and warns', async () => {
607
+ const config = baseConfig();
608
+ config.search = { item: { useIdentityServiceForInboundData: true } };
609
+ const dc = new DataConverter(config, new MapFileUtil(new Entities()));
610
+ setupTypeUtilsSpies(dc);
611
+
612
+ identifierSpy = jest.spyOn(TypeConversionUtils, 'getIdentifierPropertiesFromObject')
613
+ .mockImplementation(async () => ['itemNumber', 'roles']);
614
+ poolKeySpy = jest.spyOn(TypeConversionUtils, 'getUniquenessPoolKeyFromObject')
615
+ .mockImplementation(async () => 'item:material');
616
+
617
+ mockGetFunction.mockClear();
618
+ mockGetFunction.mockImplementation(() => [] as any);
619
+ const warnSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
620
+ const getAllSpy = jest.spyOn(dc, 'getAllObjectReferences');
621
+
622
+ try {
623
+ const result = await dc.setObjectReferenceValue(refProp, { itemNumber: 'MAT-100', roles: ['family'] });
624
+ expect(result).toEqual('');
625
+ expect(warnSpy).toHaveBeenCalled();
626
+ expect(getAllSpy).not.toHaveBeenCalled();
627
+ } finally {
628
+ warnSpy.mockRestore();
629
+ getAllSpy.mockRestore();
630
+ }
631
+ });
632
+
633
+ it('flag on, multiple identity matches - returns empty and does not throw', async () => {
634
+ const config = baseConfig();
635
+ config.search = { item: { useIdentityServiceForInboundData: true } };
636
+ const dc = new DataConverter(config, new MapFileUtil(new Entities()));
637
+ setupTypeUtilsSpies(dc);
638
+
639
+ identifierSpy = jest.spyOn(TypeConversionUtils, 'getIdentifierPropertiesFromObject')
640
+ .mockImplementation(async () => ['itemNumber', 'roles']);
641
+ poolKeySpy = jest.spyOn(TypeConversionUtils, 'getUniquenessPoolKeyFromObject')
642
+ .mockImplementation(async () => 'item:material');
643
+
644
+ mockGetFunction.mockClear();
645
+ mockGetFunction.mockImplementation(() => [
646
+ { entityReference: 'item:abc123' },
647
+ { entityReference: 'item:def456' }
648
+ ] as any);
649
+ const warnSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
650
+
651
+ try {
652
+ const result = await dc.setObjectReferenceValue(refProp, { itemNumber: 'MAT-100', roles: ['family'] });
653
+ expect(result).toEqual('');
654
+ expect(warnSpy).toHaveBeenCalled();
655
+ } finally {
656
+ warnSpy.mockRestore();
657
+ }
658
+ });
659
+
660
+ it('flag on, ambiguous identifier set - falls back to getAllObjectReferences', async () => {
661
+ const config = baseConfig();
662
+ config.search = { item: { useIdentityServiceForInboundData: true } };
663
+ const dc = new DataConverter(config, new MapFileUtil(new Entities()));
664
+ setupTypeUtilsSpies(dc, ['itemNumber', 'season', 'roles']);
665
+
666
+ identifierSpy = jest.spyOn(TypeConversionUtils, 'getIdentifierPropertiesFromObject')
667
+ .mockImplementation(async () => ['itemNumber', 'season', 'roles']);
668
+ poolKeySpy = jest.spyOn(TypeConversionUtils, 'getUniquenessPoolKeyFromObject')
669
+ .mockImplementation(async () => 'item:material');
670
+
671
+ mockGetFunction.mockClear();
672
+ mockGetFunction.mockImplementation(() => [{ id: 'abc123', typePath: 'item:material' }] as any);
673
+
674
+ const nd = { itemNumber: 'MAT-100', season: 'SS24', roles: ['family'] };
675
+ const result = await dc.setObjectReferenceValue(refProp, nd);
676
+
677
+ expect(mockGetFunction).toHaveBeenCalled();
678
+ const callArg = mockGetFunction.mock.calls[0][0];
679
+ expect(callArg.entityName).toEqual('item');
680
+ expect(callArg.entityName).not.toEqual('identity');
681
+ expect(result).toEqual('abc123');
682
+ expect(poolKeySpy).not.toHaveBeenCalled();
683
+ });
684
+
685
+ it('flag on, cache hit - second call short-circuits', async () => {
686
+ const config = baseConfig();
687
+ config.search = { item: { useIdentityServiceForInboundData: true } };
688
+ const dc = new DataConverter(config, new MapFileUtil(new Entities()));
689
+ setupTypeUtilsSpies(dc);
690
+
691
+ identifierSpy = jest.spyOn(TypeConversionUtils, 'getIdentifierPropertiesFromObject')
692
+ .mockImplementation(async () => ['itemNumber', 'roles']);
693
+ poolKeySpy = jest.spyOn(TypeConversionUtils, 'getUniquenessPoolKeyFromObject')
694
+ .mockImplementation(async () => 'item:material');
695
+
696
+ mockGetFunction.mockClear();
697
+ mockGetFunction.mockImplementation(() => [{ entityReference: 'item:abc123' }] as any);
698
+
699
+ const nd = { itemNumber: 'MAT-100', roles: ['family'] };
700
+ const r1 = await dc.setObjectReferenceValue(refProp, nd);
701
+ const r2 = await dc.setObjectReferenceValue(refProp, nd);
702
+
703
+ expect(r1).toEqual('abc123');
704
+ expect(r2).toEqual('abc123');
705
+ expect(mockGetFunction).toHaveBeenCalledTimes(1);
706
+ });
707
+
708
+ it('flag on, project-item entityType - roles is filtered, identity path used', async () => {
709
+ const projectItemProp = {
710
+ ...refProp,
711
+ referencedTypeRootSlug: 'project-item',
712
+ referencedTypePath: 'project-item'
713
+ };
714
+ const config = baseConfig();
715
+ config.search = { 'project-item': { useIdentityServiceForInboundData: true } };
716
+ const dc = new DataConverter(config, new MapFileUtil(new Entities()));
717
+ setupTypeUtilsSpies(dc, ['itemNumber', 'roles']);
718
+
719
+ identifierSpy = jest.spyOn(TypeConversionUtils, 'getIdentifierPropertiesFromObject')
720
+ .mockImplementation(async () => ['itemNumber', 'roles']);
721
+ poolKeySpy = jest.spyOn(TypeConversionUtils, 'getUniquenessPoolKeyFromObject')
722
+ .mockImplementation(async () => 'project-item');
723
+
724
+ mockGetFunction.mockClear();
725
+ mockGetFunction.mockImplementation(() => [{ entityReference: 'project-item:pi-789' }] as any);
726
+
727
+ const result = await dc.setObjectReferenceValue(projectItemProp, { itemNumber: 'X1', roles: ['family'] });
728
+
729
+ expect(mockGetFunction).toHaveBeenCalledTimes(1);
730
+ const callArg = mockGetFunction.mock.calls[0][0];
731
+ expect(callArg.entityName).toEqual('identity');
732
+ expect(callArg.criteria.propertyName).toEqual('itemNumber');
733
+ expect(result).toEqual('pi-789');
734
+ });
735
+
736
+ it('flag on, non-item entityType - roles is NOT filtered, falls back to query path', async () => {
737
+ const colorProp = {
738
+ ...refProp,
739
+ referencedTypeRootSlug: 'color',
740
+ referencedTypePath: 'color'
741
+ };
742
+ const config = baseConfig();
743
+ config.search = { color: { useIdentityServiceForInboundData: true } };
744
+ const dc = new DataConverter(config, new MapFileUtil(new Entities()));
745
+ setupTypeUtilsSpies(dc, ['colorNumber', 'roles']);
746
+
747
+ identifierSpy = jest.spyOn(TypeConversionUtils, 'getIdentifierPropertiesFromObject')
748
+ .mockImplementation(async () => ['colorNumber', 'roles']);
749
+ poolKeySpy = jest.spyOn(TypeConversionUtils, 'getUniquenessPoolKeyFromObject')
750
+ .mockImplementation(async () => 'color');
751
+
752
+ mockGetFunction.mockClear();
753
+ mockGetFunction.mockImplementation(() => [{ id: 'col-1', typePath: 'color' }] as any);
754
+
755
+ const result = await dc.setObjectReferenceValue(colorProp, { colorNumber: 'C1', roles: ['family'] });
756
+
757
+ expect(mockGetFunction).toHaveBeenCalled();
758
+ const callArg = mockGetFunction.mock.calls[0][0];
759
+ expect(callArg.entityName).toEqual('color');
760
+ expect(callArg.entityName).not.toEqual('identity');
761
+ expect(result).toEqual('col-1');
762
+ expect(poolKeySpy).not.toHaveBeenCalled();
763
+ });
764
+
765
+ it('query path, multiple matches - returns empty with single warn (no double warn)', async () => {
766
+ const dc = new DataConverter(baseConfig(), new MapFileUtil(new Entities()));
767
+ setupTypeUtilsSpies(dc, ['itemNumber']);
768
+
769
+ identifierSpy = jest.spyOn(TypeConversionUtils, 'getIdentifierPropertiesFromObject')
770
+ .mockImplementation(async () => ['itemNumber']);
771
+
772
+ mockGetFunction.mockClear();
773
+ mockGetFunction.mockImplementation(() => [
774
+ { id: 'a1', typePath: 'item:material' },
775
+ { id: 'a2', typePath: 'item:material' }
776
+ ] as any);
777
+ const warnSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
778
+
779
+ try {
780
+ const result = await dc.setObjectReferenceValue(refProp, { itemNumber: 'MAT-100' });
781
+ expect(result).toEqual('');
782
+ expect(warnSpy).toHaveBeenCalledTimes(1);
783
+ expect(warnSpy.mock.calls[0][0]).toMatch(/duplicate records/);
784
+ } finally {
785
+ warnSpy.mockRestore();
786
+ }
787
+ });
788
+
789
+ it('flag on, identity returns null - normalized to empty array, returns empty', async () => {
790
+ const config = baseConfig();
791
+ config.search = { item: { useIdentityServiceForInboundData: true } };
792
+ const dc = new DataConverter(config, new MapFileUtil(new Entities()));
793
+ setupTypeUtilsSpies(dc);
794
+
795
+ identifierSpy = jest.spyOn(TypeConversionUtils, 'getIdentifierPropertiesFromObject')
796
+ .mockImplementation(async () => ['itemNumber', 'roles']);
797
+ poolKeySpy = jest.spyOn(TypeConversionUtils, 'getUniquenessPoolKeyFromObject')
798
+ .mockImplementation(async () => 'item:material');
799
+
800
+ mockGetFunction.mockClear();
801
+ mockGetFunction.mockImplementation(() => null as any);
802
+ const warnSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
803
+
804
+ try {
805
+ const result = await dc.setObjectReferenceValue(refProp, { itemNumber: 'MAT-100', roles: ['family'] });
806
+ expect(result).toEqual('');
807
+ expect(warnSpy).toHaveBeenCalled();
808
+ } finally {
809
+ warnSpy.mockRestore();
810
+ }
811
+ });
812
+
813
+ it('null nd - returns empty string and does not query', async () => {
814
+ const dc = new DataConverter(baseConfig(), new MapFileUtil(new Entities()));
815
+ mockGetFunction.mockClear();
816
+ const result = await dc.setObjectReferenceValue(refProp, null);
817
+ expect(result).toEqual('');
818
+ expect(mockGetFunction).not.toHaveBeenCalled();
819
+ });
820
+
821
+ it('zero identifier keys - warns and returns empty string', async () => {
822
+ const dc = new DataConverter(baseConfig(), new MapFileUtil(new Entities()));
823
+ setupTypeUtilsSpies(dc);
824
+ identifierSpy = jest.spyOn(TypeConversionUtils, 'getIdentifierPropertiesFromObject')
825
+ .mockImplementation(async () => []);
826
+ mockGetFunction.mockClear();
827
+ const warnSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
828
+
829
+ try {
830
+ const result = await dc.setObjectReferenceValue(refProp, { itemNumber: 'MAT-100' });
831
+ expect(result).toEqual('');
832
+ expect(warnSpy).toHaveBeenCalledWith(expect.stringMatching(/doesnt have all "identifier" properties/));
833
+ expect(mockGetFunction).not.toHaveBeenCalled();
834
+ } finally {
835
+ warnSpy.mockRestore();
836
+ }
837
+ });
838
+
839
+ it('missing identifier keys on nd - warns and returns empty string', async () => {
840
+ const dc = new DataConverter(baseConfig(), new MapFileUtil(new Entities()));
841
+ setupTypeUtilsSpies(dc);
842
+ identifierSpy = jest.spyOn(TypeConversionUtils, 'getIdentifierPropertiesFromObject')
843
+ .mockImplementation(async () => ['itemNumber', 'season']);
844
+ mockGetFunction.mockClear();
845
+ const warnSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
846
+
847
+ try {
848
+ const result = await dc.setObjectReferenceValue(refProp, { itemNumber: 'MAT-100' });
849
+ expect(result).toEqual('');
850
+ expect(warnSpy).toHaveBeenCalledWith(expect.stringMatching(/doesnt have all "identifier" properties/));
851
+ expect(mockGetFunction).not.toHaveBeenCalled();
852
+ } finally {
853
+ warnSpy.mockRestore();
854
+ }
855
+ });
856
+
857
+ it('transformMapFile set - applyInboundTransformMap is invoked before context build', async () => {
858
+ const config = baseConfig();
859
+ config['transformMapFile'] = 'file1';
860
+ const dc = new DataConverter(config, new MapFileUtil(new Entities()));
861
+ setupTypeUtilsSpies(dc, ['itemNumber', 'roles']);
862
+
863
+ identifierSpy = jest.spyOn(TypeConversionUtils, 'getIdentifierPropertiesFromObject')
864
+ .mockImplementation(async () => ['itemNumber', 'roles']);
865
+ const mapKeySpy = jest.spyOn(TypeConversionUtils, 'getMapKeyFromObject')
866
+ .mockImplementation(async () => 'LCSMaterial');
867
+ const applyMapSpy = jest.spyOn(MapUtil, 'applyTransformMap')
868
+ .mockImplementation(async (...args) => args[2]);
869
+
870
+ mockGetFunction.mockClear();
871
+ mockGetFunction.mockImplementation(() => [{ id: 'q-1', typePath: 'item:material' }] as any);
872
+
873
+ try {
874
+ const result = await dc.setObjectReferenceValue(refProp, { itemNumber: 'MAT-100', roles: ['family'] });
875
+ expect(mapKeySpy).toHaveBeenCalledTimes(1);
876
+ expect(applyMapSpy).toHaveBeenCalledTimes(1);
877
+ expect(applyMapSpy.mock.calls[0][3]).toEqual('LCSMaterial');
878
+ expect(result).toEqual('q-1');
879
+ } finally {
880
+ mapKeySpy.mockRestore();
881
+ applyMapSpy.mockRestore();
882
+ }
883
+ });
884
+
885
+ it('transformMapFile unset - applyInboundTransformMap does not invoke map utilities', async () => {
886
+ const dc = new DataConverter(baseConfig(), new MapFileUtil(new Entities()));
887
+ setupTypeUtilsSpies(dc, ['itemNumber', 'roles']);
888
+
889
+ identifierSpy = jest.spyOn(TypeConversionUtils, 'getIdentifierPropertiesFromObject')
890
+ .mockImplementation(async () => ['itemNumber', 'roles']);
891
+ const mapKeySpy = jest.spyOn(TypeConversionUtils, 'getMapKeyFromObject');
892
+ const applyMapSpy = jest.spyOn(MapUtil, 'applyTransformMap');
893
+
894
+ mockGetFunction.mockClear();
895
+ mockGetFunction.mockImplementation(() => [{ id: 'q-2', typePath: 'item:material' }] as any);
896
+
897
+ try {
898
+ const result = await dc.setObjectReferenceValue(refProp, { itemNumber: 'MAT-100', roles: ['family'] });
899
+ expect(mapKeySpy).not.toHaveBeenCalled();
900
+ expect(applyMapSpy).not.toHaveBeenCalled();
901
+ expect(result).toEqual('q-2');
902
+ } finally {
903
+ mapKeySpy.mockRestore();
904
+ applyMapSpy.mockRestore();
905
+ }
906
+ });
907
+
908
+ it('query path success - writes id to cache (second call short-circuits)', async () => {
909
+ const dc = new DataConverter(baseConfig(), new MapFileUtil(new Entities()));
910
+ setupTypeUtilsSpies(dc, ['itemNumber', 'roles']);
911
+
912
+ identifierSpy = jest.spyOn(TypeConversionUtils, 'getIdentifierPropertiesFromObject')
913
+ .mockImplementation(async () => ['itemNumber', 'roles']);
914
+
915
+ mockGetFunction.mockClear();
916
+ mockGetFunction.mockImplementation(() => [{ id: 'cached-q', typePath: 'item:material' }] as any);
917
+
918
+ const nd = { itemNumber: 'MAT-100', roles: ['family'] };
919
+ const r1 = await dc.setObjectReferenceValue(refProp, nd);
920
+ const callsAfterFirst = mockGetFunction.mock.calls.length;
921
+ const r2 = await dc.setObjectReferenceValue(refProp, nd);
922
+
923
+ expect(r1).toEqual('cached-q');
924
+ expect(r2).toEqual('cached-q');
925
+ expect(mockGetFunction.mock.calls.length).toEqual(callsAfterFirst);
926
+ });
927
+
928
+ it('query path with subtype filter - applies checkKeysAndValues when entityType !== entityTypePath', async () => {
929
+ const dc = new DataConverter(baseConfig(), new MapFileUtil(new Entities()));
930
+ setupTypeUtilsSpies(dc, ['itemNumber']);
931
+
932
+ identifierSpy = jest.spyOn(TypeConversionUtils, 'getIdentifierPropertiesFromObject')
933
+ .mockImplementation(async () => ['itemNumber', 'season']);
934
+ const checkSpy = jest.spyOn(dc, 'checkKeysAndValues')
935
+ .mockImplementation((_criteria, arr) => arr);
936
+
937
+ mockGetFunction.mockClear();
938
+ mockGetFunction.mockImplementation(() => [{ id: 'sub-1', typePath: 'item:material' }] as any);
939
+
940
+ try {
941
+ const result = await dc.setObjectReferenceValue(refProp, { itemNumber: 'MAT-100', season: 'SS24' });
942
+ expect(checkSpy).toHaveBeenCalledTimes(1);
943
+ expect(checkSpy.mock.calls[0][2]).toEqual('item:material');
944
+ expect(result).toEqual('sub-1');
945
+ } finally {
946
+ checkSpy.mockRestore();
947
+ }
948
+ });
949
+
950
+ it('pickSingleResult single result - identity branch parses id from entityReference', async () => {
951
+ const config = baseConfig();
952
+ config.search = { item: { useIdentityServiceForInboundData: true } };
953
+ const dc = new DataConverter(config, new MapFileUtil(new Entities()));
954
+ setupTypeUtilsSpies(dc);
955
+
956
+ identifierSpy = jest.spyOn(TypeConversionUtils, 'getIdentifierPropertiesFromObject')
957
+ .mockImplementation(async () => ['itemNumber', 'roles']);
958
+ poolKeySpy = jest.spyOn(TypeConversionUtils, 'getUniquenessPoolKeyFromObject')
959
+ .mockImplementation(async () => 'item:material');
960
+
961
+ mockGetFunction.mockClear();
962
+ mockGetFunction.mockImplementation(() => [{ entityReference: 'item:parsed-id-from-ref' }] as any);
963
+
964
+ const result = await dc.setObjectReferenceValue(refProp, { itemNumber: 'MAT-100', roles: ['family'] });
965
+ expect(result).toEqual('parsed-id-from-ref');
966
+ });
967
+ });
968
+
969
+ describe('getObjectReferenceValue - use mapping', () => {
970
+
971
+ const maps = require('./data-converter-spec-mockData');
972
+ const mapping = maps['mapping'];
973
+ const config: FCConfig = {
974
+ apiHost: 'host',
975
+ userName: () => 'user',
976
+ password: () => 'pass',
977
+ urlContext: 'xxx',
978
+ transformMapFile: 'file1',
979
+ vibeEventEndpoint: '/rfa/vibeiq/vibeEvents',
980
+ csrfEndpoint: '/servlet/rest/security/csrf',
981
+ itemPreDevelopmentLifecycleStages: ['concept']
982
+ } as any;
983
+
984
+ const mapFileUtil = new MapFileUtil(new Entities());
985
+ const dc = new DataConverter(config, mapFileUtil);
986
+
987
+ const ref1Prop = {
988
+ id: 'cJoZQvoj7dkfCBJq',
989
+ propertyType: 'object_reference',
990
+ slug: 'ref1',
991
+ label: 'Object Ref#1',
992
+ referencedTypeRootSlug: 'color'
993
+
994
+ };
995
+ const ref2Prop = {
996
+ id: 'cJoZQvoj7dkfCBJq',
997
+ propertyType: 'object_reference',
998
+ slug: 'ref2',
999
+ label: 'Object Ref#2',
1000
+ referencedTypeRootSlug: 'color'
1001
+
1002
+ };
1003
+ const ref3Prop = {
1004
+ id: 'cJoZQvoj7dkfCBJq',
1005
+ propertyType: 'object_reference',
1006
+ slug: 'ref3',
1007
+ label: 'Object Ref#3',
1008
+ referencedTypeRootSlug: 'color'
1009
+
1010
+ };
1011
+ const newData = {
1012
+ ref1Id: 1234,
1013
+ ref1: mockObj1234,
1014
+ ref2Id: 2222,
1015
+ ref2: mockObj2222,
1016
+ ref3Id: 1234,
1017
+ ref3: mockObj1234
1018
+ };
1019
+
1020
+ it('mapping test', async () =>{
1021
+ const oobFunction = dc.getFlexPLMObjectData;
1022
+ try {
1023
+ dc.getFlexPLMObjectData = async (newData, /*dataToSkip: string[], inflateObjRef: boolean*/) => {
1024
+ return newData;
1025
+ };
1026
+ mockGetFunction.mockClear();
1027
+
1028
+ let spyGetObjectClass = jest.spyOn(TypeConversionUtils, 'getObjectClass')
1029
+ .mockImplementation(async () => {return 'LCSColor'});
1030
+
1031
+ let spyGetObjectTypePath = jest.spyOn(TypeConversionUtils, 'getObjectTypePath')
1032
+ .mockImplementation(async () => {return 'Color'});
1033
+
1034
+ let spyGetMapKey = jest.spyOn(TypeConversionUtils, 'getMapKey')
1035
+ .mockImplementation(async () => {return 'LCSColor'});
1036
+
1037
+ let spyApplyTransformMap = jest.spyOn(MapUtil, 'applyTransformMap')
1038
+ .mockImplementation(async (...args) => {return args[2]});
1039
+
1040
+ const r1 = await dc.getObjectReferenceValue(ref1Prop, newData, true);
1041
+ const r2 = await dc.getObjectReferenceValue(ref2Prop, newData, true);
1042
+
1043
+ expect(spyGetObjectClass).toHaveBeenCalledTimes(2);
1044
+ expect(spyGetObjectTypePath).toHaveBeenCalledTimes(2);
1045
+ expect(spyGetMapKey).toHaveBeenCalledTimes(2);
1046
+ expect(spyApplyTransformMap).toHaveBeenCalledTimes(2);
1047
+
1048
+ } finally {
1049
+ dc.getFlexPLMObjectData = oobFunction;
1050
+ }
1051
+ });
1052
+ });
1053
+
1054
+ describe('getEntityValues', () => {
1055
+ const config: FCConfig = {
1056
+ apiHost: 'host',
1057
+ userName: () => 'user',
1058
+ password: () => 'pass',
1059
+ urlContext: 'xxx',
1060
+ vibeEventEndpoint: '/rfa/vibeiq/vibeEvents',
1061
+ csrfEndpoint: '/servlet/rest/security/csrf',
1062
+ itemPreDevelopmentLifecycleStages: ['concept']
1063
+ };
1064
+ const mapFileUtil = new MapFileUtil(new Entities());
1065
+ const dc = new DataConverter(config, mapFileUtil);
1066
+
1067
+ const runWithStubs = async (typePath: string, objectClass: string, data: any) => {
1068
+ const tcoSpy = jest.spyOn(dc['typeUtils'], 'getEntityTypeClientOptionsUsingMapping')
1069
+ .mockImplementation(async () => ({ root: 'item' }));
1070
+ const typeSpy = jest.spyOn(dc['typeUtils'], 'getByRootAndPath')
1071
+ .mockImplementation(async () => ({ typePath, typeProperties: [] }));
1072
+ const filterSpy = jest.spyOn(dc['typeUtils'], 'filterTypeProperties')
1073
+ .mockImplementation(() => []);
1074
+ try {
1075
+ return await dc.getEntityValues(objectClass, data);
1076
+ } finally {
1077
+ tcoSpy.mockRestore();
1078
+ typeSpy.mockRestore();
1079
+ filterSpy.mockRestore();
1080
+ }
1081
+ };
1082
+
1083
+ it('LCSProduct -> roles family', async () => {
1084
+ const result = await runWithStubs('item', 'LCSProduct', { itemNumber: 'X1' });
1085
+ expect(result['roles']).toEqual(['family']);
1086
+ });
1087
+
1088
+ it('LCSSKU -> roles color, option', async () => {
1089
+ const result = await runWithStubs('item', 'LCSSKU', { itemNumber: 'X1' });
1090
+ expect(result['roles']).toEqual(['color', 'option']);
1091
+ });
1092
+
1093
+ it('LCSMaterial -> roles family', async () => {
1094
+ const result = await runWithStubs('item:material', 'LCSMaterial', { itemNumber: 'MAT-100' });
1095
+ expect(result['roles']).toEqual(['family']);
1096
+ });
1097
+ });
1098
+
1099
+ describe('setEnumerationKeys', () =>{
1100
+ const config: FCConfig = {
1101
+ apiHost: 'host',
1102
+ userName: () => 'user',
1103
+ password: () => 'pass',
1104
+ urlContext: 'xxx',
1105
+ vibeEventEndpoint: '/rfa/vibeiq/vibeEvents',
1106
+ csrfEndpoint: '/servlet/rest/security/csrf',
1107
+ itemPreDevelopmentLifecycleStages: ['concept']
1108
+ };
1109
+
1110
+ const mapFileUtil = new MapFileUtil(new Entities());
1111
+ const dc = new DataConverter(config, mapFileUtil);
1112
+ const enumProp = {
1113
+ id: 'cJoZQvoj7dkfCBJq',
1114
+ propertyType: 'multi_select',
1115
+ slug: 'flexMultiSelect',
1116
+ label: 'Flex Multi Select',
1117
+ options: [
1118
+ {
1119
+ value: 'one',
1120
+ display: 'One'
1121
+ },
1122
+ {
1123
+ value: 'two',
1124
+ display: 'Two'
1125
+ },
1126
+ {
1127
+ value: 'three',
1128
+ display: 'Three'
1129
+ }
1130
+ ],
1131
+ };
1132
+
1133
+ const enumPropNoList = {
1134
+ id: 'cJoZQvoj7dkfCBJq',
1135
+ propertyType: 'multi_select',
1136
+ slug: 'flexMultiSelect',
1137
+ label: 'Flex Multi Select',
1138
+ };
1139
+
1140
+ it('match 1 key', () =>{
1141
+ const newData = [{value: 'one', display: 'One'}];
1142
+
1143
+ const returnValue = dc.setEnumerationKeys(enumProp, newData, false);
1144
+ expect(returnValue).toEqual(['one']);
1145
+ });
1146
+
1147
+ it('match 2 key', () =>{
1148
+ const newData = [{value: 'one', display: 'One'}, {value: 'two', display: 'Two'}];
1149
+
1150
+ const returnValue = dc.setEnumerationKeys(enumProp, newData, false);
1151
+ expect(returnValue).toEqual(['one', 'two']);
1152
+ });
1153
+
1154
+ it('match 1 display', () =>{
1155
+ const newData = [{value: 'one', display: 'One'}];
1156
+
1157
+ const returnValue = dc.setEnumerationKeys(enumProp, newData, true);
1158
+ expect(returnValue).toEqual(['one']);
1159
+ });
1160
+
1161
+ it('match 2 display', () =>{
1162
+ const newData = [{value: 'one', display: 'One'}, {value: 'two', display: 'Two'}];
1163
+
1164
+ const returnValue = dc.setEnumerationKeys(enumProp, newData, true);
1165
+ expect(returnValue).toEqual(['one', 'two']);
1166
+ });
1167
+
1168
+ it('property no list', () =>{
1169
+ const newData = [{value: 'one', display: 'One'}, {value: 'two', display: 'Two'}];
1170
+
1171
+ const returnValue = dc.setEnumerationKeys(enumPropNoList, newData, false);
1172
+ expect(returnValue).toEqual([]);
1173
+ });
1174
+
1175
+ });
1176
+
1177
+ describe('checkKeysAndValues', () =>{
1178
+ const config: FCConfig = {
1179
+ apiHost: 'host',
1180
+ userName: () => 'user',
1181
+ password: () => 'pass',
1182
+ urlContext: 'xxx',
1183
+ vibeEventEndpoint: '/rfa/vibeiq/vibeEvents',
1184
+ csrfEndpoint: '/servlet/rest/security/csrf',
1185
+ itemPreDevelopmentLifecycleStages: ['concept']
1186
+ };
1187
+
1188
+ const mapFileUtil = new MapFileUtil(new Entities());
1189
+ const dc = new DataConverter(config, mapFileUtil);
1190
+ const groupData = [
1191
+ {name: 'Group 1', typePath: 'custom-entity:grouping'},
1192
+ {name: 'Group 2', typePath: 'custom-entity:grouping'},
1193
+ {name: 'Group 2', typePath: 'custom-entity:grouping'},
1194
+ {name: 'Group 4', typePath: 'custom-entity:grouping'},
1195
+ {name: 'Group 4', typePath: 'custom-entity:grouping:sub'},
1196
+ {name: 'Group 5', typePath: 'custom-entity:grouping:sub'}
1197
+ ];
1198
+ //item:product:newBalance:accessories, item:product:newBalance:apparel
1199
+
1200
+ it('Group 1', () =>{
1201
+ const criteria = {
1202
+ name: 'Group 1'
1203
+ }
1204
+ const typePath = 'custom-entity:grouping';
1205
+ const results = dc.checkKeysAndValues(criteria, groupData, typePath);
1206
+ expect(results.length).toBe(1);
1207
+ });
1208
+
1209
+ it('Group 5 - sub type of typePath', () =>{
1210
+ const criteria = {
1211
+ name: 'Group 5'
1212
+ }
1213
+ const typePath = 'custom-entity:grouping';
1214
+ const results = dc.checkKeysAndValues(criteria, groupData, typePath);
1215
+ expect(results.length).toBe(1);
1216
+ });
1217
+ it('Group 2 - returns the 2 matching', () =>{
1218
+ const criteria = {
1219
+ name: 'Group 2'
1220
+ }
1221
+ const typePath = 'custom-entity:grouping';
1222
+ const results = dc.checkKeysAndValues(criteria, groupData, typePath);
1223
+ expect(results.length).toBe(2);
1224
+ });
1225
+
1226
+ it('2 Same Name - but 1 is a sub type; returns 2', () =>{
1227
+ const criteria = {
1228
+ name: 'Group 4'
1229
+ }
1230
+ const typePath = 'custom-entity:grouping';
1231
+ const results = dc.checkKeysAndValues(criteria, groupData, typePath);
1232
+ expect(results.length).toBe(2);
1233
+ });
1234
+
1235
+ it('2 Same Name - but 1 wrong type', () =>{
1236
+ const criteria = {
1237
+ name: 'Group 1'
1238
+ }
1239
+ const testData =[...groupData];
1240
+ testData.push({name: 'Group 1', typePath: 'custom-entity:label'});
1241
+ const typePath = 'custom-entity:grouping';
1242
+ const results = dc.checkKeysAndValues(criteria, testData, typePath);
1243
+ expect(results.length).toBe(1);
1244
+ });
1245
+
1246
+ it('first & last entity have the wrong typePath', () =>{
1247
+ const criteria ={
1248
+ objectId: "2562",
1249
+ };
1250
+ const typePath = 'custom-entity:group2';
1251
+
1252
+ const testData = [
1253
+ {"typePath":"custom-entity:group1","name":"BLACK (BK)","id":"o1v2rh8olgQ78GcL","objectId":"2562","entityType":"custom-entity"},
1254
+ {"typePath":"custom-entity:group2","name":"BLACK (BK)","id":"t5n22S2gqswe8GcL","objectId":"2562","entityType":"custom-entity"},
1255
+ {"typePath":"custom-entity:group1","name":"BLACK (BK)","id":"t5rh8o2gqswk3drt","objectId":"2562","entityType":"custom-entity"}
1256
+ ];
1257
+ const results = dc.checkKeysAndValues(criteria, testData, typePath);
1258
+ expect(results.length).toBe(1);
1259
+
1260
+ });
1261
+ });
1262
+
1263
+ describe('filterOutArchivedAndTrashedEntities', () =>{
1264
+ const config: FCConfig = {
1265
+ apiHost: 'host',
1266
+ userName: () => 'user',
1267
+ password: () => 'pass',
1268
+ urlContext: 'xxx',
1269
+ vibeEventEndpoint: '/rfa/vibeiq/vibeEvents',
1270
+ csrfEndpoint: '/servlet/rest/security/csrf',
1271
+ itemPreDevelopmentLifecycleStages: ['concept']
1272
+ };
1273
+
1274
+ const mapFileUtil = new MapFileUtil(new Entities());
1275
+ const dc = new DataConverter(config, mapFileUtil);
1276
+
1277
+ it('filter out isArchived and isTrashed entities', () =>{
1278
+ const entities = [
1279
+ {id: '1', name: 'Entity 1', isArchived: false, isTrashed: false},
1280
+ {id: '2', name: 'Entity 2', isArchived: true, isTrashed: false},
1281
+ {id: '3', name: 'Entity 3', isArchived: false, isTrashed: true},
1282
+ {id: '4', name: 'Entity 4', isArchived: false, isTrashed: false}
1283
+ ];
1284
+
1285
+ const filteredEntities = dc.filterOutArchivedAndTrashedEntities(entities);
1286
+ expect(filteredEntities.length).toBe(2);
1287
+ expect(filteredEntities).toEqual([
1288
+ {id: '1', name: 'Entity 1', isArchived: false, isTrashed: false},
1289
+ {id: '4', name: 'Entity 4', isArchived: false, isTrashed: false}
1290
+ ]);
1291
+ });
1292
+ it('no entities to filter', () =>{
1293
+ const entities = [];
1294
+ const filteredEntities = dc.filterOutArchivedAndTrashedEntities(entities);
1295
+ expect(filteredEntities.length).toBe(0);
1296
+ });
1297
+ it('all entities are archived or trashed', () =>{
1298
+ const entities = [
1299
+ {id: '1', name: 'Entity 1', isArchived: true, isTrashed: false},
1300
+ {id: '2', name: 'Entity 2', isArchived: false, isTrashed: true}
1301
+ ];
1302
+
1303
+ const filteredEntities = dc.filterOutArchivedAndTrashedEntities(entities);
1304
+ expect(filteredEntities.length).toBe(0);
1305
+ });
1306
+ });
1307
+
1308
+ describe('setUserListValue', () =>{
1309
+ const config: FCConfig = {
1310
+ apiHost: 'host',
1311
+ userName: () => 'user',
1312
+ password: () => 'pass',
1313
+ urlContext: 'xxx',
1314
+ vibeEventEndpoint: '/rfa/vibeiq/vibeEvents',
1315
+ csrfEndpoint: '/servlet/rest/security/csrf',
1316
+ itemPreDevelopmentLifecycleStages: ['concept']
1317
+ };
1318
+ const userListProp1 = {};
1319
+ const userEmailMapping = [
1320
+ {
1321
+ id: "gxgr46kvdeEOn4cH",
1322
+ email: "jessica.smith@vibeiq.com"
1323
+ },
1324
+
1325
+ {
1326
+ id: "Rl5D0sjuAwelScEK",
1327
+ email: "adam.smith@vibeiq.com"
1328
+ }
1329
+ ];
1330
+
1331
+ const mapFileUtil = new MapFileUtil(new Entities());
1332
+ const dc = new DataConverter(config, mapFileUtil);
1333
+ let spyGetUserByEmail = jest.spyOn(dc, 'getUserByEmail')
1334
+ .mockImplementation(async (nd) => {
1335
+ let emaildInput = nd?.email.toLowerCase();
1336
+ return userEmailMapping.find((user) => user.email === emaildInput);
1337
+ });
1338
+ let spyProcessGroupMemberCheck = jest.spyOn(dc, 'processGroupMemberCheck')
1339
+ .mockImplementation(async (nd) => { return; });
1340
+
1341
+ afterEach(() => {
1342
+ spyGetUserByEmail.mockClear();
1343
+ spyProcessGroupMemberCheck.mockClear();
1344
+ DataConverter.clearStaticUserCache();
1345
+ });
1346
+ afterAll(() => {
1347
+ spyGetUserByEmail.mockRestore();
1348
+ spyProcessGroupMemberCheck.mockRestore();
1349
+ });
1350
+
1351
+ it('no value', async () =>{
1352
+ const newData = {};
1353
+ const returnValue = await dc.setUserListValue(userListProp1, newData);
1354
+
1355
+ expect(returnValue).toEqual('');
1356
+ });
1357
+
1358
+ it('miss cache', async () =>{
1359
+ const newData = {email: 'adam.smith@vibeiq.com'};
1360
+ const returnValue = await dc.setUserListValue(userListProp1, newData);
1361
+ console.log('returnValue', JSON.stringify(returnValue));
1362
+ expect(returnValue).toEqual('Rl5D0sjuAwelScEK');
1363
+ expect(spyGetUserByEmail).toHaveBeenCalledTimes(1);
1364
+ expect(spyProcessGroupMemberCheck).toHaveBeenCalledTimes(1);
1365
+ });
1366
+
1367
+ it('miss cache - two different emails', async () =>{
1368
+ let newData = {email: 'adam.smith@vibeiq.com'};
1369
+ let returnValue = await dc.setUserListValue(userListProp1, newData);
1370
+ expect(returnValue).toEqual('Rl5D0sjuAwelScEK');
1371
+ expect(spyGetUserByEmail).toHaveBeenCalledTimes(1);
1372
+ expect(spyProcessGroupMemberCheck).toHaveBeenCalledTimes(1);
1373
+
1374
+ newData = {email: 'jessica.smith@vibeiq.com'};
1375
+ returnValue = await dc.setUserListValue(userListProp1, newData);
1376
+ expect(spyGetUserByEmail).toHaveBeenCalledTimes(2);
1377
+ expect(spyProcessGroupMemberCheck).toHaveBeenCalledTimes(2);
1378
+ });
1379
+
1380
+ it('hit cache same email', async () =>{
1381
+ const newData = {email: 'adam.smith@vibeiq.com'};
1382
+ let returnValue = await dc.setUserListValue(userListProp1, newData);
1383
+ expect(returnValue).toEqual('Rl5D0sjuAwelScEK');
1384
+ expect(spyGetUserByEmail).toHaveBeenCalledTimes(1);
1385
+ expect(spyProcessGroupMemberCheck).toHaveBeenCalledTimes(1);
1386
+
1387
+ returnValue = await dc.setUserListValue(userListProp1, newData);
1388
+ expect(returnValue).toEqual('Rl5D0sjuAwelScEK');
1389
+ expect(spyGetUserByEmail).toHaveBeenCalledTimes(1);
1390
+ expect(spyProcessGroupMemberCheck).toHaveBeenCalledTimes(2);
1391
+ });
1392
+
1393
+ it('hit cache same email - new DataConverter entity', async () =>{
1394
+ const newData = {email: 'adam.smith@vibeiq.com'};
1395
+ let returnValue = await dc.setUserListValue(userListProp1, newData);
1396
+ expect(returnValue).toEqual('Rl5D0sjuAwelScEK');
1397
+ expect(spyGetUserByEmail).toHaveBeenCalledTimes(1);
1398
+ expect(spyProcessGroupMemberCheck).toHaveBeenCalledTimes(1);
1399
+
1400
+ const dc2 = new DataConverter(config, mapFileUtil);
1401
+ let spyGetUserByEmail2 = jest.spyOn(dc2, 'getUserByEmail')
1402
+ .mockImplementation(async (nd) => {
1403
+ let emaildInput = nd?.email.toLowerCase();
1404
+ return userEmailMapping.find((user) => user.email === emaildInput);
1405
+ });
1406
+ let spyProcessGroupMemberCheck2 = jest.spyOn(dc2, 'processGroupMemberCheck')
1407
+ .mockImplementation(async (nd) => { return; });
1408
+
1409
+ returnValue = await dc2.setUserListValue(userListProp1, newData);
1410
+ expect(returnValue).toEqual('Rl5D0sjuAwelScEK');
1411
+ expect(spyGetUserByEmail2).toHaveBeenCalledTimes(0);
1412
+ expect(spyProcessGroupMemberCheck2).toHaveBeenCalledTimes(1);
1413
+
1414
+ spyGetUserByEmail2.mockRestore();
1415
+ spyProcessGroupMemberCheck2.mockRestore();
1416
+ });
1417
+
1418
+ });
1419
+
1420
+ describe('getUserListValue', () =>{
1421
+ const config: FCConfig = {
1422
+ apiHost: 'host',
1423
+ userName: () => 'user',
1424
+ password: () => 'pass',
1425
+ urlContext: 'xxx',
1426
+ vibeEventEndpoint: '/rfa/vibeiq/vibeEvents',
1427
+ csrfEndpoint: '/servlet/rest/security/csrf',
1428
+ itemPreDevelopmentLifecycleStages: ['concept']
1429
+ };
1430
+ const userListProp1 = {
1431
+ slug: 'userList1'
1432
+ };
1433
+ const userEmailMapping = [
1434
+ {
1435
+ id: "gxgr46kvdeEOn4cH",
1436
+ email: "jessica.smith@vibeiq.com",
1437
+ first: 'Jessica',
1438
+ last: 'Smith'
1439
+ },
1440
+
1441
+ {
1442
+ id: "Rl5D0sjuAwelScEK",
1443
+ email: "adam.smith@vibeiq.com",
1444
+ first: 'Adam',
1445
+ last: 'Smith'
1446
+ }
1447
+ ];
1448
+
1449
+ const mapFileUtil = new MapFileUtil(new Entities());
1450
+ const dc = new DataConverter(config, mapFileUtil);
1451
+
1452
+ //getUserById
1453
+ let spyGetUserById = jest.spyOn(dc, 'getUserById')
1454
+ .mockImplementation(async (nd) => {
1455
+ return userEmailMapping.find((user) => user.id === nd);
1456
+ });
1457
+
1458
+ afterEach(() => {
1459
+ spyGetUserById.mockClear();
1460
+ DataConverter.clearStaticUserCache();
1461
+ });
1462
+ afterAll(() => {
1463
+ spyGetUserById.mockRestore();
1464
+ });
1465
+
1466
+ it('no value', async () =>{
1467
+ const newData = {};
1468
+ const returnValue = await dc.getUserListValue(userListProp1, newData);
1469
+
1470
+ expect(returnValue).toEqual({});
1471
+ });
1472
+
1473
+ it('miss cache', async () =>{
1474
+ const newData = {
1475
+ userList1Id: 'gxgr46kvdeEOn4cH'
1476
+ };
1477
+
1478
+ const returnValue = await dc.getUserListValue(userListProp1, newData);
1479
+
1480
+ expect(spyGetUserById).toHaveBeenCalledTimes(1);
1481
+ expect(returnValue.email).toEqual('jessica.smith@vibeiq.com');
1482
+ expect(returnValue.firstName).toEqual('Jessica');
1483
+ expect(returnValue.lastName).toEqual('Smith');
1484
+
1485
+ });
1486
+
1487
+ it('miss cache - two different emails', async () =>{
1488
+ let newData = { userList1Id: 'gxgr46kvdeEOn4cH'};
1489
+ let returnValue = await dc.getUserListValue(userListProp1, newData);
1490
+
1491
+ expect(spyGetUserById).toHaveBeenCalledTimes(1);
1492
+ expect(returnValue.email).toEqual('jessica.smith@vibeiq.com');
1493
+ expect(returnValue.firstName).toEqual('Jessica');
1494
+ expect(returnValue.lastName).toEqual('Smith');
1495
+
1496
+ newData = { userList1Id: 'Rl5D0sjuAwelScEK' };
1497
+ returnValue = await dc.getUserListValue(userListProp1, newData);
1498
+
1499
+ expect(spyGetUserById).toHaveBeenCalledTimes(2);
1500
+ expect(returnValue.email).toEqual('adam.smith@vibeiq.com');
1501
+ expect(returnValue.firstName).toEqual('Adam');
1502
+ expect(returnValue.lastName).toEqual('Smith');
1503
+ });
1504
+
1505
+ it('hit cache same email', async () =>{
1506
+ const newData = { userList1Id: 'gxgr46kvdeEOn4cH'};
1507
+ let returnValue = await dc.getUserListValue(userListProp1, newData);
1508
+
1509
+ expect(spyGetUserById).toHaveBeenCalledTimes(1);
1510
+ expect(returnValue.email).toEqual('jessica.smith@vibeiq.com');
1511
+ expect(returnValue.firstName).toEqual('Jessica');
1512
+ expect(returnValue.lastName).toEqual('Smith');
1513
+
1514
+ returnValue = await dc.getUserListValue(userListProp1, newData);
1515
+ expect(spyGetUserById).toHaveBeenCalledTimes(1);
1516
+ expect(returnValue.email).toEqual('jessica.smith@vibeiq.com');
1517
+ expect(returnValue.firstName).toEqual('Jessica');
1518
+ expect(returnValue.lastName).toEqual('Smith');
1519
+ });
1520
+
1521
+ it('hit cache same email - new DataConverter entity', async () =>{
1522
+ const newData = { userList1Id: 'gxgr46kvdeEOn4cH'};
1523
+ let returnValue = await dc.getUserListValue(userListProp1, newData);
1524
+
1525
+ expect(spyGetUserById).toHaveBeenCalledTimes(1);
1526
+ expect(returnValue.email).toEqual('jessica.smith@vibeiq.com');
1527
+ expect(returnValue.firstName).toEqual('Jessica');
1528
+ expect(returnValue.lastName).toEqual('Smith');
1529
+
1530
+ const dc2 = new DataConverter(config, mapFileUtil);
1531
+ let spyGetUserById2 = jest.spyOn(dc2, 'getUserById')
1532
+ .mockImplementation(async (nd) => {
1533
+ return userEmailMapping.find((user) => user.id === nd);
1534
+ });
1535
+
1536
+ returnValue = await dc2.getUserListValue(userListProp1, newData);
1537
+ expect(spyGetUserById2).toHaveBeenCalledTimes(0);
1538
+ expect(returnValue.email).toEqual('jessica.smith@vibeiq.com');
1539
+ expect(returnValue.firstName).toEqual('Jessica');
1540
+ expect(returnValue.lastName).toEqual('Smith');
1541
+ });
1542
+
1543
+ });
1544
+
1545
+
1546
+ describe('getFlexPLMValue size_range', () => {
1547
+ const config: FCConfig = {
1548
+ apiHost: 'host',
1549
+ userName: () => 'user',
1550
+ password: () => 'pass',
1551
+ urlContext: 'xxx',
1552
+ vibeEventEndpoint: '/rfa/vibeiq/vibeEvents',
1553
+ csrfEndpoint: '/servlet/rest/security/csrf',
1554
+ itemPreDevelopmentLifecycleStages: ['concept']
1555
+ };
1556
+
1557
+ const mapFileUtil = new MapFileUtil(new Entities());
1558
+ const dc = new DataConverter(config, mapFileUtil);
1559
+
1560
+ const sizeRangeProp = {
1561
+ propertyType: 'size_range',
1562
+ slug: 'sizeRange',
1563
+ label: 'Size Range',
1564
+ };
1565
+
1566
+ it('returns sizeRange object when value is present', async () => {
1567
+ const newData = { sizeRange: { sizes: ['PRE', 'NB'] } };
1568
+ const returnValue = await dc.getFlexPLMValue(sizeRangeProp, newData, true);
1569
+ expect(returnValue).toEqual({ sizes: ['PRE', 'NB'] });
1570
+ });
1571
+
1572
+ it('returns null when sizeRange is null', async () => {
1573
+ const newData = { sizeRange: null };
1574
+ const returnValue = await dc.getFlexPLMValue(sizeRangeProp, newData, true);
1575
+ expect(returnValue).toBeNull();
1576
+ });
1577
+
1578
+ it('returns undefined when sizeRange is missing', async () => {
1579
+ const newData = {};
1580
+ const returnValue = await dc.getFlexPLMValue(sizeRangeProp, newData, true);
1581
+ expect(returnValue).toBeUndefined();
1582
+ });
1583
+ });
1584
+
1585
+ describe('getEntityValue size_range', () => {
1586
+ const config: FCConfig = {
1587
+ apiHost: 'host',
1588
+ userName: () => 'user',
1589
+ password: () => 'pass',
1590
+ urlContext: 'xxx',
1591
+ vibeEventEndpoint: '/rfa/vibeiq/vibeEvents',
1592
+ csrfEndpoint: '/servlet/rest/security/csrf',
1593
+ itemPreDevelopmentLifecycleStages: ['concept']
1594
+ };
1595
+
1596
+ const mapFileUtil = new MapFileUtil(new Entities());
1597
+ const dc = new DataConverter(config, mapFileUtil);
1598
+
1599
+ const sizeRangeProp = {
1600
+ propertyType: 'size_range',
1601
+ slug: 'sizeRange',
1602
+ label: 'Size Range',
1603
+ };
1604
+
1605
+ it('returns sizeRange object when value is present', async () => {
1606
+ const data = { sizeRange: { sizes: ['PRE', 'NB'] } };
1607
+ const returnValue = await dc.getEntityValue(sizeRangeProp, data);
1608
+ expect(returnValue).toEqual({ sizes: ['PRE', 'NB'] });
1609
+ });
1610
+
1611
+ it('returns null when sizeRange is null', async () => {
1612
+ const data = { sizeRange: null };
1613
+ const returnValue = await dc.getEntityValue(sizeRangeProp, data);
1614
+ expect(returnValue).toBeNull();
1615
+ });
1616
+
1617
+ it('returns undefined when sizeRange is missing', async () => {
1618
+ const data = {};
1619
+ const returnValue = await dc.getEntityValue(sizeRangeProp, data);
1620
+ expect(returnValue).toBeUndefined();
1621
+ });
1622
+ });