@contrail/flexplm 1.1.12 → 1.1.14

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 (67) hide show
  1. package/.github/pull_request_template.md +30 -0
  2. package/.github/workflows/flexplm-lib.yml +27 -0
  3. package/lib/flexplm-utils.spec.d.ts +1 -0
  4. package/lib/flexplm-utils.spec.js +26 -0
  5. package/lib/publish/base-process-publish-assortment.js +2 -4
  6. package/lib/publish/base-process-publish-assortment.spec.d.ts +1 -0
  7. package/lib/publish/base-process-publish-assortment.spec.js +1053 -0
  8. package/lib/util/config-defaults.spec.d.ts +1 -0
  9. package/lib/util/config-defaults.spec.js +264 -0
  10. package/lib/util/data-converter.spec.d.ts +1 -0
  11. package/lib/util/data-converter.spec.js +591 -0
  12. package/lib/util/map-utils.d.ts +2 -2
  13. package/lib/util/map-utils.js +5 -28
  14. package/lib/util/map-utils.spec.d.ts +1 -0
  15. package/lib/util/map-utils.spec.js +89 -0
  16. package/lib/util/thumbnail-util.spec.d.ts +1 -0
  17. package/lib/util/thumbnail-util.spec.js +132 -0
  18. package/lib/util/type-conversion-utils-spec-mockData.js +21 -0
  19. package/lib/util/type-conversion-utils.d.ts +7 -0
  20. package/lib/util/type-conversion-utils.js +88 -4
  21. package/lib/util/type-conversion-utils.spec.d.ts +1 -0
  22. package/lib/util/type-conversion-utils.spec.js +547 -0
  23. package/lib/util/type-defaults.d.ts +5 -0
  24. package/lib/util/type-defaults.js +66 -0
  25. package/lib/util/type-defaults.spec.d.ts +1 -0
  26. package/lib/util/type-defaults.spec.js +460 -0
  27. package/lib/util/type-utils.spec.d.ts +1 -0
  28. package/lib/util/type-utils.spec.js +190 -0
  29. package/package.json +2 -2
  30. package/publish.bat +5 -0
  31. package/publish.sh +5 -0
  32. package/src/entity-processor/base-entity-processor.ts +183 -0
  33. package/src/flexplm-request.ts +28 -0
  34. package/src/flexplm-utils.spec.ts +27 -0
  35. package/src/flexplm-utils.ts +29 -0
  36. package/src/index.ts +20 -0
  37. package/src/interfaces/interfaces.ts +120 -0
  38. package/src/interfaces/item-family-changes.ts +67 -0
  39. package/src/interfaces/publish-change-data.ts +43 -0
  40. package/src/publish/base-process-publish-assortment-callback.ts +23 -0
  41. package/src/publish/base-process-publish-assortment.spec.ts +1239 -0
  42. package/src/publish/base-process-publish-assortment.ts +1024 -0
  43. package/src/publish/mockData.ts +4561 -0
  44. package/src/transform/identifier-conversion.ts +226 -0
  45. package/src/util/config-defaults.spec.ts +315 -0
  46. package/src/util/config-defaults.ts +79 -0
  47. package/src/util/data-converter-spec-mockData.ts +231 -0
  48. package/src/util/data-converter.spec.ts +872 -0
  49. package/src/util/data-converter.ts +389 -0
  50. package/src/util/federation.ts +172 -0
  51. package/src/util/flexplm-connect.ts +169 -0
  52. package/src/util/logger-config.ts +20 -0
  53. package/src/util/map-util-spec-mockData.ts +231 -0
  54. package/src/util/map-utils.spec.ts +103 -0
  55. package/src/util/map-utils.ts +40 -0
  56. package/src/util/mockData.ts +98 -0
  57. package/src/util/thumbnail-util.spec.ts +152 -0
  58. package/src/util/thumbnail-util.ts +128 -0
  59. package/src/util/type-conversion-utils-spec-mockData.ts +238 -0
  60. package/src/util/type-conversion-utils.spec.ts +601 -0
  61. package/src/util/type-conversion-utils.ts +345 -0
  62. package/src/util/type-defaults.spec.ts +592 -0
  63. package/src/util/type-defaults.ts +261 -0
  64. package/src/util/type-utils.spec.ts +227 -0
  65. package/src/util/type-utils.ts +124 -0
  66. package/tsconfig.json +27 -0
  67. package/tslint.json +57 -0
