@contrail/flexplm 1.1.65 → 1.1.66

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.
@@ -280,6 +280,9 @@ class BaseEntityProcessor {
280
280
  const flexPayload = (payload) ? payload[0] : undefined;
281
281
  let outboundEntityUpdates = undefined;
282
282
  if (flexPayload && 'OK' === flexPayload.status) {
283
+ if (flexPayload.data && !flexPayload.data?.flexPLMObjectClass) {
284
+ flexPayload.data.flexPLMObjectClass = flexPayload.objectClass;
285
+ }
283
286
  const inboundData = await this.getTransformedData(flexPayload);
284
287
  outboundEntityUpdates = await this.getUpdatesForEntity(event.newData, inboundData);
285
288
  }
@@ -91,6 +91,85 @@ describe('BaseEntityProcessor', () => {
91
91
  expect(getUpdatesForEntitySpy).toBeCalledTimes(0);
92
92
  expect(updates).toBeUndefined();
93
93
  });
94
+ it('should set flexPLMObjectClass when data exists but flexPLMObjectClass is missing', async () => {
95
+ const btep = new TestBaseEntityProcessor(config, dc, mapFileUtil, 'test');
96
+ const event = { newData: { id: '123' } };
97
+ const flexResponse = {
98
+ data: {
99
+ payload: [
100
+ {
101
+ status: 'OK',
102
+ objectClass: 'Material',
103
+ data: {
104
+ name: 'Test Material'
105
+ }
106
+ }
107
+ ]
108
+ }
109
+ };
110
+ const getTransformedDataSpy = jest.spyOn(btep, 'getTransformedData').mockReturnValue(Promise.resolve({}));
111
+ const returnValue = {
112
+ name: 'Test'
113
+ };
114
+ const getUpdatesForEntitySpy = jest.spyOn(btep, 'getUpdatesForEntity').mockReturnValue(Promise.resolve(returnValue));
115
+ await btep.getOutboundEntityUpdates(event, flexResponse);
116
+ expect(flexResponse.data.payload[0].data['flexPLMObjectClass']).toBe('Material');
117
+ expect(getTransformedDataSpy).toBeCalledTimes(1);
118
+ expect(getTransformedDataSpy).toBeCalledWith(flexResponse.data.payload[0]);
119
+ expect(getUpdatesForEntitySpy).toBeCalledTimes(1);
120
+ });
121
+ it('should not override existing flexPLMObjectClass', async () => {
122
+ const btep = new TestBaseEntityProcessor(config, dc, mapFileUtil, 'test');
123
+ const event = { newData: { id: '123' } };
124
+ const flexResponse = {
125
+ data: {
126
+ payload: [
127
+ {
128
+ status: 'OK',
129
+ objectClass: 'Material',
130
+ data: {
131
+ name: 'Test Material',
132
+ flexPLMObjectClass: 'ExistingClass'
133
+ }
134
+ }
135
+ ]
136
+ }
137
+ };
138
+ const getTransformedDataSpy = jest.spyOn(btep, 'getTransformedData').mockReturnValue(Promise.resolve({}));
139
+ const returnValue = {
140
+ name: 'Test'
141
+ };
142
+ const getUpdatesForEntitySpy = jest.spyOn(btep, 'getUpdatesForEntity').mockReturnValue(Promise.resolve(returnValue));
143
+ await btep.getOutboundEntityUpdates(event, flexResponse);
144
+ expect(flexResponse.data.payload[0].data.flexPLMObjectClass).toBe('ExistingClass');
145
+ expect(getTransformedDataSpy).toBeCalledTimes(1);
146
+ expect(getTransformedDataSpy).toBeCalledWith(flexResponse.data.payload[0]);
147
+ expect(getUpdatesForEntitySpy).toBeCalledTimes(1);
148
+ });
149
+ it('should handle when data is null or undefined', async () => {
150
+ const btep = new TestBaseEntityProcessor(config, dc, mapFileUtil, 'test');
151
+ const event = { newData: { id: '123' } };
152
+ const flexResponse = {
153
+ data: {
154
+ payload: [
155
+ {
156
+ status: 'OK',
157
+ objectClass: 'Material',
158
+ data: null
159
+ }
160
+ ]
161
+ }
162
+ };
163
+ const getTransformedDataSpy = jest.spyOn(btep, 'getTransformedData').mockReturnValue(Promise.resolve({}));
164
+ const returnValue = {
165
+ name: 'Test'
166
+ };
167
+ const getUpdatesForEntitySpy = jest.spyOn(btep, 'getUpdatesForEntity').mockReturnValue(Promise.resolve(returnValue));
168
+ await btep.getOutboundEntityUpdates(event, flexResponse);
169
+ expect(getTransformedDataSpy).toBeCalledTimes(1);
170
+ expect(getTransformedDataSpy).toBeCalledWith(flexResponse.data.payload[0]);
171
+ expect(getUpdatesForEntitySpy).toBeCalledTimes(1);
172
+ });
94
173
  });
