@contrail/flexplm 1.1.13 → 1.1.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/.github/pull_request_template.md +30 -0
  2. package/.github/workflows/flexplm-lib.yml +27 -0
  3. package/lib/flexplm-utils.spec.d.ts +1 -0
  4. package/lib/flexplm-utils.spec.js +26 -0
  5. package/lib/publish/base-process-publish-assortment.spec.d.ts +1 -0
  6. package/lib/publish/base-process-publish-assortment.spec.js +1053 -0
  7. package/lib/util/config-defaults.spec.d.ts +1 -0
  8. package/lib/util/config-defaults.spec.js +264 -0
  9. package/lib/util/data-converter.d.ts +4 -0
  10. package/lib/util/data-converter.js +88 -1
  11. package/lib/util/data-converter.spec.d.ts +1 -0
  12. package/lib/util/data-converter.spec.js +591 -0
  13. package/lib/util/map-utils.d.ts +2 -2
  14. package/lib/util/map-utils.js +5 -28
  15. package/lib/util/map-utils.spec.d.ts +1 -0
  16. package/lib/util/map-utils.spec.js +89 -0
  17. package/lib/util/thumbnail-util.spec.d.ts +1 -0
  18. package/lib/util/thumbnail-util.spec.js +132 -0
  19. package/lib/util/type-conversion-utils-spec-mockData.js +21 -0
  20. package/lib/util/type-conversion-utils.d.ts +7 -0
  21. package/lib/util/type-conversion-utils.js +88 -4
  22. package/lib/util/type-conversion-utils.spec.d.ts +1 -0
  23. package/lib/util/type-conversion-utils.spec.js +547 -0
  24. package/lib/util/type-defaults.d.ts +5 -0
  25. package/lib/util/type-defaults.js +66 -0
  26. package/lib/util/type-defaults.spec.d.ts +1 -0
  27. package/lib/util/type-defaults.spec.js +460 -0
  28. package/lib/util/type-utils.spec.d.ts +1 -0
  29. package/lib/util/type-utils.spec.js +190 -0
  30. package/package.json +2 -2
  31. package/publish.bat +5 -0
  32. package/publish.sh +5 -0
  33. package/src/entity-processor/base-entity-processor.ts +183 -0
  34. package/src/flexplm-request.ts +28 -0
  35. package/src/flexplm-utils.spec.ts +27 -0
  36. package/src/flexplm-utils.ts +29 -0
  37. package/src/index.ts +20 -0
  38. package/src/interfaces/interfaces.ts +120 -0
  39. package/src/interfaces/item-family-changes.ts +67 -0
  40. package/src/interfaces/publish-change-data.ts +43 -0
  41. package/src/publish/base-process-publish-assortment-callback.ts +23 -0
  42. package/src/publish/base-process-publish-assortment.spec.ts +1239 -0
  43. package/src/publish/base-process-publish-assortment.ts +1024 -0
  44. package/src/publish/mockData.ts +4561 -0
  45. package/src/transform/identifier-conversion.ts +226 -0
  46. package/src/util/config-defaults.spec.ts +315 -0
  47. package/src/util/config-defaults.ts +79 -0
  48. package/src/util/data-converter-spec-mockData.ts +231 -0
  49. package/src/util/data-converter.spec.ts +872 -0
  50. package/src/util/data-converter.ts +507 -0
  51. package/src/util/federation.ts +172 -0
  52. package/src/util/flexplm-connect.ts +169 -0
  53. package/src/util/logger-config.ts +20 -0
  54. package/src/util/map-util-spec-mockData.ts +231 -0
  55. package/src/util/map-utils.spec.ts +103 -0
  56. package/src/util/map-utils.ts +40 -0
  57. package/src/util/mockData.ts +98 -0
  58. package/src/util/thumbnail-util.spec.ts +152 -0
  59. package/src/util/thumbnail-util.ts +128 -0
  60. package/src/util/type-conversion-utils-spec-mockData.ts +238 -0
  61. package/src/util/type-conversion-utils.spec.ts +601 -0
  62. package/src/util/type-conversion-utils.ts +345 -0
  63. package/src/util/type-defaults.spec.ts +592 -0
  64. package/src/util/type-defaults.ts +261 -0
  65. package/src/util/type-utils.spec.ts +227 -0
  66. package/src/util/type-utils.ts +124 -0
  67. package/tsconfig.json +27 -0
  68. package/tslint.json +57 -0
