@contrail/flexplm 1.1.63 → 1.1.64
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.
- package/lib/util/data-converter.d.ts +1 -0
- package/lib/util/data-converter.js +12 -2
- package/lib/util/data-converter.spec.js +40 -0
- package/package.json +1 -1
- package/src/util/data-converter.spec.ts +45 -0
- package/src/util/data-converter.ts +19 -2
- package/src/util/type-conversion-utils.spec.ts +643 -643
|
@@ -1,644 +1,644 @@
|
|
|
1
|
-
import { MapFileUtil } from '@contrail/transform-data';
|
|
2
|
-
import { Entities } from '@contrail/sdk';
|
|
3
|
-
import { TypeConversionUtils } from './type-conversion-utils';
|
|
4
|
-
import { TypeDefaults } from './type-defaults';
|
|
5
|
-
|
|
6
|
-
const maps = require('./type-conversion-utils-spec-mockData');
|
|
7
|
-
const mapping = maps['mapping'];
|
|
8
|
-
|
|
9
|
-
const TRANSFORM_MAP_FILE = 'test-transformMapping';
|
|
10
|
-
describe('conversion-utils', () => {
|
|
11
|
-
describe('getObjectClass', () => {
|
|
12
|
-
const mapFileUtil = new MapFileUtil(new Entities());
|
|
13
|
-
|
|
14
|
-
it('flexPLMObjectClass', async () => {
|
|
15
|
-
const objectClass = 'ObjectClass';
|
|
16
|
-
const entity = {
|
|
17
|
-
flexPLMObjectClass: objectClass
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
const results = await TypeConversionUtils.getObjectClass(TRANSFORM_MAP_FILE, mapFileUtil, entity);
|
|
21
|
-
expect(results).toEqual(objectClass);
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
it('uses mapping-catName', async () =>{
|
|
25
|
-
const expectedClass = 'LCSLast';
|
|
26
|
-
const entity = {
|
|
27
|
-
entityType: 'custom-entity',
|
|
28
|
-
typePath: 'custom-entity:catName'
|
|
29
|
-
};
|
|
30
|
-
const spy = jest.spyOn(mapFileUtil, 'getMapFile')
|
|
31
|
-
.mockImplementation(async () =>{
|
|
32
|
-
return mapping;
|
|
33
|
-
});
|
|
34
|
-
try{
|
|
35
|
-
const results = await TypeConversionUtils.getObjectClass(TRANSFORM_MAP_FILE, mapFileUtil, entity);
|
|
36
|
-
expect(results).toEqual(expectedClass);
|
|
37
|
-
|
|
38
|
-
} finally {
|
|
39
|
-
spy.mockRestore();
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it('uses default-noMap', async () =>{
|
|
44
|
-
const expectedClass = 'LCSColor';
|
|
45
|
-
const entity = {
|
|
46
|
-
entityType: 'color',
|
|
47
|
-
typePath: 'color:noMap'
|
|
48
|
-
};
|
|
49
|
-
const spy = jest.spyOn(mapFileUtil, 'getMapFile')
|
|
50
|
-
.mockImplementation(async () =>{
|
|
51
|
-
return mapping;
|
|
52
|
-
});
|
|
53
|
-
const spyIdentifiers = jest.spyOn(TypeDefaults, 'getDefaultObjectClass')
|
|
54
|
-
.mockImplementation(() => expectedClass);
|
|
55
|
-
try{
|
|
56
|
-
const results = await TypeConversionUtils.getObjectClass(TRANSFORM_MAP_FILE, mapFileUtil, entity);
|
|
57
|
-
expect(results).toEqual(expectedClass);
|
|
58
|
-
expect(spyIdentifiers).toBeCalledTimes(2);
|
|
59
|
-
|
|
60
|
-
} finally {
|
|
61
|
-
spy.mockRestore();
|
|
62
|
-
spyIdentifiers.mockRestore();
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
describe('getObjectTypePath', () =>{
|
|
68
|
-
const mapFileUtil = new MapFileUtil(new Entities());
|
|
69
|
-
|
|
70
|
-
it('flexPLMTypePath', async () => {
|
|
71
|
-
const typePath = 'Product';
|
|
72
|
-
const entity = {
|
|
73
|
-
flexPLMTypePath: typePath
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
const results = await TypeConversionUtils.getObjectTypePath(TRANSFORM_MAP_FILE, mapFileUtil, entity);
|
|
77
|
-
expect(results).toEqual(typePath);
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
it('uses mapping-catName', async () =>{
|
|
81
|
-
const expectedTypePath = 'Last\\catName';
|
|
82
|
-
const entity = {
|
|
83
|
-
entityType: 'custom-entity',
|
|
84
|
-
typePath: 'custom-entity:catName'
|
|
85
|
-
};
|
|
86
|
-
const spy = jest.spyOn(mapFileUtil, 'getMapFile')
|
|
87
|
-
.mockImplementation(async () =>{
|
|
88
|
-
return mapping;
|
|
89
|
-
});
|
|
90
|
-
try{
|
|
91
|
-
const results = await TypeConversionUtils.getObjectTypePath(TRANSFORM_MAP_FILE, mapFileUtil, entity);
|
|
92
|
-
expect(results).toEqual(expectedTypePath);
|
|
93
|
-
|
|
94
|
-
} finally {
|
|
95
|
-
spy.mockRestore();
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
it('uses default-noMap', async () =>{
|
|
100
|
-
const expectedTypePath = 'Color';
|
|
101
|
-
const entity = {
|
|
102
|
-
entityType: 'color',
|
|
103
|
-
typePath: 'color:noMap'
|
|
104
|
-
};
|
|
105
|
-
const spy = jest.spyOn(mapFileUtil, 'getMapFile')
|
|
106
|
-
.mockImplementation(async () =>{
|
|
107
|
-
return mapping;
|
|
108
|
-
});
|
|
109
|
-
const spyIdentifiers = jest.spyOn(TypeDefaults, 'getDefaultObjectTypePath')
|
|
110
|
-
.mockImplementation(() => expectedTypePath);
|
|
111
|
-
try{
|
|
112
|
-
const results = await TypeConversionUtils.getObjectTypePath(TRANSFORM_MAP_FILE, mapFileUtil, entity);
|
|
113
|
-
expect(results).toEqual(expectedTypePath);
|
|
114
|
-
expect(spyIdentifiers).toBeCalledTimes(1);
|
|
115
|
-
|
|
116
|
-
} finally {
|
|
117
|
-
spy.mockRestore();
|
|
118
|
-
spyIdentifiers.mockRestore();
|
|
119
|
-
}
|
|
120
|
-
});
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
describe('getIdentifierProperties', () =>{
|
|
124
|
-
const mapFileUtil = new MapFileUtil(new Entities());
|
|
125
|
-
|
|
126
|
-
it('flexPLMIdentifierProperties', async () => {
|
|
127
|
-
const properties = ['optionName'];
|
|
128
|
-
const entity = {
|
|
129
|
-
flexPLMIdentifierProperties: properties
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
const results = await TypeConversionUtils.getIdentifierProperties(TRANSFORM_MAP_FILE, mapFileUtil, entity);
|
|
133
|
-
expect(results).toHaveLength(1);
|
|
134
|
-
expect(results).toEqual(properties);
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
it('uses mapping-catName', async () =>{
|
|
138
|
-
const properties = ['catName', 'catNumber'];
|
|
139
|
-
const entity = {
|
|
140
|
-
entityType: 'custom-entity',
|
|
141
|
-
typePath: 'custom-entity:catName'
|
|
142
|
-
};
|
|
143
|
-
const spy = jest.spyOn(mapFileUtil, 'getMapFile')
|
|
144
|
-
.mockImplementation(async () =>{
|
|
145
|
-
return mapping;
|
|
146
|
-
});
|
|
147
|
-
try{
|
|
148
|
-
const results = await TypeConversionUtils.getIdentifierProperties(TRANSFORM_MAP_FILE, mapFileUtil, entity);
|
|
149
|
-
expect(results).toHaveLength(2);
|
|
150
|
-
expect(results).toEqual(properties);
|
|
151
|
-
|
|
152
|
-
} finally {
|
|
153
|
-
spy.mockRestore();
|
|
154
|
-
}
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
it('uses default-noMap', async () =>{
|
|
158
|
-
const properties = ['itemNumber'];
|
|
159
|
-
const entity = {
|
|
160
|
-
entityType: 'item',
|
|
161
|
-
typePath: 'item',
|
|
162
|
-
roles: ['family']
|
|
163
|
-
};
|
|
164
|
-
const spy = jest.spyOn(mapFileUtil, 'getMapFile')
|
|
165
|
-
.mockImplementation(async () =>{
|
|
166
|
-
return mapping;
|
|
167
|
-
});
|
|
168
|
-
const spyIdentifiers = jest.spyOn(TypeDefaults, 'getDefaultIdentifierProperties')
|
|
169
|
-
.mockImplementation(() => properties);
|
|
170
|
-
try{
|
|
171
|
-
const results = await TypeConversionUtils.getIdentifierProperties(TRANSFORM_MAP_FILE, mapFileUtil, entity);
|
|
172
|
-
expect(results).toEqual(properties);
|
|
173
|
-
expect(results).toHaveLength(1);
|
|
174
|
-
expect(spyIdentifiers).toBeCalledTimes(1);
|
|
175
|
-
|
|
176
|
-
} finally {
|
|
177
|
-
spy.mockRestore();
|
|
178
|
-
spyIdentifiers.mockRestore();
|
|
179
|
-
}
|
|
180
|
-
});
|
|
181
|
-
});
|
|
182
|
-
|
|
183
|
-
describe('getInformationalProperties', () =>{
|
|
184
|
-
const mapFileUtil = new MapFileUtil(new Entities());
|
|
185
|
-
|
|
186
|
-
it('flexPLMIdentifierProperties', async () => {
|
|
187
|
-
const properties = ['optionName'];
|
|
188
|
-
const entity = {
|
|
189
|
-
flexPLMInformationalProperties: properties
|
|
190
|
-
};
|
|
191
|
-
|
|
192
|
-
const results = await TypeConversionUtils.getInformationalProperties(TRANSFORM_MAP_FILE, mapFileUtil, entity);
|
|
193
|
-
expect(results).toHaveLength(1);
|
|
194
|
-
expect(results).toEqual(properties);
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
it('uses mapping-catName', async () =>{
|
|
198
|
-
const properties = ['longName'];
|
|
199
|
-
const entity = {
|
|
200
|
-
entityType: 'custom-entity',
|
|
201
|
-
typePath: 'custom-entity:catName'
|
|
202
|
-
};
|
|
203
|
-
const spy = jest.spyOn(mapFileUtil, 'getMapFile')
|
|
204
|
-
.mockImplementation(async () =>{
|
|
205
|
-
return mapping;
|
|
206
|
-
});
|
|
207
|
-
try{
|
|
208
|
-
const results = await TypeConversionUtils.getInformationalProperties(TRANSFORM_MAP_FILE, mapFileUtil, entity);
|
|
209
|
-
expect(results).toHaveLength(1);
|
|
210
|
-
expect(results).toEqual(properties);
|
|
211
|
-
|
|
212
|
-
} finally {
|
|
213
|
-
spy.mockRestore();
|
|
214
|
-
}
|
|
215
|
-
});
|
|
216
|
-
|
|
217
|
-
it('uses default-noMap', async () =>{
|
|
218
|
-
const properties = ['optionName', 'description'];
|
|
219
|
-
const entity = {
|
|
220
|
-
entityType: 'item',
|
|
221
|
-
typePath: 'item',
|
|
222
|
-
roles: ['color']
|
|
223
|
-
};
|
|
224
|
-
const spy = jest.spyOn(mapFileUtil, 'getMapFile')
|
|
225
|
-
.mockImplementation(async () =>{
|
|
226
|
-
return mapping;
|
|
227
|
-
});
|
|
228
|
-
const spyIdentifiers = jest.spyOn(TypeDefaults, 'getDefaultInformationalProperties')
|
|
229
|
-
.mockImplementation(() => properties);
|
|
230
|
-
try{
|
|
231
|
-
const results = await TypeConversionUtils.getInformationalProperties(TRANSFORM_MAP_FILE, mapFileUtil, entity);
|
|
232
|
-
expect(results).toEqual(properties);
|
|
233
|
-
expect(results).toHaveLength(2);
|
|
234
|
-
expect(spyIdentifiers).toBeCalledTimes(1);
|
|
235
|
-
|
|
236
|
-
} finally {
|
|
237
|
-
spy.mockRestore();
|
|
238
|
-
spyIdentifiers.mockRestore();
|
|
239
|
-
}
|
|
240
|
-
});
|
|
241
|
-
});
|
|
242
|
-
|
|
243
|
-
describe('getMapKey', () =>{
|
|
244
|
-
const mapFileUtil = new MapFileUtil(new Entities());
|
|
245
|
-
|
|
246
|
-
it('custom-entity:pack', async () =>{
|
|
247
|
-
const spy = jest.spyOn(mapFileUtil, 'getMapFile')
|
|
248
|
-
.mockImplementation(async () =>{
|
|
249
|
-
return mapping;
|
|
250
|
-
});
|
|
251
|
-
const entity = {
|
|
252
|
-
typePath: 'custom-entity:pack',
|
|
253
|
-
entityType: 'custom-entity'
|
|
254
|
-
}
|
|
255
|
-
const expectedMapKey = 'packaging';
|
|
256
|
-
|
|
257
|
-
try{
|
|
258
|
-
const results = await TypeConversionUtils.getMapKey(TRANSFORM_MAP_FILE, mapFileUtil, entity, TypeConversionUtils.VIBE2FLEX_DIRECTION);
|
|
259
|
-
expect(results).toEqual(expectedMapKey);
|
|
260
|
-
|
|
261
|
-
} finally {
|
|
262
|
-
spy.mockRestore();
|
|
263
|
-
}
|
|
264
|
-
});
|
|
265
|
-
|
|
266
|
-
it('custom-entity:prefix', async () =>{
|
|
267
|
-
const spy = jest.spyOn(mapFileUtil, 'getMapFile')
|
|
268
|
-
.mockImplementation(async () =>{
|
|
269
|
-
return mapping;
|
|
270
|
-
});
|
|
271
|
-
const entity = {
|
|
272
|
-
typePath: 'custom-entity:prefix',
|
|
273
|
-
entityType: 'custom-entity'
|
|
274
|
-
}
|
|
275
|
-
const expectedMapKey = 'prefix';
|
|
276
|
-
|
|
277
|
-
try{
|
|
278
|
-
const results = await TypeConversionUtils.getMapKey(TRANSFORM_MAP_FILE, mapFileUtil, entity, TypeConversionUtils.VIBE2FLEX_DIRECTION);
|
|
279
|
-
expect(results).toEqual(expectedMapKey);
|
|
280
|
-
|
|
281
|
-
} finally {
|
|
282
|
-
spy.mockRestore();
|
|
283
|
-
}
|
|
284
|
-
});
|
|
285
|
-
|
|
286
|
-
it('color - no mapping exists', async () =>{
|
|
287
|
-
const spy = jest.spyOn(mapFileUtil, 'getMapFile')
|
|
288
|
-
.mockImplementation(async () =>{
|
|
289
|
-
return mapping;
|
|
290
|
-
});
|
|
291
|
-
const entity = {
|
|
292
|
-
typePath: 'color',
|
|
293
|
-
entityType: 'color'
|
|
294
|
-
}
|
|
295
|
-
const expectedMapKey = 'LCSColor';
|
|
296
|
-
|
|
297
|
-
try{
|
|
298
|
-
const results = await TypeConversionUtils.getMapKey(TRANSFORM_MAP_FILE, mapFileUtil, entity, TypeConversionUtils.VIBE2FLEX_DIRECTION);
|
|
299
|
-
expect(results).toEqual(expectedMapKey);
|
|
300
|
-
|
|
301
|
-
} finally {
|
|
302
|
-
spy.mockRestore();
|
|
303
|
-
}
|
|
304
|
-
});
|
|
305
|
-
});
|
|
306
|
-
|
|
307
|
-
describe('getEntityClassFromObject', () => {
|
|
308
|
-
const mapFileUtil = new MapFileUtil(new Entities());
|
|
309
|
-
|
|
310
|
-
it('vibeIQEntityClass', async () => {
|
|
311
|
-
const objectClass = 'ObjectClass';
|
|
312
|
-
const object = {
|
|
313
|
-
vibeIQEntityClass: objectClass
|
|
314
|
-
};
|
|
315
|
-
|
|
316
|
-
const results = await TypeConversionUtils.getEntityClassFromObject(TRANSFORM_MAP_FILE, mapFileUtil, object);
|
|
317
|
-
expect(results).toEqual(objectClass);
|
|
318
|
-
});
|
|
319
|
-
|
|
320
|
-
it('uses mapping-catName', async () =>{
|
|
321
|
-
const expectedClass = 'custom-entity';
|
|
322
|
-
const object = {
|
|
323
|
-
flexPLMObjectClass: 'LCSLast',
|
|
324
|
-
flexPLMTypePath: 'Last\\catName'
|
|
325
|
-
};
|
|
326
|
-
const spy = jest.spyOn(mapFileUtil, 'getMapFile')
|
|
327
|
-
.mockImplementation(async () =>{
|
|
328
|
-
return mapping;
|
|
329
|
-
});
|
|
330
|
-
try{
|
|
331
|
-
const results = await TypeConversionUtils.getEntityClassFromObject(TRANSFORM_MAP_FILE, mapFileUtil, object);
|
|
332
|
-
expect(results).toEqual(expectedClass);
|
|
333
|
-
|
|
334
|
-
} finally {
|
|
335
|
-
spy.mockRestore();
|
|
336
|
-
}
|
|
337
|
-
});
|
|
338
|
-
|
|
339
|
-
it('uses default-noMap', async () =>{
|
|
340
|
-
const expectedClass = 'color';
|
|
341
|
-
const entity = {
|
|
342
|
-
flexPLMObjectClass: 'LCSColor',
|
|
343
|
-
flexPLMTypePath: 'Color'
|
|
344
|
-
};
|
|
345
|
-
const spy = jest.spyOn(mapFileUtil, 'getMapFile')
|
|
346
|
-
.mockImplementation(async () =>{
|
|
347
|
-
return mapping;
|
|
348
|
-
});
|
|
349
|
-
const spyIdentifiers = jest.spyOn(TypeDefaults, 'getDefaultEntityClass')
|
|
350
|
-
.mockImplementation(() => expectedClass);
|
|
351
|
-
try{
|
|
352
|
-
const results = await TypeConversionUtils.getEntityClassFromObject(TRANSFORM_MAP_FILE, mapFileUtil, entity);
|
|
353
|
-
expect(results).toEqual(expectedClass);
|
|
354
|
-
expect(spyIdentifiers).toBeCalledTimes(1);
|
|
355
|
-
|
|
356
|
-
} finally {
|
|
357
|
-
spy.mockRestore();
|
|
358
|
-
spyIdentifiers.mockRestore();
|
|
359
|
-
}
|
|
360
|
-
});
|
|
361
|
-
});
|
|
362
|
-
|
|
363
|
-
describe('getEntityTypePathFromOjbect', () =>{
|
|
364
|
-
const mapFileUtil = new MapFileUtil(new Entities());
|
|
365
|
-
|
|
366
|
-
it('vibeIQTypePath', async () => {
|
|
367
|
-
const typePath = 'item';
|
|
368
|
-
const entity = {
|
|
369
|
-
vibeIQTypePath: typePath
|
|
370
|
-
};
|
|
371
|
-
|
|
372
|
-
const results = await TypeConversionUtils.getEntityTypePathFromOjbect(TRANSFORM_MAP_FILE, mapFileUtil, entity);
|
|
373
|
-
expect(results).toEqual(typePath);
|
|
374
|
-
});
|
|
375
|
-
|
|
376
|
-
it('uses mapping-catName', async () =>{
|
|
377
|
-
const expectedTypePath = 'custom-entity:catName';
|
|
378
|
-
const entity = {
|
|
379
|
-
flexPLMObjectClass: 'LCSLast',
|
|
380
|
-
flexPLMTypePath: 'Last\\catName'
|
|
381
|
-
};
|
|
382
|
-
const spy = jest.spyOn(mapFileUtil, 'getMapFile')
|
|
383
|
-
.mockImplementation(async () =>{
|
|
384
|
-
return mapping;
|
|
385
|
-
});
|
|
386
|
-
try{
|
|
387
|
-
const results = await TypeConversionUtils.getEntityTypePathFromOjbect(TRANSFORM_MAP_FILE, mapFileUtil, entity);
|
|
388
|
-
expect(results).toEqual(expectedTypePath);
|
|
389
|
-
|
|
390
|
-
} finally {
|
|
391
|
-
spy.mockRestore();
|
|
392
|
-
}
|
|
393
|
-
});
|
|
394
|
-
|
|
395
|
-
it('uses default-noMap', async () =>{
|
|
396
|
-
const expectedTypePath = 'color';
|
|
397
|
-
const entity = {
|
|
398
|
-
flexPLMObjectClass: 'LCSColor',
|
|
399
|
-
flexPLMTypePath: 'Color'
|
|
400
|
-
};
|
|
401
|
-
const spy = jest.spyOn(mapFileUtil, 'getMapFile')
|
|
402
|
-
.mockImplementation(async () =>{
|
|
403
|
-
return mapping;
|
|
404
|
-
});
|
|
405
|
-
const spyIdentifiers = jest.spyOn(TypeDefaults, 'getDefaultEntityTypePath')
|
|
406
|
-
.mockImplementation(() => expectedTypePath);
|
|
407
|
-
try{
|
|
408
|
-
const results = await TypeConversionUtils.getEntityTypePathFromOjbect(TRANSFORM_MAP_FILE, mapFileUtil, entity);
|
|
409
|
-
expect(results).toEqual(expectedTypePath);
|
|
410
|
-
expect(spyIdentifiers).toBeCalledTimes(1);
|
|
411
|
-
|
|
412
|
-
} finally {
|
|
413
|
-
spy.mockRestore();
|
|
414
|
-
spyIdentifiers.mockRestore();
|
|
415
|
-
}
|
|
416
|
-
});
|
|
417
|
-
});
|
|
418
|
-
|
|
419
|
-
describe('getIdentifierPropertiesFromObject', () =>{
|
|
420
|
-
const mapFileUtil = new MapFileUtil(new Entities());
|
|
421
|
-
|
|
422
|
-
it('flexPLMIdentifierProperties', async () => {
|
|
423
|
-
const properties = ['optionName'];
|
|
424
|
-
const object = {
|
|
425
|
-
vibeIQIdentifierProperties: properties
|
|
426
|
-
};
|
|
427
|
-
|
|
428
|
-
const results = await TypeConversionUtils.getIdentifierPropertiesFromObject(TRANSFORM_MAP_FILE, mapFileUtil, object);
|
|
429
|
-
expect(results).toHaveLength(1);
|
|
430
|
-
expect(results).toEqual(properties);
|
|
431
|
-
});
|
|
432
|
-
|
|
433
|
-
it('uses mapping-catName', async () =>{
|
|
434
|
-
const properties = ['catName', 'catNumber'];
|
|
435
|
-
const object = {
|
|
436
|
-
flexPLMObjectClass: 'LCSLast',
|
|
437
|
-
flexPLMTypePath: 'Last\\catName'
|
|
438
|
-
};
|
|
439
|
-
const spy = jest.spyOn(mapFileUtil, 'getMapFile')
|
|
440
|
-
.mockImplementation(async () =>{
|
|
441
|
-
return mapping;
|
|
442
|
-
});
|
|
443
|
-
try{
|
|
444
|
-
const results = await TypeConversionUtils.getIdentifierPropertiesFromObject(TRANSFORM_MAP_FILE, mapFileUtil, object);
|
|
445
|
-
expect(results).toHaveLength(2);
|
|
446
|
-
expect(results).toEqual(properties);
|
|
447
|
-
|
|
448
|
-
} finally {
|
|
449
|
-
spy.mockRestore();
|
|
450
|
-
}
|
|
451
|
-
});
|
|
452
|
-
|
|
453
|
-
it('uses default-noMap', async () =>{
|
|
454
|
-
const properties = ['itemNumber'];
|
|
455
|
-
const object = {
|
|
456
|
-
flexPLMObjectClass: 'LCSProduct',
|
|
457
|
-
flexPLMTypePath: 'Product'
|
|
458
|
-
};
|
|
459
|
-
const spy = jest.spyOn(mapFileUtil, 'getMapFile')
|
|
460
|
-
.mockImplementation(async () =>{
|
|
461
|
-
return mapping;
|
|
462
|
-
});
|
|
463
|
-
const spyIdentifiers = jest.spyOn(TypeDefaults, 'getDefaultIdentifierPropertiesFromObject')
|
|
464
|
-
.mockImplementation(() => properties);
|
|
465
|
-
try{
|
|
466
|
-
const results = await TypeConversionUtils.getIdentifierPropertiesFromObject(TRANSFORM_MAP_FILE, mapFileUtil, object);
|
|
467
|
-
expect(results).toEqual(properties);
|
|
468
|
-
expect(results).toHaveLength(1);
|
|
469
|
-
expect(spyIdentifiers).toBeCalledTimes(1);
|
|
470
|
-
|
|
471
|
-
} finally {
|
|
472
|
-
spy.mockRestore();
|
|
473
|
-
spyIdentifiers.mockRestore();
|
|
474
|
-
}
|
|
475
|
-
});
|
|
476
|
-
});
|
|
477
|
-
|
|
478
|
-
describe('getInformationalPropertiesFromObject', () =>{
|
|
479
|
-
const mapFileUtil = new MapFileUtil(new Entities());
|
|
480
|
-
|
|
481
|
-
it('vibeIQInformationalProperties', async () => {
|
|
482
|
-
const properties = ['optionName'];
|
|
483
|
-
const object = {
|
|
484
|
-
vibeIQInformationalProperties: properties
|
|
485
|
-
};
|
|
486
|
-
|
|
487
|
-
const results = await TypeConversionUtils.getInformationalPropertiesFromObject(TRANSFORM_MAP_FILE, mapFileUtil, object);
|
|
488
|
-
expect(results).toHaveLength(1);
|
|
489
|
-
expect(results).toEqual(properties);
|
|
490
|
-
});
|
|
491
|
-
|
|
492
|
-
it('uses mapping-catName', async () =>{
|
|
493
|
-
const properties = ['longName'];
|
|
494
|
-
const object = {
|
|
495
|
-
flexPLMObjectClass: 'LCSLast',
|
|
496
|
-
flexPLMTypePath: 'Last\\catName'
|
|
497
|
-
};
|
|
498
|
-
const spy = jest.spyOn(mapFileUtil, 'getMapFile')
|
|
499
|
-
.mockImplementation(async () =>{
|
|
500
|
-
return mapping;
|
|
501
|
-
});
|
|
502
|
-
try{
|
|
503
|
-
const results = await TypeConversionUtils.getInformationalPropertiesFromObject(TRANSFORM_MAP_FILE, mapFileUtil, object);
|
|
504
|
-
expect(results).toHaveLength(1);
|
|
505
|
-
expect(results).toEqual(properties);
|
|
506
|
-
|
|
507
|
-
} finally {
|
|
508
|
-
spy.mockRestore();
|
|
509
|
-
}
|
|
510
|
-
});
|
|
511
|
-
|
|
512
|
-
it('uses default-noMap', async () =>{
|
|
513
|
-
const properties = ['optionName', 'description'];
|
|
514
|
-
const object = {
|
|
515
|
-
flexPLMObjectClass: 'LCSSKU',
|
|
516
|
-
typePath: 'Product'
|
|
517
|
-
};
|
|
518
|
-
const spy = jest.spyOn(mapFileUtil, 'getMapFile')
|
|
519
|
-
.mockImplementation(async () =>{
|
|
520
|
-
return mapping;
|
|
521
|
-
});
|
|
522
|
-
const spyIdentifiers = jest.spyOn(TypeDefaults, 'getDefaultInformationalPropertiesFromObject')
|
|
523
|
-
.mockImplementation(() => properties);
|
|
524
|
-
try{
|
|
525
|
-
const results = await TypeConversionUtils.getInformationalPropertiesFromObject(TRANSFORM_MAP_FILE, mapFileUtil, object);
|
|
526
|
-
expect(results).toEqual(properties);
|
|
527
|
-
expect(results).toHaveLength(2);
|
|
528
|
-
expect(spyIdentifiers).toBeCalledTimes(1);
|
|
529
|
-
|
|
530
|
-
} finally {
|
|
531
|
-
spy.mockRestore();
|
|
532
|
-
spyIdentifiers.mockRestore();
|
|
533
|
-
}
|
|
534
|
-
});
|
|
535
|
-
});
|
|
536
|
-
|
|
537
|
-
describe('getMapKeyFromObject', () =>{
|
|
538
|
-
const mapFileUtil = new MapFileUtil(new Entities());
|
|
539
|
-
|
|
540
|
-
it('Revisable Entity\\packaging', async () =>{
|
|
541
|
-
const spy = jest.spyOn(mapFileUtil, 'getMapFile')
|
|
542
|
-
.mockImplementation(async () =>{
|
|
543
|
-
return mapping;
|
|
544
|
-
});
|
|
545
|
-
const object = {
|
|
546
|
-
flexPLMObjectClass: 'LCSRevisableEntity',
|
|
547
|
-
flexPLMTypePath: 'Revisable Entity\\packaging'
|
|
548
|
-
}
|
|
549
|
-
const expectedMapKey = 'packaging';
|
|
550
|
-
|
|
551
|
-
try{
|
|
552
|
-
const results = await TypeConversionUtils.getMapKeyFromObject(TRANSFORM_MAP_FILE, mapFileUtil, object, TypeConversionUtils.FLEX2VIBE_DIRECTION);
|
|
553
|
-
expect(results).toEqual(expectedMapKey);
|
|
554
|
-
|
|
555
|
-
} finally {
|
|
556
|
-
spy.mockRestore();
|
|
557
|
-
}
|
|
558
|
-
});
|
|
559
|
-
|
|
560
|
-
it('Revisable Entity\\prefix', async () =>{
|
|
561
|
-
const spy = jest.spyOn(mapFileUtil, 'getMapFile')
|
|
562
|
-
.mockImplementation(async () =>{
|
|
563
|
-
return mapping;
|
|
564
|
-
});
|
|
565
|
-
const object = {
|
|
566
|
-
flexPLMObjectClass: 'LCSRevisableEntity',
|
|
567
|
-
flexPLMTypePath: 'Revisable Entity\\prefix'
|
|
568
|
-
}
|
|
569
|
-
const expectedMapKey = 'prefix';
|
|
570
|
-
|
|
571
|
-
try{
|
|
572
|
-
const results = await TypeConversionUtils.getMapKeyFromObject(TRANSFORM_MAP_FILE, mapFileUtil, object, TypeConversionUtils.FLEX2VIBE_DIRECTION);
|
|
573
|
-
expect(results).toEqual(expectedMapKey);
|
|
574
|
-
|
|
575
|
-
} finally {
|
|
576
|
-
spy.mockRestore();
|
|
577
|
-
}
|
|
578
|
-
});
|
|
579
|
-
|
|
580
|
-
it('color - no mapping exists', async () =>{
|
|
581
|
-
const spy = jest.spyOn(mapFileUtil, 'getMapFile')
|
|
582
|
-
.mockImplementation(async () =>{
|
|
583
|
-
return mapping;
|
|
584
|
-
});
|
|
585
|
-
const object = {
|
|
586
|
-
flexPLMObjectClass: 'LCSColor',
|
|
587
|
-
flexPLMTypePath: 'Color'
|
|
588
|
-
}
|
|
589
|
-
const expectedMapKey = 'LCSColor';
|
|
590
|
-
|
|
591
|
-
try{
|
|
592
|
-
const results = await TypeConversionUtils.getMapKeyFromObject(TRANSFORM_MAP_FILE, mapFileUtil, object, TypeConversionUtils.FLEX2VIBE_DIRECTION);
|
|
593
|
-
expect(results).toEqual(expectedMapKey);
|
|
594
|
-
|
|
595
|
-
} finally {
|
|
596
|
-
spy.mockRestore();
|
|
597
|
-
}
|
|
598
|
-
});
|
|
599
|
-
});
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
describe('isInboundCreatableFromObject', () =>{
|
|
603
|
-
const mapFileUtil = new MapFileUtil(new Entities());
|
|
604
|
-
|
|
605
|
-
it('Revisable Entity\\packaging', async () =>{
|
|
606
|
-
const spy = jest.spyOn(mapFileUtil, 'getMapFile')
|
|
607
|
-
.mockImplementation(async () =>{
|
|
608
|
-
return mapping;
|
|
609
|
-
});
|
|
610
|
-
const object = {
|
|
611
|
-
flexPLMObjectClass: 'LCSRevisableEntity',
|
|
612
|
-
flexPLMTypePath: 'Revisable Entity\\packaging'
|
|
613
|
-
}
|
|
614
|
-
|
|
615
|
-
try{
|
|
616
|
-
const results = await TypeConversionUtils.isInboundCreatableFromObject(TRANSFORM_MAP_FILE, mapFileUtil, object);
|
|
617
|
-
expect(results).toBeFalsy();
|
|
618
|
-
|
|
619
|
-
} finally {
|
|
620
|
-
spy.mockRestore();
|
|
621
|
-
}
|
|
622
|
-
});
|
|
623
|
-
|
|
624
|
-
it('Revisable Entity\\prefix', async () =>{
|
|
625
|
-
const spy = jest.spyOn(mapFileUtil, 'getMapFile')
|
|
626
|
-
.mockImplementation(async () =>{
|
|
627
|
-
return mapping;
|
|
628
|
-
});
|
|
629
|
-
const object = {
|
|
630
|
-
flexPLMObjectClass: 'LCSRevisableEntity',
|
|
631
|
-
flexPLMTypePath: 'Revisable Entity\\prefix'
|
|
632
|
-
}
|
|
633
|
-
|
|
634
|
-
try{
|
|
635
|
-
const results = await TypeConversionUtils.isInboundCreatableFromObject(TRANSFORM_MAP_FILE, mapFileUtil, object);
|
|
636
|
-
expect(results).toBeTruthy();
|
|
637
|
-
|
|
638
|
-
} finally {
|
|
639
|
-
spy.mockRestore();
|
|
640
|
-
}
|
|
641
|
-
});
|
|
642
|
-
|
|
643
|
-
});
|
|
1
|
+
import { MapFileUtil } from '@contrail/transform-data';
|
|
2
|
+
import { Entities } from '@contrail/sdk';
|
|
3
|
+
import { TypeConversionUtils } from './type-conversion-utils';
|
|
4
|
+
import { TypeDefaults } from './type-defaults';
|
|
5
|
+
|
|
6
|
+
const maps = require('./type-conversion-utils-spec-mockData');
|
|
7
|
+
const mapping = maps['mapping'];
|
|
8
|
+
|
|
9
|
+
const TRANSFORM_MAP_FILE = 'test-transformMapping';
|
|
10
|
+
describe('conversion-utils', () => {
|
|
11
|
+
describe('getObjectClass', () => {
|
|
12
|
+
const mapFileUtil = new MapFileUtil(new Entities());
|
|
13
|
+
|
|
14
|
+
it('flexPLMObjectClass', async () => {
|
|
15
|
+
const objectClass = 'ObjectClass';
|
|
16
|
+
const entity = {
|
|
17
|
+
flexPLMObjectClass: objectClass
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const results = await TypeConversionUtils.getObjectClass(TRANSFORM_MAP_FILE, mapFileUtil, entity);
|
|
21
|
+
expect(results).toEqual(objectClass);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('uses mapping-catName', async () =>{
|
|
25
|
+
const expectedClass = 'LCSLast';
|
|
26
|
+
const entity = {
|
|
27
|
+
entityType: 'custom-entity',
|
|
28
|
+
typePath: 'custom-entity:catName'
|
|
29
|
+
};
|
|
30
|
+
const spy = jest.spyOn(mapFileUtil, 'getMapFile')
|
|
31
|
+
.mockImplementation(async () =>{
|
|
32
|
+
return mapping;
|
|
33
|
+
});
|
|
34
|
+
try{
|
|
35
|
+
const results = await TypeConversionUtils.getObjectClass(TRANSFORM_MAP_FILE, mapFileUtil, entity);
|
|
36
|
+
expect(results).toEqual(expectedClass);
|
|
37
|
+
|
|
38
|
+
} finally {
|
|
39
|
+
spy.mockRestore();
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('uses default-noMap', async () =>{
|
|
44
|
+
const expectedClass = 'LCSColor';
|
|
45
|
+
const entity = {
|
|
46
|
+
entityType: 'color',
|
|
47
|
+
typePath: 'color:noMap'
|
|
48
|
+
};
|
|
49
|
+
const spy = jest.spyOn(mapFileUtil, 'getMapFile')
|
|
50
|
+
.mockImplementation(async () =>{
|
|
51
|
+
return mapping;
|
|
52
|
+
});
|
|
53
|
+
const spyIdentifiers = jest.spyOn(TypeDefaults, 'getDefaultObjectClass')
|
|
54
|
+
.mockImplementation(() => expectedClass);
|
|
55
|
+
try{
|
|
56
|
+
const results = await TypeConversionUtils.getObjectClass(TRANSFORM_MAP_FILE, mapFileUtil, entity);
|
|
57
|
+
expect(results).toEqual(expectedClass);
|
|
58
|
+
expect(spyIdentifiers).toBeCalledTimes(2);
|
|
59
|
+
|
|
60
|
+
} finally {
|
|
61
|
+
spy.mockRestore();
|
|
62
|
+
spyIdentifiers.mockRestore();
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
describe('getObjectTypePath', () =>{
|
|
68
|
+
const mapFileUtil = new MapFileUtil(new Entities());
|
|
69
|
+
|
|
70
|
+
it('flexPLMTypePath', async () => {
|
|
71
|
+
const typePath = 'Product';
|
|
72
|
+
const entity = {
|
|
73
|
+
flexPLMTypePath: typePath
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
const results = await TypeConversionUtils.getObjectTypePath(TRANSFORM_MAP_FILE, mapFileUtil, entity);
|
|
77
|
+
expect(results).toEqual(typePath);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('uses mapping-catName', async () =>{
|
|
81
|
+
const expectedTypePath = 'Last\\catName';
|
|
82
|
+
const entity = {
|
|
83
|
+
entityType: 'custom-entity',
|
|
84
|
+
typePath: 'custom-entity:catName'
|
|
85
|
+
};
|
|
86
|
+
const spy = jest.spyOn(mapFileUtil, 'getMapFile')
|
|
87
|
+
.mockImplementation(async () =>{
|
|
88
|
+
return mapping;
|
|
89
|
+
});
|
|
90
|
+
try{
|
|
91
|
+
const results = await TypeConversionUtils.getObjectTypePath(TRANSFORM_MAP_FILE, mapFileUtil, entity);
|
|
92
|
+
expect(results).toEqual(expectedTypePath);
|
|
93
|
+
|
|
94
|
+
} finally {
|
|
95
|
+
spy.mockRestore();
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it('uses default-noMap', async () =>{
|
|
100
|
+
const expectedTypePath = 'Color';
|
|
101
|
+
const entity = {
|
|
102
|
+
entityType: 'color',
|
|
103
|
+
typePath: 'color:noMap'
|
|
104
|
+
};
|
|
105
|
+
const spy = jest.spyOn(mapFileUtil, 'getMapFile')
|
|
106
|
+
.mockImplementation(async () =>{
|
|
107
|
+
return mapping;
|
|
108
|
+
});
|
|
109
|
+
const spyIdentifiers = jest.spyOn(TypeDefaults, 'getDefaultObjectTypePath')
|
|
110
|
+
.mockImplementation(() => expectedTypePath);
|
|
111
|
+
try{
|
|
112
|
+
const results = await TypeConversionUtils.getObjectTypePath(TRANSFORM_MAP_FILE, mapFileUtil, entity);
|
|
113
|
+
expect(results).toEqual(expectedTypePath);
|
|
114
|
+
expect(spyIdentifiers).toBeCalledTimes(1);
|
|
115
|
+
|
|
116
|
+
} finally {
|
|
117
|
+
spy.mockRestore();
|
|
118
|
+
spyIdentifiers.mockRestore();
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
describe('getIdentifierProperties', () =>{
|
|
124
|
+
const mapFileUtil = new MapFileUtil(new Entities());
|
|
125
|
+
|
|
126
|
+
it('flexPLMIdentifierProperties', async () => {
|
|
127
|
+
const properties = ['optionName'];
|
|
128
|
+
const entity = {
|
|
129
|
+
flexPLMIdentifierProperties: properties
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
const results = await TypeConversionUtils.getIdentifierProperties(TRANSFORM_MAP_FILE, mapFileUtil, entity);
|
|
133
|
+
expect(results).toHaveLength(1);
|
|
134
|
+
expect(results).toEqual(properties);
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it('uses mapping-catName', async () =>{
|
|
138
|
+
const properties = ['catName', 'catNumber'];
|
|
139
|
+
const entity = {
|
|
140
|
+
entityType: 'custom-entity',
|
|
141
|
+
typePath: 'custom-entity:catName'
|
|
142
|
+
};
|
|
143
|
+
const spy = jest.spyOn(mapFileUtil, 'getMapFile')
|
|
144
|
+
.mockImplementation(async () =>{
|
|
145
|
+
return mapping;
|
|
146
|
+
});
|
|
147
|
+
try{
|
|
148
|
+
const results = await TypeConversionUtils.getIdentifierProperties(TRANSFORM_MAP_FILE, mapFileUtil, entity);
|
|
149
|
+
expect(results).toHaveLength(2);
|
|
150
|
+
expect(results).toEqual(properties);
|
|
151
|
+
|
|
152
|
+
} finally {
|
|
153
|
+
spy.mockRestore();
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
it('uses default-noMap', async () =>{
|
|
158
|
+
const properties = ['itemNumber'];
|
|
159
|
+
const entity = {
|
|
160
|
+
entityType: 'item',
|
|
161
|
+
typePath: 'item',
|
|
162
|
+
roles: ['family']
|
|
163
|
+
};
|
|
164
|
+
const spy = jest.spyOn(mapFileUtil, 'getMapFile')
|
|
165
|
+
.mockImplementation(async () =>{
|
|
166
|
+
return mapping;
|
|
167
|
+
});
|
|
168
|
+
const spyIdentifiers = jest.spyOn(TypeDefaults, 'getDefaultIdentifierProperties')
|
|
169
|
+
.mockImplementation(() => properties);
|
|
170
|
+
try{
|
|
171
|
+
const results = await TypeConversionUtils.getIdentifierProperties(TRANSFORM_MAP_FILE, mapFileUtil, entity);
|
|
172
|
+
expect(results).toEqual(properties);
|
|
173
|
+
expect(results).toHaveLength(1);
|
|
174
|
+
expect(spyIdentifiers).toBeCalledTimes(1);
|
|
175
|
+
|
|
176
|
+
} finally {
|
|
177
|
+
spy.mockRestore();
|
|
178
|
+
spyIdentifiers.mockRestore();
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
describe('getInformationalProperties', () =>{
|
|
184
|
+
const mapFileUtil = new MapFileUtil(new Entities());
|
|
185
|
+
|
|
186
|
+
it('flexPLMIdentifierProperties', async () => {
|
|
187
|
+
const properties = ['optionName'];
|
|
188
|
+
const entity = {
|
|
189
|
+
flexPLMInformationalProperties: properties
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
const results = await TypeConversionUtils.getInformationalProperties(TRANSFORM_MAP_FILE, mapFileUtil, entity);
|
|
193
|
+
expect(results).toHaveLength(1);
|
|
194
|
+
expect(results).toEqual(properties);
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
it('uses mapping-catName', async () =>{
|
|
198
|
+
const properties = ['longName'];
|
|
199
|
+
const entity = {
|
|
200
|
+
entityType: 'custom-entity',
|
|
201
|
+
typePath: 'custom-entity:catName'
|
|
202
|
+
};
|
|
203
|
+
const spy = jest.spyOn(mapFileUtil, 'getMapFile')
|
|
204
|
+
.mockImplementation(async () =>{
|
|
205
|
+
return mapping;
|
|
206
|
+
});
|
|
207
|
+
try{
|
|
208
|
+
const results = await TypeConversionUtils.getInformationalProperties(TRANSFORM_MAP_FILE, mapFileUtil, entity);
|
|
209
|
+
expect(results).toHaveLength(1);
|
|
210
|
+
expect(results).toEqual(properties);
|
|
211
|
+
|
|
212
|
+
} finally {
|
|
213
|
+
spy.mockRestore();
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
it('uses default-noMap', async () =>{
|
|
218
|
+
const properties = ['optionName', 'description'];
|
|
219
|
+
const entity = {
|
|
220
|
+
entityType: 'item',
|
|
221
|
+
typePath: 'item',
|
|
222
|
+
roles: ['color']
|
|
223
|
+
};
|
|
224
|
+
const spy = jest.spyOn(mapFileUtil, 'getMapFile')
|
|
225
|
+
.mockImplementation(async () =>{
|
|
226
|
+
return mapping;
|
|
227
|
+
});
|
|
228
|
+
const spyIdentifiers = jest.spyOn(TypeDefaults, 'getDefaultInformationalProperties')
|
|
229
|
+
.mockImplementation(() => properties);
|
|
230
|
+
try{
|
|
231
|
+
const results = await TypeConversionUtils.getInformationalProperties(TRANSFORM_MAP_FILE, mapFileUtil, entity);
|
|
232
|
+
expect(results).toEqual(properties);
|
|
233
|
+
expect(results).toHaveLength(2);
|
|
234
|
+
expect(spyIdentifiers).toBeCalledTimes(1);
|
|
235
|
+
|
|
236
|
+
} finally {
|
|
237
|
+
spy.mockRestore();
|
|
238
|
+
spyIdentifiers.mockRestore();
|
|
239
|
+
}
|
|
240
|
+
});
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
describe('getMapKey', () =>{
|
|
244
|
+
const mapFileUtil = new MapFileUtil(new Entities());
|
|
245
|
+
|
|
246
|
+
it('custom-entity:pack', async () =>{
|
|
247
|
+
const spy = jest.spyOn(mapFileUtil, 'getMapFile')
|
|
248
|
+
.mockImplementation(async () =>{
|
|
249
|
+
return mapping;
|
|
250
|
+
});
|
|
251
|
+
const entity = {
|
|
252
|
+
typePath: 'custom-entity:pack',
|
|
253
|
+
entityType: 'custom-entity'
|
|
254
|
+
}
|
|
255
|
+
const expectedMapKey = 'packaging';
|
|
256
|
+
|
|
257
|
+
try{
|
|
258
|
+
const results = await TypeConversionUtils.getMapKey(TRANSFORM_MAP_FILE, mapFileUtil, entity, TypeConversionUtils.VIBE2FLEX_DIRECTION);
|
|
259
|
+
expect(results).toEqual(expectedMapKey);
|
|
260
|
+
|
|
261
|
+
} finally {
|
|
262
|
+
spy.mockRestore();
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
it('custom-entity:prefix', async () =>{
|
|
267
|
+
const spy = jest.spyOn(mapFileUtil, 'getMapFile')
|
|
268
|
+
.mockImplementation(async () =>{
|
|
269
|
+
return mapping;
|
|
270
|
+
});
|
|
271
|
+
const entity = {
|
|
272
|
+
typePath: 'custom-entity:prefix',
|
|
273
|
+
entityType: 'custom-entity'
|
|
274
|
+
}
|
|
275
|
+
const expectedMapKey = 'prefix';
|
|
276
|
+
|
|
277
|
+
try{
|
|
278
|
+
const results = await TypeConversionUtils.getMapKey(TRANSFORM_MAP_FILE, mapFileUtil, entity, TypeConversionUtils.VIBE2FLEX_DIRECTION);
|
|
279
|
+
expect(results).toEqual(expectedMapKey);
|
|
280
|
+
|
|
281
|
+
} finally {
|
|
282
|
+
spy.mockRestore();
|
|
283
|
+
}
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
it('color - no mapping exists', async () =>{
|
|
287
|
+
const spy = jest.spyOn(mapFileUtil, 'getMapFile')
|
|
288
|
+
.mockImplementation(async () =>{
|
|
289
|
+
return mapping;
|
|
290
|
+
});
|
|
291
|
+
const entity = {
|
|
292
|
+
typePath: 'color',
|
|
293
|
+
entityType: 'color'
|
|
294
|
+
}
|
|
295
|
+
const expectedMapKey = 'LCSColor';
|
|
296
|
+
|
|
297
|
+
try{
|
|
298
|
+
const results = await TypeConversionUtils.getMapKey(TRANSFORM_MAP_FILE, mapFileUtil, entity, TypeConversionUtils.VIBE2FLEX_DIRECTION);
|
|
299
|
+
expect(results).toEqual(expectedMapKey);
|
|
300
|
+
|
|
301
|
+
} finally {
|
|
302
|
+
spy.mockRestore();
|
|
303
|
+
}
|
|
304
|
+
});
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
describe('getEntityClassFromObject', () => {
|
|
308
|
+
const mapFileUtil = new MapFileUtil(new Entities());
|
|
309
|
+
|
|
310
|
+
it('vibeIQEntityClass', async () => {
|
|
311
|
+
const objectClass = 'ObjectClass';
|
|
312
|
+
const object = {
|
|
313
|
+
vibeIQEntityClass: objectClass
|
|
314
|
+
};
|
|
315
|
+
|
|
316
|
+
const results = await TypeConversionUtils.getEntityClassFromObject(TRANSFORM_MAP_FILE, mapFileUtil, object);
|
|
317
|
+
expect(results).toEqual(objectClass);
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
it('uses mapping-catName', async () =>{
|
|
321
|
+
const expectedClass = 'custom-entity';
|
|
322
|
+
const object = {
|
|
323
|
+
flexPLMObjectClass: 'LCSLast',
|
|
324
|
+
flexPLMTypePath: 'Last\\catName'
|
|
325
|
+
};
|
|
326
|
+
const spy = jest.spyOn(mapFileUtil, 'getMapFile')
|
|
327
|
+
.mockImplementation(async () =>{
|
|
328
|
+
return mapping;
|
|
329
|
+
});
|
|
330
|
+
try{
|
|
331
|
+
const results = await TypeConversionUtils.getEntityClassFromObject(TRANSFORM_MAP_FILE, mapFileUtil, object);
|
|
332
|
+
expect(results).toEqual(expectedClass);
|
|
333
|
+
|
|
334
|
+
} finally {
|
|
335
|
+
spy.mockRestore();
|
|
336
|
+
}
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
it('uses default-noMap', async () =>{
|
|
340
|
+
const expectedClass = 'color';
|
|
341
|
+
const entity = {
|
|
342
|
+
flexPLMObjectClass: 'LCSColor',
|
|
343
|
+
flexPLMTypePath: 'Color'
|
|
344
|
+
};
|
|
345
|
+
const spy = jest.spyOn(mapFileUtil, 'getMapFile')
|
|
346
|
+
.mockImplementation(async () =>{
|
|
347
|
+
return mapping;
|
|
348
|
+
});
|
|
349
|
+
const spyIdentifiers = jest.spyOn(TypeDefaults, 'getDefaultEntityClass')
|
|
350
|
+
.mockImplementation(() => expectedClass);
|
|
351
|
+
try{
|
|
352
|
+
const results = await TypeConversionUtils.getEntityClassFromObject(TRANSFORM_MAP_FILE, mapFileUtil, entity);
|
|
353
|
+
expect(results).toEqual(expectedClass);
|
|
354
|
+
expect(spyIdentifiers).toBeCalledTimes(1);
|
|
355
|
+
|
|
356
|
+
} finally {
|
|
357
|
+
spy.mockRestore();
|
|
358
|
+
spyIdentifiers.mockRestore();
|
|
359
|
+
}
|
|
360
|
+
});
|
|
361
|
+
});
|
|
362
|
+
|
|
363
|
+
describe('getEntityTypePathFromOjbect', () =>{
|
|
364
|
+
const mapFileUtil = new MapFileUtil(new Entities());
|
|
365
|
+
|
|
366
|
+
it('vibeIQTypePath', async () => {
|
|
367
|
+
const typePath = 'item';
|
|
368
|
+
const entity = {
|
|
369
|
+
vibeIQTypePath: typePath
|
|
370
|
+
};
|
|
371
|
+
|
|
372
|
+
const results = await TypeConversionUtils.getEntityTypePathFromOjbect(TRANSFORM_MAP_FILE, mapFileUtil, entity);
|
|
373
|
+
expect(results).toEqual(typePath);
|
|
374
|
+
});
|
|
375
|
+
|
|
376
|
+
it('uses mapping-catName', async () =>{
|
|
377
|
+
const expectedTypePath = 'custom-entity:catName';
|
|
378
|
+
const entity = {
|
|
379
|
+
flexPLMObjectClass: 'LCSLast',
|
|
380
|
+
flexPLMTypePath: 'Last\\catName'
|
|
381
|
+
};
|
|
382
|
+
const spy = jest.spyOn(mapFileUtil, 'getMapFile')
|
|
383
|
+
.mockImplementation(async () =>{
|
|
384
|
+
return mapping;
|
|
385
|
+
});
|
|
386
|
+
try{
|
|
387
|
+
const results = await TypeConversionUtils.getEntityTypePathFromOjbect(TRANSFORM_MAP_FILE, mapFileUtil, entity);
|
|
388
|
+
expect(results).toEqual(expectedTypePath);
|
|
389
|
+
|
|
390
|
+
} finally {
|
|
391
|
+
spy.mockRestore();
|
|
392
|
+
}
|
|
393
|
+
});
|
|
394
|
+
|
|
395
|
+
it('uses default-noMap', async () =>{
|
|
396
|
+
const expectedTypePath = 'color';
|
|
397
|
+
const entity = {
|
|
398
|
+
flexPLMObjectClass: 'LCSColor',
|
|
399
|
+
flexPLMTypePath: 'Color'
|
|
400
|
+
};
|
|
401
|
+
const spy = jest.spyOn(mapFileUtil, 'getMapFile')
|
|
402
|
+
.mockImplementation(async () =>{
|
|
403
|
+
return mapping;
|
|
404
|
+
});
|
|
405
|
+
const spyIdentifiers = jest.spyOn(TypeDefaults, 'getDefaultEntityTypePath')
|
|
406
|
+
.mockImplementation(() => expectedTypePath);
|
|
407
|
+
try{
|
|
408
|
+
const results = await TypeConversionUtils.getEntityTypePathFromOjbect(TRANSFORM_MAP_FILE, mapFileUtil, entity);
|
|
409
|
+
expect(results).toEqual(expectedTypePath);
|
|
410
|
+
expect(spyIdentifiers).toBeCalledTimes(1);
|
|
411
|
+
|
|
412
|
+
} finally {
|
|
413
|
+
spy.mockRestore();
|
|
414
|
+
spyIdentifiers.mockRestore();
|
|
415
|
+
}
|
|
416
|
+
});
|
|
417
|
+
});
|
|
418
|
+
|
|
419
|
+
describe('getIdentifierPropertiesFromObject', () =>{
|
|
420
|
+
const mapFileUtil = new MapFileUtil(new Entities());
|
|
421
|
+
|
|
422
|
+
it('flexPLMIdentifierProperties', async () => {
|
|
423
|
+
const properties = ['optionName'];
|
|
424
|
+
const object = {
|
|
425
|
+
vibeIQIdentifierProperties: properties
|
|
426
|
+
};
|
|
427
|
+
|
|
428
|
+
const results = await TypeConversionUtils.getIdentifierPropertiesFromObject(TRANSFORM_MAP_FILE, mapFileUtil, object);
|
|
429
|
+
expect(results).toHaveLength(1);
|
|
430
|
+
expect(results).toEqual(properties);
|
|
431
|
+
});
|
|
432
|
+
|
|
433
|
+
it('uses mapping-catName', async () =>{
|
|
434
|
+
const properties = ['catName', 'catNumber'];
|
|
435
|
+
const object = {
|
|
436
|
+
flexPLMObjectClass: 'LCSLast',
|
|
437
|
+
flexPLMTypePath: 'Last\\catName'
|
|
438
|
+
};
|
|
439
|
+
const spy = jest.spyOn(mapFileUtil, 'getMapFile')
|
|
440
|
+
.mockImplementation(async () =>{
|
|
441
|
+
return mapping;
|
|
442
|
+
});
|
|
443
|
+
try{
|
|
444
|
+
const results = await TypeConversionUtils.getIdentifierPropertiesFromObject(TRANSFORM_MAP_FILE, mapFileUtil, object);
|
|
445
|
+
expect(results).toHaveLength(2);
|
|
446
|
+
expect(results).toEqual(properties);
|
|
447
|
+
|
|
448
|
+
} finally {
|
|
449
|
+
spy.mockRestore();
|
|
450
|
+
}
|
|
451
|
+
});
|
|
452
|
+
|
|
453
|
+
it('uses default-noMap', async () =>{
|
|
454
|
+
const properties = ['itemNumber'];
|
|
455
|
+
const object = {
|
|
456
|
+
flexPLMObjectClass: 'LCSProduct',
|
|
457
|
+
flexPLMTypePath: 'Product'
|
|
458
|
+
};
|
|
459
|
+
const spy = jest.spyOn(mapFileUtil, 'getMapFile')
|
|
460
|
+
.mockImplementation(async () =>{
|
|
461
|
+
return mapping;
|
|
462
|
+
});
|
|
463
|
+
const spyIdentifiers = jest.spyOn(TypeDefaults, 'getDefaultIdentifierPropertiesFromObject')
|
|
464
|
+
.mockImplementation(() => properties);
|
|
465
|
+
try{
|
|
466
|
+
const results = await TypeConversionUtils.getIdentifierPropertiesFromObject(TRANSFORM_MAP_FILE, mapFileUtil, object);
|
|
467
|
+
expect(results).toEqual(properties);
|
|
468
|
+
expect(results).toHaveLength(1);
|
|
469
|
+
expect(spyIdentifiers).toBeCalledTimes(1);
|
|
470
|
+
|
|
471
|
+
} finally {
|
|
472
|
+
spy.mockRestore();
|
|
473
|
+
spyIdentifiers.mockRestore();
|
|
474
|
+
}
|
|
475
|
+
});
|
|
476
|
+
});
|
|
477
|
+
|
|
478
|
+
describe('getInformationalPropertiesFromObject', () =>{
|
|
479
|
+
const mapFileUtil = new MapFileUtil(new Entities());
|
|
480
|
+
|
|
481
|
+
it('vibeIQInformationalProperties', async () => {
|
|
482
|
+
const properties = ['optionName'];
|
|
483
|
+
const object = {
|
|
484
|
+
vibeIQInformationalProperties: properties
|
|
485
|
+
};
|
|
486
|
+
|
|
487
|
+
const results = await TypeConversionUtils.getInformationalPropertiesFromObject(TRANSFORM_MAP_FILE, mapFileUtil, object);
|
|
488
|
+
expect(results).toHaveLength(1);
|
|
489
|
+
expect(results).toEqual(properties);
|
|
490
|
+
});
|
|
491
|
+
|
|
492
|
+
it('uses mapping-catName', async () =>{
|
|
493
|
+
const properties = ['longName'];
|
|
494
|
+
const object = {
|
|
495
|
+
flexPLMObjectClass: 'LCSLast',
|
|
496
|
+
flexPLMTypePath: 'Last\\catName'
|
|
497
|
+
};
|
|
498
|
+
const spy = jest.spyOn(mapFileUtil, 'getMapFile')
|
|
499
|
+
.mockImplementation(async () =>{
|
|
500
|
+
return mapping;
|
|
501
|
+
});
|
|
502
|
+
try{
|
|
503
|
+
const results = await TypeConversionUtils.getInformationalPropertiesFromObject(TRANSFORM_MAP_FILE, mapFileUtil, object);
|
|
504
|
+
expect(results).toHaveLength(1);
|
|
505
|
+
expect(results).toEqual(properties);
|
|
506
|
+
|
|
507
|
+
} finally {
|
|
508
|
+
spy.mockRestore();
|
|
509
|
+
}
|
|
510
|
+
});
|
|
511
|
+
|
|
512
|
+
it('uses default-noMap', async () =>{
|
|
513
|
+
const properties = ['optionName', 'description'];
|
|
514
|
+
const object = {
|
|
515
|
+
flexPLMObjectClass: 'LCSSKU',
|
|
516
|
+
typePath: 'Product'
|
|
517
|
+
};
|
|
518
|
+
const spy = jest.spyOn(mapFileUtil, 'getMapFile')
|
|
519
|
+
.mockImplementation(async () =>{
|
|
520
|
+
return mapping;
|
|
521
|
+
});
|
|
522
|
+
const spyIdentifiers = jest.spyOn(TypeDefaults, 'getDefaultInformationalPropertiesFromObject')
|
|
523
|
+
.mockImplementation(() => properties);
|
|
524
|
+
try{
|
|
525
|
+
const results = await TypeConversionUtils.getInformationalPropertiesFromObject(TRANSFORM_MAP_FILE, mapFileUtil, object);
|
|
526
|
+
expect(results).toEqual(properties);
|
|
527
|
+
expect(results).toHaveLength(2);
|
|
528
|
+
expect(spyIdentifiers).toBeCalledTimes(1);
|
|
529
|
+
|
|
530
|
+
} finally {
|
|
531
|
+
spy.mockRestore();
|
|
532
|
+
spyIdentifiers.mockRestore();
|
|
533
|
+
}
|
|
534
|
+
});
|
|
535
|
+
});
|
|
536
|
+
|
|
537
|
+
describe('getMapKeyFromObject', () =>{
|
|
538
|
+
const mapFileUtil = new MapFileUtil(new Entities());
|
|
539
|
+
|
|
540
|
+
it('Revisable Entity\\packaging', async () =>{
|
|
541
|
+
const spy = jest.spyOn(mapFileUtil, 'getMapFile')
|
|
542
|
+
.mockImplementation(async () =>{
|
|
543
|
+
return mapping;
|
|
544
|
+
});
|
|
545
|
+
const object = {
|
|
546
|
+
flexPLMObjectClass: 'LCSRevisableEntity',
|
|
547
|
+
flexPLMTypePath: 'Revisable Entity\\packaging'
|
|
548
|
+
}
|
|
549
|
+
const expectedMapKey = 'packaging';
|
|
550
|
+
|
|
551
|
+
try{
|
|
552
|
+
const results = await TypeConversionUtils.getMapKeyFromObject(TRANSFORM_MAP_FILE, mapFileUtil, object, TypeConversionUtils.FLEX2VIBE_DIRECTION);
|
|
553
|
+
expect(results).toEqual(expectedMapKey);
|
|
554
|
+
|
|
555
|
+
} finally {
|
|
556
|
+
spy.mockRestore();
|
|
557
|
+
}
|
|
558
|
+
});
|
|
559
|
+
|
|
560
|
+
it('Revisable Entity\\prefix', async () =>{
|
|
561
|
+
const spy = jest.spyOn(mapFileUtil, 'getMapFile')
|
|
562
|
+
.mockImplementation(async () =>{
|
|
563
|
+
return mapping;
|
|
564
|
+
});
|
|
565
|
+
const object = {
|
|
566
|
+
flexPLMObjectClass: 'LCSRevisableEntity',
|
|
567
|
+
flexPLMTypePath: 'Revisable Entity\\prefix'
|
|
568
|
+
}
|
|
569
|
+
const expectedMapKey = 'prefix';
|
|
570
|
+
|
|
571
|
+
try{
|
|
572
|
+
const results = await TypeConversionUtils.getMapKeyFromObject(TRANSFORM_MAP_FILE, mapFileUtil, object, TypeConversionUtils.FLEX2VIBE_DIRECTION);
|
|
573
|
+
expect(results).toEqual(expectedMapKey);
|
|
574
|
+
|
|
575
|
+
} finally {
|
|
576
|
+
spy.mockRestore();
|
|
577
|
+
}
|
|
578
|
+
});
|
|
579
|
+
|
|
580
|
+
it('color - no mapping exists', async () =>{
|
|
581
|
+
const spy = jest.spyOn(mapFileUtil, 'getMapFile')
|
|
582
|
+
.mockImplementation(async () =>{
|
|
583
|
+
return mapping;
|
|
584
|
+
});
|
|
585
|
+
const object = {
|
|
586
|
+
flexPLMObjectClass: 'LCSColor',
|
|
587
|
+
flexPLMTypePath: 'Color'
|
|
588
|
+
}
|
|
589
|
+
const expectedMapKey = 'LCSColor';
|
|
590
|
+
|
|
591
|
+
try{
|
|
592
|
+
const results = await TypeConversionUtils.getMapKeyFromObject(TRANSFORM_MAP_FILE, mapFileUtil, object, TypeConversionUtils.FLEX2VIBE_DIRECTION);
|
|
593
|
+
expect(results).toEqual(expectedMapKey);
|
|
594
|
+
|
|
595
|
+
} finally {
|
|
596
|
+
spy.mockRestore();
|
|
597
|
+
}
|
|
598
|
+
});
|
|
599
|
+
});
|
|
600
|
+
|
|
601
|
+
|
|
602
|
+
describe('isInboundCreatableFromObject', () =>{
|
|
603
|
+
const mapFileUtil = new MapFileUtil(new Entities());
|
|
604
|
+
|
|
605
|
+
it('Revisable Entity\\packaging', async () =>{
|
|
606
|
+
const spy = jest.spyOn(mapFileUtil, 'getMapFile')
|
|
607
|
+
.mockImplementation(async () =>{
|
|
608
|
+
return mapping;
|
|
609
|
+
});
|
|
610
|
+
const object = {
|
|
611
|
+
flexPLMObjectClass: 'LCSRevisableEntity',
|
|
612
|
+
flexPLMTypePath: 'Revisable Entity\\packaging'
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
try{
|
|
616
|
+
const results = await TypeConversionUtils.isInboundCreatableFromObject(TRANSFORM_MAP_FILE, mapFileUtil, object);
|
|
617
|
+
expect(results).toBeFalsy();
|
|
618
|
+
|
|
619
|
+
} finally {
|
|
620
|
+
spy.mockRestore();
|
|
621
|
+
}
|
|
622
|
+
});
|
|
623
|
+
|
|
624
|
+
it('Revisable Entity\\prefix', async () =>{
|
|
625
|
+
const spy = jest.spyOn(mapFileUtil, 'getMapFile')
|
|
626
|
+
.mockImplementation(async () =>{
|
|
627
|
+
return mapping;
|
|
628
|
+
});
|
|
629
|
+
const object = {
|
|
630
|
+
flexPLMObjectClass: 'LCSRevisableEntity',
|
|
631
|
+
flexPLMTypePath: 'Revisable Entity\\prefix'
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
try{
|
|
635
|
+
const results = await TypeConversionUtils.isInboundCreatableFromObject(TRANSFORM_MAP_FILE, mapFileUtil, object);
|
|
636
|
+
expect(results).toBeTruthy();
|
|
637
|
+
|
|
638
|
+
} finally {
|
|
639
|
+
spy.mockRestore();
|
|
640
|
+
}
|
|
641
|
+
});
|
|
642
|
+
|
|
643
|
+
});
|
|
644
644
|
});
|