@contrail/flexplm 1.1.61 → 1.1.62

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.
@@ -1,981 +1,996 @@
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('getObjectReferenceValue - use mapping', () => {
513
-
514
- const maps = require('./data-converter-spec-mockData');
515
- const mapping = maps['mapping'];
516
- const config: FCConfig = {
517
- apiHost: 'host',
518
- userName: () => 'user',
519
- password: () => 'pass',
520
- urlContext: 'xxx',
521
- transformMapFile: 'file1',
522
- vibeEventEndpoint: '/rfa/vibeiq/vibeEvents',
523
- csrfEndpoint: '/servlet/rest/security/csrf',
524
- itemPreDevelopmentLifecycleStages: ['concept']
525
- } as any;
526
-
527
- const mapFileUtil = new MapFileUtil(new Entities());
528
- const dc = new DataConverter(config, mapFileUtil);
529
-
530
- const ref1Prop = {
531
- id: 'cJoZQvoj7dkfCBJq',
532
- propertyType: 'object_reference',
533
- slug: 'ref1',
534
- label: 'Object Ref#1',
535
- referencedTypeRootSlug: 'color'
536
-
537
- };
538
- const ref2Prop = {
539
- id: 'cJoZQvoj7dkfCBJq',
540
- propertyType: 'object_reference',
541
- slug: 'ref2',
542
- label: 'Object Ref#2',
543
- referencedTypeRootSlug: 'color'
544
-
545
- };
546
- const ref3Prop = {
547
- id: 'cJoZQvoj7dkfCBJq',
548
- propertyType: 'object_reference',
549
- slug: 'ref3',
550
- label: 'Object Ref#3',
551
- referencedTypeRootSlug: 'color'
552
-
553
- };
554
- const newData = {
555
- ref1Id: 1234,
556
- ref1: mockObj1234,
557
- ref2Id: 2222,
558
- ref2: mockObj2222,
559
- ref3Id: 1234,
560
- ref3: mockObj1234
561
- };
562
-
563
- it('mapping test', async () =>{
564
- const oobFunction = dc.getFlexPLMObjectData;
565
- try {
566
- dc.getFlexPLMObjectData = async (newData, /*dataToSkip: string[], inflateObjRef: boolean*/) => {
567
- return newData;
568
- };
569
- mockGetFunction.mockClear();
570
-
571
- let spyGetObjectClass = jest.spyOn(TypeConversionUtils, 'getObjectClass')
572
- .mockImplementation(async () => {return 'LCSColor'});
573
-
574
- let spyGetObjectTypePath = jest.spyOn(TypeConversionUtils, 'getObjectTypePath')
575
- .mockImplementation(async () => {return 'Color'});
576
-
577
- let spyGetMapKey = jest.spyOn(TypeConversionUtils, 'getMapKey')
578
- .mockImplementation(async () => {return 'LCSColor'});
579
-
580
- let spyApplyTransformMap = jest.spyOn(MapUtil, 'applyTransformMap')
581
- .mockImplementation(async (...args) => {return args[2]});
582
-
583
- const r1 = await dc.getObjectReferenceValue(ref1Prop, newData, true);
584
- const r2 = await dc.getObjectReferenceValue(ref2Prop, newData, true);
585
-
586
- expect(spyGetObjectClass).toHaveBeenCalledTimes(2);
587
- expect(spyGetObjectTypePath).toHaveBeenCalledTimes(2);
588
- expect(spyGetMapKey).toHaveBeenCalledTimes(2);
589
- expect(spyApplyTransformMap).toHaveBeenCalledTimes(2);
590
-
591
- } finally {
592
- dc.getFlexPLMObjectData = oobFunction;
593
- }
594
- });
595
- });
596
-
597
- describe('setEnumerationKeys', () =>{
598
- const config: FCConfig = {
599
- apiHost: 'host',
600
- userName: () => 'user',
601
- password: () => 'pass',
602
- urlContext: 'xxx',
603
- vibeEventEndpoint: '/rfa/vibeiq/vibeEvents',
604
- csrfEndpoint: '/servlet/rest/security/csrf',
605
- itemPreDevelopmentLifecycleStages: ['concept']
606
- };
607
-
608
- const mapFileUtil = new MapFileUtil(new Entities());
609
- const dc = new DataConverter(config, mapFileUtil);
610
- const enumProp = {
611
- id: 'cJoZQvoj7dkfCBJq',
612
- propertyType: 'multi_select',
613
- slug: 'flexMultiSelect',
614
- label: 'Flex Multi Select',
615
- options: [
616
- {
617
- value: 'one',
618
- display: 'One'
619
- },
620
- {
621
- value: 'two',
622
- display: 'Two'
623
- },
624
- {
625
- value: 'three',
626
- display: 'Three'
627
- }
628
- ],
629
- };
630
-
631
- const enumPropNoList = {
632
- id: 'cJoZQvoj7dkfCBJq',
633
- propertyType: 'multi_select',
634
- slug: 'flexMultiSelect',
635
- label: 'Flex Multi Select',
636
- };
637
-
638
- it('match 1 key', () =>{
639
- const newData = [{value: 'one', display: 'One'}];
640
-
641
- const returnValue = dc.setEnumerationKeys(enumProp, newData, false);
642
- expect(returnValue).toEqual(['one']);
643
- });
644
-
645
- it('match 2 key', () =>{
646
- const newData = [{value: 'one', display: 'One'}, {value: 'two', display: 'Two'}];
647
-
648
- const returnValue = dc.setEnumerationKeys(enumProp, newData, false);
649
- expect(returnValue).toEqual(['one', 'two']);
650
- });
651
-
652
- it('match 1 display', () =>{
653
- const newData = [{value: 'one', display: 'One'}];
654
-
655
- const returnValue = dc.setEnumerationKeys(enumProp, newData, true);
656
- expect(returnValue).toEqual(['one']);
657
- });
658
-
659
- it('match 2 display', () =>{
660
- const newData = [{value: 'one', display: 'One'}, {value: 'two', display: 'Two'}];
661
-
662
- const returnValue = dc.setEnumerationKeys(enumProp, newData, true);
663
- expect(returnValue).toEqual(['one', 'two']);
664
- });
665
-
666
- it('property no list', () =>{
667
- const newData = [{value: 'one', display: 'One'}, {value: 'two', display: 'Two'}];
668
-
669
- const returnValue = dc.setEnumerationKeys(enumPropNoList, newData, false);
670
- expect(returnValue).toEqual([]);
671
- });
672
-
673
- });
674
-
675
- describe('checkKeysAndValues', () =>{
676
- const config: FCConfig = {
677
- apiHost: 'host',
678
- userName: () => 'user',
679
- password: () => 'pass',
680
- urlContext: 'xxx',
681
- vibeEventEndpoint: '/rfa/vibeiq/vibeEvents',
682
- csrfEndpoint: '/servlet/rest/security/csrf',
683
- itemPreDevelopmentLifecycleStages: ['concept']
684
- };
685
-
686
- const mapFileUtil = new MapFileUtil(new Entities());
687
- const dc = new DataConverter(config, mapFileUtil);
688
- const groupData = [
689
- {name: 'Group 1', typePath: 'custom-entity:grouping'},
690
- {name: 'Group 2', typePath: 'custom-entity:grouping'},
691
- {name: 'Group 2', typePath: 'custom-entity:grouping'},
692
- {name: 'Group 4', typePath: 'custom-entity:grouping'},
693
- {name: 'Group 4', typePath: 'custom-entity:grouping:sub'},
694
- {name: 'Group 5', typePath: 'custom-entity:grouping:sub'}
695
- ];
696
- //item:product:newBalance:accessories, item:product:newBalance:apparel
697
-
698
- it('Group 1', () =>{
699
- const criteria = {
700
- name: 'Group 1'
701
- }
702
- const typePath = 'custom-entity:grouping';
703
- const results = dc.checkKeysAndValues(criteria, groupData, typePath);
704
- expect(results.length).toBe(1);
705
- });
706
-
707
- it('Group 5 - sub type of typePath', () =>{
708
- const criteria = {
709
- name: 'Group 5'
710
- }
711
- const typePath = 'custom-entity:grouping';
712
- const results = dc.checkKeysAndValues(criteria, groupData, typePath);
713
- expect(results.length).toBe(1);
714
- });
715
- it('Group 2 - returns the 2 matching', () =>{
716
- const criteria = {
717
- name: 'Group 2'
718
- }
719
- const typePath = 'custom-entity:grouping';
720
- const results = dc.checkKeysAndValues(criteria, groupData, typePath);
721
- expect(results.length).toBe(2);
722
- });
723
-
724
- it('2 Same Name - but 1 is a sub type; returns 2', () =>{
725
- const criteria = {
726
- name: 'Group 4'
727
- }
728
- const typePath = 'custom-entity:grouping';
729
- const results = dc.checkKeysAndValues(criteria, groupData, typePath);
730
- expect(results.length).toBe(2);
731
- });
732
-
733
- it('2 Same Name - but 1 wrong type', () =>{
734
- const criteria = {
735
- name: 'Group 1'
736
- }
737
- const testData =[...groupData];
738
- testData.push({name: 'Group 1', typePath: 'custom-entity:label'});
739
- const typePath = 'custom-entity:grouping';
740
- const results = dc.checkKeysAndValues(criteria, testData, typePath);
741
- expect(results.length).toBe(1);
742
- });
743
-
744
- });
745
-
746
- describe('setUserListValue', () =>{
747
- const config: FCConfig = {
748
- apiHost: 'host',
749
- userName: () => 'user',
750
- password: () => 'pass',
751
- urlContext: 'xxx',
752
- vibeEventEndpoint: '/rfa/vibeiq/vibeEvents',
753
- csrfEndpoint: '/servlet/rest/security/csrf',
754
- itemPreDevelopmentLifecycleStages: ['concept']
755
- };
756
- const userListProp1 = {};
757
- const userEmailMapping = [
758
- {
759
- id: "gxgr46kvdeEOn4cH",
760
- email: "jessica.smith@vibeiq.com"
761
- },
762
-
763
- {
764
- id: "Rl5D0sjuAwelScEK",
765
- email: "adam.smith@vibeiq.com"
766
- }
767
- ];
768
-
769
- const mapFileUtil = new MapFileUtil(new Entities());
770
- const dc = new DataConverter(config, mapFileUtil);
771
- let spyGetUserByEmail = jest.spyOn(dc, 'getUserByEmail')
772
- .mockImplementation(async (nd) => {
773
- let emaildInput = nd?.email.toLowerCase();
774
- return userEmailMapping.find((user) => user.email === emaildInput);
775
- });
776
- let spyProcessGroupMemberCheck = jest.spyOn(dc, 'processGroupMemberCheck')
777
- .mockImplementation(async (nd) => { return; });
778
-
779
- afterEach(() => {
780
- spyGetUserByEmail.mockClear();
781
- spyProcessGroupMemberCheck.mockClear();
782
- DataConverter.clearStaticUserCache();
783
- });
784
- afterAll(() => {
785
- spyGetUserByEmail.mockRestore();
786
- spyProcessGroupMemberCheck.mockRestore();
787
- });
788
-
789
- it('no value', async () =>{
790
- const newData = {};
791
- const returnValue = await dc.setUserListValue(userListProp1, newData);
792
-
793
- expect(returnValue).toEqual('');
794
- });
795
-
796
- it('miss cache', async () =>{
797
- const newData = {email: 'adam.smith@vibeiq.com'};
798
- const returnValue = await dc.setUserListValue(userListProp1, newData);
799
- console.log('returnValue', JSON.stringify(returnValue));
800
- expect(returnValue).toEqual('Rl5D0sjuAwelScEK');
801
- expect(spyGetUserByEmail).toHaveBeenCalledTimes(1);
802
- expect(spyProcessGroupMemberCheck).toHaveBeenCalledTimes(1);
803
- });
804
-
805
- it('miss cache - two different emails', async () =>{
806
- let newData = {email: 'adam.smith@vibeiq.com'};
807
- let returnValue = await dc.setUserListValue(userListProp1, newData);
808
- expect(returnValue).toEqual('Rl5D0sjuAwelScEK');
809
- expect(spyGetUserByEmail).toHaveBeenCalledTimes(1);
810
- expect(spyProcessGroupMemberCheck).toHaveBeenCalledTimes(1);
811
-
812
- newData = {email: 'jessica.smith@vibeiq.com'};
813
- returnValue = await dc.setUserListValue(userListProp1, newData);
814
- expect(spyGetUserByEmail).toHaveBeenCalledTimes(2);
815
- expect(spyProcessGroupMemberCheck).toHaveBeenCalledTimes(2);
816
- });
817
-
818
- it('hit cache same email', async () =>{
819
- const newData = {email: 'adam.smith@vibeiq.com'};
820
- let returnValue = await dc.setUserListValue(userListProp1, newData);
821
- expect(returnValue).toEqual('Rl5D0sjuAwelScEK');
822
- expect(spyGetUserByEmail).toHaveBeenCalledTimes(1);
823
- expect(spyProcessGroupMemberCheck).toHaveBeenCalledTimes(1);
824
-
825
- returnValue = await dc.setUserListValue(userListProp1, newData);
826
- expect(returnValue).toEqual('Rl5D0sjuAwelScEK');
827
- expect(spyGetUserByEmail).toHaveBeenCalledTimes(1);
828
- expect(spyProcessGroupMemberCheck).toHaveBeenCalledTimes(2);
829
- });
830
-
831
- it('hit cache same email - new DataConverter entity', async () =>{
832
- const newData = {email: 'adam.smith@vibeiq.com'};
833
- let returnValue = await dc.setUserListValue(userListProp1, newData);
834
- expect(returnValue).toEqual('Rl5D0sjuAwelScEK');
835
- expect(spyGetUserByEmail).toHaveBeenCalledTimes(1);
836
- expect(spyProcessGroupMemberCheck).toHaveBeenCalledTimes(1);
837
-
838
- const dc2 = new DataConverter(config, mapFileUtil);
839
- let spyGetUserByEmail2 = jest.spyOn(dc2, 'getUserByEmail')
840
- .mockImplementation(async (nd) => {
841
- let emaildInput = nd?.email.toLowerCase();
842
- return userEmailMapping.find((user) => user.email === emaildInput);
843
- });
844
- let spyProcessGroupMemberCheck2 = jest.spyOn(dc2, 'processGroupMemberCheck')
845
- .mockImplementation(async (nd) => { return; });
846
-
847
- returnValue = await dc2.setUserListValue(userListProp1, newData);
848
- expect(returnValue).toEqual('Rl5D0sjuAwelScEK');
849
- expect(spyGetUserByEmail2).toHaveBeenCalledTimes(0);
850
- expect(spyProcessGroupMemberCheck2).toHaveBeenCalledTimes(1);
851
-
852
- spyGetUserByEmail2.mockRestore();
853
- spyProcessGroupMemberCheck2.mockRestore();
854
- });
855
-
856
- });
857
-
858
- describe('getUserListValue', () =>{
859
- const config: FCConfig = {
860
- apiHost: 'host',
861
- userName: () => 'user',
862
- password: () => 'pass',
863
- urlContext: 'xxx',
864
- vibeEventEndpoint: '/rfa/vibeiq/vibeEvents',
865
- csrfEndpoint: '/servlet/rest/security/csrf',
866
- itemPreDevelopmentLifecycleStages: ['concept']
867
- };
868
- const userListProp1 = {
869
- slug: 'userList1'
870
- };
871
- const userEmailMapping = [
872
- {
873
- id: "gxgr46kvdeEOn4cH",
874
- email: "jessica.smith@vibeiq.com",
875
- first: 'Jessica',
876
- last: 'Smith'
877
- },
878
-
879
- {
880
- id: "Rl5D0sjuAwelScEK",
881
- email: "adam.smith@vibeiq.com",
882
- first: 'Adam',
883
- last: 'Smith'
884
- }
885
- ];
886
-
887
- const mapFileUtil = new MapFileUtil(new Entities());
888
- const dc = new DataConverter(config, mapFileUtil);
889
-
890
- //getUserById
891
- let spyGetUserById = jest.spyOn(dc, 'getUserById')
892
- .mockImplementation(async (nd) => {
893
- return userEmailMapping.find((user) => user.id === nd);
894
- });
895
-
896
- afterEach(() => {
897
- spyGetUserById.mockClear();
898
- DataConverter.clearStaticUserCache();
899
- });
900
- afterAll(() => {
901
- spyGetUserById.mockRestore();
902
- });
903
-
904
- it('no value', async () =>{
905
- const newData = {};
906
- const returnValue = await dc.getUserListValue(userListProp1, newData);
907
-
908
- expect(returnValue).toEqual({});
909
- });
910
-
911
- it('miss cache', async () =>{
912
- const newData = {
913
- userList1Id: 'gxgr46kvdeEOn4cH'
914
- };
915
-
916
- const returnValue = await dc.getUserListValue(userListProp1, newData);
917
-
918
- expect(spyGetUserById).toHaveBeenCalledTimes(1);
919
- expect(returnValue.email).toEqual('jessica.smith@vibeiq.com');
920
- expect(returnValue.firstName).toEqual('Jessica');
921
- expect(returnValue.lastName).toEqual('Smith');
922
-
923
- });
924
-
925
- it('miss cache - two different emails', async () =>{
926
- let newData = { userList1Id: 'gxgr46kvdeEOn4cH'};
927
- let returnValue = await dc.getUserListValue(userListProp1, newData);
928
-
929
- expect(spyGetUserById).toHaveBeenCalledTimes(1);
930
- expect(returnValue.email).toEqual('jessica.smith@vibeiq.com');
931
- expect(returnValue.firstName).toEqual('Jessica');
932
- expect(returnValue.lastName).toEqual('Smith');
933
-
934
- newData = { userList1Id: 'Rl5D0sjuAwelScEK' };
935
- returnValue = await dc.getUserListValue(userListProp1, newData);
936
-
937
- expect(spyGetUserById).toHaveBeenCalledTimes(2);
938
- expect(returnValue.email).toEqual('adam.smith@vibeiq.com');
939
- expect(returnValue.firstName).toEqual('Adam');
940
- expect(returnValue.lastName).toEqual('Smith');
941
- });
942
-
943
- it('hit cache same email', async () =>{
944
- const newData = { userList1Id: 'gxgr46kvdeEOn4cH'};
945
- let returnValue = await dc.getUserListValue(userListProp1, newData);
946
-
947
- expect(spyGetUserById).toHaveBeenCalledTimes(1);
948
- expect(returnValue.email).toEqual('jessica.smith@vibeiq.com');
949
- expect(returnValue.firstName).toEqual('Jessica');
950
- expect(returnValue.lastName).toEqual('Smith');
951
-
952
- returnValue = await dc.getUserListValue(userListProp1, newData);
953
- expect(spyGetUserById).toHaveBeenCalledTimes(1);
954
- expect(returnValue.email).toEqual('jessica.smith@vibeiq.com');
955
- expect(returnValue.firstName).toEqual('Jessica');
956
- expect(returnValue.lastName).toEqual('Smith');
957
- });
958
-
959
- it('hit cache same email - new DataConverter entity', async () =>{
960
- const newData = { userList1Id: 'gxgr46kvdeEOn4cH'};
961
- let returnValue = await dc.getUserListValue(userListProp1, newData);
962
-
963
- expect(spyGetUserById).toHaveBeenCalledTimes(1);
964
- expect(returnValue.email).toEqual('jessica.smith@vibeiq.com');
965
- expect(returnValue.firstName).toEqual('Jessica');
966
- expect(returnValue.lastName).toEqual('Smith');
967
-
968
- const dc2 = new DataConverter(config, mapFileUtil);
969
- let spyGetUserById2 = jest.spyOn(dc2, 'getUserById')
970
- .mockImplementation(async (nd) => {
971
- return userEmailMapping.find((user) => user.id === nd);
972
- });
973
-
974
- returnValue = await dc2.getUserListValue(userListProp1, newData);
975
- expect(spyGetUserById2).toHaveBeenCalledTimes(0);
976
- expect(returnValue.email).toEqual('jessica.smith@vibeiq.com');
977
- expect(returnValue.firstName).toEqual('Jessica');
978
- expect(returnValue.lastName).toEqual('Smith');
979
- });
980
-
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']).toBe('');
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('getObjectReferenceValue - use mapping', () => {
513
+
514
+ const maps = require('./data-converter-spec-mockData');
515
+ const mapping = maps['mapping'];
516
+ const config: FCConfig = {
517
+ apiHost: 'host',
518
+ userName: () => 'user',
519
+ password: () => 'pass',
520
+ urlContext: 'xxx',
521
+ transformMapFile: 'file1',
522
+ vibeEventEndpoint: '/rfa/vibeiq/vibeEvents',
523
+ csrfEndpoint: '/servlet/rest/security/csrf',
524
+ itemPreDevelopmentLifecycleStages: ['concept']
525
+ } as any;
526
+
527
+ const mapFileUtil = new MapFileUtil(new Entities());
528
+ const dc = new DataConverter(config, mapFileUtil);
529
+
530
+ const ref1Prop = {
531
+ id: 'cJoZQvoj7dkfCBJq',
532
+ propertyType: 'object_reference',
533
+ slug: 'ref1',
534
+ label: 'Object Ref#1',
535
+ referencedTypeRootSlug: 'color'
536
+
537
+ };
538
+ const ref2Prop = {
539
+ id: 'cJoZQvoj7dkfCBJq',
540
+ propertyType: 'object_reference',
541
+ slug: 'ref2',
542
+ label: 'Object Ref#2',
543
+ referencedTypeRootSlug: 'color'
544
+
545
+ };
546
+ const ref3Prop = {
547
+ id: 'cJoZQvoj7dkfCBJq',
548
+ propertyType: 'object_reference',
549
+ slug: 'ref3',
550
+ label: 'Object Ref#3',
551
+ referencedTypeRootSlug: 'color'
552
+
553
+ };
554
+ const newData = {
555
+ ref1Id: 1234,
556
+ ref1: mockObj1234,
557
+ ref2Id: 2222,
558
+ ref2: mockObj2222,
559
+ ref3Id: 1234,
560
+ ref3: mockObj1234
561
+ };
562
+
563
+ it('mapping test', async () =>{
564
+ const oobFunction = dc.getFlexPLMObjectData;
565
+ try {
566
+ dc.getFlexPLMObjectData = async (newData, /*dataToSkip: string[], inflateObjRef: boolean*/) => {
567
+ return newData;
568
+ };
569
+ mockGetFunction.mockClear();
570
+
571
+ let spyGetObjectClass = jest.spyOn(TypeConversionUtils, 'getObjectClass')
572
+ .mockImplementation(async () => {return 'LCSColor'});
573
+
574
+ let spyGetObjectTypePath = jest.spyOn(TypeConversionUtils, 'getObjectTypePath')
575
+ .mockImplementation(async () => {return 'Color'});
576
+
577
+ let spyGetMapKey = jest.spyOn(TypeConversionUtils, 'getMapKey')
578
+ .mockImplementation(async () => {return 'LCSColor'});
579
+
580
+ let spyApplyTransformMap = jest.spyOn(MapUtil, 'applyTransformMap')
581
+ .mockImplementation(async (...args) => {return args[2]});
582
+
583
+ const r1 = await dc.getObjectReferenceValue(ref1Prop, newData, true);
584
+ const r2 = await dc.getObjectReferenceValue(ref2Prop, newData, true);
585
+
586
+ expect(spyGetObjectClass).toHaveBeenCalledTimes(2);
587
+ expect(spyGetObjectTypePath).toHaveBeenCalledTimes(2);
588
+ expect(spyGetMapKey).toHaveBeenCalledTimes(2);
589
+ expect(spyApplyTransformMap).toHaveBeenCalledTimes(2);
590
+
591
+ } finally {
592
+ dc.getFlexPLMObjectData = oobFunction;
593
+ }
594
+ });
595
+ });
596
+
597
+ describe('setEnumerationKeys', () =>{
598
+ const config: FCConfig = {
599
+ apiHost: 'host',
600
+ userName: () => 'user',
601
+ password: () => 'pass',
602
+ urlContext: 'xxx',
603
+ vibeEventEndpoint: '/rfa/vibeiq/vibeEvents',
604
+ csrfEndpoint: '/servlet/rest/security/csrf',
605
+ itemPreDevelopmentLifecycleStages: ['concept']
606
+ };
607
+
608
+ const mapFileUtil = new MapFileUtil(new Entities());
609
+ const dc = new DataConverter(config, mapFileUtil);
610
+ const enumProp = {
611
+ id: 'cJoZQvoj7dkfCBJq',
612
+ propertyType: 'multi_select',
613
+ slug: 'flexMultiSelect',
614
+ label: 'Flex Multi Select',
615
+ options: [
616
+ {
617
+ value: 'one',
618
+ display: 'One'
619
+ },
620
+ {
621
+ value: 'two',
622
+ display: 'Two'
623
+ },
624
+ {
625
+ value: 'three',
626
+ display: 'Three'
627
+ }
628
+ ],
629
+ };
630
+
631
+ const enumPropNoList = {
632
+ id: 'cJoZQvoj7dkfCBJq',
633
+ propertyType: 'multi_select',
634
+ slug: 'flexMultiSelect',
635
+ label: 'Flex Multi Select',
636
+ };
637
+
638
+ it('match 1 key', () =>{
639
+ const newData = [{value: 'one', display: 'One'}];
640
+
641
+ const returnValue = dc.setEnumerationKeys(enumProp, newData, false);
642
+ expect(returnValue).toEqual(['one']);
643
+ });
644
+
645
+ it('match 2 key', () =>{
646
+ const newData = [{value: 'one', display: 'One'}, {value: 'two', display: 'Two'}];
647
+
648
+ const returnValue = dc.setEnumerationKeys(enumProp, newData, false);
649
+ expect(returnValue).toEqual(['one', 'two']);
650
+ });
651
+
652
+ it('match 1 display', () =>{
653
+ const newData = [{value: 'one', display: 'One'}];
654
+
655
+ const returnValue = dc.setEnumerationKeys(enumProp, newData, true);
656
+ expect(returnValue).toEqual(['one']);
657
+ });
658
+
659
+ it('match 2 display', () =>{
660
+ const newData = [{value: 'one', display: 'One'}, {value: 'two', display: 'Two'}];
661
+
662
+ const returnValue = dc.setEnumerationKeys(enumProp, newData, true);
663
+ expect(returnValue).toEqual(['one', 'two']);
664
+ });
665
+
666
+ it('property no list', () =>{
667
+ const newData = [{value: 'one', display: 'One'}, {value: 'two', display: 'Two'}];
668
+
669
+ const returnValue = dc.setEnumerationKeys(enumPropNoList, newData, false);
670
+ expect(returnValue).toEqual([]);
671
+ });
672
+
673
+ });
674
+
675
+ describe('checkKeysAndValues', () =>{
676
+ const config: FCConfig = {
677
+ apiHost: 'host',
678
+ userName: () => 'user',
679
+ password: () => 'pass',
680
+ urlContext: 'xxx',
681
+ vibeEventEndpoint: '/rfa/vibeiq/vibeEvents',
682
+ csrfEndpoint: '/servlet/rest/security/csrf',
683
+ itemPreDevelopmentLifecycleStages: ['concept']
684
+ };
685
+
686
+ const mapFileUtil = new MapFileUtil(new Entities());
687
+ const dc = new DataConverter(config, mapFileUtil);
688
+ const groupData = [
689
+ {name: 'Group 1', typePath: 'custom-entity:grouping'},
690
+ {name: 'Group 2', typePath: 'custom-entity:grouping'},
691
+ {name: 'Group 2', typePath: 'custom-entity:grouping'},
692
+ {name: 'Group 4', typePath: 'custom-entity:grouping'},
693
+ {name: 'Group 4', typePath: 'custom-entity:grouping:sub'},
694
+ {name: 'Group 5', typePath: 'custom-entity:grouping:sub'}
695
+ ];
696
+ //item:product:newBalance:accessories, item:product:newBalance:apparel
697
+
698
+ it('Group 1', () =>{
699
+ const criteria = {
700
+ name: 'Group 1'
701
+ }
702
+ const typePath = 'custom-entity:grouping';
703
+ const results = dc.checkKeysAndValues(criteria, groupData, typePath);
704
+ expect(results.length).toBe(1);
705
+ });
706
+
707
+ it('Group 5 - sub type of typePath', () =>{
708
+ const criteria = {
709
+ name: 'Group 5'
710
+ }
711
+ const typePath = 'custom-entity:grouping';
712
+ const results = dc.checkKeysAndValues(criteria, groupData, typePath);
713
+ expect(results.length).toBe(1);
714
+ });
715
+ it('Group 2 - returns the 2 matching', () =>{
716
+ const criteria = {
717
+ name: 'Group 2'
718
+ }
719
+ const typePath = 'custom-entity:grouping';
720
+ const results = dc.checkKeysAndValues(criteria, groupData, typePath);
721
+ expect(results.length).toBe(2);
722
+ });
723
+
724
+ it('2 Same Name - but 1 is a sub type; returns 2', () =>{
725
+ const criteria = {
726
+ name: 'Group 4'
727
+ }
728
+ const typePath = 'custom-entity:grouping';
729
+ const results = dc.checkKeysAndValues(criteria, groupData, typePath);
730
+ expect(results.length).toBe(2);
731
+ });
732
+
733
+ it('2 Same Name - but 1 wrong type', () =>{
734
+ const criteria = {
735
+ name: 'Group 1'
736
+ }
737
+ const testData =[...groupData];
738
+ testData.push({name: 'Group 1', typePath: 'custom-entity:label'});
739
+ const typePath = 'custom-entity:grouping';
740
+ const results = dc.checkKeysAndValues(criteria, testData, typePath);
741
+ expect(results.length).toBe(1);
742
+ });
743
+
744
+ it('first & last entity have the wrong typePath', () =>{
745
+ const criteria ={
746
+ objectId: "2562",
747
+ };
748
+ const typePath = 'custom-entity:group2';
749
+
750
+ const testData = [
751
+ {"typePath":"custom-entity:group1","name":"BLACK (BK)","id":"o1v2rh8olgQ78GcL","objectId":"2562","entityType":"custom-entity"},
752
+ {"typePath":"custom-entity:group2","name":"BLACK (BK)","id":"t5n22S2gqswe8GcL","objectId":"2562","entityType":"custom-entity"},
753
+ {"typePath":"custom-entity:group1","name":"BLACK (BK)","id":"t5rh8o2gqswk3drt","objectId":"2562","entityType":"custom-entity"}
754
+ ];
755
+ const results = dc.checkKeysAndValues(criteria, testData, typePath);
756
+ expect(results.length).toBe(1);
757
+
758
+ });
759
+ });
760
+
761
+ describe('setUserListValue', () =>{
762
+ const config: FCConfig = {
763
+ apiHost: 'host',
764
+ userName: () => 'user',
765
+ password: () => 'pass',
766
+ urlContext: 'xxx',
767
+ vibeEventEndpoint: '/rfa/vibeiq/vibeEvents',
768
+ csrfEndpoint: '/servlet/rest/security/csrf',
769
+ itemPreDevelopmentLifecycleStages: ['concept']
770
+ };
771
+ const userListProp1 = {};
772
+ const userEmailMapping = [
773
+ {
774
+ id: "gxgr46kvdeEOn4cH",
775
+ email: "jessica.smith@vibeiq.com"
776
+ },
777
+
778
+ {
779
+ id: "Rl5D0sjuAwelScEK",
780
+ email: "adam.smith@vibeiq.com"
781
+ }
782
+ ];
783
+
784
+ const mapFileUtil = new MapFileUtil(new Entities());
785
+ const dc = new DataConverter(config, mapFileUtil);
786
+ let spyGetUserByEmail = jest.spyOn(dc, 'getUserByEmail')
787
+ .mockImplementation(async (nd) => {
788
+ let emaildInput = nd?.email.toLowerCase();
789
+ return userEmailMapping.find((user) => user.email === emaildInput);
790
+ });
791
+ let spyProcessGroupMemberCheck = jest.spyOn(dc, 'processGroupMemberCheck')
792
+ .mockImplementation(async (nd) => { return; });
793
+
794
+ afterEach(() => {
795
+ spyGetUserByEmail.mockClear();
796
+ spyProcessGroupMemberCheck.mockClear();
797
+ DataConverter.clearStaticUserCache();
798
+ });
799
+ afterAll(() => {
800
+ spyGetUserByEmail.mockRestore();
801
+ spyProcessGroupMemberCheck.mockRestore();
802
+ });
803
+
804
+ it('no value', async () =>{
805
+ const newData = {};
806
+ const returnValue = await dc.setUserListValue(userListProp1, newData);
807
+
808
+ expect(returnValue).toEqual('');
809
+ });
810
+
811
+ it('miss cache', async () =>{
812
+ const newData = {email: 'adam.smith@vibeiq.com'};
813
+ const returnValue = await dc.setUserListValue(userListProp1, newData);
814
+ console.log('returnValue', JSON.stringify(returnValue));
815
+ expect(returnValue).toEqual('Rl5D0sjuAwelScEK');
816
+ expect(spyGetUserByEmail).toHaveBeenCalledTimes(1);
817
+ expect(spyProcessGroupMemberCheck).toHaveBeenCalledTimes(1);
818
+ });
819
+
820
+ it('miss cache - two different emails', async () =>{
821
+ let newData = {email: 'adam.smith@vibeiq.com'};
822
+ let returnValue = await dc.setUserListValue(userListProp1, newData);
823
+ expect(returnValue).toEqual('Rl5D0sjuAwelScEK');
824
+ expect(spyGetUserByEmail).toHaveBeenCalledTimes(1);
825
+ expect(spyProcessGroupMemberCheck).toHaveBeenCalledTimes(1);
826
+
827
+ newData = {email: 'jessica.smith@vibeiq.com'};
828
+ returnValue = await dc.setUserListValue(userListProp1, newData);
829
+ expect(spyGetUserByEmail).toHaveBeenCalledTimes(2);
830
+ expect(spyProcessGroupMemberCheck).toHaveBeenCalledTimes(2);
831
+ });
832
+
833
+ it('hit cache same email', async () =>{
834
+ const newData = {email: 'adam.smith@vibeiq.com'};
835
+ let returnValue = await dc.setUserListValue(userListProp1, newData);
836
+ expect(returnValue).toEqual('Rl5D0sjuAwelScEK');
837
+ expect(spyGetUserByEmail).toHaveBeenCalledTimes(1);
838
+ expect(spyProcessGroupMemberCheck).toHaveBeenCalledTimes(1);
839
+
840
+ returnValue = await dc.setUserListValue(userListProp1, newData);
841
+ expect(returnValue).toEqual('Rl5D0sjuAwelScEK');
842
+ expect(spyGetUserByEmail).toHaveBeenCalledTimes(1);
843
+ expect(spyProcessGroupMemberCheck).toHaveBeenCalledTimes(2);
844
+ });
845
+
846
+ it('hit cache same email - new DataConverter entity', async () =>{
847
+ const newData = {email: 'adam.smith@vibeiq.com'};
848
+ let returnValue = await dc.setUserListValue(userListProp1, newData);
849
+ expect(returnValue).toEqual('Rl5D0sjuAwelScEK');
850
+ expect(spyGetUserByEmail).toHaveBeenCalledTimes(1);
851
+ expect(spyProcessGroupMemberCheck).toHaveBeenCalledTimes(1);
852
+
853
+ const dc2 = new DataConverter(config, mapFileUtil);
854
+ let spyGetUserByEmail2 = jest.spyOn(dc2, 'getUserByEmail')
855
+ .mockImplementation(async (nd) => {
856
+ let emaildInput = nd?.email.toLowerCase();
857
+ return userEmailMapping.find((user) => user.email === emaildInput);
858
+ });
859
+ let spyProcessGroupMemberCheck2 = jest.spyOn(dc2, 'processGroupMemberCheck')
860
+ .mockImplementation(async (nd) => { return; });
861
+
862
+ returnValue = await dc2.setUserListValue(userListProp1, newData);
863
+ expect(returnValue).toEqual('Rl5D0sjuAwelScEK');
864
+ expect(spyGetUserByEmail2).toHaveBeenCalledTimes(0);
865
+ expect(spyProcessGroupMemberCheck2).toHaveBeenCalledTimes(1);
866
+
867
+ spyGetUserByEmail2.mockRestore();
868
+ spyProcessGroupMemberCheck2.mockRestore();
869
+ });
870
+
871
+ });
872
+
873
+ describe('getUserListValue', () =>{
874
+ const config: FCConfig = {
875
+ apiHost: 'host',
876
+ userName: () => 'user',
877
+ password: () => 'pass',
878
+ urlContext: 'xxx',
879
+ vibeEventEndpoint: '/rfa/vibeiq/vibeEvents',
880
+ csrfEndpoint: '/servlet/rest/security/csrf',
881
+ itemPreDevelopmentLifecycleStages: ['concept']
882
+ };
883
+ const userListProp1 = {
884
+ slug: 'userList1'
885
+ };
886
+ const userEmailMapping = [
887
+ {
888
+ id: "gxgr46kvdeEOn4cH",
889
+ email: "jessica.smith@vibeiq.com",
890
+ first: 'Jessica',
891
+ last: 'Smith'
892
+ },
893
+
894
+ {
895
+ id: "Rl5D0sjuAwelScEK",
896
+ email: "adam.smith@vibeiq.com",
897
+ first: 'Adam',
898
+ last: 'Smith'
899
+ }
900
+ ];
901
+
902
+ const mapFileUtil = new MapFileUtil(new Entities());
903
+ const dc = new DataConverter(config, mapFileUtil);
904
+
905
+ //getUserById
906
+ let spyGetUserById = jest.spyOn(dc, 'getUserById')
907
+ .mockImplementation(async (nd) => {
908
+ return userEmailMapping.find((user) => user.id === nd);
909
+ });
910
+
911
+ afterEach(() => {
912
+ spyGetUserById.mockClear();
913
+ DataConverter.clearStaticUserCache();
914
+ });
915
+ afterAll(() => {
916
+ spyGetUserById.mockRestore();
917
+ });
918
+
919
+ it('no value', async () =>{
920
+ const newData = {};
921
+ const returnValue = await dc.getUserListValue(userListProp1, newData);
922
+
923
+ expect(returnValue).toEqual({});
924
+ });
925
+
926
+ it('miss cache', async () =>{
927
+ const newData = {
928
+ userList1Id: 'gxgr46kvdeEOn4cH'
929
+ };
930
+
931
+ const returnValue = await dc.getUserListValue(userListProp1, newData);
932
+
933
+ expect(spyGetUserById).toHaveBeenCalledTimes(1);
934
+ expect(returnValue.email).toEqual('jessica.smith@vibeiq.com');
935
+ expect(returnValue.firstName).toEqual('Jessica');
936
+ expect(returnValue.lastName).toEqual('Smith');
937
+
938
+ });
939
+
940
+ it('miss cache - two different emails', async () =>{
941
+ let newData = { userList1Id: 'gxgr46kvdeEOn4cH'};
942
+ let returnValue = await dc.getUserListValue(userListProp1, newData);
943
+
944
+ expect(spyGetUserById).toHaveBeenCalledTimes(1);
945
+ expect(returnValue.email).toEqual('jessica.smith@vibeiq.com');
946
+ expect(returnValue.firstName).toEqual('Jessica');
947
+ expect(returnValue.lastName).toEqual('Smith');
948
+
949
+ newData = { userList1Id: 'Rl5D0sjuAwelScEK' };
950
+ returnValue = await dc.getUserListValue(userListProp1, newData);
951
+
952
+ expect(spyGetUserById).toHaveBeenCalledTimes(2);
953
+ expect(returnValue.email).toEqual('adam.smith@vibeiq.com');
954
+ expect(returnValue.firstName).toEqual('Adam');
955
+ expect(returnValue.lastName).toEqual('Smith');
956
+ });
957
+
958
+ it('hit cache same email', async () =>{
959
+ const newData = { userList1Id: 'gxgr46kvdeEOn4cH'};
960
+ let returnValue = await dc.getUserListValue(userListProp1, newData);
961
+
962
+ expect(spyGetUserById).toHaveBeenCalledTimes(1);
963
+ expect(returnValue.email).toEqual('jessica.smith@vibeiq.com');
964
+ expect(returnValue.firstName).toEqual('Jessica');
965
+ expect(returnValue.lastName).toEqual('Smith');
966
+
967
+ returnValue = await dc.getUserListValue(userListProp1, newData);
968
+ expect(spyGetUserById).toHaveBeenCalledTimes(1);
969
+ expect(returnValue.email).toEqual('jessica.smith@vibeiq.com');
970
+ expect(returnValue.firstName).toEqual('Jessica');
971
+ expect(returnValue.lastName).toEqual('Smith');
972
+ });
973
+
974
+ it('hit cache same email - new DataConverter entity', async () =>{
975
+ const newData = { userList1Id: 'gxgr46kvdeEOn4cH'};
976
+ let returnValue = await dc.getUserListValue(userListProp1, newData);
977
+
978
+ expect(spyGetUserById).toHaveBeenCalledTimes(1);
979
+ expect(returnValue.email).toEqual('jessica.smith@vibeiq.com');
980
+ expect(returnValue.firstName).toEqual('Jessica');
981
+ expect(returnValue.lastName).toEqual('Smith');
982
+
983
+ const dc2 = new DataConverter(config, mapFileUtil);
984
+ let spyGetUserById2 = jest.spyOn(dc2, 'getUserById')
985
+ .mockImplementation(async (nd) => {
986
+ return userEmailMapping.find((user) => user.id === nd);
987
+ });
988
+
989
+ returnValue = await dc2.getUserListValue(userListProp1, newData);
990
+ expect(spyGetUserById2).toHaveBeenCalledTimes(0);
991
+ expect(returnValue.email).toEqual('jessica.smith@vibeiq.com');
992
+ expect(returnValue.firstName).toEqual('Jessica');
993
+ expect(returnValue.lastName).toEqual('Smith');
994
+ });
995
+
981
996
  });