95
174
  describe('queryEntityWithSubType', () => {
96
175
  const config = {};
@@ -3,7 +3,6 @@ import { DataConverter } from '../util/data-converter';
3
3
  import { ItemFamilyChanges } from '../interfaces/item-family-changes';
4
4
  import { PublishChangeData } from '../interfaces/publish-change-data';
5
5
  import { MapFileUtil } from '@contrail/transform-data';
6
- import { AssortmentPublishChange } from '@contrail/entity-types';
7
6
  export declare class BaseProcessPublishAssortment {
8
7
  private TTL;
9
8
  static ASSORTMENT_NOT_PUBLISHABLE: string;
@@ -36,16 +35,16 @@ export declare class BaseProcessPublishAssortment {
36
35
  getSnapshotVersion(assortment: any, apc: any): Promise<number | string>;
37
36
  getSeasonFederation(assortmentId: any): Promise<SeasonFederation>;
38
37
  getAssortment(assortmentId: any): Promise<any>;
39
- getSinceDate(assortmentId: any, assortmentPublishChangeId: any, apcHistory: AssortmentPublishChange[]): Promise<Date>;
40
- getApcHistory(assortmentId: string): Promise<AssortmentPublishChange[]>;
38
+ getSinceDate(assortmentId: any, assortmentPublishChangeId: any, apcHistory: object[]): Promise<Date>;
39
+ getApcHistory(assortmentId: any): Promise<any>;
41
40
  protected updatedSinceDate(entity: any, sinceDate: Date): boolean;
42
- getSinceDateFromAPCSpecificDate(apcHistory: AssortmentPublishChange[], assortmentPublishChangeId: string, specificDate: Date): Date;
43
- getSinceDateDaysPrevious(apcHistory: AssortmentPublishChange[], assortmentPublishChangeId: string, daysBack: any): Date;
44
- getSinceDateFromAPCs(apcHistory: AssortmentPublishChange[], assortmentPublishChangeId: string, pastPublishCount?: number): Date;
45
- protected getPublisher(assortmentPublishChange: AssortmentPublishChange): {};
46
- downloadAssortmentPublishChange(assortmentId: string, assortmentPublishChangeId: string): Promise<AssortmentPublishChange>;
47
- downloadHydratedChangeDetail(assortmentPublishChange: AssortmentPublishChange): Promise<any>;
48
- downloadAssortmentBaseline(assortmentPublishChange: AssortmentPublishChange): Promise<any>;
41
+ getSinceDateFromAPCSpecificDate(apcHistory: any[], assortmentPublishChangeId: string, specificDate: Date): Date;
42
+ getSinceDateDaysPrevious(apcHistory: any[], assortmentPublishChangeId: string, daysBack: any): Date;
43
+ getSinceDateFromAPCs(apcHistory: any[], assortmentPublishChangeId: string, pastPublishCount?: number): Date;
44
+ protected getPublisher(assortmentPublishChange: any): {};
45
+ downloadAssortmentPublishChange(assortmentId: string, assortmentPublishChangeId: string): Promise<any>;
46
+ downloadHydratedChangeDetail(assortmentPublishChange: any): Promise<any>;
47
+ downloadAssortmentBaseline(assortmentPublishChange: any): Promise<any>;
49
48
  getDeleteChanges(assortmentPublishChange: any, apcHistory: any[], assortmentBaseline: any, sinceDate: Date): Promise<[]>;
50
49
  getBaselineItemIds(assortmentBaseline: any): string[];
51
50
  downloadDeleteChanges(apc: any): Promise<any>;
@@ -200,30 +200,14 @@ class BaseProcessPublishAssortment {
200
200
  return sinceDate;
201
201
  }
202
202
  async getApcHistory(assortmentId) {
203
- const apcs = [];
204
- const MAX_PAGES = 1000;
205
- let nextPageKey = null;
206
- const options = {
207
- entityName: 'assortment',
208
- id: assortmentId,
209
- apiVersion: sdk_1.API_VERSION.V2,
210
- nextPageKey,
211
- relation: 'history',
212
- };
213
- let i = 0;
214
- do {
215
- const response = await new sdk_1.Entities().get(options);
216
- if (response?.results) {
217
- apcs.push(...response.results);
203
+ const resource = `/assortments/${assortmentId}/history/`;
204
+ return sdk_1.Request.request(resource, {
205
+ method: 'GET',
206
+ headers: {
207
+ Accept: 'application/json',
208
+ 'Content-Type': 'application/json'
218
209
  }
219
- nextPageKey = response?.nextPageKey;
220
- options.nextPageKey = nextPageKey;
221
- i++;
222
- } while (nextPageKey && i < MAX_PAGES);
223
- if (i === MAX_PAGES && nextPageKey) {
224
- throw new Error('Max pages reached getting APC history for assortmentId: ' + assortmentId);
225
- }
226
- return apcs;
210
+ });
227
211
  }
228
212
  updatedSinceDate(entity, sinceDate) {
229
213
  const updatedOn = entity?.updatedOn;
@@ -277,8 +261,13 @@ class BaseProcessPublishAssortment {
277
261
  if (apcHistory.length === 1) {
278
262
  return new Date(0);
279
263
  }
280
- const apc = apcHistory.find(apc => apc.id === assortmentPublishChangeId);
264
+ const apcIndex = apcHistory.findIndex(apc => apc.id === assortmentPublishChangeId);
265
+ if (apcIndex === 0) {
266
+ return new Date(0);
267
+ }
268
+ const apc = apcHistory[apcIndex];
281
269
  const apcDate = new Date(apc?.createdOn);
270
+ let sinceDate = new Date(0);
282
271
  const dateArray = [];
283
272
  for (const tempapc of apcHistory) {
284
273
  if (assortmentPublishChangeId !== tempapc?.id) {
@@ -288,12 +277,10 @@ class BaseProcessPublishAssortment {
288
277
  }
289
278
  }
290
279
  }
291
- if (dateArray.length === 0 || pastPublishCount > dateArray.length) {
292
- return new Date(0);
293
- }
294
- dateArray.sort((a, b) => { return a.getTime() - b.getTime(); });
295
- const arrIndex = dateArray.length - pastPublishCount;
296
- return dateArray[arrIndex];
280
+ dateArray.sort((a, b) => { return Date.parse(a) - Date.parse(b); });
281
+ const arrIndex = (dateArray.length - pastPublishCount > 0) ? dateArray.length - pastPublishCount : 0;
282
+ sinceDate = dateArray[arrIndex];
283
+ return sinceDate;
297
284
  }
298
285
  getPublisher(assortmentPublishChange) {
299
286
  const createdBy = assortmentPublishChange?.createdBy;
@@ -624,8 +624,8 @@ describe('getSinceDateDaysPrevious', () => {
624
624
  expect(sinceDate).toEqual(matchDate);
625
625
  });
626
626
  });
627
- describe('getSinceDateFromAPCs - plan history in ascending order', () => {
628
- it('oldest / only apc', () => {
627
+ describe('getSinceDateFromAPCs', () => {
628
+ it('first / only apc', () => {
629
629
  const history = new Array(...mockData_1.plan1_history).slice(0, 1);
630
630
  const lastAPCId = 'v9BKkHo-tpL0wUZN';
631
631
  const matchDate = new Date(0);
@@ -636,7 +636,7 @@ describe('getSinceDateFromAPCs - plan history in ascending order', () => {
636
636
  const sinceDate = ppa.getSinceDateFromAPCs(history, lastAPCId);
637
637
  expect(sinceDate).toEqual(matchDate);
638
638
  });
639
- it('oldest / multiple apcs in history -ascending order', () => {
639
+ it('first / multiple apcs in history', () => {
640
640
  const history = new Array(...mockData_1.plan1_history).slice(0, 3);
641
641
  const lastAPCId = 'v9BKkHo-tpL0wUZN';
642
642
  const matchDate = new Date(0);
@@ -647,7 +647,7 @@ describe('getSinceDateFromAPCs - plan history in ascending order', () => {
647
647
  const sinceDate = ppa.getSinceDateFromAPCs(history, lastAPCId);
648
648
  expect(sinceDate).toEqual(matchDate);
649
649
  });
650
- it('most recent apc -ascending order', () => {
650
+ it('last apc', () => {
651
651
  const history = new Array(...mockData_1.plan1_history);
652
652
  const lastAPCId = 'sJbGx1Fpq1v2MmcI';
653
653
  const matchDate = new Date('2023-01-17T22:40:07.288Z');
@@ -658,7 +658,7 @@ describe('getSinceDateFromAPCs - plan history in ascending order', () => {
658
658
  const sinceDate = ppa.getSinceDateFromAPCs(history, lastAPCId);
659
659
  expect(sinceDate).toEqual(matchDate);
660
660
  });
661
- it('apc in the middle -ascending order', () => {
661
+ it('apc in the middle', () => {
662
662
  const history = new Array(...mockData_1.plan1_history);
663
663
  const lastAPCId = 'GiT9CZXZGVljoYMR';
664
664
  const matchDate = new Date('2023-01-16T21:50:42.742Z');
@@ -669,10 +669,10 @@ describe('getSinceDateFromAPCs - plan history in ascending order', () => {
669
669
  const sinceDate = ppa.getSinceDateFromAPCs(history, lastAPCId);
670
670
  expect(sinceDate).toEqual(matchDate);
671
671
  });
672
- it('pastPublishCount greater than array size -ascending order; so include all changes', () => {
672
+ it('pastPublishCount greater than array size', () => {
673
673
  const history = new Array(...mockData_1.plan1_history);
674
674
  const lastAPCId = 'sJbGx1Fpq1v2MmcI';
675
- const matchDate = new Date(0);
675
+ const matchDate = new Date('2023-01-15T19:13:58.902Z');
676
676
  const config = {};
677
677
  const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
678
678
  const dc = new data_converter_1.DataConverter(config, mapFileUtil);
@@ -680,7 +680,7 @@ describe('getSinceDateFromAPCs - plan history in ascending order', () => {
680
680
  const sinceDate = ppa.getSinceDateFromAPCs(history, lastAPCId, 20);
681
681
  expect(sinceDate).toEqual(matchDate);
682
682
  });
683
- it('pastPublishCount at 3 -ascending order', () => {
683
+ it('pastPublishCount at 3 ', () => {
684
684
  const history = new Array(...mockData_1.plan1_history);
685
685
  const lastAPCId = 'sJbGx1Fpq1v2MmcI';
686
686
  const matchDate = new Date('2023-01-17T22:35:20.517Z');
@@ -692,74 +692,6 @@ describe('getSinceDateFromAPCs - plan history in ascending order', () => {
692
692
  expect(sinceDate).toEqual(matchDate);
693
693
  });
694
694
  });
695
- describe('getSinceDateFromAPCs - plan history in descending order', () => {
696
- it('oldest / only apc', () => {
697
- const history = new Array(...mockData_1.plan1_history_descending).slice(0, 1);
698
- const lastAPCId = 'sJbGx1Fpq1v2MmcI';
699
- const matchDate = new Date(0);
700
- const config = {};
701
- const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
702
- const dc = new data_converter_1.DataConverter(config, mapFileUtil);
703
- const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
704
- const sinceDate = ppa.getSinceDateFromAPCs(history, lastAPCId);
705
- expect(sinceDate).toEqual(matchDate);
706
- });
707
- it('oldest / multiple apcs in history -descending order', () => {
708
- const history = new Array(...mockData_1.plan1_history_descending).slice(0, 3);
709
- const lastAPCId = '4JM83QNiIO0IBkck';
710
- const matchDate = new Date(0);
711
- const config = {};
712
- const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
713
- const dc = new data_converter_1.DataConverter(config, mapFileUtil);
714
- const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
715
- const sinceDate = ppa.getSinceDateFromAPCs(history, lastAPCId);
716
- expect(sinceDate).toEqual(matchDate);
717
- });
718
- it('most recent apc -descending order', () => {
719
- const history = new Array(...mockData_1.plan1_history_descending);
720
- const lastAPCId = 'sJbGx1Fpq1v2MmcI';
721
- const matchDate = new Date('2023-01-17T22:40:07.288Z');
722
- const config = {};
723
- const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
724
- const dc = new data_converter_1.DataConverter(config, mapFileUtil);
725
- const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
726
- const sinceDate = ppa.getSinceDateFromAPCs(history, lastAPCId);
727
- expect(sinceDate).toEqual(matchDate);
728
- });
729
- it('apc in the middle -descending order', () => {
730
- const history = new Array(...mockData_1.plan1_history_descending);
731
- const lastAPCId = 'GiT9CZXZGVljoYMR';
732
- const matchDate = new Date('2023-01-16T21:50:42.742Z');
733
- const config = {};
734
- const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
735
- const dc = new data_converter_1.DataConverter(config, mapFileUtil);
736
- const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
737
- const sinceDate = ppa.getSinceDateFromAPCs(history, lastAPCId);
738
- expect(sinceDate).toEqual(matchDate);
739
- });
740
- it('pastPublishCount greater than array size -descending order; so include all changes', () => {
741
- const history = new Array(...mockData_1.plan1_history_descending);
742
- const lastAPCId = 'sJbGx1Fpq1v2MmcI';
743
- const matchDate = new Date(0);
744
- const config = {};
745
- const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
746
- const dc = new data_converter_1.DataConverter(config, mapFileUtil);
747
- const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
748
- const sinceDate = ppa.getSinceDateFromAPCs(history, lastAPCId, 20);
749
- expect(sinceDate).toEqual(matchDate);
750
- });
751
- it('pastPublishCount at 3 -descending order', () => {
752
- const history = new Array(...mockData_1.plan1_history_descending);
753
- const lastAPCId = 'sJbGx1Fpq1v2MmcI';
754
- const matchDate = new Date('2023-01-17T22:35:20.517Z');
755
- const config = {};
756
- const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
757
- const dc = new data_converter_1.DataConverter(config, mapFileUtil);
758
- const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
759
- const sinceDate = ppa.getSinceDateFromAPCs(history, lastAPCId, 3);
760
- expect(sinceDate).toEqual(matchDate);
761
- });
762
- });
763
695
  describe('getDeleteChanges', () => {
764
696
  const config = {};
765
697
  const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
@@ -993,7 +925,6 @@ describe('buildDeleteChanges', () => {
993
925
  ];
994
926
  const apc = {};
995
927
  const fullAPC = {
996
- id: 'apcId',
997
928
  deleteDataDownloadLink: 'deleteDataDownloadLink',
998
929
  returnedDeleteData
999
930
  };
@@ -1019,7 +950,6 @@ describe('buildDeleteChanges', () => {
1019
950
  ];
1020
951
  const apc = {};
1021
952
  const fullAPC = {
1022
- id: 'apcId',
1023
953
  returnedDeleteData
1024
954
  };
1025
955
  const previousApc = undefined;
@@ -1049,9 +979,7 @@ describe('buildDeleteChanges', () => {
1049
979
  deletes: [{ id: '1' }, { id: '3' }]
1050
980
  }
1051
981
  };
1052
- const previousApc = {
1053
- id: 'previousApcId',
1054
- };
982
+ const previousApc = {};
1055
983
  const fullPreviousApc = {
1056
984
  id: previousApcId,
1057
985
  assortmentBaselineDownloadLink: 'assortmentBaselineDownloadLink'
@@ -66,74 +66,6 @@ export declare const plan1_history: ({
66
66
  createdById: string;
67
67
  adds: number;
68
68
  })[];
69
- export declare const plan1_history_descending: ({
70
- summary: {
71
- assortmentId: string;
72
- count: number;
73
- aggregates: {
74
- flexCurrency: {
75
- average: number;
76
- total: number;
77
- min: number;
78
- max: number;
79
- };
80
- totalMargin: {};
81
- };
82
- updatedOn: string;
83
- id: string;
84
- updatedById: string;
85
- createdOn: string;
86
- createdById: string;
87
- orgId: string;
88
- };
89
- deletes: number;
90
- versionComments: string;
91
- unchanged: number;
92
- updatedOn: string;
93
- versionName: string;
94
- updates: number;
95
- updatedById: string;
96
- createdOn: string;
97
- orgId: string;
98
- familyItemsRemoved: number;
99
- createdBy: string;
100
- assortmentId: string;
101
- id: string;
102
- errors: number;
103
- createdById: string;
104
- adds: number;
105
- } | {
106
- summary: {
107
- assortmentId: string;
108
- count: number;
109
- aggregates: {
110
- totalMargin: {};
111
- flexCurrency?: undefined;
112
- };
113
- updatedOn: string;
114
- id: string;
115
- updatedById: string;
116
- createdOn: string;
117
- createdById: string;
118
- orgId: string;
119
- };
120
- deletes: number;
121
- versionComments: string;
122
- unchanged: number;
123
- updatedOn: string;
124
- versionName: string;
125
- updates: number;
126
- updatedById: string;
127
- createdOn: string;
128
- orgId: string;
129
- familyItemsRemoved: number;
130
- createdBy: string;
131
- assortmentId: string;
132
- id: string;
133
- errors: number;
134
- createdById: string;
135
- adds: number;
136
- })[];
137
69
  export declare const plan1_across_month_DST: {
138
70
  versionName: string;
139
71
  createdOn: string;