@@ -0,0 +1,591 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const mockObj1234 = {
4
+ id: 1234,
5
+ typePath: 'color'
6
+ };
7
+ const mockObj2222 = {
8
+ id: 2222,
9
+ typePath: 'color'
10
+ };
11
+ const mockGetFunction = jest.fn((options) => {
12
+ return (options?.criteria?.id === 1234)
13
+ ? [mockObj1234]
14
+ : [mockObj2222];
15
+ });
16
+ jest.mock('@contrail/sdk', () => {
17
+ const origModule = jest.requireActual('@contrail/sdk');
18
+ return {
19
+ __esModule: true,
20
+ ...origModule,
21
+ Entities: class {
22
+ constructor() {
23
+ this.get = mockGetFunction;
24
+ }
25
+ },
26
+ };
27
+ });
28
+ const sdk_1 = require("@contrail/sdk");
29
+ const transform_data_1 = require("@contrail/transform-data");
30
+ const data_converter_1 = require("./data-converter");
31
+ const type_conversion_utils_1 = require("./type-conversion-utils");
32
+ const map_utils_1 = require("./map-utils");
33
+ describe('getFlexPLMValue multi_select', () => {
34
+ const config = {
35
+ apiHost: 'host',
36
+ userName: () => 'user',
37
+ password: () => 'pass',
38
+ urlContext: 'xxx',
39
+ vibeEventEndpoint: '/rfa/vibeiq/vibeEvents',
40
+ csrfEndpoint: '/servlet/rest/security/csrf',
41
+ itemPreDevelopmentLifecycleStages: ['concept']
42
+ };
43
+ const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
44
+ const dc = new data_converter_1.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
+ it('multi_select_null', async () => {
66
+ const newData = {
67
+ flexMultiSelect: null
68
+ };
69
+ const returnValue = await dc.getFlexPLMValue(enumAtt, newData, true);
70
+ expect(returnValue).toEqual([]);
71
+ });
72
+ it('multi_select_no_values', async () => {
73
+ const newData = {
74
+ flexMultiSelect: []
75
+ };
76
+ const returnValue = await dc.getFlexPLMValue(enumAtt, newData, true);
77
+ expect(returnValue).toEqual(newData.flexMultiSelect);
78
+ });
79
+ it('multi_select_two_values', async () => {
80
+ const newData = {
81
+ flexMultiSelect: ['one', 'three']
82
+ };
83
+ const optionValues = [
84
+ { value: 'one', display: 'One' },
85
+ { value: 'three', display: 'Three' }
86
+ ];
87
+ const returnValue = await dc.getFlexPLMValue(enumAtt, newData, true);
88
+ expect(returnValue).toEqual(optionValues);
89
+ });
90
+ });
91
+ describe('getEnumerationValue', () => {
92
+ const config = {
93
+ apiHost: 'host',
94
+ userName: () => 'user',
95
+ password: () => 'pass',
96
+ urlContext: 'xxx',
97
+ vibeEventEndpoint: '/rfa/vibeiq/vibeEvents',
98
+ csrfEndpoint: '/servlet/rest/security/csrf',
99
+ itemPreDevelopmentLifecycleStages: ['concept']
100
+ };
101
+ const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
102
+ const dc = new data_converter_1.DataConverter(config, mapFileUtil);
103
+ const enumProp = {
104
+ id: 'cJoZQvoj7dkfCBJq',
105
+ propertyType: 'choice',
106
+ slug: 'flexChoice',
107
+ label: 'Flex Choice',
108
+ options: [
109
+ {
110
+ value: 'one',
111
+ display: 'One'
112
+ },
113
+ {
114
+ value: 'two',
115
+ display: 'Two'
116
+ },
117
+ {
118
+ value: 'three',
119
+ display: 'Three'
120
+ }
121
+ ],
122
+ };
123
+ const enumPropNoList = {
124
+ id: 'cJoZQvoj7dkfCBJq',
125
+ propertyType: 'choice',
126
+ slug: 'flexChoice',
127
+ label: 'Flex Choice',
128
+ };
129
+ it('match 1 key', () => {
130
+ const nd = 'one';
131
+ const expectedValue = { value: 'one', display: 'One' };
132
+ const returnValue = dc.getEnumerationValue(enumProp, nd);
133
+ expect(returnValue).toEqual(expectedValue);
134
+ });
135
+ it('wrong key', () => {
136
+ const nd = 'one1';
137
+ const expectedValue = {};
138
+ const returnValue = dc.getEnumerationValue(enumProp, nd);
139
+ expect(returnValue).toEqual(expectedValue);
140
+ });
141
+ it('property no list', () => {
142
+ const nd = 'one1';
143
+ const expectedValue = {};
144
+ const returnValue = dc.getEnumerationValue(enumPropNoList, nd);
145
+ expect(returnValue).toEqual(expectedValue);
146
+ });
147
+ });
148
+ describe('getEnumerationValue multi_select', () => {
149
+ const config = {
150
+ apiHost: 'host',
151
+ userName: () => 'user',
152
+ password: () => 'pass',
153
+ urlContext: 'xxx',
154
+ vibeEventEndpoint: '/rfa/vibeiq/vibeEvents',
155
+ csrfEndpoint: '/servlet/rest/security/csrf',
156
+ itemPreDevelopmentLifecycleStages: ['concept']
157
+ };
158
+ const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
159
+ const dc = new data_converter_1.DataConverter(config, mapFileUtil);
160
+ const enumAtt = {
161
+ id: 'cJoZQvoj7dkfCBJq',
162
+ propertyType: 'multi_select',
163
+ slug: 'flexMultiSelect',
164
+ label: 'Flex Multi Select',
165
+ options: [
166
+ {
167
+ value: 'one',
168
+ display: 'One'
169
+ },
170
+ {
171
+ value: 'two',
172
+ display: 'Two'
173
+ },
174
+ {
175
+ value: 'three',
176
+ display: 'Three'
177
+ }
178
+ ],
179
+ };
180
+ it('multi_select_null', async () => {
181
+ const nd = null;
182
+ const returnValue = await dc.getEnumerationValue(enumAtt, nd);
183
+ expect(returnValue).toEqual([]);
184
+ });
185
+ it('multi_select_no_values', async () => {
186
+ const nd = [];
187
+ const returnValue = await dc.getEnumerationValue(enumAtt, nd);
188
+ expect(returnValue).toEqual(nd);
189
+ });
190
+ it('multi select one string value', async () => {
191
+ const nd = 'one';
192
+ const optionValues = [
193
+ { value: 'one', display: 'One' }
194
+ ];
195
+ const returnValue = await dc.getEnumerationValue(enumAtt, nd);
196
+ expect(returnValue).toEqual(optionValues);
197
+ });
198
+ it('multi_select_two_values', async () => {
199
+ const nd = ['one', 'three'];
200
+ const optionValues = [
201
+ { value: 'one', display: 'One' },
202
+ { value: 'three', display: 'Three' }
203
+ ];
204
+ const returnValue = await dc.getEnumerationValue(enumAtt, nd);
205
+ expect(returnValue).toEqual(optionValues);
206
+ });
207
+ });
208
+ describe('getPersistableChanges', () => {
209
+ const config = {
210
+ apiHost: 'host',
211
+ userName: () => 'user',
212
+ password: () => 'pass',
213
+ urlContext: 'xxx',
214
+ vibeEventEndpoint: '/rfa/vibeiq/vibeEvents',
215
+ csrfEndpoint: '/servlet/rest/security/csrf',
216
+ itemPreDevelopmentLifecycleStages: ['concept']
217
+ };
218
+ const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
219
+ const dc = new data_converter_1.DataConverter(config, mapFileUtil);
220
+ it('no changes', () => {
221
+ const entity = {
222
+ num: 1
223
+ };
224
+ const potentialChanges = {};
225
+ const diffs = dc.getPersistableChanges(entity, potentialChanges);
226
+ expect(Object.getOwnPropertyNames(diffs).length).toEqual(0);
227
+ });
228
+ it('same value', () => {
229
+ const entity = {
230
+ str: 'test',
231
+ num: 1
232
+ };
233
+ const potentialChanges = {
234
+ str: 'test',
235
+ num: 1
236
+ };
237
+ const diffs = dc.getPersistableChanges(entity, potentialChanges);
238
+ expect(Object.getOwnPropertyNames(diffs).length).toEqual(0);
239
+ });
240
+ it('diff num value', () => {
241
+ const entity = {
242
+ str: 'option 1 string-Changed',
243
+ num: 12
244
+ };
245
+ const potentialChanges = {
246
+ str: 'option 1 string-Changed',
247
+ num: 1
248
+ };
249
+ const diffs = dc.getPersistableChanges(entity, potentialChanges);
250
+ expect(Object.getOwnPropertyNames(diffs).length).toEqual(1);
251
+ expect(diffs['num']).toEqual(potentialChanges['num']);
252
+ });
253
+ it('zero num value', () => {
254
+ const entity = {
255
+ str: 'option 1 string-Changed',
256
+ num: 12
257
+ };
258
+ const potentialChanges = {
259
+ str: 'option 1 string-Changed',
260
+ num: 0
261
+ };
262
+ const diffs = dc.getPersistableChanges(entity, potentialChanges);
263
+ expect(Object.getOwnPropertyNames(diffs).length).toEqual(1);
264
+ expect(diffs['num']).toEqual(potentialChanges['num']);
265
+ });
266
+ it('diff str value', () => {
267
+ const entity = {
268
+ str: 'test',
269
+ num: 1
270
+ };
271
+ const potentialChanges = {
272
+ str: 'test-1',
273
+ num: 1
274
+ };
275
+ const diffs = dc.getPersistableChanges(entity, potentialChanges);
276
+ expect(Object.getOwnPropertyNames(diffs).length).toEqual(1);
277
+ expect(diffs['str']).toEqual(potentialChanges['str']);
278
+ });
279
+ it('empty str value', () => {
280
+ const entity = {
281
+ str: 'test',
282
+ num: 1
283
+ };
284
+ const potentialChanges = {
285
+ str: '',
286
+ num: 1
287
+ };
288
+ const diffs = dc.getPersistableChanges(entity, potentialChanges);
289
+ expect(Object.getOwnPropertyNames(diffs).length).toEqual(1);
290
+ expect(diffs['str']).toEqual(potentialChanges['str']);
291
+ });
292
+ });
293
+ describe('getObjectReferenceValue cache', () => {
294
+ const config = {
295
+ apiHost: 'host',
296
+ userName: () => 'user',
297
+ password: () => 'pass',
298
+ urlContext: 'xxx',
299
+ vibeEventEndpoint: '/rfa/vibeiq/vibeEvents',
300
+ csrfEndpoint: '/servlet/rest/security/csrf',
301
+ itemPreDevelopmentLifecycleStages: ['concept']
302
+ };
303
+ const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
304
+ const dc = new data_converter_1.DataConverter(config, mapFileUtil);
305
+ const ref1Prop = {
306
+ id: 'cJoZQvoj7dkfCBJq',
307
+ propertyType: 'object_reference',
308
+ slug: 'ref1',
309
+ label: 'Object Ref#1',
310
+ referencedTypeRootSlug: 'color'
311
+ };
312
+ const ref2Prop = {
313
+ id: 'cJoZQvoj7dkfCBJq',
314
+ propertyType: 'object_reference',
315
+ slug: 'ref2',
316
+ label: 'Object Ref#2',
317
+ referencedTypeRootSlug: 'color'
318
+ };
319
+ const ref3Prop = {
320
+ id: 'cJoZQvoj7dkfCBJq',
321
+ propertyType: 'object_reference',
322
+ slug: 'ref3',
323
+ label: 'Object Ref#3',
324
+ referencedTypeRootSlug: 'color'
325
+ };
326
+ const newData = {
327
+ ref1Id: 1234,
328
+ ref2Id: 2222,
329
+ ref3Id: 1234
330
+ };
331
+ it('cache hit', async () => {
332
+ const oobFunction = dc.getFlexPLMObjectData;
333
+ try {
334
+ dc.getFlexPLMObjectData = async (newData) => {
335
+ return newData;
336
+ };
337
+ mockGetFunction.mockClear();
338
+ const r1 = await dc.getObjectReferenceValue(ref1Prop, newData, true);
339
+ const r2 = await dc.getObjectReferenceValue(ref2Prop, newData, true);
340
+ const r3 = await dc.getObjectReferenceValue(ref3Prop, newData, true);
341
+ expect(mockGetFunction).toHaveBeenCalledTimes(2);
342
+ expect(r1).toEqual(mockObj1234);
343
+ expect(r2).toEqual(mockObj2222);
344
+ expect(r3).toEqual(mockObj1234);
345
+ }
346
+ finally {
347
+ dc.getFlexPLMObjectData = oobFunction;
348
+ }
349
+ });
350
+ });
351
+ describe('getObjectReferenceValue bad value', () => {
352
+ const config = {
353
+ apiHost: 'host',
354
+ userName: () => 'user',
355
+ password: () => 'pass',
356
+ urlContext: 'xxx',
357
+ vibeEventEndpoint: '/rfa/vibeiq/vibeEvents',
358
+ csrfEndpoint: '/servlet/rest/security/csrf',
359
+ itemPreDevelopmentLifecycleStages: ['concept']
360
+ };
361
+ const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
362
+ const dc = new data_converter_1.DataConverter(config, mapFileUtil);
363
+ const ref1Prop = {
364
+ id: 'cJoZQvoj7dkfCBJq',
365
+ propertyType: 'object_reference',
366
+ slug: 'ref1',
367
+ label: 'Object Ref#1',
368
+ referencedTypeRootSlug: 'color'
369
+ };
370
+ const ref2Prop = {
371
+ id: 'cJoZQvoj7dkfCBJq',
372
+ propertyType: 'object_reference',
373
+ slug: 'ref2',
374
+ label: 'Object Ref#2',
375
+ referencedTypeRootSlug: 'color'
376
+ };
377
+ const ref3Prop = {
378
+ id: 'cJoZQvoj7dkfCBJq',
379
+ propertyType: 'object_reference',
380
+ slug: 'ref3',
381
+ label: 'Object Ref#3',
382
+ referencedTypeRootSlug: 'color'
383
+ };
384
+ const newData = {
385
+ ref1Id: 1234,
386
+ ref2Id: 2222,
387
+ ref3Id: 1234,
388
+ ref3: 'old value'
389
+ };
390
+ it('old string value', async () => {
391
+ const oobFunction = dc.getFlexPLMObjectData;
392
+ try {
393
+ dc.getFlexPLMObjectData = async (newData) => {
394
+ return newData;
395
+ };
396
+ mockGetFunction.mockClear();
397
+ const r3 = await dc.getObjectReferenceValue(ref3Prop, newData, true);
398
+ expect(r3).toEqual(mockObj1234);
399
+ }
400
+ finally {
401
+ dc.getFlexPLMObjectData = oobFunction;
402
+ }
403
+ });
404
+ it('only id', async () => {
405
+ const oobFunction = dc.getFlexPLMObjectData;
406
+ try {
407
+ dc.getFlexPLMObjectData = async (newData) => {
408
+ return newData;
409
+ };
410
+ mockGetFunction.mockClear();
411
+ const r2 = await dc.getObjectReferenceValue(ref2Prop, newData, true);
412
+ expect(r2).toEqual(mockObj2222);
413
+ }
414
+ finally {
415
+ dc.getFlexPLMObjectData = oobFunction;
416
+ }
417
+ });
418
+ it('already references object', async () => {
419
+ const testData = {
420
+ ref1Id: 1234,
421
+ ref1: mockObj1234,
422
+ ref2Id: 2222,
423
+ ref3Id: 1234,
424
+ ref3: 'old value'
425
+ };
426
+ const oobFunction = dc.getFlexPLMObjectData;
427
+ try {
428
+ dc.getFlexPLMObjectData = async (newData) => {
429
+ return newData;
430
+ };
431
+ mockGetFunction.mockClear();
432
+ const r1 = await dc.getObjectReferenceValue(ref1Prop, testData, true);
433
+ expect(r1).toEqual(mockObj1234);
434
+ }
435
+ finally {
436
+ dc.getFlexPLMObjectData = oobFunction;
437
+ }
438
+ });
439
+ it('old string value, no refId', async () => {
440
+ const testData = {
441
+ ref1: 'old value'
442
+ };
443
+ const oobFunction = dc.getFlexPLMObjectData;
444
+ try {
445
+ dc.getFlexPLMObjectData = async (newData) => {
446
+ return newData;
447
+ };
448
+ mockGetFunction.mockClear();
449
+ const r1 = await dc.getObjectReferenceValue(ref1Prop, testData, true);
450
+ expect(r1).toEqual({});
451
+ }
452
+ finally {
453
+ dc.getFlexPLMObjectData = oobFunction;
454
+ }
455
+ });
456
+ });
457
+ describe('getObjectReferenceValue - use mapping', () => {
458
+ const maps = require('./data-converter-spec-mockData');
459
+ const mapping = maps['mapping'];
460
+ const config = {
461
+ apiHost: 'host',
462
+ userName: () => 'user',
463
+ password: () => 'pass',
464
+ urlContext: 'xxx',
465
+ transformMapFile: 'file1',
466
+ vibeEventEndpoint: '/rfa/vibeiq/vibeEvents',
467
+ csrfEndpoint: '/servlet/rest/security/csrf',
468
+ itemPreDevelopmentLifecycleStages: ['concept']
469
+ };
470
+ const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
471
+ const dc = new data_converter_1.DataConverter(config, mapFileUtil);
472
+ const ref1Prop = {
473
+ id: 'cJoZQvoj7dkfCBJq',
474
+ propertyType: 'object_reference',
475
+ slug: 'ref1',
476
+ label: 'Object Ref#1',
477
+ referencedTypeRootSlug: 'color'
478
+ };
479
+ const ref2Prop = {
480
+ id: 'cJoZQvoj7dkfCBJq',
481
+ propertyType: 'object_reference',
482
+ slug: 'ref2',
483
+ label: 'Object Ref#2',
484
+ referencedTypeRootSlug: 'color'
485
+ };
486
+ const ref3Prop = {
487
+ id: 'cJoZQvoj7dkfCBJq',
488
+ propertyType: 'object_reference',
489
+ slug: 'ref3',
490
+ label: 'Object Ref#3',
491
+ referencedTypeRootSlug: 'color'
492
+ };
493
+ const newData = {
494
+ ref1Id: 1234,
495
+ ref1: mockObj1234,
496
+ ref2Id: 2222,
497
+ ref2: mockObj2222,
498
+ ref3Id: 1234,
499
+ ref3: mockObj1234
500
+ };
501
+ it('mapping test', async () => {
502
+ const oobFunction = dc.getFlexPLMObjectData;
503
+ try {
504
+ dc.getFlexPLMObjectData = async (newData) => {
505
+ return newData;
506
+ };
507
+ mockGetFunction.mockClear();
508
+ let spyGetObjectClass = jest.spyOn(type_conversion_utils_1.TypeConversionUtils, 'getObjectClass')
509
+ .mockImplementation(async () => { return 'LCSColor'; });
510
+ let spyGetObjectTypePath = jest.spyOn(type_conversion_utils_1.TypeConversionUtils, 'getObjectTypePath')
511
+ .mockImplementation(async () => { return 'Color'; });
512
+ let spyGetMapKey = jest.spyOn(type_conversion_utils_1.TypeConversionUtils, 'getMapKey')
513
+ .mockImplementation(async () => { return 'LCSColor'; });
514
+ let spyApplyTransformMap = jest.spyOn(map_utils_1.MapUtil, 'applyTransformMap')
515
+ .mockImplementation(async (...args) => { return args[2]; });
516
+ const r1 = await dc.getObjectReferenceValue(ref1Prop, newData, true);
517
+ const r2 = await dc.getObjectReferenceValue(ref2Prop, newData, true);
518
+ expect(spyGetObjectClass).toHaveBeenCalledTimes(2);
519
+ expect(spyGetObjectTypePath).toHaveBeenCalledTimes(2);
520
+ expect(spyGetMapKey).toHaveBeenCalledTimes(2);
521
+ expect(spyApplyTransformMap).toHaveBeenCalledTimes(2);
522
+ }
523
+ finally {
524
+ dc.getFlexPLMObjectData = oobFunction;
525
+ }
526
+ });
527
+ });
528
+ describe('setEnumerationKeys', () => {
529
+ const config = {
530
+ apiHost: 'host',
531
+ userName: () => 'user',
532
+ password: () => 'pass',
533
+ urlContext: 'xxx',
534
+ vibeEventEndpoint: '/rfa/vibeiq/vibeEvents',
535
+ csrfEndpoint: '/servlet/rest/security/csrf',
536
+ itemPreDevelopmentLifecycleStages: ['concept']
537
+ };
538
+ const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
539
+ const dc = new data_converter_1.DataConverter(config, mapFileUtil);
540
+ const enumProp = {
541
+ id: 'cJoZQvoj7dkfCBJq',
542
+ propertyType: 'multi_select',
543
+ slug: 'flexMultiSelect',
544
+ label: 'Flex Multi Select',
545
+ options: [
546
+ {
547
+ value: 'one',
548
+ display: 'One'
549
+ },
550
+ {
551
+ value: 'two',
552
+ display: 'Two'
553
+ },
554
+ {
555
+ value: 'three',
556
+ display: 'Three'
557
+ }
558
+ ],
559
+ };
560
+ const enumPropNoList = {
561
+ id: 'cJoZQvoj7dkfCBJq',
562
+ propertyType: 'multi_select',
563
+ slug: 'flexMultiSelect',
564
+ label: 'Flex Multi Select',
565
+ };
566
+ it('match 1 key', () => {
567
+ const newData = [{ value: 'one', display: 'One' }];
568
+ const returnValue = dc.setEnumerationKeys(enumProp, newData, false);
569
+ expect(returnValue).toEqual(['one']);
570
+ });
571
+ it('match 2 key', () => {
572
+ const newData = [{ value: 'one', display: 'One' }, { value: 'two', display: 'Two' }];
573
+ const returnValue = dc.setEnumerationKeys(enumProp, newData, false);
574
+ expect(returnValue).toEqual(['one', 'two']);
575
+ });
576
+ it('match 1 display', () => {
577
+ const newData = [{ value: 'one', display: 'One' }];
578
+ const returnValue = dc.setEnumerationKeys(enumProp, newData, true);
579
+ expect(returnValue).toEqual(['one']);
580
+ });
581
+ it('match 2 display', () => {
582
+ const newData = [{ value: 'one', display: 'One' }, { value: 'two', display: 'Two' }];
583
+ const returnValue = dc.setEnumerationKeys(enumProp, newData, true);
584
+ expect(returnValue).toEqual(['one', 'two']);
585
+ });
586
+ it('property no list', () => {
587
+ const newData = [{ value: 'one', display: 'One' }, { value: 'two', display: 'Two' }];
588
+ const returnValue = dc.setEnumerationKeys(enumPropNoList, newData, false);
589
+ expect(returnValue).toEqual([]);
590
+ });
591
+ });
@@ -1,6 +1,6 @@
1
1
  import { MapFileUtil } from '@contrail/transform-data';
