@contrail/flexplm 1.4.0 → 1.5.0-alpha.0d65410

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.
@@ -369,6 +369,26 @@ describe('Type Defaults', () => {
369
369
  const entityClass = type_defaults_1.TypeDefaults.getDefaultEntityClass(object);
370
370
  expect(entityClass).toBe('custom-entity');
371
371
  });
372
+ it('item - LCSMaterial - processAsItem=true', () => {
373
+ const object = {
374
+ flexPLMObjectClass: 'LCSMaterial'
375
+ };
376
+ type_defaults_1.TypeDefaults.applyConfig({ LCSMaterial: { processAsItem: true } });
377
+ try {
378
+ const entityClass = type_defaults_1.TypeDefaults.getDefaultEntityClass(object);
379
+ expect(entityClass).toBe('item');
380
+ }
381
+ finally {
382
+ type_defaults_1.TypeDefaults.applyConfig({});
383
+ }
384
+ });
385
+ it('custom-entity - LCSMaterial - processAsItem=false (default)', () => {
386
+ const object = {
387
+ flexPLMObjectClass: 'LCSMaterial'
388
+ };
389
+ const entityClass = type_defaults_1.TypeDefaults.getDefaultEntityClass(object);
390
+ expect(entityClass).toBe('custom-entity');
391
+ });
372
392
  });
