@contrail/flexplm 1.1.43 → 1.1.45

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.
@@ -27,4 +27,5 @@ Describe the testing you added to this PR
27
27
 
28
28
 
29
29
  ## Link to Jira ticket(s)
30
+ https://vibe-team.atlassian.net/browse/TICKET_NUMBER_HERE
30
31
 
@@ -162,7 +162,8 @@ class BaseEntityProcessor {
162
162
  return flexResponse;
163
163
  }
164
164
  async getOutboundEntityUpdates(event, flexResponse) {
165
- const flexPayload = flexResponse?.data?.payload[0];
165
+ const payload = flexResponse?.data?.payload;
166
+ const flexPayload = (payload) ? payload[0] : undefined;
166
167
  let outboundEntityUpdates = undefined;
167
168
  if (flexPayload && 'OK' === flexPayload.status) {
168
169
  const inboundData = await this.getTransformedData(flexPayload);
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const sdk_1 = require("@contrail/sdk");
4
+ const transform_data_1 = require("@contrail/transform-data");
5
+ const data_converter_1 = require("../util/data-converter");
6
+ const base_entity_processor_1 = require("./base-entity-processor");
7
+ class TestBaseEntityProcessor extends base_entity_processor_1.BaseEntityProcessor {
8
+ getIncomingEntity(event, inboundData) {
9
+ throw new Error("Method not implemented.");
10
+ }
11
+ getCreateEntity(inboundData) {
12
+ throw new Error("Method not implemented.");
13
+ }
14
+ getOutgoingUpsertPayload(entityType, event) {
15
+ throw new Error("Method not implemented.");
16
+ }
17
+ }
18
+ describe('BaseEntityProcessor', () => {
19
+ describe('getOutboundEntityUpdates', () => {
20
+ const config = {};
21
+ const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
22
+ const dc = new data_converter_1.DataConverter(config, mapFileUtil);
23
+ it('no payload', async () => {
24
+ const btep = new TestBaseEntityProcessor(config, dc, mapFileUtil, 'test');
25
+ const event = {};
26
+ const flexResponse = {};
27
+ const updates = await btep.getOutboundEntityUpdates(event, flexResponse);
28
+ expect(updates).toBeUndefined();
29
+ });
30
+ it('flexPayload.status === OK', async () => {
31
+ const btep = new TestBaseEntityProcessor(config, dc, mapFileUtil, 'test');
32
+ const event = {};
33
+ const flexResponse = {
34
+ data: {
35
+ payload: [
36
+ {
37
+ status: 'OK'
38
+ }
39
+ ]
40
+ }
41
+ };
42
+ const getTransformedDataSpy = jest.spyOn(btep, 'getTransformedData').mockReturnValue(Promise.resolve({}));
43
+ const returnValue = {
44
+ name: 'Test'
45
+ };
46
+ const getUpdatesForEntitySpy = jest.spyOn(btep, 'getUpdatesForEntity').mockReturnValue(Promise.resolve(returnValue));
47
+ const updates = await btep.getOutboundEntityUpdates(event, flexResponse);
48
+ expect(getTransformedDataSpy).toBeCalledTimes(1);
49
+ expect(getUpdatesForEntitySpy).toBeCalledTimes(1);
50
+ expect(updates).toBe(returnValue);
51
+ });
52
+ it('flexPayload.status === FAIL', async () => {
53
+ const btep = new TestBaseEntityProcessor(config, dc, mapFileUtil, 'test');
54
+ const event = {};
55
+ const flexResponse = {
56
+ data: {
57
+ payload: [
58
+ {
59
+ status: 'FAIL'
60
+ }
61
+ ]
62
+ }
63
+ };
64
+ const getTransformedDataSpy = jest.spyOn(btep, 'getTransformedData').mockReturnValue(Promise.resolve({}));
65
+ const returnValue = {
66
+ name: 'Test'
67
+ };
68
+ const getUpdatesForEntitySpy = jest.spyOn(btep, 'getUpdatesForEntity').mockReturnValue(Promise.resolve(returnValue));
69
+ const updates = await btep.getOutboundEntityUpdates(event, flexResponse);
70
+ expect(getTransformedDataSpy).toBeCalledTimes(0);
71
+ expect(getUpdatesForEntitySpy).toBeCalledTimes(0);
72
+ expect(updates).toBeUndefined();
73
+ });
74
+ });
75
+ });
@@ -69,6 +69,7 @@ export interface AsyncEventsPayloadType extends AsyncPayloadType {
69
69
  events?: PayloadType[];
70
70
  eventsFileId?: string;
71
71
  eventsDownloadLink?: string;
72
+ eventsAdminDownloadLink?: string;
72
73
  }
73
74
  export interface EntityPayloadType extends PayloadType {
74
75
  entityReference: string;
@@ -584,7 +584,8 @@ class BaseProcessPublishAssortment {
584
584
  eventType,
585
585
  objectClass: 'LCSSeason',
586
586
  eventsFileId: uploadFile.id,
587
- eventsDownloadLink: uploadFile.downloadUrl
587
+ eventsDownloadLink: uploadFile.downloadUrl,
588
+ eventsAdminDownloadLink: uploadFile.adminDownloadUrl
588
589
  };
589
590
  if (sendMode === 'vibeiqfile') {
590
591
  const flexPLMConnect = new flexplm_connect_1.FlexPLMConnect(this.config);
@@ -1,6 +1,8 @@
1
1
  import { FCConfig } from '../interfaces/interfaces';
2
2
  export declare class ConfigDefaults {
3
3
  static NEED_CONFIG_VALUES: string;
4
+ static STATIC_CONFIG_CACHE: {};
4
5
  static setConfigDefaults(config: any): Promise<FCConfig>;
5
6
  static getConfigFile(fileId: string): Promise<any>;
7
+ static clearConfigCache(): void;
6
8
  }
@@ -46,6 +46,10 @@ class ConfigDefaults {
46
46
  }
47
47
  static async getConfigFile(fileId) {
48
48
  try {
49
+ if (ConfigDefaults.STATIC_CONFIG_CACHE[fileId]) {
50
+ console.debug('returning cached config file: ' + fileId);
51
+ return ConfigDefaults.STATIC_CONFIG_CACHE[fileId];
52
+ }
49
53
  const options = {
50
54
  entityName: 'file',
51
55
  id: fileId,
@@ -62,6 +66,9 @@ class ConfigDefaults {
62
66
  }
63
67
  const response = await fetch(downloadUrl);
64
68
  const config = await response.json();
69
+ if (config) {
70
+ ConfigDefaults.STATIC_CONFIG_CACHE[fileId] = config;
71
+ }
65
72
  return config ? config : {};
66
73
  }
67
74
  catch (e) {
@@ -69,6 +76,10 @@ class ConfigDefaults {
69
76
  return {};
70
77
  }
71
78
  }
79
+ static clearConfigCache() {
80
+ ConfigDefaults.STATIC_CONFIG_CACHE = {};
81
+ }
72
82
  }
73
83
  exports.ConfigDefaults = ConfigDefaults;
74
84
  ConfigDefaults.NEED_CONFIG_VALUES = 'To connect to FlexPLM all these APP values need to be set apiHost, userName, and password';
85
+ ConfigDefaults.STATIC_CONFIG_CACHE = {};
@@ -265,6 +265,9 @@ describe('all tests', () => {
265
265
  });
266
266
  });
267
267
  describe('getConfigFile', () => {
268
+ beforeEach(() => {
269
+ config_defaults_1.ConfigDefaults.clearConfigCache();
270
+ });
268
271
  it('response has test var', async () => {
269
272
  fetchJson = { testVar: true };
270
273
  entityObject = { downloadUrl: 'http://sss.com' };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrail/flexplm",
3
- "version": "1.1.43",
3
+ "version": "1.1.45",
4
4
  "description": "Library used for integration with flexplm.",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -41,7 +41,7 @@
41
41
  "dependencies": {
42
42
  "@contrail/app-framework": "^1.2.4",
43
43
  "@contrail/sdk": "^1.3.7",
44
- "@contrail/transform-data": "^1.0.15",
44
+ "@contrail/transform-data": "^1.1.1",
45
45
  "axios": "^1.4.0",
46
46
  "p-limit": "^3.1.0"
47
47
  }
@@ -0,0 +1,80 @@
1
+ import { Entities } from "@contrail/sdk";
2
+ import { MapFileUtil } from "@contrail/transform-data";
3
+ import { EntityPayloadType, FCConfig } from "../interfaces/interfaces";
4
+ import { DataConverter } from "../util/data-converter";
5
+ import { BaseEntityProcessor, IncomingEntityResponse } from "./base-entity-processor";
6
+
7
+ class TestBaseEntityProcessor extends BaseEntityProcessor {
8
+ protected getIncomingEntity(event: any, inboundData: any): Promise<IncomingEntityResponse> {
9
+ throw new Error("Method not implemented.");
10
+ }
11
+ protected getCreateEntity(inboundData: any): Promise<IncomingEntityResponse> {
12
+ throw new Error("Method not implemented.");
13
+ }
14
+ protected getOutgoingUpsertPayload(entityType: any, event: any): Promise<EntityPayloadType> {
15
+ throw new Error("Method not implemented.");
16
+ }
17
+
18
+ }
19
+ describe('BaseEntityProcessor', () =>{
20
+ describe('getOutboundEntityUpdates', () =>{
21
+
22
+ const config = {} as FCConfig;
23
+ const mapFileUtil = new MapFileUtil(new Entities());
24
+ const dc = new DataConverter(config, mapFileUtil);
25
+ it('no payload', async () =>{
26
+ const btep = new TestBaseEntityProcessor(config, dc, mapFileUtil, 'test');
27
+ const event = {};
28
+ const flexResponse = {};
29
+
30
+ const updates = await btep.getOutboundEntityUpdates(event, flexResponse);
31
+ expect(updates).toBeUndefined();
32
+ });
33
+
34
+ it('flexPayload.status === OK', async () =>{
35
+ const btep = new TestBaseEntityProcessor(config, dc, mapFileUtil, 'test');
36
+ const event = {};
37
+ const flexResponse = {
38
+ data: {
39
+ payload: [
40
+ {
41
+ status: 'OK'
42
+ }
43
+ ]
44
+ }
45
+ };
46
+ const getTransformedDataSpy = jest.spyOn(btep, 'getTransformedData').mockReturnValue(Promise.resolve({}));
47
+ const returnValue = {
48
+ name: 'Test'
49
+ };
50
+ const getUpdatesForEntitySpy = jest.spyOn(btep, 'getUpdatesForEntity').mockReturnValue(Promise.resolve(returnValue));
51
+ const updates = await btep.getOutboundEntityUpdates(event, flexResponse);
52
+ expect(getTransformedDataSpy).toBeCalledTimes(1);
53
+ expect(getUpdatesForEntitySpy).toBeCalledTimes(1);
54
+ expect(updates).toBe(returnValue);
55
+ });
56
+
57
+ it('flexPayload.status === FAIL', async () =>{
58
+ const btep = new TestBaseEntityProcessor(config, dc, mapFileUtil, 'test');
59
+ const event = {};
60
+ const flexResponse = {
61
+ data: {
62
+ payload: [
63
+ {
64
+ status: 'FAIL'
65
+ }
66
+ ]
67
+ }
68
+ };
69
+ const getTransformedDataSpy = jest.spyOn(btep, 'getTransformedData').mockReturnValue(Promise.resolve({}));
70
+ const returnValue = {
71
+ name: 'Test'
72
+ };
73
+ const getUpdatesForEntitySpy = jest.spyOn(btep, 'getUpdatesForEntity').mockReturnValue(Promise.resolve(returnValue));
74
+ const updates = await btep.getOutboundEntityUpdates(event, flexResponse);
75
+ expect(getTransformedDataSpy).toBeCalledTimes(0);
76
+ expect(getUpdatesForEntitySpy).toBeCalledTimes(0);
77
+ expect(updates).toBeUndefined();
78
+ });
79
+ });
80
+ });
@@ -210,7 +210,8 @@ export abstract class BaseEntityProcessor {
210
210
  }
211
211
 
212
212
  async getOutboundEntityUpdates(event, flexResponse): Promise<any> {
213
- const flexPayload = flexResponse?.data?.payload[0];
213
+ const payload = flexResponse?.data?.payload;
214
+ const flexPayload = (payload)? payload[0] : undefined;
214
215
  let outboundEntityUpdates = undefined;
215
216
  if(flexPayload && 'OK' === flexPayload.status) {
216
217
  const inboundData = await this.getTransformedData(flexPayload);
@@ -74,6 +74,7 @@ export interface AsyncEventsPayloadType extends AsyncPayloadType {
74
74
  events?: PayloadType[];
75
75
  eventsFileId?: string;
76
76
  eventsDownloadLink?: string;
77
+ eventsAdminDownloadLink?: string;
77
78
  }
78
79
 
79
80
  export interface EntityPayloadType extends PayloadType {
@@ -707,8 +707,9 @@ export class BaseProcessPublishAssortment {
707
707
  eventType,
708
708
  objectClass: 'LCSSeason',
709
709
  eventsFileId: uploadFile.id,
710
- eventsDownloadLink: uploadFile.downloadUrl
711
- };
710
+ eventsDownloadLink: uploadFile.downloadUrl,
711
+ eventsAdminDownloadLink: uploadFile.adminDownloadUrl
712
+ };
712
713
 
713
714
  if (sendMode === 'vibeiqfile') {
714
715
  const flexPLMConnect = new FlexPLMConnect(this.config);
@@ -315,6 +315,10 @@ describe('all tests', () => {
315
315
  });
316
316
 
317
317
  describe('getConfigFile', () => {
318
+ beforeEach(() => {
319
+ ConfigDefaults.clearConfigCache();
320
+ });
321
+
318
322
  it('response has test var', async () => {
319
323
  fetchJson = { testVar: true };
320
324
  entityObject = { downloadUrl: 'http://sss.com' };
@@ -4,6 +4,7 @@ import { ObjectUtil } from '@contrail/util';
4
4
 
5
5
  export class ConfigDefaults {
6
6
  static NEED_CONFIG_VALUES = 'To connect to FlexPLM all these APP values need to be set apiHost, userName, and password';
7
+ static STATIC_CONFIG_CACHE = {};
7
8
  static async setConfigDefaults(config): Promise<FCConfig> {
8
9
  //Validate config
9
10
  if (!config.apiHost || !config.userName || !config.password) {
@@ -55,6 +56,10 @@ export class ConfigDefaults {
55
56
  static async getConfigFile(fileId: string) {
56
57
  try {
57
58
 
59
+ if(ConfigDefaults.STATIC_CONFIG_CACHE[fileId]){
60
+ console.debug('returning cached config file: ' + fileId);
61
+ return ConfigDefaults.STATIC_CONFIG_CACHE[fileId];
62
+ }
58
63
  const options = {
59
64
  entityName: 'file',
60
65
  id: fileId,
@@ -72,10 +77,17 @@ export class ConfigDefaults {
72
77
  }
73
78
  const response = await fetch(downloadUrl);
74
79
  const config = await response.json();
80
+ if(config){
81
+ ConfigDefaults.STATIC_CONFIG_CACHE[fileId] = config;
82
+ }
75
83
  return config ? config: {};
76
84
  }catch(e){
77
85
  console.log('Error getting config file: ' + fileId + '- ' +e.message);
78
86
  return {};
79
87
  }
80
88
  }
89
+
90
+ static clearConfigCache(){
91
+ ConfigDefaults.STATIC_CONFIG_CACHE = {};
92
+ }
81
93
  }