2
2
  export declare class MapUtil {
3
- static applyTransformMap(transformMapFile: any, mapFileUtil: any, data: any, type: string, direction: string): Promise<any>;
3
+ static applyTransformMap(transformMapFile: any, mapFileUtil: any, data: any, mapSectionKey: string, direction: string): Promise<any>;
4
4
  static getMapKey(transformMapFile: any, mapFileUtil: MapFileUtil, data: any, type: string, direction: string): Promise<string>;
5
- static getFullMapSection(transformMapFile: string, mapFileUtil: MapFileUtil, mapKey: string): Promise<any>;
5
+ static getFullMapSection(transformMapFile: string, mapFileUtil: MapFileUtil, mapSectionKey: string): Promise<any>;
6
6
  }
@@ -1,38 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MapUtil = void 0;
4
- const transform_data_1 = require("@contrail/transform-data");
5
4
  class MapUtil {
6
- static async applyTransformMap(transformMapFile, mapFileUtil, data, type, direction) {
7
- if (transformMapFile) {
8
- const mapping = await mapFileUtil.getMappingSection(transformMapFile, type, direction);
9
- if (mapping) {
10
- const tasks = transform_data_1.MapFileUtil.getTransformTasks(mapping);
11
- if (tasks.length > 0) {
12
- const convertedArray = transform_data_1.TransformProcessor.transformData([data], tasks);
13
- data = convertedArray[0];
14
- }
15
- }
16
- }
17
- return data;
5
+ static async applyTransformMap(transformMapFile, mapFileUtil, data, mapSectionKey, direction) {
6
+ return await mapFileUtil.applyTransformMap(transformMapFile, data, mapSectionKey, direction);
18
7
  }
19
8
  static async getMapKey(transformMapFile, mapFileUtil, data, type, direction) {
20
- const mappingData = await mapFileUtil.getMappingSection(transformMapFile, 'typeConversion', direction);
21
- if (mappingData && mappingData[type] && mappingData[type]['getMapKey']) {
22
- const mapKey = await mappingData[type]['getMapKey'](data);
23
- return mapKey;
24
- }
25
- return undefined;
9
+ return await mapFileUtil.getMapKey(transformMapFile, data, type, direction);
26
10
  }
27
- static async getFullMapSection(transformMapFile, mapFileUtil, mapKey) {
28
- if (mapKey) {
29
- const mapFile = await mapFileUtil.getMapFile(transformMapFile);
30
- if (mapFile) {
31
- const mapSection = mapFile[mapKey];
32
- return mapSection;
33
- }
34
- }
35
- return undefined;
11
+ static async getFullMapSection(transformMapFile, mapFileUtil, mapSectionKey) {
12
+ return await mapFileUtil.getFullMapSection(transformMapFile, mapSectionKey);
36
13
  }
37
14
  }
38
15
  exports.MapUtil = MapUtil;
@@ -0,0 +1 @@
1
+ export {};