373
393
  describe('getDefaultEntityTypePath', () => {
374
394
  it('LCSProduct', () => {
@@ -420,6 +440,25 @@ describe('Type Defaults', () => {
420
440
  const typePath = type_defaults_1.TypeDefaults.getDefaultEntityTypePath(object);
421
441
  expect(typePath).toBe('assortment');
422
442
  });
443
+ it('LCSMaterial - processAsItem=true', () => {
444
+ const object = {
445
+ flexPLMObjectClass: 'LCSMaterial'
446
+ };
447
+ type_defaults_1.TypeDefaults.applyConfig({ LCSMaterial: { processAsItem: true } });
448
+ try {
449
+ const typePath = type_defaults_1.TypeDefaults.getDefaultEntityTypePath(object);
450
+ expect(typePath).toBe('item:material');
451
+ }
452
+ finally {
453
+ type_defaults_1.TypeDefaults.applyConfig({});
454
+ }
455
+ });
456
+ it('LCSMaterial - processAsItem=false (default) throws', () => {
457
+ const object = {
458
+ flexPLMObjectClass: 'LCSMaterial'
459
+ };
460
+ expect(() => type_defaults_1.TypeDefaults.getDefaultEntityTypePath(object)).toThrowError(type_defaults_1.TypeDefaults.NO_TYPE_PATH);
461
+ });
423
462
  });
424
463
  describe('getDefaultIdentifierPropertiesFromObject', () => {
425
464
  it('LCSProduct', () => {
@@ -478,6 +517,28 @@ describe('Type Defaults', () => {
478
517
  expect(defaultIdentifiers).toContain('name');
479
518
  expect(defaultIdentifiers).toHaveLength(1);
480
519
  });
520
+ it('LCSMaterial - processAsItem=true', () => {
521
+ const object = {
522
+ flexPLMObjectClass: 'LCSMaterial'
523
+ };
524
+ type_defaults_1.TypeDefaults.applyConfig({ LCSMaterial: { processAsItem: true } });
525
+ try {
526
+ const defaultIdentifiers = type_defaults_1.TypeDefaults.getDefaultIdentifierPropertiesFromObject(object);
527
+ expect(defaultIdentifiers).toContain('itemNumber');
528
+ expect(defaultIdentifiers).toHaveLength(1);
529
+ }
530
+ finally {
531
+ type_defaults_1.TypeDefaults.applyConfig({});
532
+ }
533
+ });
534
+ it('LCSMaterial - processAsItem=false (default)', () => {
535
+ const object = {
536
+ flexPLMObjectClass: 'LCSMaterial'
537
+ };
538
+ const defaultIdentifiers = type_defaults_1.TypeDefaults.getDefaultIdentifierPropertiesFromObject(object);
539
+ expect(defaultIdentifiers).toContain('name');
540
+ expect(defaultIdentifiers).toHaveLength(1);
541
+ });
481
542
  });
482
543
  describe('getDefaultInformationalPropertiesFromObject', () => {
483
544
  it('LCSProduct', () => {
@@ -512,5 +573,54 @@ describe('Type Defaults', () => {
512
573
  expect(defaultIdentifiers).toContain('name');
513
574
  expect(defaultIdentifiers).toHaveLength(1);
514
575
  });
576
+ it('LCSMaterial - processAsItem=true', () => {
577
+ const object = {
578
+ flexPLMObjectClass: 'LCSMaterial'
579
+ };
580
+ type_defaults_1.TypeDefaults.applyConfig({ LCSMaterial: { processAsItem: true } });
581
+ try {
582
+ const defaultIdentifiers = type_defaults_1.TypeDefaults.getDefaultInformationalPropertiesFromObject(object);
583
+ expect(defaultIdentifiers).toContain('name');
584
+ expect(defaultIdentifiers).toHaveLength(1);
585
+ }
586
+ finally {
587
+ type_defaults_1.TypeDefaults.applyConfig({});
588
+ }
589
+ });
590
+ it('LCSMaterial - processAsItem=false (default) yields no informational props', () => {
591
+ const object = {
592
+ flexPLMObjectClass: 'LCSMaterial'
593
+ };
594
+ const defaultIdentifiers = type_defaults_1.TypeDefaults.getDefaultInformationalPropertiesFromObject(object);
595
+ expect(defaultIdentifiers).toHaveLength(0);
596
+ });
597
+ });
598
+ describe('applyConfig', () => {
599
+ afterEach(() => {
600
+ type_defaults_1.TypeDefaults.applyConfig({});
601
+ });
602
+ it('sets processLCSMaterialAsItem=true when processAsItem=true', () => {
603
+ type_defaults_1.TypeDefaults.applyConfig({ LCSMaterial: { processAsItem: true } });
604
+ expect(type_defaults_1.TypeDefaults.processLCSMaterialAsItem).toBe(true);
605
+ });
606
+ it('sets processLCSMaterialAsItem=true when processAsItem=\"true\" (string)', () => {
607
+ type_defaults_1.TypeDefaults.applyConfig({ LCSMaterial: { processAsItem: 'true' } });
608
+ expect(type_defaults_1.TypeDefaults.processLCSMaterialAsItem).toBe(true);
609
+ });
610
+ it('sets processLCSMaterialAsItem=false when processAsItem=false', () => {
611
+ type_defaults_1.TypeDefaults.processLCSMaterialAsItem = true;
612
+ type_defaults_1.TypeDefaults.applyConfig({ LCSMaterial: { processAsItem: false } });
613
+ expect(type_defaults_1.TypeDefaults.processLCSMaterialAsItem).toBe(false);
614
+ });
615
+ it('sets processLCSMaterialAsItem=false when LCSMaterial missing', () => {
616
+ type_defaults_1.TypeDefaults.processLCSMaterialAsItem = true;
617
+ type_defaults_1.TypeDefaults.applyConfig({});
618
+ expect(type_defaults_1.TypeDefaults.processLCSMaterialAsItem).toBe(false);
619
+ });
620
+ it('sets processLCSMaterialAsItem=false when config is null/undefined', () => {
621
+ type_defaults_1.TypeDefaults.processLCSMaterialAsItem = true;
622
+ type_defaults_1.TypeDefaults.applyConfig(undefined);
623
+ expect(type_defaults_1.TypeDefaults.processLCSMaterialAsItem).toBe(false);
624
+ });
515
625
  });
516
626
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrail/flexplm",
3
- "version": "1.4.0",
3
+ "version": "1.5.0-alpha.0d65410",
4
4
  "description": "Library used for integration with flexplm.",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -3,6 +3,7 @@ import { IdentifierConversion } from "./identifier-conversion";
3
3
  import { DataConverter } from "../util/data-converter";
4
4
  import { FCConfig } from "../interfaces/interfaces";
5
5
  import { Entities } from "@contrail/sdk";
6
+ import { TypeDefaults } from "../util/type-defaults";
6
7
 
7
8
  const mapFile1Data = require('./identifier-conversion-spec-mockData');
8
9
  const mapFile1Mappings = mapFile1Data?.mapping;
@@ -309,6 +310,37 @@ describe('getItemCriteriaFromObject', () => {
309
310
  }
310
311
  });
311
312
 
313
+ it('should return the item family criteria from the object -LCSMaterial', async () => {
314
+ const object = {
315
+ "flexPLMObjectClass": "LCSMaterial",
316
+ "flexPLMTypePath": "Material\\form",
317
+ "itemNumber": "MAT-100"
318
+ };
319
+ const criteriaObject = {
320
+ flexPLMObjectClass: 'LCSMaterial',
321
+ itemNumber: 'MAT-100',
322
+ flexPLMTypePath: 'Material\\form',
323
+ };
324
+ const resultsObject = {
325
+ roles: 'family',
326
+ itemNumber: 'MAT-100'
327
+ };
328
+ let getEntityValuesSpyOn = undefined
329
+ TypeDefaults.applyConfig({ LCSMaterial: { processAsItem: true } });
330
+ try {
331
+
332
+ getEntityValuesSpyOn = jest.spyOn(dc, 'getEntityValues');
333
+ const result = await IdentifierConversion.getItemCriteriaFromObject(transformMapFile1, mapFileUtil, dc, object);
334
+ expect(getEntityValuesSpyOn).toHaveBeenCalledWith('LCSMaterial', criteriaObject, []);
335
+ expect(result).toEqual(resultsObject);
336
+ } finally {
337
+ if (getEntityValuesSpyOn) {
338
+ getEntityValuesSpyOn.mockRestore();
339
+ }
340
+ TypeDefaults.applyConfig({});
341
+ }
342
+ });
343
+
312
344
  it('should return the item option criteria from the object -uniqueIdentifierA, uniqueIdentifierB', async () => {
313
345
  const object = {
314
346
  "flexBoolean": false,
@@ -274,7 +274,7 @@ export class IdentifierConversion {
274
274
 
275
275
  static async getItemCriteriaFromObject(transformMapFile: string, mapFileUtil: MapFileUtil, dc: DataConverter, object: any): Promise<any> {
276
276
  const criteria = await IdentifierConversion.getEntityCriteriaFromObject(transformMapFile, mapFileUtil, dc, object);
277
- const roles = (object.flexPLMObjectClass === 'LCSProduct') ? 'family' : 'color';
277
+ const roles = (['LCSProduct', 'LCSMaterial'].includes(object.flexPLMObjectClass)) ? 'family' : 'color';
278
278
  criteria['roles'] = roles;
279
279
 
280
280
  return criteria;
@@ -1,5 +1,6 @@
1
1
  import { ConfigDefaults } from './config-defaults';
2
2
  import { FCConfig } from '../interfaces/interfaces';
3
+ import { TypeDefaults } from './type-defaults';
3
4
 
4
5
  let entityObject = {};
5
6
  jest.mock('@contrail/sdk', () => {
@@ -356,6 +357,58 @@ describe('all tests', () => {
356
357
  });
357
358
  });
358
359
 
360
+ describe('getDefaultConfig', () => {
361
+ it('returns LCSMaterial.processAsItem=false by default', () => {
362
+ const dc: any = ConfigDefaults.getDefaultConfig();
363
+ expect(dc.LCSMaterial).toBeDefined();
364
+ expect(dc.LCSMaterial.processAsItem).toBe(false);
365
+ });
366
+
367
+ it('returns a fresh object each call (no shared reference)', () => {
368
+ const a: any = ConfigDefaults.getDefaultConfig();
369
+ const b: any = ConfigDefaults.getDefaultConfig();
370
+ expect(a).not.toBe(b);
371
+ expect(a.LCSMaterial).not.toBe(b.LCSMaterial);
372
+ a.LCSMaterial.processAsItem = true;
373
+ expect(b.LCSMaterial.processAsItem).toBe(false);
374
+ });
375
+ });
376
+
377
+ describe('setConfigDefaults - LCSMaterial', () => {
378
+ const config = {
379
+ apiHost: 'http://test.com',
380
+ userName: 'vibeiq',
381
+ password: 'vibeiq'
382
+ };
383
+
384
+ it('LCSMaterial.processAsItem-get default', async () => {
385
+ const startConfig = Object.assign({}, config);
386
+ const fcConfig: any = await ConfigDefaults.setConfigDefaults(startConfig);
387
+ expect(fcConfig.LCSMaterial.processAsItem).toBe(false);
388
+ });
389
+
390
+ it('LCSMaterial.processAsItem-override', async () => {
391
+ const startConfig: any = Object.assign({}, config);
392
+ startConfig.LCSMaterial = { processAsItem: true };
393
+ const fcConfig: any = await ConfigDefaults.setConfigDefaults(startConfig);
394
+ expect(fcConfig.LCSMaterial.processAsItem).toBe(true);
395
+ });
396
+
397
+ it('applies LCSMaterial.processAsItem to TypeDefaults', async () => {
398
+ try {
399
+ const startConfig: any = Object.assign({}, config, { LCSMaterial: { processAsItem: true } });
400
+ await ConfigDefaults.setConfigDefaults(startConfig);
401
+ expect(TypeDefaults.processLCSMaterialAsItem).toBe(true);
402
+
403
+ const defaultStart: any = Object.assign({}, config);
404
+ await ConfigDefaults.setConfigDefaults(defaultStart);
405
+ expect(TypeDefaults.processLCSMaterialAsItem).toBe(false);
406
+ } finally {
407
+ TypeDefaults.applyConfig({});
408
+ }
409
+ });
410
+ });
411
+
359
412
  describe('getConfigFile', () => {
360
413
  beforeEach(() => {
361
414
  ConfigDefaults.clearConfigCache();
@@ -1,6 +1,7 @@
1
1
  import { Entities } from '@contrail/sdk';
2
2
  import { FCConfig } from '../interfaces/interfaces';
3
3
  import { ObjectUtil } from '@contrail/util';
4
+ import { TypeDefaults } from './type-defaults';
4
5
 
5
6
  export class ConfigDefaults {
6
7
  static NEED_CONFIG_VALUES = 'To connect to FlexPLM all these APP values need to be set apiHost, userName, and password';
@@ -18,22 +19,7 @@ export class ConfigDefaults {
18
19
  delete config['itemPreDevelopmentLifecycleStages'];
19
20
  }
20
21
 
21
- const defaultConfig = {
22
- urlContext: '/Windchill',
23
- sendMode: {
24
- ASYNC_PUBLISH_SEASON: 'vibeiqfile'
25
- },
26
- itemPreDevelopmentLifecycleStages: ['concept'],
27
- identifierAtts: {
28
- LCSProduct: ['itemNumber'],
29
- LCSSeason: ['flexPLMSeasonName'],
30
- LCSSKU: ['itemNumber']
31
- },
32
- csrfEndpoint: '/servlet/rest/security/csrf',
33
- vibeEventEndpoint: '/rfa/vibeiq/vibeEvents',
34
- payloadDefaultAsArray: true
35
- };
36
- const configArr = [defaultConfig];
22
+ const configArr = [ConfigDefaults.getDefaultConfig()];
37
23
 
38
24
  if(config.configFile){
39
25
  const fileConfig = await ConfigDefaults.getConfigFile(config.configFile);
@@ -49,10 +35,33 @@ export class ConfigDefaults {
49
35
  //Don't allow overwriting this.
50
36
  outputConfig['OOBvibeEventEndpoint'] = '/rfa/vibeiq/vibeEvents';
51
37
 
38
+ TypeDefaults.applyConfig(outputConfig);
39
+
52
40
  console.log('outputConfig: ' + JSON.stringify(outputConfig));
53
41
  return outputConfig as FCConfig;
54
42
  }
55
43
 
44
+ static getDefaultConfig() {
45
+ return {
46
+ urlContext: '/Windchill',
47
+ sendMode: {
48
+ ASYNC_PUBLISH_SEASON: 'vibeiqfile'
49
+ },
50
+ itemPreDevelopmentLifecycleStages: ['concept'],
51
+ identifierAtts: {
52
+ LCSProduct: ['itemNumber'],
53
+ LCSSeason: ['flexPLMSeasonName'],
54
+ LCSSKU: ['itemNumber']
55
+ },
56
+ LCSMaterial: {
57
+ processAsItem: false
58
+ },
59
+ csrfEndpoint: '/servlet/rest/security/csrf',
60
+ vibeEventEndpoint: '/rfa/vibeiq/vibeEvents',
61
+ payloadDefaultAsArray: true
62
+ };
63
+ }
64
+
56
65
  static async getConfigFile(fileId: string) {
57
66
  try {
58
67