@@ -0,0 +1,1053 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const base_process_publish_assortment_1 = require("./base-process-publish-assortment");
4
+ const mockData_1 = require("./mockData");
5
+ const data_converter_1 = require("../util/data-converter");
6
+ const publish_change_data_1 = require("../interfaces/publish-change-data");
7
+ const transform_data_1 = require("@contrail/transform-data");
8
+ const sdk_1 = require("@contrail/sdk");
9
+ const type_conversion_utils_1 = require("../util/type-conversion-utils");
10
+ const map_utils_1 = require("../util/map-utils");
11
+ const item_family_changes_1 = require("../interfaces/item-family-changes");
12
+ let federatedId = '';
13
+ jest.mock('../util/data-converter', () => {
14
+ return {
15
+ DataConverter: class {
16
+ getFlexPLMObjectData(newData, dataToSkip, inflateObjRef) {
17
+ return newData;
18
+ }
19
+ }
20
+ };
21
+ });
22
+ jest.mock('../util/federation', () => {
23
+ return {
24
+ Federation: class {
25
+ getFederatedMappedRefId() {
26
+ return federatedId;
27
+ }
28
+ }
29
+ };
30
+ });
31
+ jest.mock('@contrail/sdk', () => {
32
+ const entityObject = { publishToFlexPLM: true };
33
+ return {
34
+ Entities: class {
35
+ get() {
36
+ return entityObject;
37
+ }
38
+ }
39
+ };
40
+ });
41
+ describe('process publish assortment', () => {
42
+ const config = {
43
+ identifierAtts: {
44
+ LCSSeason: ['flexPLMSeasonName']
45
+ }
46
+ };
47
+ beforeEach(() => {
48
+ federatedId = '';
49
+ });
50
+ it('No Federation Info', async () => {
51
+ const event = {
52
+ assortmentId: 'B3oRQpYVYzcJAJtQ'
53
+ };
54
+ const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
55
+ const dc = new data_converter_1.DataConverter(config, mapFileUtil);
56
+ const results = await new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil).process(event);
57
+ expect(results['results']['message']).toEqual(base_process_publish_assortment_1.BaseProcessPublishAssortment.ASSORTMENT_NO_FED_INFO + config.identifierAtts.LCSSeason);
58
+ });
59
+ });
60
+ describe('getSeasonFederation', () => {
61
+ const config = {
62
+ identifierAtts: {
63
+ LCSSeason: ['flexPLMSeasonName']
64
+ }
65
+ };
66
+ beforeEach(() => {
67
+ federatedId = '';
68
+ });
69
+ it('No Federation Info', async () => {
70
+ const assortmentId = 'B3oRQpYVYzcJAJtQ';
71
+ try {
72
+ const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
73
+ const dc = new data_converter_1.DataConverter(config, mapFileUtil);
74
+ await new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil).getSeasonFederation(assortmentId);
75
+ }
76
+ catch (e) {
77
+ expect(e.message).toEqual(base_process_publish_assortment_1.BaseProcessPublishAssortment.ASSORTMENT_NO_FED_INFO + config.identifierAtts.LCSSeason);
78
+ }
79
+ });
80
+ });
81
+ describe('Test getSinceDate', () => {
82
+ it('getSinceDate from getSinceDateFromAPCs', async () => {
83
+ const history = new Array(...mockData_1.plan1_history);
84
+ const lastAPCId = 'sJbGx1Fpq1v2MmcI';
85
+ const matchDate = new Date('2023-01-17T22:40:07.288Z');
86
+ const config = {};
87
+ const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
88
+ const dc = new data_converter_1.DataConverter(config, mapFileUtil);
89
+ const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
90
+ ppa.getApcHistory = async () => {
91
+ return history;
92
+ };
93
+ const sinceDate = await ppa.getSinceDate('oqIFX3ELRy8sFRd0', lastAPCId, history);
94
+ expect(sinceDate).toEqual(matchDate);
95
+ });
96
+ it('getSinceDate date from config as year', async () => {
97
+ const history = new Array(...mockData_1.plan1_history);
98
+ const lastAPCId = 'sJbGx1Fpq1v2MmcI';
99
+ const matchDate = new Date('2023-01-17T22:35:20.517Z');
100
+ const config = { sinceDate: '2023-01-17' };
101
+ const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
102
+ const dc = new data_converter_1.DataConverter(config, mapFileUtil);
103
+ const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
104
+ ppa.getApcHistory = async () => {
105
+ return history;
106
+ };
107
+ const sinceDate = await ppa.getSinceDate('oqIFX3ELRy8sFRd0', lastAPCId, history);
108
+ expect(sinceDate).toEqual(matchDate);
109
+ });
110
+ it('getSinceDate date from config numberofdays-cross month', async () => {
111
+ const count = 10;
112
+ const history = new Array(...mockData_1.plan1_across_month_DST);
113
+ const lastAPCId = '_mj--7nlyp7mmDrK';
114
+ const matchDate = new Date('2023-02-25T19:13:58.902Z');
115
+ const config = { sinceDate: 'numberofdays:' + count };
116
+ const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
117
+ const dc = new data_converter_1.DataConverter(config, mapFileUtil);
118
+ const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
119
+ const sinceDate = await ppa.getSinceDate('oqIFX3ELRy8sFRd0', lastAPCId, history);
120
+ expect(sinceDate).toEqual(matchDate);
121
+ });
122
+ it('getSinceDate date from config numberofdays-cross DST', async () => {
123
+ const count = 12;
124
+ const history = new Array(...mockData_1.plan1_across_month_DST);
125
+ const lastAPCId = 'sJbGx1Fpq1v2MmcI';
126
+ const matchDate = new Date('2023-03-06T21:50:42.742Z');
127
+ const config = { sinceDate: 'numberofdays:' + count };
128
+ const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
129
+ const dc = new data_converter_1.DataConverter(config, mapFileUtil);
130
+ const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
131
+ const sinceDate = await ppa.getSinceDate('oqIFX3ELRy8sFRd0', lastAPCId, history);
132
+ expect(sinceDate).toEqual(matchDate);
133
+ });
134
+ it('getSinceDate date from config numberofpublishes', async () => {
135
+ const count = 3;
136
+ const history = new Array(...mockData_1.plan1_history);
137
+ const lastAPCId = 'sJbGx1Fpq1v2MmcI';
138
+ const matchDate = new Date('2023-01-17T22:35:20.517Z');
139
+ const config = { sinceDate: 'numberofpublishes:' + count };
140
+ const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
141
+ const dc = new data_converter_1.DataConverter(config, mapFileUtil);
142
+ const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
143
+ const sinceDate = await ppa.getSinceDate('oqIFX3ELRy8sFRd0', lastAPCId, history);
144
+ expect(sinceDate).toEqual(matchDate);
145
+ });
146
+ it('getSinceDate date from config numberofpublishes', async () => {
147
+ const count = 3;
148
+ const history = new Array(...mockData_1.plan1_history);
149
+ const lastAPCId = 'sJbGx1Fpq1v2MmcI';
150
+ const matchDate = new Date('2023-01-17T22:35:20.517Z');
151
+ const config = { sinceDate: 'numberofpublishes:' + count };
152
+ const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
153
+ const dc = new data_converter_1.DataConverter(config, mapFileUtil);
154
+ const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
155
+ ppa.getApcHistory = async () => {
156
+ return history;
157
+ };
158
+ const sinceDate = await ppa.getSinceDate('oqIFX3ELRy8sFRd0', lastAPCId, history);
159
+ expect(sinceDate).toEqual(matchDate);
160
+ });
161
+ });
162
+ describe('getSinceDateFromAPCSpecificDate', () => {
163
+ it('last apc - one day', () => {
164
+ const history = new Array(...mockData_1.plan1_history);
165
+ const lastAPCId = 'sJbGx1Fpq1v2MmcI';
166
+ const matchDate = new Date('2023-01-17T22:35:20.517Z');
167
+ const config = {};
168
+ const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
169
+ const dc = new data_converter_1.DataConverter(config, mapFileUtil);
170
+ const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
171
+ const sinceDate = ppa.getSinceDateFromAPCSpecificDate(history, lastAPCId, new Date('2023-01-17T00:00:00.000Z'));
172
+ expect(sinceDate).toEqual(matchDate);
173
+ });
174
+ it('apc in the middle - one day', () => {
175
+ const history = new Array(...mockData_1.plan1_history);
176
+ const lastAPCId = 'GiT9CZXZGVljoYMR';
177
+ const matchDate = new Date('2023-01-16T19:16:06.233Z');
178
+ const config = {};
179
+ const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
180
+ const dc = new data_converter_1.DataConverter(config, mapFileUtil);
181
+ const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
182
+ const sinceDate = ppa.getSinceDateFromAPCSpecificDate(history, lastAPCId, new Date('2023-01-16T00:00:00.000Z'));
183
+ expect(sinceDate).toEqual(matchDate);
184
+ });
185
+ it('before initial publish', () => {
186
+ const history = new Array(...mockData_1.plan1_history);
187
+ const lastAPCId = 'sJbGx1Fpq1v2MmcI';
188
+ const matchDate = new Date('2023-01-15T19:13:58.902Z');
189
+ const config = {};
190
+ const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
191
+ const dc = new data_converter_1.DataConverter(config, mapFileUtil);
192
+ const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
193
+ const sinceDate = ppa.getSinceDateFromAPCSpecificDate(history, lastAPCId, new Date('2021-01-17T00:00:00.000Z'));
194
+ expect(sinceDate).toEqual(matchDate);
195
+ });
196
+ it('numberofdays at 2 ', () => {
197
+ const history = new Array(...mockData_1.plan1_history);
198
+ const lastAPCId = 'sJbGx1Fpq1v2MmcI';
199
+ const matchDate = new Date('2023-01-16T19:16:06.233Z');
200
+ const config = {};
201
+ const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
202
+ const dc = new data_converter_1.DataConverter(config, mapFileUtil);
203
+ const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
204
+ const sinceDate = ppa.getSinceDateFromAPCSpecificDate(history, lastAPCId, new Date('2023-01-16T00:00:00.000Z'));
205
+ expect(sinceDate).toEqual(matchDate);
206
+ });
207
+ });
208
+ describe('getSinceDateDaysPrevious', () => {
209
+ it('last apc - one day', () => {
210
+ const history = new Array(...mockData_1.plan1_history);
211
+ const lastAPCId = 'sJbGx1Fpq1v2MmcI';
212
+ const matchDate = new Date('2023-01-17T22:35:20.517Z');
213
+ const config = {};
214
+ const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
215
+ const dc = new data_converter_1.DataConverter(config, mapFileUtil);
216
+ const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
217
+ const sinceDate = ppa.getSinceDateDaysPrevious(history, lastAPCId, 1);
218
+ expect(sinceDate).toEqual(matchDate);
219
+ });
220
+ it('apc in the middle - one day', () => {
221
+ const history = new Array(...mockData_1.plan1_history);
222
+ const lastAPCId = 'GiT9CZXZGVljoYMR';
223
+ const matchDate = new Date('2023-01-16T19:16:06.233Z');
224
+ const config = {};
225
+ const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
226
+ const dc = new data_converter_1.DataConverter(config, mapFileUtil);
227
+ const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
228
+ const sinceDate = ppa.getSinceDateDaysPrevious(history, lastAPCId, 1);
229
+ expect(sinceDate).toEqual(matchDate);
230
+ });
231
+ it('numberofdays greater than array size', () => {
232
+ const history = new Array(...mockData_1.plan1_history);
233
+ const lastAPCId = 'sJbGx1Fpq1v2MmcI';
234
+ const matchDate = new Date('2023-01-15T19:13:58.902Z');
235
+ const config = {};
236
+ const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
237
+ const dc = new data_converter_1.DataConverter(config, mapFileUtil);
238
+ const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
239
+ const sinceDate = ppa.getSinceDateDaysPrevious(history, lastAPCId, 5);
240
+ expect(sinceDate).toEqual(matchDate);
241
+ });
242
+ it('numberofdays at 2 ', () => {
243
+ const history = new Array(...mockData_1.plan1_history);
244
+ const lastAPCId = 'sJbGx1Fpq1v2MmcI';
245
+ const matchDate = new Date('2023-01-16T19:16:06.233Z');
246
+ const config = {};
247
+ const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
248
+ const dc = new data_converter_1.DataConverter(config, mapFileUtil);
249
+ const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
250
+ const sinceDate = ppa.getSinceDateDaysPrevious(history, lastAPCId, 2);
251
+ expect(sinceDate).toEqual(matchDate);
252
+ });
253
+ });
254
+ describe('getSinceDateFromAPCs', () => {
255
+ it('first / only apc', () => {
256
+ const history = new Array(...mockData_1.plan1_history).slice(0, 1);
257
+ const lastAPCId = 'v9BKkHo-tpL0wUZN';
258
+ const matchDate = new Date(0);
259
+ const config = {};
260
+ const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
261
+ const dc = new data_converter_1.DataConverter(config, mapFileUtil);
262
+ const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
263
+ const sinceDate = ppa.getSinceDateFromAPCs(history, lastAPCId);
264
+ expect(sinceDate).toEqual(matchDate);
265
+ });
266
+ it('first / multiple apcs in history', () => {
267
+ const history = new Array(...mockData_1.plan1_history).slice(0, 3);
268
+ const lastAPCId = 'v9BKkHo-tpL0wUZN';
269
+ const matchDate = new Date(0);
270
+ const config = {};
271
+ const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
272
+ const dc = new data_converter_1.DataConverter(config, mapFileUtil);
273
+ const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
274
+ const sinceDate = ppa.getSinceDateFromAPCs(history, lastAPCId);
275
+ expect(sinceDate).toEqual(matchDate);
276
+ });
277
+ it('last apc', () => {
278
+ const history = new Array(...mockData_1.plan1_history);
279
+ const lastAPCId = 'sJbGx1Fpq1v2MmcI';
280
+ const matchDate = new Date('2023-01-17T22:40:07.288Z');
281
+ const config = {};
282
+ const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
283
+ const dc = new data_converter_1.DataConverter(config, mapFileUtil);
284
+ const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
285
+ const sinceDate = ppa.getSinceDateFromAPCs(history, lastAPCId);
286
+ expect(sinceDate).toEqual(matchDate);
287
+ });
288
+ it('apc in the middle', () => {
289
+ const history = new Array(...mockData_1.plan1_history);
290
+ const lastAPCId = 'GiT9CZXZGVljoYMR';
291
+ const matchDate = new Date('2023-01-16T21:50:42.742Z');
292
+ const config = {};
293
+ const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
294
+ const dc = new data_converter_1.DataConverter(config, mapFileUtil);
295
+ const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
296
+ const sinceDate = ppa.getSinceDateFromAPCs(history, lastAPCId);
297
+ expect(sinceDate).toEqual(matchDate);
298
+ });
299
+ it('pastPublishCount greater than array size', () => {
300
+ const history = new Array(...mockData_1.plan1_history);
301
+ const lastAPCId = 'sJbGx1Fpq1v2MmcI';
302
+ const matchDate = new Date('2023-01-15T19:13:58.902Z');
303
+ const config = {};
304
+ const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
305
+ const dc = new data_converter_1.DataConverter(config, mapFileUtil);
306
+ const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
307
+ const sinceDate = ppa.getSinceDateFromAPCs(history, lastAPCId, 20);
308
+ expect(sinceDate).toEqual(matchDate);
309
+ });
310
+ it('pastPublishCount at 3 ', () => {
311
+ const history = new Array(...mockData_1.plan1_history);
312
+ const lastAPCId = 'sJbGx1Fpq1v2MmcI';
313
+ const matchDate = new Date('2023-01-17T22:35:20.517Z');
314
+ const config = {};
315
+ const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
316
+ const dc = new data_converter_1.DataConverter(config, mapFileUtil);
317
+ const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
318
+ const sinceDate = ppa.getSinceDateFromAPCs(history, lastAPCId, 3);
319
+ expect(sinceDate).toEqual(matchDate);
320
+ });
321
+ });
322
+ describe('getDeleteChanges', () => {
323
+ const config = {};
324
+ const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
325
+ const dc = new data_converter_1.DataConverter(config, mapFileUtil);
326
+ it('no deletes - 1 apc', async () => {
327
+ const history = new Array(...mockData_1.apc_2bOWR2j9R0QThDVu_delete_history);
328
+ const lastAPCId = 'SYHfQzYWlfXDqK7r';
329
+ const apcIndex = history.findIndex(pc => pc.id === lastAPCId);
330
+ const apc = history[apcIndex];
331
+ const previousApc = (apcIndex > 0)
332
+ ? history[apcIndex - 1]
333
+ : undefined;
334
+ const apcDate = (previousApc) ? new Date(previousApc['createdOn']) : new Date(0);
335
+ const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
336
+ const spy = jest.spyOn(ppa, 'downloadDeleteChanges')
337
+ .mockImplementation(async (assortmentPublishChange) => {
338
+ let deleteChanges = [];
339
+ if (assortmentPublishChange) {
340
+ const apcId = assortmentPublishChange['id'];
341
+ const apc = history.find(apc => apc['id'] === apcId);
342
+ deleteChanges = apc['deleteData'];
343
+ }
344
+ return deleteChanges;
345
+ });
346
+ const deleteChanges = await ppa.getDeleteChanges(apc, history, apc['assortmentBaseline'], apcDate);
347
+ expect(deleteChanges).toEqual([]);
348
+ spy.mockRestore();
349
+ });
350
+ it('1 delete - 1 apc', async () => {
351
+ const history = new Array(...mockData_1.apc_2bOWR2j9R0QThDVu_delete_history);
352
+ const lastAPCId = 'JreGRNvoJ3FsoRZI';
353
+ const apcIndex = history.findIndex(pc => pc.id === lastAPCId);
354
+ const apc = history[apcIndex];
355
+ const previousApc = (apcIndex > 0)
356
+ ? history[apcIndex - 1]
357
+ : undefined;
358
+ const apcDate = (previousApc) ? new Date(previousApc['createdOn']) : new Date(0);
359
+ const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
360
+ const spy = jest.spyOn(ppa, 'downloadDeleteChanges')
361
+ .mockImplementation(async (assortmentPublishChange) => {
362
+ let deleteChanges = [];
363
+ if (assortmentPublishChange) {
364
+ const apcId = assortmentPublishChange['id'];
365
+ const apc = history.find(apc => apc['id'] === apcId);
366
+ deleteChanges = apc['deleteData'];
367
+ }
368
+ return deleteChanges;
369
+ });
370
+ const deleteChanges = await ppa.getDeleteChanges(apc, history, apc['assortmentBaseline'], apcDate);
371
+ expect(deleteChanges).toHaveLength(1);
372
+ spy.mockRestore();
373
+ });
374
+ it('no deletes - testing #3 apc', async () => {
375
+ const history = new Array(...mockData_1.apc_2bOWR2j9R0QThDVu_delete_history);
376
+ const lastAPCId = 'NaPUhAdEzKB-5tQ3';
377
+ const apcIndex = history.findIndex(pc => pc.id === lastAPCId);
378
+ const apc = history[apcIndex];
379
+ const previousApc = (apcIndex > 0)
380
+ ? history[apcIndex - 1]
381
+ : undefined;
382
+ const apcDate = (previousApc) ? new Date(previousApc['createdOn']) : new Date(0);
383
+ const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
384
+ const spy = jest.spyOn(ppa, 'downloadDeleteChanges')
385
+ .mockImplementation(async (assortmentPublishChange) => {
386
+ let deleteChanges = [];
387
+ if (assortmentPublishChange) {
388
+ const apcId = assortmentPublishChange['id'];
389
+ const apc = history.find(apc => apc['id'] === apcId);
390
+ deleteChanges = apc['deleteData'];
391
+ }
392
+ return deleteChanges;
393
+ });
394
+ const deleteChanges = await ppa.getDeleteChanges(apc, history, apc['assortmentBaseline'], apcDate);
395
+ expect(deleteChanges).toEqual([]);
396
+ spy.mockRestore();
397
+ });
398
+ it('1 delete - 1 apc', async () => {
399
+ const history = new Array(...mockData_1.apc_2bOWR2j9R0QThDVu_delete_history);
400
+ const lastAPCId = 'CHGKSCT358qyh1Nu';
401
+ const apcIndex = history.findIndex(pc => pc.id === lastAPCId);
402
+ const apc = history[apcIndex];
403
+ const previousApc = (apcIndex > 0)
404
+ ? history[apcIndex - 1]
405
+ : undefined;
406
+ const apcDate = (previousApc) ? new Date(previousApc['createdOn']) : new Date(0);
407
+ const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
408
+ const spy = jest.spyOn(ppa, 'downloadDeleteChanges')
409
+ .mockImplementation(async (assortmentPublishChange) => {
410
+ let deleteChanges = [];
411
+ if (assortmentPublishChange) {
412
+ const apcId = assortmentPublishChange['id'];
413
+ const apc = history.find(apc => apc['id'] === apcId);
414
+ deleteChanges = apc['deleteData'];
415
+ }
416
+ return deleteChanges;
417
+ });
418
+ const deleteChanges = await ppa.getDeleteChanges(apc, history, apc['assortmentBaseline'], apcDate);
419
+ expect(deleteChanges).toHaveLength(1);
420
+ spy.mockRestore();
421
+ });
422
+ it('1 delete - 2 apc (most recent delete apc, no change earlier apc)', async () => {
423
+ const history = new Array(...mockData_1.apc_2bOWR2j9R0QThDVu_delete_history);
424
+ const lastAPCId = 'CHGKSCT358qyh1Nu';
425
+ const apc = history.find(pc => pc.id === lastAPCId);
426
+ const baseApcId = 'JreGRNvoJ3FsoRZI';
427
+ const baseApc = history.find(pc => pc.id === baseApcId);
428
+ const apcDate = new Date(baseApc['createdOn']);
429
+ const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
430
+ const spy = jest.spyOn(ppa, 'downloadDeleteChanges')
431
+ .mockImplementation(async (assortmentPublishChange) => {
432
+ let deleteChanges = [];
433
+ if (assortmentPublishChange) {
434
+ const apcId = assortmentPublishChange['id'];
435
+ const apc = history.find(apc => apc['id'] === apcId);
436
+ deleteChanges = apc['deleteData'];
437
+ }
438
+ return deleteChanges;
439
+ });
440
+ const deleteChanges = await ppa.getDeleteChanges(apc, history, apc['assortmentBaseline'], apcDate);
441
+ expect(deleteChanges).toHaveLength(1);
442
+ const item = deleteChanges[0];
443
+ expect(item).not.toBeNull();
444
+ expect(item['itemId']).toEqual('qNCQmTFcFxwbT-oG');
445
+ spy.mockRestore();
446
+ });
447
+ it('1 delete - 2 apc (most recent no change, 1 delete earlier apc)', async () => {
448
+ const history = new Array(...mockData_1.apc_2bOWR2j9R0QThDVu_delete_history);
449
+ const lastAPCId = 'NaPUhAdEzKB-5tQ3';
450
+ const apc = history.find(pc => pc.id === lastAPCId);
451
+ const baseApcId = 'SYHfQzYWlfXDqK7r';
452
+ const baseApc = history.find(pc => pc.id === baseApcId);
453
+ const apcDate = new Date(baseApc['createdOn']);
454
+ const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
455
+ const spy = jest.spyOn(ppa, 'downloadDeleteChanges')
456
+ .mockImplementation(async (assortmentPublishChange) => {
457
+ let deleteChanges = [];
458
+ if (assortmentPublishChange) {
459
+ const apcId = assortmentPublishChange['id'];
460
+ const apc = history.find(apc => apc['id'] === apcId);
461
+ deleteChanges = apc['deleteData'];
462
+ }
463
+ return deleteChanges;
464
+ });
465
+ const deleteChanges = await ppa.getDeleteChanges(apc, history, apc['assortmentBaseline'], apcDate);
466
+ expect(deleteChanges).toHaveLength(1);
467
+ const item = deleteChanges[0];
468
+ expect(item).not.toBeNull();
469
+ expect(item['itemId']).toEqual('SfUAZy_Hj631h2Kg');
470
+ spy.mockRestore();
471
+ });
472
+ it('2 delete - 3 apc (most recent delete apc, no change middle apc, 1 delete)', async () => {
473
+ const history = new Array(...mockData_1.apc_2bOWR2j9R0QThDVu_delete_history);
474
+ const lastAPCId = 'CHGKSCT358qyh1Nu';
475
+ const apc = history.find(pc => pc.id === lastAPCId);
476
+ const baseApcId = 'SYHfQzYWlfXDqK7r';
477
+ const baseApc = history.find(pc => pc.id === baseApcId);
478
+ const apcDate = new Date(baseApc['createdOn']);
479
+ const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
480
+ const spy = jest.spyOn(ppa, 'downloadDeleteChanges')
481
+ .mockImplementation(async (assortmentPublishChange) => {
482
+ let deleteChanges = [];
483
+ if (assortmentPublishChange) {
484
+ const apcId = assortmentPublishChange['id'];
485
+ const apc = history.find(apc => apc['id'] === apcId);
486
+ deleteChanges = apc['deleteData'];
487
+ }
488
+ return deleteChanges;
489
+ });
490
+ const deleteChanges = await ppa.getDeleteChanges(apc, history, apc['assortmentBaseline'], apcDate);
491
+ expect(deleteChanges).toHaveLength(2);
492
+ const itemIds = deleteChanges.map(dItem => dItem['itemId']);
493
+ expect(itemIds).toContain('SfUAZy_Hj631h2Kg');
494
+ expect(itemIds).toContain('qNCQmTFcFxwbT-oG');
495
+ spy.mockRestore();
496
+ });
497
+ it('1 delete - 4 apc (most recent re-add, 1 delete, no change middle apc, 1 delete)', async () => {
498
+ console.log('1 delete - 4 apc (most recent re-add, 1 delete, no change middle apc, 1 delete)');
499
+ const history = new Array(...mockData_1.apc_2bOWR2j9R0QThDVu_delete_history);
500
+ const lastAPCId = 'H4L4dHziO6WZRIwa';
501
+ const apc = history.find(pc => pc.id === lastAPCId);
502
+ const baseApcId = 'SYHfQzYWlfXDqK7r';
503
+ const baseApc = history.find(pc => pc.id === baseApcId);
504
+ const apcDate = new Date(baseApc['createdOn']);
505
+ const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
506
+ const spy = jest.spyOn(ppa, 'downloadDeleteChanges')
507
+ .mockImplementation(async (assortmentPublishChange) => {
508
+ let deleteChanges = [];
509
+ if (assortmentPublishChange) {
510
+ const apcId = assortmentPublishChange['id'];
511
+ const apc = history.find(apc => apc['id'] === apcId);
512
+ deleteChanges = apc['deleteData'];
513
+ }
514
+ return deleteChanges;
515
+ });
516
+ const deleteChanges = await ppa.getDeleteChanges(apc, history, apc['assortmentBaseline'], apcDate);
517
+ expect(deleteChanges).toHaveLength(1);
518
+ const itemIds = deleteChanges.map(dItem => dItem['itemId']);
519
+ expect(itemIds).toContain('qNCQmTFcFxwbT-oG');
520
+ spy.mockRestore();
521
+ });
522
+ });
523
+ describe('buildDeleteChanges', () => {
524
+ const config = {};
525
+ const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
526
+ const dc = new data_converter_1.DataConverter(config, mapFileUtil);
527
+ beforeEach(() => {
528
+ jest.clearAllMocks();
529
+ });
530
+ it('apc has valid deleteDataDownloadLink', async () => {
531
+ const returnedDeleteData = [
532
+ {}
533
+ ];
534
+ const apc = {
535
+ deleteDataDownloadLink: 'deleteDataDownloadLink',
536
+ returnedDeleteData
537
+ };
538
+ const previousApc = {};
539
+ const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
540
+ const spy = jest.spyOn(ppa, 'downloadDeleteChanges')
541
+ .mockImplementation(async (assortmentPublishChange) => {
542
+ return assortmentPublishChange['returnedDeleteData'];
543
+ });
544
+ const deleteChanges = await ppa.buildDeleteChanges(apc, previousApc);
545
+ expect(deleteChanges).toHaveLength(returnedDeleteData.length);
546
+ expect(spy).toBeCalledWith(apc);
547
+ spy.mockRestore();
548
+ });
549
+ it('apc no deleteDataDownloadLink, but fullAPC has valid link', async () => {
550
+ const returnedDeleteData = [
551
+ {}
552
+ ];
553
+ const apc = {};
554
+ const fullAPC = {
555
+ deleteDataDownloadLink: 'deleteDataDownloadLink',
556
+ returnedDeleteData
557
+ };
558
+ const previousApc = {};
559
+ const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
560
+ const spy = jest.spyOn(ppa, 'downloadDeleteChanges')
561
+ .mockImplementation(async (assortmentPublishChange) => {
562
+ return assortmentPublishChange['returnedDeleteData'];
563
+ });
564
+ const spy2 = jest.spyOn(ppa, 'downloadAssortmentPublishChange')
565
+ .mockImplementation(async () => {
566
+ return fullAPC;
567
+ });
568
+ const deleteChanges = await ppa.buildDeleteChanges(apc, previousApc);
569
+ expect(deleteChanges).toHaveLength(returnedDeleteData.length);
570
+ expect(spy).toBeCalledWith(fullAPC);
571
+ spy.mockRestore();
572
+ spy2.mockRestore();
573
+ });
574
+ it('apc & fullAPC no deleteDataDownloadLink, error no previousApc', async () => {
575
+ const returnedDeleteData = [
576
+ {}
577
+ ];
578
+ const apc = {};
579
+ const fullAPC = {
580
+ returnedDeleteData
581
+ };
582
+ const previousApc = undefined;
583
+ const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
584
+ const spy2 = jest.spyOn(ppa, 'downloadAssortmentPublishChange')
585
+ .mockImplementation(async () => {
586
+ return fullAPC;
587
+ });
588
+ expect(async () => { await ppa.buildDeleteChanges(apc, previousApc); }).rejects.toThrow(new Error(base_process_publish_assortment_1.BaseProcessPublishAssortment.NOT_ABLE_TO_PROCESS_DELETE_CHANGES));
589
+ spy2.mockRestore();
590
+ });
591
+ it('apc & fullAPC no deleteDataDownloadLink, use previousApc.assortmentBaselineDownloadLink', async () => {
592
+ const assortmentId = '123';
593
+ const apcId = '456';
594
+ const previousApcId = '987';
595
+ const apc = {
596
+ assortmentId,
597
+ id: apcId,
598
+ detail: {
599
+ deletes: [{ id: '1' }, { id: '3' }]
600
+ }
601
+ };
602
+ const fullAPC = {
603
+ assortmentId,
604
+ id: apcId,
605
+ detail: {
606
+ deletes: [{ id: '1' }, { id: '3' }]
607
+ }
608
+ };
609
+ const previousApc = {};
610
+ const fullPreviousApc = {
611
+ id: previousApcId,
612
+ assortmentBaselineDownloadLink: 'assortmentBaselineDownloadLink'
613
+ };
614
+ const previousApcBaseline = {
615
+ assortmentItems: [
616
+ { itemId: '1' },
617
+ { itemId: '2' },
618
+ { itemId: '3' }
619
+ ]
620
+ };
621
+ const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
622
+ const spyDownloadDeleteChanges = jest.spyOn(ppa, 'downloadDeleteChanges')
623
+ .mockImplementation(async (assortmentPublishChange) => {
624
+ return assortmentPublishChange['returnedDeleteData'];
625
+ });
626
+ const spyDownloadAssortmentPublishChange = jest.spyOn(ppa, 'downloadAssortmentPublishChange')
627
+ .mockImplementation(async (assortmentId, id) => {
628
+ if (id === apcId) {
629
+ return fullAPC;
630
+ }
631
+ else {
632
+ return fullPreviousApc;
633
+ }
634
+ });
635
+ const spyDownloadAssortmentBaseline = jest.spyOn(ppa, 'downloadAssortmentBaseline')
636
+ .mockImplementation(async () => {
637
+ return previousApcBaseline;
638
+ });
639
+ const deleteChanges = await ppa.buildDeleteChanges(apc, previousApc);
640
+ expect(deleteChanges).toHaveLength(apc.detail.deletes.length);
641
+ expect(spyDownloadAssortmentBaseline).toBeCalledWith(fullPreviousApc);
642
+ spyDownloadDeleteChanges.mockRestore();
643
+ spyDownloadAssortmentPublishChange.mockRestore();
644
+ spyDownloadAssortmentBaseline.mockRestore();
645
+ });
646
+ it('apc & fullAPC no deleteDataDownloadLink, use fullPreviousApc.assortmentBaselineDownloadLink', async () => {
647
+ const assortmentId = '123';
648
+ const apcId = '456';
649
+ const apc = {
650
+ assortmentId,
651
+ id: apcId,
652
+ detail: {
653
+ deletes: [{ id: '1' }, { id: '3' }]
654
+ }
655
+ };
656
+ const fullAPC = {
657
+ assortmentId,
658
+ id: apcId,
659
+ detail: {
660
+ deletes: [{ id: '1' }, { id: '3' }]
661
+ }
662
+ };
663
+ const previousApc = {
664
+ assortmentBaselineDownloadLink: 'assortmentBaselineDownloadLink'
665
+ };
666
+ const previousApcBaseline = {
667
+ assortmentItems: [
668
+ { itemId: '1' },
669
+ { itemId: '2' },
670
+ { itemId: '3' }
671
+ ]
672
+ };
673
+ const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
674
+ const spyDownloadDeleteChanges = jest.spyOn(ppa, 'downloadDeleteChanges')
675
+ .mockImplementation(async (assortmentPublishChange) => {
676
+ return assortmentPublishChange['returnedDeleteData'];
677
+ });
678
+ const spyDownloadAssortmentPublishChange = jest.spyOn(ppa, 'downloadAssortmentPublishChange')
679
+ .mockImplementation(async () => {
680
+ return fullAPC;
681
+ });
682
+ const spyDownloadAssortmentBaseline = jest.spyOn(ppa, 'downloadAssortmentBaseline')
683
+ .mockImplementation(async () => {
684
+ return previousApcBaseline;
685
+ });
686
+ const deleteChanges = await ppa.buildDeleteChanges(apc, previousApc);
687
+ expect(deleteChanges).toHaveLength(apc.detail.deletes.length);
688
+ expect(spyDownloadAssortmentBaseline).toBeCalledWith(previousApc);
689
+ spyDownloadDeleteChanges.mockRestore();
690
+ spyDownloadAssortmentPublishChange.mockRestore();
691
+ spyDownloadAssortmentBaseline.mockRestore();
692
+ });
693
+ });
694
+ describe('getItemFamilyChanges', () => {
695
+ const filterFullChange = (fullChange, itemFamilyIds) => {
696
+ const fChange = Object.assign({}, fullChange);
697
+ fChange['assortmentItems'] = fChange['assortmentItems']
698
+ .filter(assortItem => itemFamilyIds.includes(assortItem['item']['itemFamilyId']));
699
+ return fChange;
700
+ };
701
+ const filterDeleteChange = (deleteChange, itemFamilyIds) => {
702
+ let dChange = Array.from(deleteChange);
703
+ dChange = dChange.filter(assortItem => itemFamilyIds.includes(assortItem['item']['itemFamilyId']));
704
+ return dChange;
705
+ };
706
+ const filterHydratedDetails = (hydratedDetails, itemFamilyIds) => {
707
+ const hDetails = Object.assign({}, hydratedDetails);
708
+ hDetails['adds'] = hDetails['adds']
709
+ .filter(assortItem => itemFamilyIds.includes(assortItem['item']['itemFamilyId']));
710
+ hDetails['deletes'] = hDetails['deletes']
711
+ .filter(assortItem => itemFamilyIds.includes(assortItem['item']['itemFamilyId']));
712
+ hDetails['familyItemsRemoved'] = hDetails['familyItemsRemoved']
713
+ .filter(assortItem => itemFamilyIds.includes(assortItem['item']['itemFamilyId']));
714
+ return hDetails;
715
+ };
716
+ it('Feb 3 - No Option A', () => {
717
+ const itemFamilyId = 'kh1Rtb7kie7Vk5vo';
718
+ const fullChange = filterFullChange(mockData_1.fall_2003_fullChange, [itemFamilyId]);
719
+ const hydratedDetails = filterHydratedDetails(mockData_1.fall_2003_hydratedDetails, [itemFamilyId]);
720
+ const seasonFed = {
721
+ entityReference: 'assortment:' + fullChange['id'],
722
+ objectClass: 'LCSSeason',
723
+ federationId: 'VR:...LCSSeason:1'
724
+ };
725
+ const itemToFederatedIdMapping = new Map();
726
+ mockData_1.fall_2003_fedMapping.forEach(mapping => itemToFederatedIdMapping.set(mapping.reference, mapping.mappedReference));
727
+ const sinceDate = new Date('2023-02-01T00:00:00.000Z');
728
+ const config = {};
729
+ const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
730
+ const dc = new data_converter_1.DataConverter(config, mapFileUtil);
731
+ const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
732
+ const assortmentItemFullChangeMap = ppa.getFullChangeAssortmentMap(fullChange);
733
+ const assortmentItemDeleteMap = new Map();
734
+ const pcd = new publish_change_data_1.PublishChangeData(fullChange['id'], seasonFed, 'i-OONhGKbJAfRKo-', sinceDate);
735
+ pcd.itemToFederatedIdMapping = itemToFederatedIdMapping;
736
+ pcd.releasedForDevelopmentItemIds.push(itemFamilyId);
737
+ pcd.itemFamilyChanges = ppa.getItemFamilyChanges(pcd, hydratedDetails, assortmentItemFullChangeMap, assortmentItemDeleteMap);
738
+ const ifcs = pcd.itemFamilyChanges;
739
+ expect(ifcs.size).toEqual(1);
740
+ const ifc = ifcs.get(itemFamilyId);
741
+ expect(ifc.familyAdd).toBe(true);
742
+ expect(ifc.colorAdds.length).toEqual(0);
743
+ });
744
+ it('Feb 3 - 1 Option A', () => {
745
+ const itemFamilyId = 'U9QryfGVOYMAkBP_';
746
+ const fullChange = filterFullChange(mockData_1.fall_2003_fullChange, [itemFamilyId]);
747
+ const hydratedDetails = filterHydratedDetails(mockData_1.fall_2003_hydratedDetails, [itemFamilyId]);
748
+ const seasonFed = {
749
+ entityReference: 'assortment:' + fullChange['id'],
750
+ objectClass: 'LCSSeason',
751
+ federationId: 'VR:...LCSSeason:1'
752
+ };
753
+ const itemToFederatedIdMapping = new Map();
754
+ mockData_1.fall_2003_fedMapping.forEach(mapping => itemToFederatedIdMapping.set(mapping.reference, mapping.mappedReference));
755
+ const sinceDate = new Date('2023-02-01T00:00:00.000Z');
756
+ const config = {};
757
+ const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
758
+ const dc = new data_converter_1.DataConverter(config, mapFileUtil);
759
+ const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
760
+ const assortmentItemFullChangeMap = ppa.getFullChangeAssortmentMap(fullChange);
761
+ const assortmentItemDeleteMap = new Map();
762
+ const pcd = new publish_change_data_1.PublishChangeData(fullChange['id'], seasonFed, 'i-OONhGKbJAfRKo-', sinceDate);
763
+ pcd.itemToFederatedIdMapping = itemToFederatedIdMapping;
764
+ pcd.releasedForDevelopmentItemIds.push('jFAp5SmYqhXoX-ZI');
765
+ pcd.releasedForDevelopmentItemIds.push('U9QryfGVOYMAkBP_');
766
+ pcd.itemFamilyChanges = ppa.getItemFamilyChanges(pcd, hydratedDetails, assortmentItemFullChangeMap, assortmentItemDeleteMap);
767
+ const ifcs = pcd.itemFamilyChanges;
768
+ expect(ifcs.size).toEqual(1);
769
+ const ifc = ifcs.get(itemFamilyId);
770
+ expect(ifc.colorAdds.length).toEqual(1);
771
+ });
772
+ it('Feb 3 - 2+ Option A', () => {
773
+ const itemFamilyId = 'tvCyTuL6hF3MwbjJ';
774
+ const fullChange = filterFullChange(mockData_1.fall_2003_fullChange, [itemFamilyId]);
775
+ const hydratedDetails = filterHydratedDetails(mockData_1.fall_2003_hydratedDetails, [itemFamilyId]);
776
+ const seasonFed = {
777
+ entityReference: 'assortment:' + fullChange['id'],
778
+ objectClass: 'LCSSeason',
779
+ federationId: 'VR:...LCSSeason:1'
780
+ };
781
+ const itemToFederatedIdMapping = new Map();
782
+ mockData_1.fall_2003_fedMapping.forEach(mapping => itemToFederatedIdMapping.set(mapping.reference, mapping.mappedReference));
783
+ const sinceDate = new Date('2023-02-01T00:00:00.000Z');
784
+ const config = {};
785
+ const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
786
+ const dc = new data_converter_1.DataConverter(config, mapFileUtil);
787
+ const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
788
+ const assortmentItemFullChangeMap = ppa.getFullChangeAssortmentMap(fullChange);
789
+ const assortmentItemDeleteMap = new Map();
790
+ const pcd = new publish_change_data_1.PublishChangeData(fullChange['id'], seasonFed, 'i-OONhGKbJAfRKo-', sinceDate);
791
+ pcd.itemToFederatedIdMapping = itemToFederatedIdMapping;
792
+ pcd.releasedForDevelopmentItemIds.push('jezonPsoRUlA52iz');
793
+ pcd.releasedForDevelopmentItemIds.push('VGo0fWmBBEZoghgk');
794
+ pcd.releasedForDevelopmentItemIds.push('tvCyTuL6hF3MwbjJ');
795
+ pcd.itemFamilyChanges = ppa.getItemFamilyChanges(pcd, hydratedDetails, assortmentItemFullChangeMap, assortmentItemDeleteMap);
796
+ const ifcs = pcd.itemFamilyChanges;
797
+ expect(ifcs.size).toEqual(1);
798
+ const ifc = ifcs.get(itemFamilyId);
799
+ expect(ifc.colorAdds.length).toEqual(2);
800
+ });
801
+ it('Feb 3 - 2+ Option A & Feb 3 - 1 Option A', () => {
802
+ const oneOption_itemFamilyId = 'U9QryfGVOYMAkBP_';
803
+ const twoOption_itemFamilyId = 'tvCyTuL6hF3MwbjJ';
804
+ const bothFamilyIds = [oneOption_itemFamilyId, twoOption_itemFamilyId];
805
+ const fullChange = filterFullChange(mockData_1.fall_2003_fullChange, bothFamilyIds);
806
+ const hydratedDetails = filterHydratedDetails(mockData_1.fall_2003_hydratedDetails, bothFamilyIds);
807
+ const seasonFed = {
808
+ entityReference: 'assortment:' + fullChange['id'],
809
+ objectClass: 'LCSSeason',
810
+ federationId: 'VR:...LCSSeason:1'
811
+ };
812
+ const itemToFederatedIdMapping = new Map();
813
+ mockData_1.fall_2003_fedMapping.forEach(mapping => itemToFederatedIdMapping.set(mapping.reference, mapping.mappedReference));
814
+ const sinceDate = new Date('2023-02-01T00:00:00.000Z');
815
+ const config = {};
816
+ const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
817
+ const dc = new data_converter_1.DataConverter(config, mapFileUtil);
818
+ const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
819
+ const assortmentItemFullChangeMap = ppa.getFullChangeAssortmentMap(fullChange);
820
+ const assortmentItemDeleteMap = new Map();
821
+ const pcd = new publish_change_data_1.PublishChangeData(fullChange['id'], seasonFed, 'i-OONhGKbJAfRKo-', sinceDate);
822
+ pcd.itemToFederatedIdMapping = itemToFederatedIdMapping;
823
+ pcd.releasedForDevelopmentItemIds.push('jFAp5SmYqhXoX-ZI');
824
+ pcd.releasedForDevelopmentItemIds.push('jezonPsoRUlA52iz');
825
+ pcd.releasedForDevelopmentItemIds.push('VGo0fWmBBEZoghgk');
826
+ pcd.releasedForDevelopmentItemIds.push('U9QryfGVOYMAkBP_');
827
+ pcd.releasedForDevelopmentItemIds.push('tvCyTuL6hF3MwbjJ');
828
+ pcd.itemFamilyChanges = ppa.getItemFamilyChanges(pcd, hydratedDetails, assortmentItemFullChangeMap, assortmentItemDeleteMap);
829
+ const ifcs = pcd.itemFamilyChanges;
830
+ expect(ifcs.size).toEqual(2);
831
+ let ifc = ifcs.get(oneOption_itemFamilyId);
832
+ expect(ifc.colorAdds.length).toEqual(1);
833
+ ifc = ifcs.get(twoOption_itemFamilyId);
834
+ expect(ifc.colorAdds.length).toEqual(2);
835
+ });
836
+ it('Feb 3 - 2+ Option A & Feb 3 - No Option A', () => {
837
+ const noOption_itemFamilyId = 'kh1Rtb7kie7Vk5vo';
838
+ const twoOption_itemFamilyId = 'tvCyTuL6hF3MwbjJ';
839
+ const bothFamilyIds = [noOption_itemFamilyId, twoOption_itemFamilyId];
840
+ const fullChange = filterFullChange(mockData_1.fall_2003_fullChange, bothFamilyIds);
841
+ const hydratedDetails = filterHydratedDetails(mockData_1.fall_2003_hydratedDetails, bothFamilyIds);
842
+ const seasonFed = {
843
+ entityReference: 'assortment:' + fullChange['id'],
844
+ objectClass: 'LCSSeason',
845
+ federationId: 'VR:...LCSSeason:1'
846
+ };
847
+ const itemToFederatedIdMapping = new Map();
848
+ mockData_1.fall_2003_fedMapping.forEach(mapping => itemToFederatedIdMapping.set(mapping.reference, mapping.mappedReference));
849
+ const sinceDate = new Date('2023-02-01T00:00:00.000Z');
850
+ const config = {};
851
+ const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
852
+ const dc = new data_converter_1.DataConverter(config, mapFileUtil);
853
+ const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
854
+ const assortmentItemFullChangeMap = ppa.getFullChangeAssortmentMap(fullChange);
855
+ const assortmentItemDeleteMap = new Map();
856
+ const pcd = new publish_change_data_1.PublishChangeData(fullChange['id'], seasonFed, 'i-OONhGKbJAfRKo-', sinceDate);
857
+ pcd.itemToFederatedIdMapping = itemToFederatedIdMapping;
858
+ pcd.releasedForDevelopmentItemIds.push(noOption_itemFamilyId);
859
+ pcd.releasedForDevelopmentItemIds.push('jezonPsoRUlA52iz');
860
+ pcd.releasedForDevelopmentItemIds.push('VGo0fWmBBEZoghgk');
861
+ pcd.releasedForDevelopmentItemIds.push('kh1Rtb7kie7Vk5vo');
862
+ pcd.releasedForDevelopmentItemIds.push('tvCyTuL6hF3MwbjJ');
863
+ pcd.itemFamilyChanges = ppa.getItemFamilyChanges(pcd, hydratedDetails, assortmentItemFullChangeMap, assortmentItemDeleteMap);
864
+ const ifcs = pcd.itemFamilyChanges;
865
+ expect(ifcs.size).toEqual(2);
866
+ let ifc = ifcs.get(noOption_itemFamilyId);
867
+ expect(ifc.familyAdd).toBe(true);
868
+ expect(ifc.colorAdds.length).toEqual(0);
869
+ ifc = ifcs.get(twoOption_itemFamilyId);
870
+ expect(ifc.colorAdds.length).toEqual(2);
871
+ });
872
+ it('Feb 3 - 1 Option B -remove option - leave family', () => {
873
+ const itemFamilyId = 'EejAxj-KK_GGr5Kh';
874
+ const fullChange = filterFullChange(mockData_1.fall_2003_fullChange_run2, [itemFamilyId]);
875
+ const hydratedDetails = filterHydratedDetails(mockData_1.fall_2003_hydratedDetails_run2, [itemFamilyId]);
876
+ const deleteChanges = filterDeleteChange(mockData_1.fall_2003_deleteChanges_run2, [itemFamilyId]);
877
+ const seasonFed = {
878
+ entityReference: 'assortment:' + fullChange['id'],
879
+ objectClass: 'LCSSeason',
880
+ federationId: 'VR:...LCSSeason:1'
881
+ };
882
+ const itemToFederatedIdMapping = new Map();
883
+ mockData_1.fall_2003_fedMapping.forEach(mapping => itemToFederatedIdMapping.set(mapping.reference, mapping.mappedReference));
884
+ const sinceDate = new Date('2023-02-01T00:00:00.000Z');
885
+ const config = {};
886
+ const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
887
+ const dc = new data_converter_1.DataConverter(config, mapFileUtil);
888
+ const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
889
+ const assortmentItemFullChangeMap = ppa.getFullChangeAssortmentMap(fullChange);
890
+ const assortmentItemDeleteMap = ppa.getDeleteChangesAssortmentMap(deleteChanges);
891
+ const pcd = new publish_change_data_1.PublishChangeData(fullChange['id'], seasonFed, 'nPxkQJrFlTikr00h', sinceDate);
892
+ pcd.itemToFederatedIdMapping = itemToFederatedIdMapping;
893
+ pcd.releasedForDevelopmentItemIds.push(itemFamilyId);
894
+ pcd.releasedForDevelopmentItemIds.push('yLhrIHYaP7B4nlkh');
895
+ pcd.itemFamilyChanges = ppa.getItemFamilyChanges(pcd, hydratedDetails, assortmentItemFullChangeMap, assortmentItemDeleteMap);
896
+ const ifcs = pcd.itemFamilyChanges;
897
+ expect(ifcs.size).toEqual(1);
898
+ const ifc = ifcs.get(itemFamilyId);
899
+ expect(ifc.familyAdd).toBe(true);
900
+ expect(ifc.colorAdds.length).toEqual(0);
901
+ expect(ifc.colorDeletes.length).toEqual(1);
902
+ });
903
+ it('Feb 3 - 1 Option C -remove family & option', () => {
904
+ const itemFamilyId = 'JEY86MOuRFv7f9OY';
905
+ const fullChange = filterFullChange(mockData_1.fall_2003_fullChange_run2, [itemFamilyId]);
906
+ const hydratedDetails = filterHydratedDetails(mockData_1.fall_2003_hydratedDetails_run2, [itemFamilyId]);
907
+ const deleteChanges = filterDeleteChange(mockData_1.fall_2003_deleteChanges_run2, [itemFamilyId]);
908
+ const seasonFed = {
909
+ entityReference: 'assortment:' + fullChange['id'],
910
+ objectClass: 'LCSSeason',
911
+ federationId: 'VR:...LCSSeason:1'
912
+ };
913
+ const itemToFederatedIdMapping = new Map();
914
+ mockData_1.fall_2003_fedMapping.forEach(mapping => itemToFederatedIdMapping.set(mapping.reference, mapping.mappedReference));
915
+ const sinceDate = new Date('2023-02-01T00:00:00.000Z');
916
+ const config = {};
917
+ const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
918
+ const dc = new data_converter_1.DataConverter(config, mapFileUtil);
919
+ const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
920
+ const assortmentItemFullChangeMap = ppa.getFullChangeAssortmentMap(fullChange);
921
+ const assortmentItemDeleteMap = ppa.getDeleteChangesAssortmentMap(deleteChanges);
922
+ const pcd = new publish_change_data_1.PublishChangeData(fullChange['id'], seasonFed, 'nPxkQJrFlTikr00h', sinceDate);
923
+ pcd.itemToFederatedIdMapping = itemToFederatedIdMapping;
924
+ pcd.releasedForDevelopmentItemIds.push(itemFamilyId);
925
+ pcd.releasedForDevelopmentItemIds.push('eZL2ChJRBlvbu3yG');
926
+ pcd.itemFamilyChanges = ppa.getItemFamilyChanges(pcd, hydratedDetails, assortmentItemFullChangeMap, assortmentItemDeleteMap);
927
+ const ifcs = pcd.itemFamilyChanges;
928
+ expect(ifcs.size).toEqual(1);
929
+ const ifc = ifcs.get(itemFamilyId);
930
+ expect(ifc.colorAdds.length).toEqual(0);
931
+ expect(ifc.colorDeletes.length).toEqual(1);
932
+ });
933
+ });
934
+ describe('getProjectItem', () => {
935
+ const config = {
936
+ identifierAtts: {
937
+ LCSSeason: ['flexPLMSeasonName']
938
+ }
939
+ };
940
+ const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
941
+ const dc = new data_converter_1.DataConverter(config, mapFileUtil);
942
+ const bppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
943
+ it('family assortment item in assortmentItemFullChangeMap', () => {
944
+ const familyId = 'w43t4';
945
+ const sinceDate = new Date();
946
+ const ifc = new item_family_changes_1.ItemFamilyChanges(familyId, sinceDate);
947
+ const projectItem = {
948
+ id: '4md02m:' + familyId
949
+ };
950
+ ifc.assortmentItemFullChangeMap.set(familyId, {
951
+ projectItem
952
+ });
953
+ const fpi = bppa.getProjectItem(ifc, familyId);
954
+ expect(fpi).toEqual(projectItem);
955
+ });
956
+ it('family assortment item NOT in assortmentItemFullChangeMap', () => {
957
+ const familyId = 'w43t4';
958
+ const optionId = 'l3mci2';
959
+ const sinceDate = new Date();
960
+ const ifc = new item_family_changes_1.ItemFamilyChanges(familyId, sinceDate);
961
+ const familyProjectItem = {
962
+ id: '4md02m:' + familyId
963
+ };
964
+ ifc.assortmentItemFullChangeMap.set(optionId, {
965
+ familyProjectItem
966
+ });
967
+ const fpi = bppa.getProjectItem(ifc, familyId);
968
+ expect(fpi).toEqual(familyProjectItem);
969
+ });
970
+ it('option assortment item in assortmentItemFullChangeMap', () => {
971
+ const familyId = 'w43t4';
972
+ const optionId = 'l3mci2';
973
+ const sinceDate = new Date();
974
+ const ifc = new item_family_changes_1.ItemFamilyChanges(familyId, sinceDate);
975
+ const projectItem = {
976
+ id: '4md02m:' + optionId
977
+ };
978
+ ifc.assortmentItemFullChangeMap.set(optionId, {
979
+ projectItem
980
+ });
981
+ const fpi = bppa.getProjectItem(ifc, optionId);
982
+ expect(fpi).toEqual(projectItem);
983
+ });
984
+ });
985
+ describe('getCarriedFromSeason', () => {
986
+ const config = {
987
+ identifierAtts: {
988
+ LCSSeason: ['flexPLMSeasonName']
989
+ }
990
+ };
991
+ const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
992
+ const dc = new data_converter_1.DataConverter(config, mapFileUtil);
993
+ const bppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
994
+ it('cache hit', async () => {
995
+ const projectItem = {
996
+ addedFromAssortment: 123
997
+ };
998
+ const origGetAssormentEntityFromId = bppa.getAssormentEntityFromId;
999
+ const origGetSeasonFederationFromAssortment = bppa.getSeasonFederationFromAssortment;
1000
+ try {
1001
+ const assortmentEntity = {};
1002
+ const seasonFed = {
1003
+ entityReference: 'assortment:123',
1004
+ objectClass: 'LCSSeason'
1005
+ };
1006
+ bppa.getAssormentEntityFromId = async (assortmentId) => { return assortmentEntity; };
1007
+ bppa.getSeasonFederationFromAssortment = async (assortment) => { return seasonFed; };
1008
+ const spyGetAssortment = jest.spyOn(bppa, 'getAssormentEntityFromId');
1009
+ const spyGetSeasonFed = jest.spyOn(bppa, 'getSeasonFederationFromAssortment');
1010
+ let sFed = await bppa.getCarriedFromSeason(projectItem);
1011
+ sFed = await bppa.getCarriedFromSeason(projectItem);
1012
+ expect(spyGetAssortment).toHaveBeenCalledTimes(1);
1013
+ expect(spyGetSeasonFed).toHaveBeenCalledTimes(1);
1014
+ }
1015
+ finally {
1016
+ bppa.getAssormentEntityFromId = origGetAssormentEntityFromId;
1017
+ bppa.getSeasonFederationFromAssortment = origGetSeasonFederationFromAssortment;
1018
+ }
1019
+ const sf = await bppa.getCarriedFromSeason(projectItem);
1020
+ });
1021
+ describe('getSeasonFederationFromAssortment', () => {
1022
+ it('Test conversion', async () => {
1023
+ const assortment = {
1024
+ id: '2we4',
1025
+ name: 'Object Name',
1026
+ notTransferred: 'This shouldnt be in the returned object'
1027
+ };
1028
+ const typePath = 'Path';
1029
+ const identifierKeys = ['name'];
1030
+ const informationKeys = [];
1031
+ const mapKey = 'mapKey';
1032
+ const spyTCU_type_path = jest.spyOn(type_conversion_utils_1.TypeConversionUtils, 'getObjectTypePath')
1033
+ .mockImplementation(async () => typePath);
1034
+ const spyDC_get_data = jest.spyOn(dc, 'getFlexPLMObjectData')
1035
+ .mockImplementation(async (data) => data);
1036
+ const spyTCU_id_keys = jest.spyOn(type_conversion_utils_1.TypeConversionUtils, 'getIdentifierProperties')
1037
+ .mockImplementation(async () => identifierKeys);
1038
+ const spyTCU_info_keys = jest.spyOn(type_conversion_utils_1.TypeConversionUtils, 'getInformationalProperties')
1039
+ .mockImplementation(async () => informationKeys);
1040
+ const spyTCU_get_map_key = jest.spyOn(type_conversion_utils_1.TypeConversionUtils, 'getMapKey')
1041
+ .mockImplementation(async () => mapKey);
1042
+ const spyMU_apply_map = jest.spyOn(map_utils_1.MapUtil, 'applyTransformMap')
1043
+ .mockImplementation(async (...args) => args[2]);
1044
+ const results = await bppa.getSeasonFederationFromAssortment(assortment);
1045
+ console.log('Test conversion: ' + JSON.stringify(results));
1046
+ expect(results['entityReference']).toBe('assortment:2we4');
1047
+ expect(results['name']).toBe('Object Name');
1048
+ expect(results['flexPLMTypePath']).toBe('Path');
1049
+ expect(results['objectClass']).toBe('LCSSeason');
1050
+ expect(results).not.toHaveProperty('notTransferred');
1051
+ });
1052
+ });
1053
+ });