@contrail/flexplm 1.3.0 → 1.3.1

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 (84) hide show
  1. package/.github/workflows/flexplm-lib.yml +1 -1
  2. package/.github/workflows/publish-to-npm.yml +35 -38
  3. package/lib/entity-processor/base-entity-processor.d.ts +42 -42
  4. package/lib/entity-processor/base-entity-processor.js +385 -385
  5. package/lib/entity-processor/base-entity-processor.spec.d.ts +1 -1
  6. package/lib/entity-processor/base-entity-processor.spec.js +397 -397
  7. package/lib/flexplm-request.d.ts +3 -3
  8. package/lib/flexplm-request.js +34 -34
  9. package/lib/flexplm-utils.d.ts +5 -5
  10. package/lib/flexplm-utils.js +33 -33
  11. package/lib/flexplm-utils.spec.d.ts +1 -1
  12. package/lib/flexplm-utils.spec.js +26 -26
  13. package/lib/index.d.ts +22 -22
  14. package/lib/index.js +38 -38
  15. package/lib/interfaces/interfaces.d.ts +105 -105
  16. package/lib/interfaces/interfaces.js +2 -2
  17. package/lib/interfaces/item-family-changes.d.ts +20 -20
  18. package/lib/interfaces/item-family-changes.js +56 -56
  19. package/lib/interfaces/publish-change-data.d.ts +19 -19
  20. package/lib/interfaces/publish-change-data.js +32 -32
  21. package/lib/publish/base-process-publish-assortment-callback.d.ts +9 -9
  22. package/lib/publish/base-process-publish-assortment-callback.js +38 -38
  23. package/lib/publish/base-process-publish-assortment.d.ts +93 -93
  24. package/lib/publish/base-process-publish-assortment.js +944 -944
  25. package/lib/publish/base-process-publish-assortment.spec.d.ts +1 -1
  26. package/lib/publish/base-process-publish-assortment.spec.js +1670 -1670
  27. package/lib/publish/mockData.d.ts +1389 -1389
  28. package/lib/publish/mockData.js +4519 -4519
  29. package/lib/transform/identifier-conversion-spec-mockData.js +444 -444
  30. package/lib/transform/identifier-conversion.d.ts +15 -15
  31. package/lib/transform/identifier-conversion.js +212 -212
  32. package/lib/transform/identifier-conversion.spec.d.ts +1 -1
  33. package/lib/transform/identifier-conversion.spec.js +339 -339
  34. package/lib/util/config-defaults.d.ts +8 -8
  35. package/lib/util/config-defaults.js +85 -85
  36. package/lib/util/config-defaults.spec.d.ts +1 -1
  37. package/lib/util/config-defaults.spec.js +293 -293
  38. package/lib/util/data-converter-spec-mockData.js +205 -205
  39. package/lib/util/data-converter.d.ts +39 -39
  40. package/lib/util/data-converter.js +592 -592
  41. package/lib/util/data-converter.spec.d.ts +1 -1
  42. package/lib/util/data-converter.spec.js +904 -904
  43. package/lib/util/error-response-object.d.ts +4 -4
  44. package/lib/util/error-response-object.js +47 -47
  45. package/lib/util/error-response-object.spec.d.ts +1 -1
  46. package/lib/util/error-response-object.spec.js +99 -99
  47. package/lib/util/event-short-message-status.d.ts +19 -19
  48. package/lib/util/event-short-message-status.js +23 -23
  49. package/lib/util/federation.d.ts +15 -15
  50. package/lib/util/federation.js +149 -149
  51. package/lib/util/flexplm-connect.d.ts +22 -22
  52. package/lib/util/flexplm-connect.js +176 -176
  53. package/lib/util/flexplm-connect.spec.d.ts +1 -1
  54. package/lib/util/flexplm-connect.spec.js +88 -88
  55. package/lib/util/logger-config.d.ts +1 -1
  56. package/lib/util/logger-config.js +26 -26
  57. package/lib/util/map-util-spec-mockData.js +205 -205
  58. package/lib/util/map-utils.d.ts +6 -6
  59. package/lib/util/map-utils.js +15 -15
  60. package/lib/util/map-utils.spec.d.ts +1 -1
  61. package/lib/util/map-utils.spec.js +89 -89
  62. package/lib/util/mockData.d.ts +80 -80
  63. package/lib/util/mockData.js +103 -103
  64. package/lib/util/thumbnail-util.d.ts +34 -34
  65. package/lib/util/thumbnail-util.js +215 -215
  66. package/lib/util/thumbnail-util.spec.d.ts +1 -1
  67. package/lib/util/thumbnail-util.spec.js +434 -434
  68. package/lib/util/type-conversion-utils-spec-mockData.js +259 -259
  69. package/lib/util/type-conversion-utils.d.ts +23 -23
  70. package/lib/util/type-conversion-utils.js +265 -265
  71. package/lib/util/type-conversion-utils.spec.d.ts +1 -1
  72. package/lib/util/type-conversion-utils.spec.js +868 -868
  73. package/lib/util/type-defaults.d.ts +16 -16
  74. package/lib/util/type-defaults.js +221 -221
  75. package/lib/util/type-defaults.spec.d.ts +1 -1
  76. package/lib/util/type-defaults.spec.js +516 -516
  77. package/lib/util/type-utils.d.ts +13 -13
  78. package/lib/util/type-utils.js +114 -114
  79. package/lib/util/type-utils.spec.d.ts +1 -1
  80. package/lib/util/type-utils.spec.js +190 -190
  81. package/package.json +1 -1
  82. package/publish.sh +0 -0
  83. package/tsconfig.json +1 -6
  84. package/.claude/settings.local.json +0 -8
@@ -1,1670 +1,1670 @@
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
- let entityObject = {};
32
- let getOptionsObject = {};
33
- jest.mock('@contrail/sdk', () => {
34
- return {
35
- Entities: class {
36
- get(_getOtionsObject) {
37
- getOptionsObject = _getOtionsObject;
38
- return entityObject;
39
- }
40
- }
41
- };
42
- });
43
- describe('process publish assortment', () => {
44
- const config = {};
45
- beforeEach(() => {
46
- federatedId = '';
47
- entityObject = { publishToFlexPLM: true };
48
- getOptionsObject = {};
49
- });
50
- afterEach(() => {
51
- jest.restoreAllMocks();
52
- });
53
- it('No Federation Info', async () => {
54
- const event = {
55
- assortmentId: 'B3oRQpYVYzcJAJtQ'
56
- };
57
- const identifierKeys = ['flexPLMSeasonName'];
58
- const informationKeys = ['name'];
59
- const spyTCU_id_keys = jest.spyOn(type_conversion_utils_1.TypeConversionUtils, 'getIdentifierProperties')
60
- .mockImplementation(async () => identifierKeys);
61
- const spyTCU_info_keys = jest.spyOn(type_conversion_utils_1.TypeConversionUtils, 'getInformationalProperties')
62
- .mockImplementation(async () => informationKeys);
63
- const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
64
- const dc = new data_converter_1.DataConverter(config, mapFileUtil);
65
- const results = await new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil).process(event);
66
- expect(results['results']['message']).toEqual(base_process_publish_assortment_1.BaseProcessPublishAssortment.ASSORTMENT_NO_FED_INFO + identifierKeys);
67
- });
68
- });
69
- describe('getPublishInfo', () => {
70
- const config = {};
71
- const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
72
- const dc = new data_converter_1.DataConverter(config, mapFileUtil);
73
- const assortmentId = 'oqIFX3ELRy8sFRd0';
74
- const versionName = 'Version 1';
75
- const versionComments = 'Some Comments';
76
- const createdOn = '2023-01-15T19:13:58.902Z';
77
- const plan_history = [
78
- {
79
- id: 'sJbGx1Fpq1v2MmcI',
80
- versionName,
81
- versionComments,
82
- createdOn
83
- }
84
- ];
85
- it('All Publish Info', async () => {
86
- const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
87
- const assortmentPublishChangeId = 'sJbGx1Fpq1v2MmcI';
88
- const publisher = {
89
- email: 'chris@vibeiq.com'
90
- };
91
- const assortmentName = 'VibeIQ Fall 2023';
92
- const versionHistoryNumber = 1234;
93
- const spyGetAssortment = jest.spyOn(ppa, 'getAssortment')
94
- .mockImplementation(async (assortmentId) => {
95
- return { id: assortmentId, name: assortmentName };
96
- });
97
- const spyyGetSnapshotVersion = jest.spyOn(ppa, 'getSnapshotVersion')
98
- .mockImplementation(async (assortmentId, assortmentPublishChangeId) => {
99
- return versionHistoryNumber;
100
- });
101
- const publishInfo = await ppa.getPublishInfo(assortmentId, assortmentPublishChangeId, plan_history, publisher);
102
- expect(publishInfo.assortmentName).toEqual(assortmentName);
103
- expect(publishInfo.versionName).toEqual(versionName);
104
- expect(publishInfo.versionComments).toEqual(versionComments);
105
- expect(publishInfo.publishDate).toEqual(createdOn);
106
- expect(publishInfo.publisher).toEqual(publisher);
107
- expect(publishInfo.versionHistoryNumber).toEqual(versionHistoryNumber);
108
- spyGetAssortment.mockRestore();
109
- spyyGetSnapshotVersion.mockRestore();
110
- });
111
- it('No Assortment Name', async () => {
112
- const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
113
- const assortmentPublishChangeId = 'sJbGx1Fpq1v2MmcI';
114
- const publisher = {
115
- email: 'chris@vibeiq.com'
116
- };
117
- const versionHistoryNumber = 1234;
118
- const spyGetAssortment = jest.spyOn(ppa, 'getAssortment')
119
- .mockImplementation(async (assortmentId) => {
120
- return { id: assortmentId, name: undefined };
121
- });
122
- const spyyGetSnapshotVersion = jest.spyOn(ppa, 'getSnapshotVersion')
123
- .mockImplementation(async (assortmentId, assortmentPublishChangeId) => {
124
- return versionHistoryNumber;
125
- });
126
- const publishInfo = await ppa.getPublishInfo(assortmentId, assortmentPublishChangeId, plan_history, publisher);
127
- expect(publishInfo.assortmentName).toBeUndefined;
128
- expect(publishInfo.versionName).toEqual(versionName);
129
- expect(publishInfo.versionComments).toEqual(versionComments);
130
- expect(publishInfo.publishDate).toEqual(createdOn);
131
- expect(publishInfo.publisher).toEqual(publisher);
132
- expect(publishInfo.versionHistoryNumber).toEqual(versionHistoryNumber);
133
- spyGetAssortment.mockRestore();
134
- spyyGetSnapshotVersion.mockRestore();
135
- });
136
- it('No Assortment', async () => {
137
- const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
138
- const assortmentPublishChangeId = 'sJbGx1Fpq1v2MmcI';
139
- const publisher = {
140
- email: 'chris@vibeiq.com'
141
- };
142
- const versionHistoryNumber = 1234;
143
- const spyGetAssortment = jest.spyOn(ppa, 'getAssortment')
144
- .mockImplementation(async (assortmentId) => {
145
- return undefined;
146
- });
147
- const spyyGetSnapshotVersion = jest.spyOn(ppa, 'getSnapshotVersion')
148
- .mockImplementation(async (assortmentId, assortmentPublishChangeId) => {
149
- return versionHistoryNumber;
150
- });
151
- const publishInfo = await ppa.getPublishInfo(assortmentId, assortmentPublishChangeId, plan_history, publisher);
152
- expect(publishInfo.assortmentName).toBeUndefined();
153
- expect(publishInfo.versionName).toEqual(versionName);
154
- expect(publishInfo.versionComments).toEqual(versionComments);
155
- expect(publishInfo.publishDate).toEqual(createdOn);
156
- expect(publishInfo.publisher).toEqual(publisher);
157
- expect(publishInfo.versionHistoryNumber).toEqual(versionHistoryNumber);
158
- spyGetAssortment.mockRestore();
159
- spyyGetSnapshotVersion.mockRestore();
160
- });
161
- it('Empty Version Name & Comments', async () => {
162
- const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
163
- const history = [
164
- {
165
- id: 'sJbGx1Fpq1v2MmcI',
166
- versionName: '',
167
- versionComments: '',
168
- createdOn
169
- }
170
- ];
171
- const assortmentPublishChangeId = 'sJbGx1Fpq1v2MmcI';
172
- const publisher = {
173
- email: 'chris@vibeiq.com'
174
- };
175
- const assortmentName = 'VibeIQ Fall 2023';
176
- const versionHistoryNumber = 1234;
177
- const spyGetAssortment = jest.spyOn(ppa, 'getAssortment')
178
- .mockImplementation(async (assortmentId) => {
179
- return { id: assortmentId, name: assortmentName };
180
- });
181
- const spyyGetSnapshotVersion = jest.spyOn(ppa, 'getSnapshotVersion')
182
- .mockImplementation(async (assortmentId, assortmentPublishChangeId) => {
183
- return versionHistoryNumber;
184
- });
185
- const publishInfo = await ppa.getPublishInfo(assortmentId, assortmentPublishChangeId, history, publisher);
186
- expect(publishInfo.assortmentName).toEqual(assortmentName);
187
- expect(publishInfo.versionName).toEqual('');
188
- expect(publishInfo.versionComments).toEqual('');
189
- expect(publishInfo.publishDate).toEqual(createdOn);
190
- expect(publishInfo.publisher).toEqual(publisher);
191
- expect(publishInfo.versionHistoryNumber).toEqual(versionHistoryNumber);
192
- spyGetAssortment.mockRestore();
193
- spyyGetSnapshotVersion.mockRestore();
194
- });
195
- it('Undefined Publisher', async () => {
196
- const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
197
- const assortmentPublishChangeId = 'sJbGx1Fpq1v2MmcI';
198
- const publisher = undefined;
199
- const assortmentName = 'VibeIQ Fall 2023';
200
- const versionHistoryNumber = 1234;
201
- const spyGetAssortment = jest.spyOn(ppa, 'getAssortment')
202
- .mockImplementation(async (assortmentId) => {
203
- return { id: assortmentId, name: assortmentName };
204
- });
205
- const spyyGetSnapshotVersion = jest.spyOn(ppa, 'getSnapshotVersion')
206
- .mockImplementation(async (assortmentId, assortmentPublishChangeId) => {
207
- return versionHistoryNumber;
208
- });
209
- const publishInfo = await ppa.getPublishInfo(assortmentId, assortmentPublishChangeId, plan_history, publisher);
210
- expect(publishInfo.assortmentName).toEqual(assortmentName);
211
- expect(publishInfo.versionName).toEqual(versionName);
212
- expect(publishInfo.versionComments).toEqual(versionComments);
213
- expect(publishInfo.publishDate).toEqual(createdOn);
214
- expect(publishInfo.publisher).toBeUndefined();
215
- expect(publishInfo.versionHistoryNumber).toEqual(versionHistoryNumber);
216
- spyGetAssortment.mockRestore();
217
- spyyGetSnapshotVersion.mockRestore();
218
- });
219
- it('No APC', async () => {
220
- const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
221
- const assortmentPublishChangeId = 'bad-id';
222
- const publisher = {
223
- email: 'chris@vibeiq.com'
224
- };
225
- const assortmentName = 'VibeIQ Fall 2023';
226
- const versionHistoryNumber = 1234;
227
- const spyGetAssortment = jest.spyOn(ppa, 'getAssortment')
228
- .mockImplementation(async (assortmentId) => {
229
- return { id: assortmentId, name: assortmentName };
230
- });
231
- const spyyGetSnapshotVersion = jest.spyOn(ppa, 'getSnapshotVersion')
232
- .mockImplementation(async (assortmentId, assortmentPublishChangeId) => {
233
- return versionHistoryNumber;
234
- });
235
- const publishInfo = await ppa.getPublishInfo(assortmentId, assortmentPublishChangeId, plan_history, publisher);
236
- expect(publishInfo.assortmentName).toEqual(assortmentName);
237
- expect(publishInfo.versionName).toBeUndefined();
238
- expect(publishInfo.versionComments).toBeUndefined();
239
- expect(publishInfo.publishDate).toBeUndefined();
240
- expect(publishInfo.publisher).toEqual(publisher);
241
- expect(publishInfo.versionHistoryNumber).toEqual(versionHistoryNumber);
242
- spyGetAssortment.mockRestore();
243
- spyyGetSnapshotVersion.mockRestore();
244
- });
245
- it('No APC history', async () => {
246
- const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
247
- const assortmentPublishChangeId = 'bad-id';
248
- const publisher = {
249
- email: 'chris@vibeiq.com'
250
- };
251
- const assortmentName = 'VibeIQ Fall 2023';
252
- const versionHistoryNumber = 1234;
253
- const spyGetAssortment = jest.spyOn(ppa, 'getAssortment')
254
- .mockImplementation(async (assortmentId) => {
255
- return { id: assortmentId, name: assortmentName };
256
- });
257
- const spyyGetSnapshotVersion = jest.spyOn(ppa, 'getSnapshotVersion')
258
- .mockImplementation(async (assortmentId, assortmentPublishChangeId) => {
259
- return versionHistoryNumber;
260
- });
261
- const publishInfo = await ppa.getPublishInfo(assortmentId, assortmentPublishChangeId, undefined, publisher);
262
- expect(publishInfo.assortmentName).toEqual(assortmentName);
263
- expect(publishInfo.versionName).toBeUndefined();
264
- expect(publishInfo.versionComments).toBeUndefined();
265
- expect(publishInfo.publishDate).toBeUndefined();
266
- expect(publishInfo.publisher).toEqual(publisher);
267
- expect(publishInfo.versionHistoryNumber).toEqual(versionHistoryNumber);
268
- spyGetAssortment.mockRestore();
269
- spyyGetSnapshotVersion.mockRestore();
270
- });
271
- });
272
- describe('getSnapshotVersion', () => {
273
- const config = {
274
- identifierAtts: {
275
- LCSSeason: ['flexPLMSeasonName']
276
- }
277
- };
278
- const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
279
- const dc = new data_converter_1.DataConverter(config, mapFileUtil);
280
- const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
281
- beforeEach(() => {
282
- federatedId = '';
283
- entityObject = { publishToFlexPLM: true };
284
- getOptionsObject = {};
285
- });
286
- it('has snapshot version', async () => {
287
- const assortment = {
288
- id: 'rm35clTNxvS4wm6y',
289
- name: 'VibeIQ Fall 2023',
290
- createdForReference: 'plan:w23wre'
291
- };
292
- const assortmentChangeId = 'sJbGx1Fpq1v2MmcI';
293
- const apc = {
294
- id: assortmentChangeId,
295
- versionName: 'Version 1',
296
- versionComments: 'Some Comments',
297
- createdOn: '2023-01-15T19:13:58.902Z'
298
- };
299
- const versionNumber = 1234;
300
- const snapshots = [
301
- {
302
- id: 'qewrwer',
303
- assortmentChangeId,
304
- versionNumber
305
- }
306
- ];
307
- entityObject = snapshots;
308
- const versionHistoryNumber = await ppa.getSnapshotVersion(assortment, apc);
309
- expect(versionHistoryNumber).toEqual(versionNumber);
310
- expect(getOptionsObject['entityName']).toEqual('entity-snapshot');
311
- expect(getOptionsObject['criteria']['entityReference']).toEqual(assortment.createdForReference);
312
- expect(getOptionsObject['criteria']['createdOn'].indexOf('ISGREATERTHAN')).toEqual(0);
313
- });
314
- it('doesnt find snapshot version, last snapshot after apc', async () => {
315
- const assortment = {
316
- id: 'rm35clTNxvS4wm6y',
317
- name: 'VibeIQ Fall 2023',
318
- createdForReference: 'plan:w23wre'
319
- };
320
- const assortmentChangeId = 'sJbGx1Fpq1v2MmcI';
321
- const apc = {
322
- id: assortmentChangeId,
323
- versionName: 'Version 1',
324
- versionComments: 'Some Comments',
325
- createdOn: '2023-01-15T19:13:58.902Z'
326
- };
327
- const versionNumber = 1234;
328
- const snapshots = [
329
- {
330
- id: 'qewrwer',
331
- assortmentChangeId: 'bad-id',
332
- createdOn: '2024-01-15T19:13:58.902Z',
333
- versionNumber
334
- }
335
- ];
336
- entityObject = snapshots;
337
- const versionHistoryNumber = await ppa.getSnapshotVersion(assortment, apc);
338
- expect(versionHistoryNumber).toEqual('unknown');
339
- expect(getOptionsObject['entityName']).toEqual('entity-snapshot');
340
- expect(getOptionsObject['criteria']['entityReference']).toEqual(assortment.createdForReference);
341
- expect(getOptionsObject['criteria']['createdOn'].indexOf('ISGREATERTHAN')).toEqual(0);
342
- });
343
- it('doesnt find snapshot version, last snapshot before apc', async () => {
344
- const assortment = {
345
- id: 'rm35clTNxvS4wm6y',
346
- name: 'VibeIQ Fall 2023',
347
- createdForReference: 'plan:w23wre'
348
- };
349
- const assortmentChangeId = 'sJbGx1Fpq1v2MmcI';
350
- const apc = {
351
- id: assortmentChangeId,
352
- versionName: 'Version 1',
353
- versionComments: 'Some Comments',
354
- createdOn: '2023-01-15T19:13:58.902Z'
355
- };
356
- const versionNumber = 1234;
357
- const snapshots = [
358
- {
359
- id: 'qewrwer',
360
- assortmentChangeId: 'bad-id',
361
- createdOn: '2023-01-14T19:13:58.902Z',
362
- versionNumber
363
- }
364
- ];
365
- entityObject = snapshots;
366
- const versionHistoryNumber = await ppa.getSnapshotVersion(assortment, apc);
367
- expect(versionHistoryNumber).toEqual('after: ' + versionNumber);
368
- expect(getOptionsObject['entityName']).toEqual('entity-snapshot');
369
- expect(getOptionsObject['criteria']['entityReference']).toEqual(assortment.createdForReference);
370
- expect(getOptionsObject['criteria']['createdOn'].indexOf('ISGREATERTHAN')).toEqual(0);
371
- });
372
- it('doesnt find snapshot version, no snapshots returned', async () => {
373
- const assortment = {
374
- id: 'rm35clTNxvS4wm6y',
375
- name: 'VibeIQ Fall 2023',
376
- createdForReference: 'plan:w23wre'
377
- };
378
- const assortmentChangeId = 'sJbGx1Fpq1v2MmcI';
379
- const apc = {
380
- id: assortmentChangeId,
381
- versionName: 'Version 1',
382
- versionComments: 'Some Comments',
383
- createdOn: '2023-01-15T19:13:58.902Z'
384
- };
385
- const snapshots = [];
386
- entityObject = snapshots;
387
- const versionHistoryNumber = await ppa.getSnapshotVersion(assortment, apc);
388
- expect(versionHistoryNumber).toEqual('unknown');
389
- expect(getOptionsObject['entityName']).toEqual('entity-snapshot');
390
- expect(getOptionsObject['criteria']['entityReference']).toEqual(assortment.createdForReference);
391
- expect(getOptionsObject['criteria']['createdOn'].indexOf('ISGREATERTHAN')).toEqual(0);
392
- });
393
- it('doesnt find snapshot version, last snapshot no createdOn', async () => {
394
- const assortment = {
395
- id: 'rm35clTNxvS4wm6y',
396
- name: 'VibeIQ Fall 2023',
397
- createdForReference: 'plan:w23wre'
398
- };
399
- const assortmentChangeId = 'sJbGx1Fpq1v2MmcI';
400
- const apc = {
401
- id: assortmentChangeId,
402
- versionName: 'Version 1',
403
- versionComments: 'Some Comments',
404
- createdOn: '2023-01-15T19:13:58.902Z'
405
- };
406
- const versionNumber = 1234;
407
- const snapshots = [
408
- {
409
- id: 'qewrwer',
410
- assortmentChangeId: 'bad-id',
411
- versionNumber
412
- }
413
- ];
414
- entityObject = snapshots;
415
- const versionHistoryNumber = await ppa.getSnapshotVersion(assortment, apc);
416
- expect(versionHistoryNumber).toEqual('unknown');
417
- expect(getOptionsObject['entityName']).toEqual('entity-snapshot');
418
- expect(getOptionsObject['criteria']['entityReference']).toEqual(assortment.createdForReference);
419
- expect(getOptionsObject['criteria']['createdOn'].indexOf('ISGREATERTHAN')).toEqual(0);
420
- });
421
- });
422
- describe('getSeasonFederation', () => {
423
- const config = {
424
- identifierAtts: {
425
- LCSSeason: ['flexPLMSeasonName']
426
- }
427
- };
428
- beforeEach(() => {
429
- federatedId = '';
430
- entityObject = { publishToFlexPLM: true };
431
- getOptionsObject = {};
432
- });
433
- afterEach(() => {
434
- jest.restoreAllMocks();
435
- });
436
- it('No Federation Info', async () => {
437
- const assortmentId = 'B3oRQpYVYzcJAJtQ';
438
- try {
439
- const identifierKeys = ['flexPLMSeasonName'];
440
- const informationKeys = ['name'];
441
- const spyTCU_id_keys = jest.spyOn(type_conversion_utils_1.TypeConversionUtils, 'getIdentifierProperties')
442
- .mockImplementation(async () => identifierKeys);
443
- const spyTCU_info_keys = jest.spyOn(type_conversion_utils_1.TypeConversionUtils, 'getInformationalProperties')
444
- .mockImplementation(async () => informationKeys);
445
- const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
446
- const dc = new data_converter_1.DataConverter(config, mapFileUtil);
447
- await new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil).getSeasonFederation(assortmentId);
448
- }
449
- catch (e) {
450
- expect(e.message).toEqual(base_process_publish_assortment_1.BaseProcessPublishAssortment.ASSORTMENT_NO_FED_INFO + config.identifierAtts.LCSSeason);
451
- }
452
- });
453
- });
454
- describe('Test getSinceDate', () => {
455
- it('getSinceDate from getSinceDateFromAPCs', async () => {
456
- const history = new Array(...mockData_1.plan1_history);
457
- const lastAPCId = 'sJbGx1Fpq1v2MmcI';
458
- const matchDate = new Date('2023-01-17T22:40:07.288Z');
459
- const config = {};
460
- const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
461
- const dc = new data_converter_1.DataConverter(config, mapFileUtil);
462
- const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
463
- ppa.getApcHistory = async () => {
464
- return history;
465
- };
466
- const sinceDate = await ppa.getSinceDate('oqIFX3ELRy8sFRd0', lastAPCId, history);
467
- expect(sinceDate).toEqual(matchDate);
468
- });
469
- it('getSinceDate date from config as year', async () => {
470
- const history = new Array(...mockData_1.plan1_history);
471
- const lastAPCId = 'sJbGx1Fpq1v2MmcI';
472
- const matchDate = new Date('2023-01-16T21:50:42.742Z');
473
- const config = { sinceDate: '2023-01-17' };
474
- const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
475
- const dc = new data_converter_1.DataConverter(config, mapFileUtil);
476
- const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
477
- ppa.getApcHistory = async () => {
478
- return history;
479
- };
480
- const sinceDate = await ppa.getSinceDate('oqIFX3ELRy8sFRd0', lastAPCId, history);
481
- expect(sinceDate).toEqual(matchDate);
482
- });
483
- it('getSinceDate date from config numberofdays-cross month', async () => {
484
- const count = 10;
485
- const history = new Array(...mockData_1.plan1_across_month_DST);
486
- const lastAPCId = '_mj--7nlyp7mmDrK';
487
- const matchDate = new Date('2023-02-25T19:13:58.902Z');
488
- const config = { sinceDate: 'numberofdays:' + count };
489
- const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
490
- const dc = new data_converter_1.DataConverter(config, mapFileUtil);
491
- const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
492
- const sinceDate = await ppa.getSinceDate('oqIFX3ELRy8sFRd0', lastAPCId, history);
493
- expect(sinceDate).toEqual(matchDate);
494
- });
495
- it('getSinceDate date from config numberofdays-cross DST', async () => {
496
- const count = 11;
497
- const history = new Array(...mockData_1.plan1_across_month_DST);
498
- const lastAPCId = 'sJbGx1Fpq1v2MmcI';
499
- const matchDate = new Date('2023-03-06T21:50:42.742Z');
500
- const config = { sinceDate: 'numberofdays:' + count };
501
- const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
502
- const dc = new data_converter_1.DataConverter(config, mapFileUtil);
503
- const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
504
- const sinceDate = await ppa.getSinceDate('oqIFX3ELRy8sFRd0', lastAPCId, history);
505
- expect(sinceDate).toEqual(matchDate);
506
- });
507
- it('getSinceDate date from config numberofpublishes', async () => {
508
- const count = 3;
509
- const history = new Array(...mockData_1.plan1_history);
510
- const lastAPCId = 'sJbGx1Fpq1v2MmcI';
511
- const matchDate = new Date('2023-01-17T22:35:20.517Z');
512
- const config = { sinceDate: 'numberofpublishes:' + count };
513
- const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
514
- const dc = new data_converter_1.DataConverter(config, mapFileUtil);
515
- const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
516
- const sinceDate = await ppa.getSinceDate('oqIFX3ELRy8sFRd0', lastAPCId, history);
517
- expect(sinceDate).toEqual(matchDate);
518
- });
519
- it('getSinceDate date from config numberofpublishes', async () => {
520
- const count = 3;
521
- const history = new Array(...mockData_1.plan1_history);
522
- const lastAPCId = 'sJbGx1Fpq1v2MmcI';
523
- const matchDate = new Date('2023-01-17T22:35:20.517Z');
524
- const config = { sinceDate: 'numberofpublishes:' + count };
525
- const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
526
- const dc = new data_converter_1.DataConverter(config, mapFileUtil);
527
- const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
528
- ppa.getApcHistory = async () => {
529
- return history;
530
- };
531
- const sinceDate = await ppa.getSinceDate('oqIFX3ELRy8sFRd0', lastAPCId, history);
532
- expect(sinceDate).toEqual(matchDate);
533
- });
534
- });
535
- describe('getSinceDateFromAPCSpecificDate', () => {
536
- it('last apc - one day', () => {
537
- const history = new Array(...mockData_1.plan1_history);
538
- const lastAPCId = 'sJbGx1Fpq1v2MmcI';
539
- const matchDate = new Date('2023-01-16T21:50:42.742Z');
540
- const config = {};
541
- const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
542
- const dc = new data_converter_1.DataConverter(config, mapFileUtil);
543
- const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
544
- const sinceDate = ppa.getSinceDateFromAPCSpecificDate(history, lastAPCId, new Date('2023-01-17T00:00:00.000Z'));
545
- expect(sinceDate).toEqual(matchDate);
546
- });
547
- it('apc in the middle - one day', () => {
548
- const history = new Array(...mockData_1.plan1_history);
549
- const lastAPCId = 'GiT9CZXZGVljoYMR';
550
- const matchDate = new Date('2023-01-15T19:13:58.902Z');
551
- const config = {};
552
- const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
553
- const dc = new data_converter_1.DataConverter(config, mapFileUtil);
554
- const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
555
- const sinceDate = ppa.getSinceDateFromAPCSpecificDate(history, lastAPCId, new Date('2023-01-16T00:00:00.000Z'));
556
- expect(sinceDate).toEqual(matchDate);
557
- });
558
- it('before initial publish', () => {
559
- const history = new Array(...mockData_1.plan1_history);
560
- const lastAPCId = 'sJbGx1Fpq1v2MmcI';
561
- const matchDate = new Date('2023-01-15T19:13:58.902Z');
562
- const config = {};
563
- const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
564
- const dc = new data_converter_1.DataConverter(config, mapFileUtil);
565
- const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
566
- const sinceDate = ppa.getSinceDateFromAPCSpecificDate(history, lastAPCId, new Date('2021-01-17T00:00:00.000Z'));
567
- expect(sinceDate).toEqual(matchDate);
568
- });
569
- it('numberofdays at 2 ', () => {
570
- const history = new Array(...mockData_1.plan1_history);
571
- const lastAPCId = 'sJbGx1Fpq1v2MmcI';
572
- const matchDate = new Date('2023-01-15T19:13:58.902Z');
573
- const config = {};
574
- const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
575
- const dc = new data_converter_1.DataConverter(config, mapFileUtil);
576
- const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
577
- const sinceDate = ppa.getSinceDateFromAPCSpecificDate(history, lastAPCId, new Date('2023-01-16T00:00:00.000Z'));
578
- expect(sinceDate).toEqual(matchDate);
579
- });
580
- });
581
- describe('getSinceDateDaysPrevious', () => {
582
- it('last apc - one day', () => {
583
- const history = new Array(...mockData_1.plan1_history);
584
- const lastAPCId = 'sJbGx1Fpq1v2MmcI';
585
- const matchDate = new Date('2023-01-16T21:50:42.742Z');
586
- const config = {};
587
- const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
588
- const dc = new data_converter_1.DataConverter(config, mapFileUtil);
589
- const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
590
- const sinceDate = ppa.getSinceDateDaysPrevious(history, lastAPCId, 1);
591
- expect(sinceDate).toEqual(matchDate);
592
- });
593
- it('apc in the middle - one day', () => {
594
- const history = new Array(...mockData_1.plan1_history);
595
- const lastAPCId = 'GiT9CZXZGVljoYMR';
596
- const matchDate = new Date('2023-01-15T19:13:58.902Z');
597
- const config = {};
598
- const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
599
- const dc = new data_converter_1.DataConverter(config, mapFileUtil);
600
- const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
601
- const sinceDate = ppa.getSinceDateDaysPrevious(history, lastAPCId, 1);
602
- expect(sinceDate).toEqual(matchDate);
603
- });
604
- it('numberofdays greater than array size', () => {
605
- const history = new Array(...mockData_1.plan1_history);
606
- const lastAPCId = 'sJbGx1Fpq1v2MmcI';
607
- const matchDate = new Date('2023-01-15T19:13:58.902Z');
608
- const config = {};
609
- const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
610
- const dc = new data_converter_1.DataConverter(config, mapFileUtil);
611
- const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
612
- const sinceDate = ppa.getSinceDateDaysPrevious(history, lastAPCId, 5);
613
- expect(sinceDate).toEqual(matchDate);
614
- });
615
- it('numberofdays at 2 ', () => {
616
- const history = new Array(...mockData_1.plan1_history);
617
- const lastAPCId = 'sJbGx1Fpq1v2MmcI';
618
- const matchDate = new Date('2023-01-15T19:13:58.902Z');
619
- const config = {};
620
- const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
621
- const dc = new data_converter_1.DataConverter(config, mapFileUtil);
622
- const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
623
- const sinceDate = ppa.getSinceDateDaysPrevious(history, lastAPCId, 2);
624
- expect(sinceDate).toEqual(matchDate);
625
- });
626
- });
627
- describe('getSinceDateFromAPCs', () => {
628
- it('first / only apc', () => {
629
- const history = new Array(...mockData_1.plan1_history).slice(0, 1);
630
- const lastAPCId = 'v9BKkHo-tpL0wUZN';
631
- const matchDate = new Date(0);
632
- const config = {};
633
- const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
634
- const dc = new data_converter_1.DataConverter(config, mapFileUtil);
635
- const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
636
- const sinceDate = ppa.getSinceDateFromAPCs(history, lastAPCId);
637
- expect(sinceDate).toEqual(matchDate);
638
- });
639
- it('first / multiple apcs in history', () => {
640
- const history = new Array(...mockData_1.plan1_history).slice(0, 3);
641
- const lastAPCId = 'v9BKkHo-tpL0wUZN';
642
- const matchDate = new Date(0);
643
- const config = {};
644
- const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
645
- const dc = new data_converter_1.DataConverter(config, mapFileUtil);
646
- const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
647
- const sinceDate = ppa.getSinceDateFromAPCs(history, lastAPCId);
648
- expect(sinceDate).toEqual(matchDate);
649
- });
650
- it('last apc', () => {
651
- const history = new Array(...mockData_1.plan1_history);
652
- const lastAPCId = 'sJbGx1Fpq1v2MmcI';
653
- const matchDate = new Date('2023-01-17T22:40:07.288Z');
654
- const config = {};
655
- const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
656
- const dc = new data_converter_1.DataConverter(config, mapFileUtil);
657
- const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
658
- const sinceDate = ppa.getSinceDateFromAPCs(history, lastAPCId);
659
- expect(sinceDate).toEqual(matchDate);
660
- });
661
- it('apc in the middle', () => {
662
- const history = new Array(...mockData_1.plan1_history);
663
- const lastAPCId = 'GiT9CZXZGVljoYMR';
664
- const matchDate = new Date('2023-01-16T21:50:42.742Z');
665
- const config = {};
666
- const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
667
- const dc = new data_converter_1.DataConverter(config, mapFileUtil);
668
- const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
669
- const sinceDate = ppa.getSinceDateFromAPCs(history, lastAPCId);
670
- expect(sinceDate).toEqual(matchDate);
671
- });
672
- it('pastPublishCount greater than array size', () => {
673
- const history = new Array(...mockData_1.plan1_history);
674
- const lastAPCId = 'sJbGx1Fpq1v2MmcI';
675
- const matchDate = new Date('2023-01-15T19:13:58.902Z');
676
- const config = {};
677
- const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
678
- const dc = new data_converter_1.DataConverter(config, mapFileUtil);
679
- const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
680
- const sinceDate = ppa.getSinceDateFromAPCs(history, lastAPCId, 20);
681
- expect(sinceDate).toEqual(matchDate);
682
- });
683
- it('pastPublishCount at 3 ', () => {
684
- const history = new Array(...mockData_1.plan1_history);
685
- const lastAPCId = 'sJbGx1Fpq1v2MmcI';
686
- const matchDate = new Date('2023-01-17T22:35:20.517Z');
687
- const config = {};
688
- const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
689
- const dc = new data_converter_1.DataConverter(config, mapFileUtil);
690
- const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
691
- const sinceDate = ppa.getSinceDateFromAPCs(history, lastAPCId, 3);
692
- expect(sinceDate).toEqual(matchDate);
693
- });
694
- });
695
- describe('getDeleteChanges', () => {
696
- const config = {};
697
- const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
698
- const dc = new data_converter_1.DataConverter(config, mapFileUtil);
699
- it('no deletes - 1 apc', async () => {
700
- const history = new Array(...mockData_1.apc_2bOWR2j9R0QThDVu_delete_history);
701
- const lastAPCId = 'SYHfQzYWlfXDqK7r';
702
- const apcIndex = history.findIndex(pc => pc.id === lastAPCId);
703
- const apc = history[apcIndex];
704
- const previousApc = (apcIndex > 0)
705
- ? history[apcIndex - 1]
706
- : undefined;
707
- const apcDate = (previousApc) ? new Date(previousApc['createdOn']) : new Date(0);
708
- const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
709
- const spy = jest.spyOn(ppa, 'downloadDeleteChanges')
710
- .mockImplementation(async (assortmentPublishChange) => {
711
- let deleteChanges = [];
712
- if (assortmentPublishChange) {
713
- const apcId = assortmentPublishChange['id'];
714
- const apc = history.find(apc => apc['id'] === apcId);
715
- deleteChanges = apc['deleteData'];
716
- }
717
- return deleteChanges;
718
- });
719
- const deleteChanges = await ppa.getDeleteChanges(apc, history, apc['assortmentBaseline'], apcDate);
720
- expect(deleteChanges).toEqual([]);
721
- spy.mockRestore();
722
- });
723
- it('1 delete - 1 apc', async () => {
724
- const history = new Array(...mockData_1.apc_2bOWR2j9R0QThDVu_delete_history);
725
- const lastAPCId = 'JreGRNvoJ3FsoRZI';
726
- const apcIndex = history.findIndex(pc => pc.id === lastAPCId);
727
- const apc = history[apcIndex];
728
- const previousApc = (apcIndex > 0)
729
- ? history[apcIndex - 1]
730
- : undefined;
731
- const apcDate = (previousApc) ? new Date(previousApc['createdOn']) : new Date(0);
732
- const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
733
- const spy = jest.spyOn(ppa, 'downloadDeleteChanges')
734
- .mockImplementation(async (assortmentPublishChange) => {
735
- let deleteChanges = [];
736
- if (assortmentPublishChange) {
737
- const apcId = assortmentPublishChange['id'];
738
- const apc = history.find(apc => apc['id'] === apcId);
739
- deleteChanges = apc['deleteData'];
740
- }
741
- return deleteChanges;
742
- });
743
- const deleteChanges = await ppa.getDeleteChanges(apc, history, apc['assortmentBaseline'], apcDate);
744
- expect(deleteChanges).toHaveLength(1);
745
- spy.mockRestore();
746
- });
747
- it('no deletes - testing #3 apc', async () => {
748
- const history = new Array(...mockData_1.apc_2bOWR2j9R0QThDVu_delete_history);
749
- const lastAPCId = 'NaPUhAdEzKB-5tQ3';
750
- const apcIndex = history.findIndex(pc => pc.id === lastAPCId);
751
- const apc = history[apcIndex];
752
- const previousApc = (apcIndex > 0)
753
- ? history[apcIndex - 1]
754
- : undefined;
755
- const apcDate = (previousApc) ? new Date(previousApc['createdOn']) : new Date(0);
756
- const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
757
- const spy = jest.spyOn(ppa, 'downloadDeleteChanges')
758
- .mockImplementation(async (assortmentPublishChange) => {
759
- let deleteChanges = [];
760
- if (assortmentPublishChange) {
761
- const apcId = assortmentPublishChange['id'];
762
- const apc = history.find(apc => apc['id'] === apcId);
763
- deleteChanges = apc['deleteData'];
764
- }
765
- return deleteChanges;
766
- });
767
- const deleteChanges = await ppa.getDeleteChanges(apc, history, apc['assortmentBaseline'], apcDate);
768
- expect(deleteChanges).toEqual([]);
769
- spy.mockRestore();
770
- });
771
- it('1 delete - 1 apc', async () => {
772
- const history = new Array(...mockData_1.apc_2bOWR2j9R0QThDVu_delete_history);
773
- const lastAPCId = 'CHGKSCT358qyh1Nu';
774
- const apcIndex = history.findIndex(pc => pc.id === lastAPCId);
775
- const apc = history[apcIndex];
776
- const previousApc = (apcIndex > 0)
777
- ? history[apcIndex - 1]
778
- : undefined;
779
- const apcDate = (previousApc) ? new Date(previousApc['createdOn']) : new Date(0);
780
- const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
781
- const spy = jest.spyOn(ppa, 'downloadDeleteChanges')
782
- .mockImplementation(async (assortmentPublishChange) => {
783
- let deleteChanges = [];
784
- if (assortmentPublishChange) {
785
- const apcId = assortmentPublishChange['id'];
786
- const apc = history.find(apc => apc['id'] === apcId);
787
- deleteChanges = apc['deleteData'];
788
- }
789
- return deleteChanges;
790
- });
791
- const deleteChanges = await ppa.getDeleteChanges(apc, history, apc['assortmentBaseline'], apcDate);
792
- expect(deleteChanges).toHaveLength(1);
793
- spy.mockRestore();
794
- });
795
- it('1 delete - 2 apc (most recent delete apc, no change earlier apc)', async () => {
796
- const history = new Array(...mockData_1.apc_2bOWR2j9R0QThDVu_delete_history);
797
- const lastAPCId = 'CHGKSCT358qyh1Nu';
798
- const apc = history.find(pc => pc.id === lastAPCId);
799
- const baseApcId = 'JreGRNvoJ3FsoRZI';
800
- const baseApc = history.find(pc => pc.id === baseApcId);
801
- const apcDate = new Date(baseApc['createdOn']);
802
- const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
803
- const spy = jest.spyOn(ppa, 'downloadDeleteChanges')
804
- .mockImplementation(async (assortmentPublishChange) => {
805
- let deleteChanges = [];
806
- if (assortmentPublishChange) {
807
- const apcId = assortmentPublishChange['id'];
808
- const apc = history.find(apc => apc['id'] === apcId);
809
- deleteChanges = apc['deleteData'];
810
- }
811
- return deleteChanges;
812
- });
813
- const deleteChanges = await ppa.getDeleteChanges(apc, history, apc['assortmentBaseline'], apcDate);
814
- expect(deleteChanges).toHaveLength(1);
815
- const item = deleteChanges[0];
816
- expect(item).not.toBeNull();
817
- expect(item['itemId']).toEqual('qNCQmTFcFxwbT-oG');
818
- spy.mockRestore();
819
- });
820
- it('1 delete - 2 apc (most recent no change, 1 delete earlier apc)', async () => {
821
- const history = new Array(...mockData_1.apc_2bOWR2j9R0QThDVu_delete_history);
822
- const lastAPCId = 'NaPUhAdEzKB-5tQ3';
823
- const apc = history.find(pc => pc.id === lastAPCId);
824
- const baseApcId = 'SYHfQzYWlfXDqK7r';
825
- const baseApc = history.find(pc => pc.id === baseApcId);
826
- const apcDate = new Date(baseApc['createdOn']);
827
- const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
828
- const spy = jest.spyOn(ppa, 'downloadDeleteChanges')
829
- .mockImplementation(async (assortmentPublishChange) => {
830
- let deleteChanges = [];
831
- if (assortmentPublishChange) {
832
- const apcId = assortmentPublishChange['id'];
833
- const apc = history.find(apc => apc['id'] === apcId);
834
- deleteChanges = apc['deleteData'];
835
- }
836
- return deleteChanges;
837
- });
838
- const deleteChanges = await ppa.getDeleteChanges(apc, history, apc['assortmentBaseline'], apcDate);
839
- expect(deleteChanges).toHaveLength(1);
840
- const item = deleteChanges[0];
841
- expect(item).not.toBeNull();
842
- expect(item['itemId']).toEqual('SfUAZy_Hj631h2Kg');
843
- spy.mockRestore();
844
- });
845
- it('2 delete - 3 apc (most recent delete apc, no change middle apc, 1 delete)', async () => {
846
- const history = new Array(...mockData_1.apc_2bOWR2j9R0QThDVu_delete_history);
847
- const lastAPCId = 'CHGKSCT358qyh1Nu';
848
- const apc = history.find(pc => pc.id === lastAPCId);
849
- const baseApcId = 'SYHfQzYWlfXDqK7r';
850
- const baseApc = history.find(pc => pc.id === baseApcId);
851
- const apcDate = new Date(baseApc['createdOn']);
852
- const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
853
- const spy = jest.spyOn(ppa, 'downloadDeleteChanges')
854
- .mockImplementation(async (assortmentPublishChange) => {
855
- let deleteChanges = [];
856
- if (assortmentPublishChange) {
857
- const apcId = assortmentPublishChange['id'];
858
- const apc = history.find(apc => apc['id'] === apcId);
859
- deleteChanges = apc['deleteData'];
860
- }
861
- return deleteChanges;
862
- });
863
- const deleteChanges = await ppa.getDeleteChanges(apc, history, apc['assortmentBaseline'], apcDate);
864
- expect(deleteChanges).toHaveLength(2);
865
- const itemIds = deleteChanges.map(dItem => dItem['itemId']);
866
- expect(itemIds).toContain('SfUAZy_Hj631h2Kg');
867
- expect(itemIds).toContain('qNCQmTFcFxwbT-oG');
868
- spy.mockRestore();
869
- });
870
- it('1 delete - 4 apc (most recent re-add, 1 delete, no change middle apc, 1 delete)', async () => {
871
- console.log('1 delete - 4 apc (most recent re-add, 1 delete, no change middle apc, 1 delete)');
872
- const history = new Array(...mockData_1.apc_2bOWR2j9R0QThDVu_delete_history);
873
- const lastAPCId = 'H4L4dHziO6WZRIwa';
874
- const apc = history.find(pc => pc.id === lastAPCId);
875
- const baseApcId = 'SYHfQzYWlfXDqK7r';
876
- const baseApc = history.find(pc => pc.id === baseApcId);
877
- const apcDate = new Date(baseApc['createdOn']);
878
- const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
879
- const spy = jest.spyOn(ppa, 'downloadDeleteChanges')
880
- .mockImplementation(async (assortmentPublishChange) => {
881
- let deleteChanges = [];
882
- if (assortmentPublishChange) {
883
- const apcId = assortmentPublishChange['id'];
884
- const apc = history.find(apc => apc['id'] === apcId);
885
- deleteChanges = apc['deleteData'];
886
- }
887
- return deleteChanges;
888
- });
889
- const deleteChanges = await ppa.getDeleteChanges(apc, history, apc['assortmentBaseline'], apcDate);
890
- expect(deleteChanges).toHaveLength(1);
891
- const itemIds = deleteChanges.map(dItem => dItem['itemId']);
892
- expect(itemIds).toContain('qNCQmTFcFxwbT-oG');
893
- spy.mockRestore();
894
- });
895
- });
896
- describe('buildDeleteChanges', () => {
897
- const config = {};
898
- const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
899
- const dc = new data_converter_1.DataConverter(config, mapFileUtil);
900
- beforeEach(() => {
901
- jest.clearAllMocks();
902
- });
903
- it('apc has valid deleteDataDownloadLink', async () => {
904
- const returnedDeleteData = [
905
- {}
906
- ];
907
- const apc = {
908
- deleteDataDownloadLink: 'deleteDataDownloadLink',
909
- returnedDeleteData
910
- };
911
- const previousApc = {};
912
- const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
913
- const spy = jest.spyOn(ppa, 'downloadDeleteChanges')
914
- .mockImplementation(async (assortmentPublishChange) => {
915
- return assortmentPublishChange['returnedDeleteData'];
916
- });
917
- const deleteChanges = await ppa.buildDeleteChanges(apc, previousApc);
918
- expect(deleteChanges).toHaveLength(returnedDeleteData.length);
919
- expect(spy).toBeCalledWith(apc);
920
- spy.mockRestore();
921
- });
922
- it('apc no deleteDataDownloadLink, but fullAPC has valid link', async () => {
923
- const returnedDeleteData = [
924
- {}
925
- ];
926
- const apc = {};
927
- const fullAPC = {
928
- deleteDataDownloadLink: 'deleteDataDownloadLink',
929
- returnedDeleteData
930
- };
931
- const previousApc = {};
932
- const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
933
- const spy = jest.spyOn(ppa, 'downloadDeleteChanges')
934
- .mockImplementation(async (assortmentPublishChange) => {
935
- return assortmentPublishChange['returnedDeleteData'];
936
- });
937
- const spy2 = jest.spyOn(ppa, 'downloadAssortmentPublishChange')
938
- .mockImplementation(async () => {
939
- return fullAPC;
940
- });
941
- const deleteChanges = await ppa.buildDeleteChanges(apc, previousApc);
942
- expect(deleteChanges).toHaveLength(returnedDeleteData.length);
943
- expect(spy).toBeCalledWith(fullAPC);
944
- spy.mockRestore();
945
- spy2.mockRestore();
946
- });
947
- it('apc & fullAPC no deleteDataDownloadLink, error no previousApc', async () => {
948
- const returnedDeleteData = [
949
- {}
950
- ];
951
- const apc = {};
952
- const fullAPC = {
953
- returnedDeleteData
954
- };
955
- const previousApc = undefined;
956
- const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
957
- const spy2 = jest.spyOn(ppa, 'downloadAssortmentPublishChange')
958
- .mockImplementation(async () => {
959
- return fullAPC;
960
- });
961
- expect(async () => { await ppa.buildDeleteChanges(apc, previousApc); }).rejects.toThrow(new Error(base_process_publish_assortment_1.BaseProcessPublishAssortment.NOT_ABLE_TO_PROCESS_DELETE_CHANGES));
962
- spy2.mockRestore();
963
- });
964
- it('apc & fullAPC no deleteDataDownloadLink, use previousApc.assortmentBaselineDownloadLink', async () => {
965
- const assortmentId = '123';
966
- const apcId = '456';
967
- const previousApcId = '987';
968
- const apc = {
969
- assortmentId,
970
- id: apcId,
971
- detail: {
972
- deletes: [{ id: '1' }, { id: '3' }]
973
- }
974
- };
975
- const fullAPC = {
976
- assortmentId,
977
- id: apcId,
978
- detail: {
979
- deletes: [{ id: '1' }, { id: '3' }]
980
- }
981
- };
982
- const previousApc = {};
983
- const fullPreviousApc = {
984
- id: previousApcId,
985
- assortmentBaselineDownloadLink: 'assortmentBaselineDownloadLink'
986
- };
987
- const previousApcBaseline = {
988
- assortmentItems: [
989
- { itemId: '1' },
990
- { itemId: '2' },
991
- { itemId: '3' }
992
- ]
993
- };
994
- const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
995
- const spyDownloadDeleteChanges = jest.spyOn(ppa, 'downloadDeleteChanges')
996
- .mockImplementation(async (assortmentPublishChange) => {
997
- return assortmentPublishChange['returnedDeleteData'];
998
- });
999
- const spyDownloadAssortmentPublishChange = jest.spyOn(ppa, 'downloadAssortmentPublishChange')
1000
- .mockImplementation(async (assortmentId, id) => {
1001
- if (id === apcId) {
1002
- return fullAPC;
1003
- }
1004
- else {
1005
- return fullPreviousApc;
1006
- }
1007
- });
1008
- const spyDownloadAssortmentBaseline = jest.spyOn(ppa, 'downloadAssortmentBaseline')
1009
- .mockImplementation(async () => {
1010
- return previousApcBaseline;
1011
- });
1012
- const deleteChanges = await ppa.buildDeleteChanges(apc, previousApc);
1013
- expect(deleteChanges).toHaveLength(apc.detail.deletes.length);
1014
- expect(spyDownloadAssortmentBaseline).toBeCalledWith(fullPreviousApc);
1015
- spyDownloadDeleteChanges.mockRestore();
1016
- spyDownloadAssortmentPublishChange.mockRestore();
1017
- spyDownloadAssortmentBaseline.mockRestore();
1018
- });
1019
- it('apc & fullAPC no deleteDataDownloadLink, use fullPreviousApc.assortmentBaselineDownloadLink', async () => {
1020
- const assortmentId = '123';
1021
- const apcId = '456';
1022
- const apc = {
1023
- assortmentId,
1024
- id: apcId,
1025
- detail: {
1026
- deletes: [{ id: '1' }, { id: '3' }]
1027
- }
1028
- };
1029
- const fullAPC = {
1030
- assortmentId,
1031
- id: apcId,
1032
- detail: {
1033
- deletes: [{ id: '1' }, { id: '3' }]
1034
- }
1035
- };
1036
- const previousApc = {
1037
- assortmentBaselineDownloadLink: 'assortmentBaselineDownloadLink'
1038
- };
1039
- const previousApcBaseline = {
1040
- assortmentItems: [
1041
- { itemId: '1' },
1042
- { itemId: '2' },
1043
- { itemId: '3' }
1044
- ]
1045
- };
1046
- const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
1047
- const spyDownloadDeleteChanges = jest.spyOn(ppa, 'downloadDeleteChanges')
1048
- .mockImplementation(async (assortmentPublishChange) => {
1049
- return assortmentPublishChange['returnedDeleteData'];
1050
- });
1051
- const spyDownloadAssortmentPublishChange = jest.spyOn(ppa, 'downloadAssortmentPublishChange')
1052
- .mockImplementation(async () => {
1053
- return fullAPC;
1054
- });
1055
- const spyDownloadAssortmentBaseline = jest.spyOn(ppa, 'downloadAssortmentBaseline')
1056
- .mockImplementation(async () => {
1057
- return previousApcBaseline;
1058
- });
1059
- const deleteChanges = await ppa.buildDeleteChanges(apc, previousApc);
1060
- expect(deleteChanges).toHaveLength(apc.detail.deletes.length);
1061
- expect(spyDownloadAssortmentBaseline).toBeCalledWith(previousApc);
1062
- spyDownloadDeleteChanges.mockRestore();
1063
- spyDownloadAssortmentPublishChange.mockRestore();
1064
- spyDownloadAssortmentBaseline.mockRestore();
1065
- });
1066
- });
1067
- describe('getItemFamilyChanges', () => {
1068
- const filterFullChange = (fullChange, itemFamilyIds) => {
1069
- const fChange = Object.assign({}, fullChange);
1070
- fChange['assortmentItems'] = fChange['assortmentItems']
1071
- .filter(assortItem => itemFamilyIds.includes(assortItem['item']['itemFamilyId']));
1072
- return fChange;
1073
- };
1074
- const filterDeleteChange = (deleteChange, itemFamilyIds) => {
1075
- let dChange = Array.from(deleteChange);
1076
- dChange = dChange.filter(assortItem => itemFamilyIds.includes(assortItem['item']['itemFamilyId']));
1077
- return dChange;
1078
- };
1079
- const filterHydratedDetails = (hydratedDetails, itemFamilyIds) => {
1080
- const hDetails = Object.assign({}, hydratedDetails);
1081
- hDetails['adds'] = hDetails['adds']
1082
- .filter(assortItem => itemFamilyIds.includes(assortItem['item']['itemFamilyId']));
1083
- hDetails['deletes'] = hDetails['deletes']
1084
- .filter(assortItem => itemFamilyIds.includes(assortItem['item']['itemFamilyId']));
1085
- hDetails['familyItemsRemoved'] = hDetails['familyItemsRemoved']
1086
- .filter(assortItem => itemFamilyIds.includes(assortItem['item']['itemFamilyId']));
1087
- return hDetails;
1088
- };
1089
- it('Feb 3 - No Option A', () => {
1090
- const itemFamilyId = 'kh1Rtb7kie7Vk5vo';
1091
- const fullChange = filterFullChange(mockData_1.fall_2003_fullChange, [itemFamilyId]);
1092
- const hydratedDetails = filterHydratedDetails(mockData_1.fall_2003_hydratedDetails, [itemFamilyId]);
1093
- const seasonFed = {
1094
- entityReference: 'assortment:' + fullChange['id'],
1095
- objectClass: 'LCSSeason',
1096
- federationId: 'VR:...LCSSeason:1'
1097
- };
1098
- const itemToFederatedIdMapping = new Map();
1099
- mockData_1.fall_2003_fedMapping.forEach(mapping => itemToFederatedIdMapping.set(mapping.reference, mapping.mappedReference));
1100
- const sinceDate = new Date('2023-02-01T00:00:00.000Z');
1101
- const config = {};
1102
- const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
1103
- const dc = new data_converter_1.DataConverter(config, mapFileUtil);
1104
- const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
1105
- const assortmentItemFullChangeMap = ppa.getFullChangeAssortmentMap(fullChange);
1106
- const assortmentItemDeleteMap = new Map();
1107
- const pcd = new publish_change_data_1.PublishChangeData(fullChange['id'], seasonFed, 'i-OONhGKbJAfRKo-', sinceDate);
1108
- pcd.itemToFederatedIdMapping = itemToFederatedIdMapping;
1109
- pcd.releasedForDevelopmentItemIds.push(itemFamilyId);
1110
- pcd.itemFamilyChanges = ppa.getItemFamilyChanges(pcd, hydratedDetails, assortmentItemFullChangeMap, assortmentItemDeleteMap);
1111
- const ifcs = pcd.itemFamilyChanges;
1112
- expect(ifcs.size).toEqual(1);
1113
- const ifc = ifcs.get(itemFamilyId);
1114
- expect(ifc.familyAdd).toBe(true);
1115
- expect(ifc.colorAdds.length).toEqual(0);
1116
- });
1117
- it('Feb 3 - 1 Option A', () => {
1118
- const itemFamilyId = 'U9QryfGVOYMAkBP_';
1119
- const fullChange = filterFullChange(mockData_1.fall_2003_fullChange, [itemFamilyId]);
1120
- const hydratedDetails = filterHydratedDetails(mockData_1.fall_2003_hydratedDetails, [itemFamilyId]);
1121
- const seasonFed = {
1122
- entityReference: 'assortment:' + fullChange['id'],
1123
- objectClass: 'LCSSeason',
1124
- federationId: 'VR:...LCSSeason:1'
1125
- };
1126
- const itemToFederatedIdMapping = new Map();
1127
- mockData_1.fall_2003_fedMapping.forEach(mapping => itemToFederatedIdMapping.set(mapping.reference, mapping.mappedReference));
1128
- const sinceDate = new Date('2023-02-01T00:00:00.000Z');
1129
- const config = {};
1130
- const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
1131
- const dc = new data_converter_1.DataConverter(config, mapFileUtil);
1132
- const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
1133
- const assortmentItemFullChangeMap = ppa.getFullChangeAssortmentMap(fullChange);
1134
- const assortmentItemDeleteMap = new Map();
1135
- const pcd = new publish_change_data_1.PublishChangeData(fullChange['id'], seasonFed, 'i-OONhGKbJAfRKo-', sinceDate);
1136
- pcd.itemToFederatedIdMapping = itemToFederatedIdMapping;
1137
- pcd.releasedForDevelopmentItemIds.push('jFAp5SmYqhXoX-ZI');
1138
- pcd.releasedForDevelopmentItemIds.push('U9QryfGVOYMAkBP_');
1139
- pcd.itemFamilyChanges = ppa.getItemFamilyChanges(pcd, hydratedDetails, assortmentItemFullChangeMap, assortmentItemDeleteMap);
1140
- const ifcs = pcd.itemFamilyChanges;
1141
- expect(ifcs.size).toEqual(1);
1142
- const ifc = ifcs.get(itemFamilyId);
1143
- expect(ifc.colorAdds.length).toEqual(1);
1144
- });
1145
- it('Feb 3 - 2+ Option A', () => {
1146
- const itemFamilyId = 'tvCyTuL6hF3MwbjJ';
1147
- const fullChange = filterFullChange(mockData_1.fall_2003_fullChange, [itemFamilyId]);
1148
- const hydratedDetails = filterHydratedDetails(mockData_1.fall_2003_hydratedDetails, [itemFamilyId]);
1149
- const seasonFed = {
1150
- entityReference: 'assortment:' + fullChange['id'],
1151
- objectClass: 'LCSSeason',
1152
- federationId: 'VR:...LCSSeason:1'
1153
- };
1154
- const itemToFederatedIdMapping = new Map();
1155
- mockData_1.fall_2003_fedMapping.forEach(mapping => itemToFederatedIdMapping.set(mapping.reference, mapping.mappedReference));
1156
- const sinceDate = new Date('2023-02-01T00:00:00.000Z');
1157
- const config = {};
1158
- const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
1159
- const dc = new data_converter_1.DataConverter(config, mapFileUtil);
1160
- const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
1161
- const assortmentItemFullChangeMap = ppa.getFullChangeAssortmentMap(fullChange);
1162
- const assortmentItemDeleteMap = new Map();
1163
- const pcd = new publish_change_data_1.PublishChangeData(fullChange['id'], seasonFed, 'i-OONhGKbJAfRKo-', sinceDate);
1164
- pcd.itemToFederatedIdMapping = itemToFederatedIdMapping;
1165
- pcd.releasedForDevelopmentItemIds.push('jezonPsoRUlA52iz');
1166
- pcd.releasedForDevelopmentItemIds.push('VGo0fWmBBEZoghgk');
1167
- pcd.releasedForDevelopmentItemIds.push('tvCyTuL6hF3MwbjJ');
1168
- pcd.itemFamilyChanges = ppa.getItemFamilyChanges(pcd, hydratedDetails, assortmentItemFullChangeMap, assortmentItemDeleteMap);
1169
- const ifcs = pcd.itemFamilyChanges;
1170
- expect(ifcs.size).toEqual(1);
1171
- const ifc = ifcs.get(itemFamilyId);
1172
- expect(ifc.colorAdds.length).toEqual(2);
1173
- });
1174
- it('Feb 3 - 2+ Option A & Feb 3 - 1 Option A', () => {
1175
- const oneOption_itemFamilyId = 'U9QryfGVOYMAkBP_';
1176
- const twoOption_itemFamilyId = 'tvCyTuL6hF3MwbjJ';
1177
- const bothFamilyIds = [oneOption_itemFamilyId, twoOption_itemFamilyId];
1178
- const fullChange = filterFullChange(mockData_1.fall_2003_fullChange, bothFamilyIds);
1179
- const hydratedDetails = filterHydratedDetails(mockData_1.fall_2003_hydratedDetails, bothFamilyIds);
1180
- const seasonFed = {
1181
- entityReference: 'assortment:' + fullChange['id'],
1182
- objectClass: 'LCSSeason',
1183
- federationId: 'VR:...LCSSeason:1'
1184
- };
1185
- const itemToFederatedIdMapping = new Map();
1186
- mockData_1.fall_2003_fedMapping.forEach(mapping => itemToFederatedIdMapping.set(mapping.reference, mapping.mappedReference));
1187
- const sinceDate = new Date('2023-02-01T00:00:00.000Z');
1188
- const config = {};
1189
- const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
1190
- const dc = new data_converter_1.DataConverter(config, mapFileUtil);
1191
- const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
1192
- const assortmentItemFullChangeMap = ppa.getFullChangeAssortmentMap(fullChange);
1193
- const assortmentItemDeleteMap = new Map();
1194
- const pcd = new publish_change_data_1.PublishChangeData(fullChange['id'], seasonFed, 'i-OONhGKbJAfRKo-', sinceDate);
1195
- pcd.itemToFederatedIdMapping = itemToFederatedIdMapping;
1196
- pcd.releasedForDevelopmentItemIds.push('jFAp5SmYqhXoX-ZI');
1197
- pcd.releasedForDevelopmentItemIds.push('jezonPsoRUlA52iz');
1198
- pcd.releasedForDevelopmentItemIds.push('VGo0fWmBBEZoghgk');
1199
- pcd.releasedForDevelopmentItemIds.push('U9QryfGVOYMAkBP_');
1200
- pcd.releasedForDevelopmentItemIds.push('tvCyTuL6hF3MwbjJ');
1201
- pcd.itemFamilyChanges = ppa.getItemFamilyChanges(pcd, hydratedDetails, assortmentItemFullChangeMap, assortmentItemDeleteMap);
1202
- const ifcs = pcd.itemFamilyChanges;
1203
- expect(ifcs.size).toEqual(2);
1204
- let ifc = ifcs.get(oneOption_itemFamilyId);
1205
- expect(ifc.colorAdds.length).toEqual(1);
1206
- ifc = ifcs.get(twoOption_itemFamilyId);
1207
- expect(ifc.colorAdds.length).toEqual(2);
1208
- });
1209
- it('Feb 3 - 2+ Option A & Feb 3 - No Option A', () => {
1210
- const noOption_itemFamilyId = 'kh1Rtb7kie7Vk5vo';
1211
- const twoOption_itemFamilyId = 'tvCyTuL6hF3MwbjJ';
1212
- const bothFamilyIds = [noOption_itemFamilyId, twoOption_itemFamilyId];
1213
- const fullChange = filterFullChange(mockData_1.fall_2003_fullChange, bothFamilyIds);
1214
- const hydratedDetails = filterHydratedDetails(mockData_1.fall_2003_hydratedDetails, bothFamilyIds);
1215
- const seasonFed = {
1216
- entityReference: 'assortment:' + fullChange['id'],
1217
- objectClass: 'LCSSeason',
1218
- federationId: 'VR:...LCSSeason:1'
1219
- };
1220
- const itemToFederatedIdMapping = new Map();
1221
- mockData_1.fall_2003_fedMapping.forEach(mapping => itemToFederatedIdMapping.set(mapping.reference, mapping.mappedReference));
1222
- const sinceDate = new Date('2023-02-01T00:00:00.000Z');
1223
- const config = {};
1224
- const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
1225
- const dc = new data_converter_1.DataConverter(config, mapFileUtil);
1226
- const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
1227
- const assortmentItemFullChangeMap = ppa.getFullChangeAssortmentMap(fullChange);
1228
- const assortmentItemDeleteMap = new Map();
1229
- const pcd = new publish_change_data_1.PublishChangeData(fullChange['id'], seasonFed, 'i-OONhGKbJAfRKo-', sinceDate);
1230
- pcd.itemToFederatedIdMapping = itemToFederatedIdMapping;
1231
- pcd.releasedForDevelopmentItemIds.push(noOption_itemFamilyId);
1232
- pcd.releasedForDevelopmentItemIds.push('jezonPsoRUlA52iz');
1233
- pcd.releasedForDevelopmentItemIds.push('VGo0fWmBBEZoghgk');
1234
- pcd.releasedForDevelopmentItemIds.push('kh1Rtb7kie7Vk5vo');
1235
- pcd.releasedForDevelopmentItemIds.push('tvCyTuL6hF3MwbjJ');
1236
- pcd.itemFamilyChanges = ppa.getItemFamilyChanges(pcd, hydratedDetails, assortmentItemFullChangeMap, assortmentItemDeleteMap);
1237
- const ifcs = pcd.itemFamilyChanges;
1238
- expect(ifcs.size).toEqual(2);
1239
- let ifc = ifcs.get(noOption_itemFamilyId);
1240
- expect(ifc.familyAdd).toBe(true);
1241
- expect(ifc.colorAdds.length).toEqual(0);
1242
- ifc = ifcs.get(twoOption_itemFamilyId);
1243
- expect(ifc.colorAdds.length).toEqual(2);
1244
- });
1245
- it('Feb 3 - 1 Option B -remove option - leave family', () => {
1246
- const itemFamilyId = 'EejAxj-KK_GGr5Kh';
1247
- const fullChange = filterFullChange(mockData_1.fall_2003_fullChange_run2, [itemFamilyId]);
1248
- const hydratedDetails = filterHydratedDetails(mockData_1.fall_2003_hydratedDetails_run2, [itemFamilyId]);
1249
- const deleteChanges = filterDeleteChange(mockData_1.fall_2003_deleteChanges_run2, [itemFamilyId]);
1250
- const seasonFed = {
1251
- entityReference: 'assortment:' + fullChange['id'],
1252
- objectClass: 'LCSSeason',
1253
- federationId: 'VR:...LCSSeason:1'
1254
- };
1255
- const itemToFederatedIdMapping = new Map();
1256
- mockData_1.fall_2003_fedMapping.forEach(mapping => itemToFederatedIdMapping.set(mapping.reference, mapping.mappedReference));
1257
- const sinceDate = new Date('2023-02-01T00:00:00.000Z');
1258
- const config = {};
1259
- const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
1260
- const dc = new data_converter_1.DataConverter(config, mapFileUtil);
1261
- const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
1262
- const assortmentItemFullChangeMap = ppa.getFullChangeAssortmentMap(fullChange);
1263
- const assortmentItemDeleteMap = ppa.getDeleteChangesAssortmentMap(deleteChanges);
1264
- const pcd = new publish_change_data_1.PublishChangeData(fullChange['id'], seasonFed, 'nPxkQJrFlTikr00h', sinceDate);
1265
- pcd.itemToFederatedIdMapping = itemToFederatedIdMapping;
1266
- pcd.releasedForDevelopmentItemIds.push(itemFamilyId);
1267
- pcd.releasedForDevelopmentItemIds.push('yLhrIHYaP7B4nlkh');
1268
- pcd.itemFamilyChanges = ppa.getItemFamilyChanges(pcd, hydratedDetails, assortmentItemFullChangeMap, assortmentItemDeleteMap);
1269
- const ifcs = pcd.itemFamilyChanges;
1270
- expect(ifcs.size).toEqual(1);
1271
- const ifc = ifcs.get(itemFamilyId);
1272
- expect(ifc.familyAdd).toBe(true);
1273
- expect(ifc.colorAdds.length).toEqual(0);
1274
- expect(ifc.colorDeletes.length).toEqual(1);
1275
- });
1276
- it('Feb 3 - 1 Option C -remove family & option', () => {
1277
- const itemFamilyId = 'JEY86MOuRFv7f9OY';
1278
- const fullChange = filterFullChange(mockData_1.fall_2003_fullChange_run2, [itemFamilyId]);
1279
- const hydratedDetails = filterHydratedDetails(mockData_1.fall_2003_hydratedDetails_run2, [itemFamilyId]);
1280
- const deleteChanges = filterDeleteChange(mockData_1.fall_2003_deleteChanges_run2, [itemFamilyId]);
1281
- const seasonFed = {
1282
- entityReference: 'assortment:' + fullChange['id'],
1283
- objectClass: 'LCSSeason',
1284
- federationId: 'VR:...LCSSeason:1'
1285
- };
1286
- const itemToFederatedIdMapping = new Map();
1287
- mockData_1.fall_2003_fedMapping.forEach(mapping => itemToFederatedIdMapping.set(mapping.reference, mapping.mappedReference));
1288
- const sinceDate = new Date('2023-02-01T00:00:00.000Z');
1289
- const config = {};
1290
- const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
1291
- const dc = new data_converter_1.DataConverter(config, mapFileUtil);
1292
- const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
1293
- const assortmentItemFullChangeMap = ppa.getFullChangeAssortmentMap(fullChange);
1294
- const assortmentItemDeleteMap = ppa.getDeleteChangesAssortmentMap(deleteChanges);
1295
- const pcd = new publish_change_data_1.PublishChangeData(fullChange['id'], seasonFed, 'nPxkQJrFlTikr00h', sinceDate);
1296
- pcd.itemToFederatedIdMapping = itemToFederatedIdMapping;
1297
- pcd.releasedForDevelopmentItemIds.push(itemFamilyId);
1298
- pcd.releasedForDevelopmentItemIds.push('eZL2ChJRBlvbu3yG');
1299
- pcd.itemFamilyChanges = ppa.getItemFamilyChanges(pcd, hydratedDetails, assortmentItemFullChangeMap, assortmentItemDeleteMap);
1300
- const ifcs = pcd.itemFamilyChanges;
1301
- expect(ifcs.size).toEqual(1);
1302
- const ifc = ifcs.get(itemFamilyId);
1303
- expect(ifc.colorAdds.length).toEqual(0);
1304
- expect(ifc.colorDeletes.length).toEqual(1);
1305
- });
1306
- });
1307
- describe('getProjectItem', () => {
1308
- const config = {
1309
- identifierAtts: {
1310
- LCSSeason: ['flexPLMSeasonName']
1311
- }
1312
- };
1313
- const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
1314
- const dc = new data_converter_1.DataConverter(config, mapFileUtil);
1315
- const bppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
1316
- it('family assortment item in assortmentItemFullChangeMap', () => {
1317
- const familyId = 'w43t4';
1318
- const sinceDate = new Date();
1319
- const ifc = new item_family_changes_1.ItemFamilyChanges(familyId, sinceDate);
1320
- const projectItem = {
1321
- id: '4md02m:' + familyId
1322
- };
1323
- ifc.assortmentItemFullChangeMap.set(familyId, {
1324
- projectItem
1325
- });
1326
- const fpi = bppa.getProjectItem(ifc, familyId);
1327
- expect(fpi).toEqual(projectItem);
1328
- });
1329
- it('family assortment item NOT in assortmentItemFullChangeMap', () => {
1330
- const familyId = 'w43t4';
1331
- const optionId = 'l3mci2';
1332
- const sinceDate = new Date();
1333
- const ifc = new item_family_changes_1.ItemFamilyChanges(familyId, sinceDate);
1334
- const familyProjectItem = {
1335
- id: '4md02m:' + familyId
1336
- };
1337
- ifc.assortmentItemFullChangeMap.set(optionId, {
1338
- familyProjectItem
1339
- });
1340
- const fpi = bppa.getProjectItem(ifc, familyId);
1341
- expect(fpi).toEqual(familyProjectItem);
1342
- });
1343
- it('option assortment item in assortmentItemFullChangeMap', () => {
1344
- const familyId = 'w43t4';
1345
- const optionId = 'l3mci2';
1346
- const sinceDate = new Date();
1347
- const ifc = new item_family_changes_1.ItemFamilyChanges(familyId, sinceDate);
1348
- const projectItem = {
1349
- id: '4md02m:' + optionId
1350
- };
1351
- ifc.assortmentItemFullChangeMap.set(optionId, {
1352
- projectItem
1353
- });
1354
- const fpi = bppa.getProjectItem(ifc, optionId);
1355
- expect(fpi).toEqual(projectItem);
1356
- });
1357
- });
1358
- describe('getCarriedFromSeason', () => {
1359
- const config = {
1360
- identifierAtts: {
1361
- LCSSeason: ['flexPLMSeasonName']
1362
- }
1363
- };
1364
- const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
1365
- const dc = new data_converter_1.DataConverter(config, mapFileUtil);
1366
- const bppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
1367
- it('cache hit', async () => {
1368
- const projectItem = {
1369
- addedFromAssortment: 123
1370
- };
1371
- const origGetAssormentEntityFromId = bppa.getAssormentEntityFromId;
1372
- const origGetSeasonFederationFromAssortment = bppa.getSeasonFederationFromAssortment;
1373
- try {
1374
- const assortmentEntity = {};
1375
- const seasonFed = {
1376
- entityReference: 'assortment:123',
1377
- objectClass: 'LCSSeason'
1378
- };
1379
- bppa.getAssormentEntityFromId = async (assortmentId) => { return assortmentEntity; };
1380
- bppa.getSeasonFederationFromAssortment = async (assortment) => { return seasonFed; };
1381
- const spyGetAssortment = jest.spyOn(bppa, 'getAssormentEntityFromId');
1382
- const spyGetSeasonFed = jest.spyOn(bppa, 'getSeasonFederationFromAssortment');
1383
- let sFed = await bppa.getCarriedFromSeason(projectItem);
1384
- sFed = await bppa.getCarriedFromSeason(projectItem);
1385
- expect(spyGetAssortment).toHaveBeenCalledTimes(1);
1386
- expect(spyGetSeasonFed).toHaveBeenCalledTimes(1);
1387
- }
1388
- finally {
1389
- bppa.getAssormentEntityFromId = origGetAssormentEntityFromId;
1390
- bppa.getSeasonFederationFromAssortment = origGetSeasonFederationFromAssortment;
1391
- }
1392
- const sf = await bppa.getCarriedFromSeason(projectItem);
1393
- });
1394
- describe('getSeasonFederationFromAssortment', () => {
1395
- it('Test conversion', async () => {
1396
- const assortment = {
1397
- id: '2we4',
1398
- name: 'Object Name',
1399
- notTransferred: 'This shouldnt be in the returned object'
1400
- };
1401
- const typePath = 'Path';
1402
- const identifierKeys = ['name'];
1403
- const informationKeys = [];
1404
- const mapKey = 'mapKey';
1405
- const spyTCU_type_path = jest.spyOn(type_conversion_utils_1.TypeConversionUtils, 'getObjectTypePath')
1406
- .mockImplementation(async () => typePath);
1407
- const spyDC_get_data = jest.spyOn(dc, 'getFlexPLMObjectData')
1408
- .mockImplementation(async (data) => data);
1409
- const spyTCU_id_keys = jest.spyOn(type_conversion_utils_1.TypeConversionUtils, 'getIdentifierProperties')
1410
- .mockImplementation(async () => identifierKeys);
1411
- const spyTCU_info_keys = jest.spyOn(type_conversion_utils_1.TypeConversionUtils, 'getInformationalProperties')
1412
- .mockImplementation(async () => informationKeys);
1413
- const spyTCU_get_map_key = jest.spyOn(type_conversion_utils_1.TypeConversionUtils, 'getMapKey')
1414
- .mockImplementation(async () => mapKey);
1415
- const spyMU_apply_map = jest.spyOn(map_utils_1.MapUtil, 'applyTransformMap')
1416
- .mockImplementation(async (...args) => args[2]);
1417
- const results = await bppa.getSeasonFederationFromAssortment(assortment);
1418
- console.log('Test conversion: ' + JSON.stringify(results));
1419
- expect(results['entityReference']).toBe('assortment:2we4');
1420
- expect(results['name']).toBe('Object Name');
1421
- expect(results['flexPLMTypePath']).toBe('Path');
1422
- expect(results['objectClass']).toBe('LCSSeason');
1423
- expect(results).not.toHaveProperty('notTransferred');
1424
- });
1425
- });
1426
- });
1427
- describe('meetsCriteria', () => {
1428
- const config = {
1429
- identifierAtts: {
1430
- LCSSeason: ['flexPLMSeasonName']
1431
- },
1432
- itemPreDevelopmentLifecycleStages: ['concept']
1433
- };
1434
- const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
1435
- const dc = new data_converter_1.DataConverter(config, mapFileUtil);
1436
- const bppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
1437
- it('no item', () => {
1438
- const aItem = {};
1439
- const results = bppa.meetsCriteria(aItem);
1440
- expect(results).toBeFalsy();
1441
- });
1442
- it('item - no lifecycle stage', () => {
1443
- const aItem = {
1444
- item: {
1445
- lifecycleStage: ''
1446
- }
1447
- };
1448
- const results = bppa.meetsCriteria(aItem);
1449
- expect(results).toBeFalsy();
1450
- });
1451
- it('item - concept lifecycle stage', () => {
1452
- const aItem = {
1453
- item: {
1454
- lifecycleStage: 'concept'
1455
- }
1456
- };
1457
- const results = bppa.meetsCriteria(aItem);
1458
- expect(results).toBeFalsy();
1459
- });
1460
- it('item - delevopment lifecycle stage', () => {
1461
- const aItem = {
1462
- item: {
1463
- lifecycleStage: 'delevopment'
1464
- }
1465
- };
1466
- const results = bppa.meetsCriteria(aItem);
1467
- expect(results).toBeTruthy();
1468
- });
1469
- });
1470
- describe('getEventsForItemFamilyChanges - conditional eventType', () => {
1471
- const config = {
1472
- identifierAtts: {
1473
- LCSSeason: ['flexPLMSeasonName']
1474
- },
1475
- itemPreDevelopmentLifecycleStages: ['concept']
1476
- };
1477
- const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
1478
- const dc = new data_converter_1.DataConverter(config, mapFileUtil);
1479
- afterEach(() => {
1480
- jest.restoreAllMocks();
1481
- });
1482
- it('should use UPSERT_ON_SEASON for LCSProductSeasonLink when isOutboundCreatableFromEntity returns true', async () => {
1483
- const bppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
1484
- const itemFamilyId = 'family123';
1485
- const prodEntityData = { id: itemFamilyId, identifier: 'FAM-123', itemNumber: 'FAM-123' };
1486
- const projectItem = { id: 'proj1', updatedOn: '2023-01-15T00:00:00.000Z' };
1487
- const assortment = { id: 'assort123', name: 'Fall 2023 Assortment', publishToFlexPLM: true };
1488
- const seasonFed = {
1489
- entityReference: 'assortment:assort123',
1490
- objectClass: 'LCSSeason',
1491
- flexPLMSeasonName: 'Fall 2023'
1492
- };
1493
- const itemFamilyChanges = new item_family_changes_1.ItemFamilyChanges(itemFamilyId, new Date('2023-01-01T00:00:00.000Z'));
1494
- itemFamilyChanges.familyAdd = true;
1495
- itemFamilyChanges.assortmentItemFullChangeMap.set(itemFamilyId, {
1496
- item: prodEntityData,
1497
- projectItem
1498
- });
1499
- jest.spyOn(bppa, 'getAssortment').mockResolvedValue(assortment);
1500
- jest.spyOn(bppa, 'getProjectItem').mockReturnValue(projectItem);
1501
- jest.spyOn(bppa, 'getSeasonalData').mockResolvedValue({ someData: 'value' });
1502
- jest.spyOn(map_utils_1.MapUtil, 'applyTransformMap').mockResolvedValue({ transformedData: 'value' });
1503
- jest.spyOn(type_conversion_utils_1.TypeConversionUtils, 'getIdentifierProperties').mockResolvedValue(['identifier']);
1504
- jest.spyOn(type_conversion_utils_1.TypeConversionUtils, 'getInformationalProperties').mockResolvedValue([]);
1505
- jest.spyOn(type_conversion_utils_1.TypeConversionUtils, 'isOutboundCreatableFromEntity').mockResolvedValue(true);
1506
- const events = await bppa.getEventsForItemFamilyChanges(itemFamilyChanges, 'assort123', seasonFed, new Map());
1507
- expect(events).toHaveLength(1);
1508
- expect(events[0].eventType).toBe('UPSERT_ON_SEASON');
1509
- expect(events[0].objectClass).toBe('LCSProductSeasonLink');
1510
- expect(type_conversion_utils_1.TypeConversionUtils.isOutboundCreatableFromEntity).toHaveBeenCalledWith(undefined, mapFileUtil, projectItem, { item: prodEntityData, assortment });
1511
- });
1512
- it('should use UPDATE_ON_SEASON for LCSProductSeasonLink when isOutboundCreatableFromEntity returns false', async () => {
1513
- const bppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
1514
- const itemFamilyId = 'family123';
1515
- const prodEntityData = { id: itemFamilyId, identifier: 'FAM-123', itemNumber: 'FAM-123' };
1516
- const projectItem = { id: 'proj1', updatedOn: '2023-01-15T00:00:00.000Z' };
1517
- const assortment = { id: 'assort123', name: 'Fall 2023 Assortment', publishToFlexPLM: true };
1518
- const seasonFed = {
1519
- entityReference: 'assortment:assort123',
1520
- objectClass: 'LCSSeason',
1521
- flexPLMSeasonName: 'Fall 2023'
1522
- };
1523
- const itemFamilyChanges = new item_family_changes_1.ItemFamilyChanges(itemFamilyId, new Date('2023-01-01T00:00:00.000Z'));
1524
- itemFamilyChanges.familyUpdate = true;
1525
- itemFamilyChanges.assortmentItemFullChangeMap.set(itemFamilyId, {
1526
- item: prodEntityData,
1527
- projectItem
1528
- });
1529
- jest.spyOn(bppa, 'getAssortment').mockResolvedValue(assortment);
1530
- jest.spyOn(bppa, 'getProjectItem').mockReturnValue(projectItem);
1531
- jest.spyOn(bppa, 'getSeasonalData').mockResolvedValue({ someData: 'value' });
1532
- jest.spyOn(map_utils_1.MapUtil, 'applyTransformMap').mockResolvedValue({ transformedData: 'value' });
1533
- jest.spyOn(type_conversion_utils_1.TypeConversionUtils, 'getIdentifierProperties').mockResolvedValue(['identifier']);
1534
- jest.spyOn(type_conversion_utils_1.TypeConversionUtils, 'getInformationalProperties').mockResolvedValue([]);
1535
- jest.spyOn(type_conversion_utils_1.TypeConversionUtils, 'isOutboundCreatableFromEntity').mockResolvedValue(false);
1536
- const events = await bppa.getEventsForItemFamilyChanges(itemFamilyChanges, 'assort123', seasonFed, new Map());
1537
- expect(events).toHaveLength(1);
1538
- expect(events[0].eventType).toBe('UPDATE_ON_SEASON');
1539
- expect(events[0].objectClass).toBe('LCSProductSeasonLink');
1540
- expect(type_conversion_utils_1.TypeConversionUtils.isOutboundCreatableFromEntity).toHaveBeenCalledWith(undefined, mapFileUtil, projectItem, { item: prodEntityData, assortment });
1541
- });
1542
- it('should use UPSERT_ON_SEASON for LCSSKUSeasonLink when isOutboundCreatableFromEntity returns true', async () => {
1543
- const bppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
1544
- const itemFamilyId = 'family123';
1545
- const colorId = 'color456';
1546
- const familyItemData = { id: itemFamilyId, identifier: 'FAM-123', itemNumber: 'FAM-123' };
1547
- const itemData = { id: colorId, identifier: 'COLOR-456', itemNumber: 'COLOR-456' };
1548
- const familyProjectItem = { id: 'proj0', updatedOn: '2023-01-14T00:00:00.000Z' };
1549
- const projectItem = { id: 'proj1', updatedOn: '2023-01-15T00:00:00.000Z' };
1550
- const assortment = { id: 'assort123', name: 'Fall 2023 Assortment', publishToFlexPLM: true };
1551
- const seasonFed = {
1552
- entityReference: 'assortment:assort123',
1553
- objectClass: 'LCSSeason',
1554
- flexPLMSeasonName: 'Fall 2023'
1555
- };
1556
- const itemFamilyChanges = new item_family_changes_1.ItemFamilyChanges(itemFamilyId, new Date('2023-01-01T00:00:00.000Z'));
1557
- itemFamilyChanges.colorAdds.push(colorId);
1558
- itemFamilyChanges.assortmentItemFullChangeMap.set(itemFamilyId, {
1559
- item: familyItemData,
1560
- projectItem: familyProjectItem
1561
- });
1562
- itemFamilyChanges.assortmentItemFullChangeMap.set(colorId, {
1563
- item: itemData,
1564
- projectItem
1565
- });
1566
- jest.spyOn(bppa, 'getAssortment').mockResolvedValue(assortment);
1567
- jest.spyOn(bppa, 'getProjectItem')
1568
- .mockReturnValueOnce(familyProjectItem)
1569
- .mockReturnValueOnce(projectItem);
1570
- jest.spyOn(bppa, 'getSeasonalData').mockResolvedValue({ someData: 'value' });
1571
- jest.spyOn(map_utils_1.MapUtil, 'applyTransformMap').mockResolvedValue({ transformedData: 'value' });
1572
- jest.spyOn(type_conversion_utils_1.TypeConversionUtils, 'getIdentifierProperties').mockResolvedValue(['identifier']);
1573
- jest.spyOn(type_conversion_utils_1.TypeConversionUtils, 'getInformationalProperties').mockResolvedValue([]);
1574
- jest.spyOn(type_conversion_utils_1.TypeConversionUtils, 'isOutboundCreatableFromEntity')
1575
- .mockResolvedValueOnce(true)
1576
- .mockResolvedValueOnce(true);
1577
- const events = await bppa.getEventsForItemFamilyChanges(itemFamilyChanges, 'assort123', seasonFed, new Map());
1578
- expect(events).toHaveLength(2);
1579
- const skuEvent = events.find(e => e.objectClass === 'LCSSKUSeasonLink');
1580
- expect(skuEvent.eventType).toBe('UPSERT_ON_SEASON');
1581
- expect(type_conversion_utils_1.TypeConversionUtils.isOutboundCreatableFromEntity).toHaveBeenCalledWith(undefined, mapFileUtil, projectItem, { item: itemData, assortment });
1582
- });
1583
- it('should use UPDATE_ON_SEASON for LCSSKUSeasonLink when isOutboundCreatableFromEntity returns false', async () => {
1584
- const bppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
1585
- const itemFamilyId = 'family123';
1586
- const colorId = 'color456';
1587
- const familyItemData = { id: itemFamilyId, identifier: 'FAM-123', itemNumber: 'FAM-123' };
1588
- const itemData = { id: colorId, identifier: 'COLOR-456', itemNumber: 'COLOR-456' };
1589
- const familyProjectItem = { id: 'proj0', updatedOn: '2023-01-14T00:00:00.000Z' };
1590
- const projectItem = { id: 'proj1', updatedOn: '2023-01-15T00:00:00.000Z' };
1591
- const assortment = { id: 'assort123', name: 'Fall 2023 Assortment', publishToFlexPLM: true };
1592
- const seasonFed = {
1593
- entityReference: 'assortment:assort123',
1594
- objectClass: 'LCSSeason',
1595
- flexPLMSeasonName: 'Fall 2023'
1596
- };
1597
- const itemFamilyChanges = new item_family_changes_1.ItemFamilyChanges(itemFamilyId, new Date('2023-01-01T00:00:00.000Z'));
1598
- itemFamilyChanges.colorUpdates.push(colorId);
1599
- itemFamilyChanges.assortmentItemFullChangeMap.set(itemFamilyId, {
1600
- item: familyItemData,
1601
- projectItem: familyProjectItem
1602
- });
1603
- itemFamilyChanges.assortmentItemFullChangeMap.set(colorId, {
1604
- item: itemData,
1605
- projectItem
1606
- });
1607
- jest.spyOn(bppa, 'getAssortment').mockResolvedValue(assortment);
1608
- jest.spyOn(bppa, 'getProjectItem')
1609
- .mockReturnValueOnce(familyProjectItem)
1610
- .mockReturnValueOnce(projectItem);
1611
- jest.spyOn(bppa, 'getSeasonalData').mockResolvedValue({ someData: 'value' });
1612
- jest.spyOn(map_utils_1.MapUtil, 'applyTransformMap').mockResolvedValue({ transformedData: 'value' });
1613
- jest.spyOn(type_conversion_utils_1.TypeConversionUtils, 'getIdentifierProperties').mockResolvedValue(['identifier']);
1614
- jest.spyOn(type_conversion_utils_1.TypeConversionUtils, 'getInformationalProperties').mockResolvedValue([]);
1615
- jest.spyOn(type_conversion_utils_1.TypeConversionUtils, 'isOutboundCreatableFromEntity')
1616
- .mockResolvedValueOnce(false)
1617
- .mockResolvedValueOnce(false);
1618
- const events = await bppa.getEventsForItemFamilyChanges(itemFamilyChanges, 'assort123', seasonFed, new Map());
1619
- expect(events).toHaveLength(2);
1620
- const skuEvent = events.find(e => e.objectClass === 'LCSSKUSeasonLink');
1621
- expect(skuEvent.eventType).toBe('UPDATE_ON_SEASON');
1622
- expect(type_conversion_utils_1.TypeConversionUtils.isOutboundCreatableFromEntity).toHaveBeenCalledWith(undefined, mapFileUtil, projectItem, { item: itemData, assortment });
1623
- });
1624
- it('should create both product and SKU events with correct eventTypes based on isOutboundCreatableFromEntity', async () => {
1625
- const bppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
1626
- const itemFamilyId = 'family123';
1627
- const colorId = 'color456';
1628
- const prodEntityData = { id: itemFamilyId, identifier: 'FAM-123', itemNumber: 'FAM-123' };
1629
- const itemData = { id: colorId, identifier: 'COLOR-456', itemNumber: 'COLOR-456' };
1630
- const familyProjectItem = { id: 'proj1', updatedOn: '2023-01-15T00:00:00.000Z' };
1631
- const colorProjectItem = { id: 'proj2', updatedOn: '2023-01-15T00:00:00.000Z' };
1632
- const assortment = { id: 'assort123', name: 'Fall 2023 Assortment', publishToFlexPLM: true };
1633
- const seasonFed = {
1634
- entityReference: 'assortment:assort123',
1635
- objectClass: 'LCSSeason',
1636
- flexPLMSeasonName: 'Fall 2023'
1637
- };
1638
- const itemFamilyChanges = new item_family_changes_1.ItemFamilyChanges(itemFamilyId, new Date('2023-01-01T00:00:00.000Z'));
1639
- itemFamilyChanges.familyAdd = true;
1640
- itemFamilyChanges.colorAdds.push(colorId);
1641
- itemFamilyChanges.assortmentItemFullChangeMap.set(itemFamilyId, {
1642
- item: prodEntityData,
1643
- projectItem: familyProjectItem
1644
- });
1645
- itemFamilyChanges.assortmentItemFullChangeMap.set(colorId, {
1646
- item: itemData,
1647
- projectItem: colorProjectItem
1648
- });
1649
- jest.spyOn(bppa, 'getAssortment').mockResolvedValue(assortment);
1650
- jest.spyOn(bppa, 'getProjectItem')
1651
- .mockReturnValueOnce(familyProjectItem)
1652
- .mockReturnValueOnce(colorProjectItem);
1653
- jest.spyOn(bppa, 'getSeasonalData').mockResolvedValue({ someData: 'value' });
1654
- jest.spyOn(map_utils_1.MapUtil, 'applyTransformMap').mockResolvedValue({ transformedData: 'value' });
1655
- jest.spyOn(type_conversion_utils_1.TypeConversionUtils, 'getIdentifierProperties').mockResolvedValue(['identifier']);
1656
- jest.spyOn(type_conversion_utils_1.TypeConversionUtils, 'getInformationalProperties').mockResolvedValue([]);
1657
- jest.spyOn(type_conversion_utils_1.TypeConversionUtils, 'isOutboundCreatableFromEntity')
1658
- .mockResolvedValueOnce(true)
1659
- .mockResolvedValueOnce(false);
1660
- const events = await bppa.getEventsForItemFamilyChanges(itemFamilyChanges, 'assort123', seasonFed, new Map());
1661
- expect(events).toHaveLength(2);
1662
- const productEvent = events.find(e => e.objectClass === 'LCSProductSeasonLink');
1663
- const skuEvent = events.find(e => e.objectClass === 'LCSSKUSeasonLink');
1664
- expect(productEvent.eventType).toBe('UPSERT_ON_SEASON');
1665
- expect(skuEvent.eventType).toBe('UPDATE_ON_SEASON');
1666
- expect(type_conversion_utils_1.TypeConversionUtils.isOutboundCreatableFromEntity).toHaveBeenCalledTimes(2);
1667
- expect(type_conversion_utils_1.TypeConversionUtils.isOutboundCreatableFromEntity).toHaveBeenNthCalledWith(1, undefined, mapFileUtil, familyProjectItem, { item: prodEntityData, assortment });
1668
- expect(type_conversion_utils_1.TypeConversionUtils.isOutboundCreatableFromEntity).toHaveBeenNthCalledWith(2, undefined, mapFileUtil, colorProjectItem, { item: itemData, assortment });
1669
- });
1670
- });
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
+ let entityObject = {};
32
+ let getOptionsObject = {};
33
+ jest.mock('@contrail/sdk', () => {
34
+ return {
35
+ Entities: class {
36
+ get(_getOtionsObject) {
37
+ getOptionsObject = _getOtionsObject;
38
+ return entityObject;
39
+ }
40
+ }
41
+ };
42
+ });
43
+ describe('process publish assortment', () => {
44
+ const config = {};
45
+ beforeEach(() => {
46
+ federatedId = '';
47
+ entityObject = { publishToFlexPLM: true };
48
+ getOptionsObject = {};
49
+ });
50
+ afterEach(() => {
51
+ jest.restoreAllMocks();
52
+ });
53
+ it('No Federation Info', async () => {
54
+ const event = {
55
+ assortmentId: 'B3oRQpYVYzcJAJtQ'
56
+ };
57
+ const identifierKeys = ['flexPLMSeasonName'];
58
+ const informationKeys = ['name'];
59
+ const spyTCU_id_keys = jest.spyOn(type_conversion_utils_1.TypeConversionUtils, 'getIdentifierProperties')
60
+ .mockImplementation(async () => identifierKeys);
61
+ const spyTCU_info_keys = jest.spyOn(type_conversion_utils_1.TypeConversionUtils, 'getInformationalProperties')
62
+ .mockImplementation(async () => informationKeys);
63
+ const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
64
+ const dc = new data_converter_1.DataConverter(config, mapFileUtil);
65
+ const results = await new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil).process(event);
66
+ expect(results['results']['message']).toEqual(base_process_publish_assortment_1.BaseProcessPublishAssortment.ASSORTMENT_NO_FED_INFO + identifierKeys);
67
+ });
68
+ });
69
+ describe('getPublishInfo', () => {
70
+ const config = {};
71
+ const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
72
+ const dc = new data_converter_1.DataConverter(config, mapFileUtil);
73
+ const assortmentId = 'oqIFX3ELRy8sFRd0';
74
+ const versionName = 'Version 1';
75
+ const versionComments = 'Some Comments';
76
+ const createdOn = '2023-01-15T19:13:58.902Z';
77
+ const plan_history = [
78
+ {
79
+ id: 'sJbGx1Fpq1v2MmcI',
80
+ versionName,
81
+ versionComments,
82
+ createdOn
83
+ }
84
+ ];
85
+ it('All Publish Info', async () => {
86
+ const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
87
+ const assortmentPublishChangeId = 'sJbGx1Fpq1v2MmcI';
88
+ const publisher = {
89
+ email: 'chris@vibeiq.com'
90
+ };
91
+ const assortmentName = 'VibeIQ Fall 2023';
92
+ const versionHistoryNumber = 1234;
93
+ const spyGetAssortment = jest.spyOn(ppa, 'getAssortment')
94
+ .mockImplementation(async (assortmentId) => {
95
+ return { id: assortmentId, name: assortmentName };
96
+ });
97
+ const spyyGetSnapshotVersion = jest.spyOn(ppa, 'getSnapshotVersion')
98
+ .mockImplementation(async (assortmentId, assortmentPublishChangeId) => {
99
+ return versionHistoryNumber;
100
+ });
101
+ const publishInfo = await ppa.getPublishInfo(assortmentId, assortmentPublishChangeId, plan_history, publisher);
102
+ expect(publishInfo.assortmentName).toEqual(assortmentName);
103
+ expect(publishInfo.versionName).toEqual(versionName);
104
+ expect(publishInfo.versionComments).toEqual(versionComments);
105
+ expect(publishInfo.publishDate).toEqual(createdOn);
106
+ expect(publishInfo.publisher).toEqual(publisher);
107
+ expect(publishInfo.versionHistoryNumber).toEqual(versionHistoryNumber);
108
+ spyGetAssortment.mockRestore();
109
+ spyyGetSnapshotVersion.mockRestore();
110
+ });
111
+ it('No Assortment Name', async () => {
112
+ const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
113
+ const assortmentPublishChangeId = 'sJbGx1Fpq1v2MmcI';
114
+ const publisher = {
115
+ email: 'chris@vibeiq.com'
116
+ };
117
+ const versionHistoryNumber = 1234;
118
+ const spyGetAssortment = jest.spyOn(ppa, 'getAssortment')
119
+ .mockImplementation(async (assortmentId) => {
120
+ return { id: assortmentId, name: undefined };
121
+ });
122
+ const spyyGetSnapshotVersion = jest.spyOn(ppa, 'getSnapshotVersion')
123
+ .mockImplementation(async (assortmentId, assortmentPublishChangeId) => {
124
+ return versionHistoryNumber;
125
+ });
126
+ const publishInfo = await ppa.getPublishInfo(assortmentId, assortmentPublishChangeId, plan_history, publisher);
127
+ expect(publishInfo.assortmentName).toBeUndefined;
128
+ expect(publishInfo.versionName).toEqual(versionName);
129
+ expect(publishInfo.versionComments).toEqual(versionComments);
130
+ expect(publishInfo.publishDate).toEqual(createdOn);
131
+ expect(publishInfo.publisher).toEqual(publisher);
132
+ expect(publishInfo.versionHistoryNumber).toEqual(versionHistoryNumber);
133
+ spyGetAssortment.mockRestore();
134
+ spyyGetSnapshotVersion.mockRestore();
135
+ });
136
+ it('No Assortment', async () => {
137
+ const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
138
+ const assortmentPublishChangeId = 'sJbGx1Fpq1v2MmcI';
139
+ const publisher = {
140
+ email: 'chris@vibeiq.com'
141
+ };
142
+ const versionHistoryNumber = 1234;
143
+ const spyGetAssortment = jest.spyOn(ppa, 'getAssortment')
144
+ .mockImplementation(async (assortmentId) => {
145
+ return undefined;
146
+ });
147
+ const spyyGetSnapshotVersion = jest.spyOn(ppa, 'getSnapshotVersion')
148
+ .mockImplementation(async (assortmentId, assortmentPublishChangeId) => {
149
+ return versionHistoryNumber;
150
+ });
151
+ const publishInfo = await ppa.getPublishInfo(assortmentId, assortmentPublishChangeId, plan_history, publisher);
152
+ expect(publishInfo.assortmentName).toBeUndefined();
153
+ expect(publishInfo.versionName).toEqual(versionName);
154
+ expect(publishInfo.versionComments).toEqual(versionComments);
155
+ expect(publishInfo.publishDate).toEqual(createdOn);
156
+ expect(publishInfo.publisher).toEqual(publisher);
157
+ expect(publishInfo.versionHistoryNumber).toEqual(versionHistoryNumber);
158
+ spyGetAssortment.mockRestore();
159
+ spyyGetSnapshotVersion.mockRestore();
160
+ });
161
+ it('Empty Version Name & Comments', async () => {
162
+ const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
163
+ const history = [
164
+ {
165
+ id: 'sJbGx1Fpq1v2MmcI',
166
+ versionName: '',
167
+ versionComments: '',
168
+ createdOn
169
+ }
170
+ ];
171
+ const assortmentPublishChangeId = 'sJbGx1Fpq1v2MmcI';
172
+ const publisher = {
173
+ email: 'chris@vibeiq.com'
174
+ };
175
+ const assortmentName = 'VibeIQ Fall 2023';
176
+ const versionHistoryNumber = 1234;
177
+ const spyGetAssortment = jest.spyOn(ppa, 'getAssortment')
178
+ .mockImplementation(async (assortmentId) => {
179
+ return { id: assortmentId, name: assortmentName };
180
+ });
181
+ const spyyGetSnapshotVersion = jest.spyOn(ppa, 'getSnapshotVersion')
182
+ .mockImplementation(async (assortmentId, assortmentPublishChangeId) => {
183
+ return versionHistoryNumber;
184
+ });
185
+ const publishInfo = await ppa.getPublishInfo(assortmentId, assortmentPublishChangeId, history, publisher);
186
+ expect(publishInfo.assortmentName).toEqual(assortmentName);
187
+ expect(publishInfo.versionName).toEqual('');
188
+ expect(publishInfo.versionComments).toEqual('');
189
+ expect(publishInfo.publishDate).toEqual(createdOn);
190
+ expect(publishInfo.publisher).toEqual(publisher);
191
+ expect(publishInfo.versionHistoryNumber).toEqual(versionHistoryNumber);
192
+ spyGetAssortment.mockRestore();
193
+ spyyGetSnapshotVersion.mockRestore();
194
+ });
195
+ it('Undefined Publisher', async () => {
196
+ const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
197
+ const assortmentPublishChangeId = 'sJbGx1Fpq1v2MmcI';
198
+ const publisher = undefined;
199
+ const assortmentName = 'VibeIQ Fall 2023';
200
+ const versionHistoryNumber = 1234;
201
+ const spyGetAssortment = jest.spyOn(ppa, 'getAssortment')
202
+ .mockImplementation(async (assortmentId) => {
203
+ return { id: assortmentId, name: assortmentName };
204
+ });
205
+ const spyyGetSnapshotVersion = jest.spyOn(ppa, 'getSnapshotVersion')
206
+ .mockImplementation(async (assortmentId, assortmentPublishChangeId) => {
207
+ return versionHistoryNumber;
208
+ });
209
+ const publishInfo = await ppa.getPublishInfo(assortmentId, assortmentPublishChangeId, plan_history, publisher);
210
+ expect(publishInfo.assortmentName).toEqual(assortmentName);
211
+ expect(publishInfo.versionName).toEqual(versionName);
212
+ expect(publishInfo.versionComments).toEqual(versionComments);
213
+ expect(publishInfo.publishDate).toEqual(createdOn);
214
+ expect(publishInfo.publisher).toBeUndefined();
215
+ expect(publishInfo.versionHistoryNumber).toEqual(versionHistoryNumber);
216
+ spyGetAssortment.mockRestore();
217
+ spyyGetSnapshotVersion.mockRestore();
218
+ });
219
+ it('No APC', async () => {
220
+ const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
221
+ const assortmentPublishChangeId = 'bad-id';
222
+ const publisher = {
223
+ email: 'chris@vibeiq.com'
224
+ };
225
+ const assortmentName = 'VibeIQ Fall 2023';
226
+ const versionHistoryNumber = 1234;
227
+ const spyGetAssortment = jest.spyOn(ppa, 'getAssortment')
228
+ .mockImplementation(async (assortmentId) => {
229
+ return { id: assortmentId, name: assortmentName };
230
+ });
231
+ const spyyGetSnapshotVersion = jest.spyOn(ppa, 'getSnapshotVersion')
232
+ .mockImplementation(async (assortmentId, assortmentPublishChangeId) => {
233
+ return versionHistoryNumber;
234
+ });
235
+ const publishInfo = await ppa.getPublishInfo(assortmentId, assortmentPublishChangeId, plan_history, publisher);
236
+ expect(publishInfo.assortmentName).toEqual(assortmentName);
237
+ expect(publishInfo.versionName).toBeUndefined();
238
+ expect(publishInfo.versionComments).toBeUndefined();
239
+ expect(publishInfo.publishDate).toBeUndefined();
240
+ expect(publishInfo.publisher).toEqual(publisher);
241
+ expect(publishInfo.versionHistoryNumber).toEqual(versionHistoryNumber);
242
+ spyGetAssortment.mockRestore();
243
+ spyyGetSnapshotVersion.mockRestore();
244
+ });
245
+ it('No APC history', async () => {
246
+ const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
247
+ const assortmentPublishChangeId = 'bad-id';
248
+ const publisher = {
249
+ email: 'chris@vibeiq.com'
250
+ };
251
+ const assortmentName = 'VibeIQ Fall 2023';
252
+ const versionHistoryNumber = 1234;
253
+ const spyGetAssortment = jest.spyOn(ppa, 'getAssortment')
254
+ .mockImplementation(async (assortmentId) => {
255
+ return { id: assortmentId, name: assortmentName };
256
+ });
257
+ const spyyGetSnapshotVersion = jest.spyOn(ppa, 'getSnapshotVersion')
258
+ .mockImplementation(async (assortmentId, assortmentPublishChangeId) => {
259
+ return versionHistoryNumber;
260
+ });
261
+ const publishInfo = await ppa.getPublishInfo(assortmentId, assortmentPublishChangeId, undefined, publisher);
262
+ expect(publishInfo.assortmentName).toEqual(assortmentName);
263
+ expect(publishInfo.versionName).toBeUndefined();
264
+ expect(publishInfo.versionComments).toBeUndefined();
265
+ expect(publishInfo.publishDate).toBeUndefined();
266
+ expect(publishInfo.publisher).toEqual(publisher);
267
+ expect(publishInfo.versionHistoryNumber).toEqual(versionHistoryNumber);
268
+ spyGetAssortment.mockRestore();
269
+ spyyGetSnapshotVersion.mockRestore();
270
+ });
271
+ });
272
+ describe('getSnapshotVersion', () => {
273
+ const config = {
274
+ identifierAtts: {
275
+ LCSSeason: ['flexPLMSeasonName']
276
+ }
277
+ };
278
+ const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
279
+ const dc = new data_converter_1.DataConverter(config, mapFileUtil);
280
+ const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
281
+ beforeEach(() => {
282
+ federatedId = '';
283
+ entityObject = { publishToFlexPLM: true };
284
+ getOptionsObject = {};
285
+ });
286
+ it('has snapshot version', async () => {
287
+ const assortment = {
288
+ id: 'rm35clTNxvS4wm6y',
289
+ name: 'VibeIQ Fall 2023',
290
+ createdForReference: 'plan:w23wre'
291
+ };
292
+ const assortmentChangeId = 'sJbGx1Fpq1v2MmcI';
293
+ const apc = {
294
+ id: assortmentChangeId,
295
+ versionName: 'Version 1',
296
+ versionComments: 'Some Comments',
297
+ createdOn: '2023-01-15T19:13:58.902Z'
298
+ };
299
+ const versionNumber = 1234;
300
+ const snapshots = [
301
+ {
302
+ id: 'qewrwer',
303
+ assortmentChangeId,
304
+ versionNumber
305
+ }
306
+ ];
307
+ entityObject = snapshots;
308
+ const versionHistoryNumber = await ppa.getSnapshotVersion(assortment, apc);
309
+ expect(versionHistoryNumber).toEqual(versionNumber);
310
+ expect(getOptionsObject['entityName']).toEqual('entity-snapshot');
311
+ expect(getOptionsObject['criteria']['entityReference']).toEqual(assortment.createdForReference);
312
+ expect(getOptionsObject['criteria']['createdOn'].indexOf('ISGREATERTHAN')).toEqual(0);
313
+ });
314
+ it('doesnt find snapshot version, last snapshot after apc', async () => {
315
+ const assortment = {
316
+ id: 'rm35clTNxvS4wm6y',
317
+ name: 'VibeIQ Fall 2023',
318
+ createdForReference: 'plan:w23wre'
319
+ };
320
+ const assortmentChangeId = 'sJbGx1Fpq1v2MmcI';
321
+ const apc = {
322
+ id: assortmentChangeId,
323
+ versionName: 'Version 1',
324
+ versionComments: 'Some Comments',
325
+ createdOn: '2023-01-15T19:13:58.902Z'
326
+ };
327
+ const versionNumber = 1234;
328
+ const snapshots = [
329
+ {
330
+ id: 'qewrwer',
331
+ assortmentChangeId: 'bad-id',
332
+ createdOn: '2024-01-15T19:13:58.902Z',
333
+ versionNumber
334
+ }
335
+ ];
336
+ entityObject = snapshots;
337
+ const versionHistoryNumber = await ppa.getSnapshotVersion(assortment, apc);
338
+ expect(versionHistoryNumber).toEqual('unknown');
339
+ expect(getOptionsObject['entityName']).toEqual('entity-snapshot');
340
+ expect(getOptionsObject['criteria']['entityReference']).toEqual(assortment.createdForReference);
341
+ expect(getOptionsObject['criteria']['createdOn'].indexOf('ISGREATERTHAN')).toEqual(0);
342
+ });
343
+ it('doesnt find snapshot version, last snapshot before apc', async () => {
344
+ const assortment = {
345
+ id: 'rm35clTNxvS4wm6y',
346
+ name: 'VibeIQ Fall 2023',
347
+ createdForReference: 'plan:w23wre'
348
+ };
349
+ const assortmentChangeId = 'sJbGx1Fpq1v2MmcI';
350
+ const apc = {
351
+ id: assortmentChangeId,
352
+ versionName: 'Version 1',
353
+ versionComments: 'Some Comments',
354
+ createdOn: '2023-01-15T19:13:58.902Z'
355
+ };
356
+ const versionNumber = 1234;
357
+ const snapshots = [
358
+ {
359
+ id: 'qewrwer',
360
+ assortmentChangeId: 'bad-id',
361
+ createdOn: '2023-01-14T19:13:58.902Z',
362
+ versionNumber
363
+ }
364
+ ];
365
+ entityObject = snapshots;
366
+ const versionHistoryNumber = await ppa.getSnapshotVersion(assortment, apc);
367
+ expect(versionHistoryNumber).toEqual('after: ' + versionNumber);
368
+ expect(getOptionsObject['entityName']).toEqual('entity-snapshot');
369
+ expect(getOptionsObject['criteria']['entityReference']).toEqual(assortment.createdForReference);
370
+ expect(getOptionsObject['criteria']['createdOn'].indexOf('ISGREATERTHAN')).toEqual(0);
371
+ });
372
+ it('doesnt find snapshot version, no snapshots returned', async () => {
373
+ const assortment = {
374
+ id: 'rm35clTNxvS4wm6y',
375
+ name: 'VibeIQ Fall 2023',
376
+ createdForReference: 'plan:w23wre'
377
+ };
378
+ const assortmentChangeId = 'sJbGx1Fpq1v2MmcI';
379
+ const apc = {
380
+ id: assortmentChangeId,
381
+ versionName: 'Version 1',
382
+ versionComments: 'Some Comments',
383
+ createdOn: '2023-01-15T19:13:58.902Z'
384
+ };
385
+ const snapshots = [];
386
+ entityObject = snapshots;
387
+ const versionHistoryNumber = await ppa.getSnapshotVersion(assortment, apc);
388
+ expect(versionHistoryNumber).toEqual('unknown');
389
+ expect(getOptionsObject['entityName']).toEqual('entity-snapshot');
390
+ expect(getOptionsObject['criteria']['entityReference']).toEqual(assortment.createdForReference);
391
+ expect(getOptionsObject['criteria']['createdOn'].indexOf('ISGREATERTHAN')).toEqual(0);
392
+ });
393
+ it('doesnt find snapshot version, last snapshot no createdOn', async () => {
394
+ const assortment = {
395
+ id: 'rm35clTNxvS4wm6y',
396
+ name: 'VibeIQ Fall 2023',
397
+ createdForReference: 'plan:w23wre'
398
+ };
399
+ const assortmentChangeId = 'sJbGx1Fpq1v2MmcI';
400
+ const apc = {
401
+ id: assortmentChangeId,
402
+ versionName: 'Version 1',
403
+ versionComments: 'Some Comments',
404
+ createdOn: '2023-01-15T19:13:58.902Z'
405
+ };
406
+ const versionNumber = 1234;
407
+ const snapshots = [
408
+ {
409
+ id: 'qewrwer',
410
+ assortmentChangeId: 'bad-id',
411
+ versionNumber
412
+ }
413
+ ];
414
+ entityObject = snapshots;
415
+ const versionHistoryNumber = await ppa.getSnapshotVersion(assortment, apc);
416
+ expect(versionHistoryNumber).toEqual('unknown');
417
+ expect(getOptionsObject['entityName']).toEqual('entity-snapshot');
418
+ expect(getOptionsObject['criteria']['entityReference']).toEqual(assortment.createdForReference);
419
+ expect(getOptionsObject['criteria']['createdOn'].indexOf('ISGREATERTHAN')).toEqual(0);
420
+ });
421
+ });
422
+ describe('getSeasonFederation', () => {
423
+ const config = {
424
+ identifierAtts: {
425
+ LCSSeason: ['flexPLMSeasonName']
426
+ }
427
+ };
428
+ beforeEach(() => {
429
+ federatedId = '';
430
+ entityObject = { publishToFlexPLM: true };
431
+ getOptionsObject = {};
432
+ });
433
+ afterEach(() => {
434
+ jest.restoreAllMocks();
435
+ });
436
+ it('No Federation Info', async () => {
437
+ const assortmentId = 'B3oRQpYVYzcJAJtQ';
438
+ try {
439
+ const identifierKeys = ['flexPLMSeasonName'];
440
+ const informationKeys = ['name'];
441
+ const spyTCU_id_keys = jest.spyOn(type_conversion_utils_1.TypeConversionUtils, 'getIdentifierProperties')
442
+ .mockImplementation(async () => identifierKeys);
443
+ const spyTCU_info_keys = jest.spyOn(type_conversion_utils_1.TypeConversionUtils, 'getInformationalProperties')
444
+ .mockImplementation(async () => informationKeys);
445
+ const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
446
+ const dc = new data_converter_1.DataConverter(config, mapFileUtil);
447
+ await new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil).getSeasonFederation(assortmentId);
448
+ }
449
+ catch (e) {
450
+ expect(e.message).toEqual(base_process_publish_assortment_1.BaseProcessPublishAssortment.ASSORTMENT_NO_FED_INFO + config.identifierAtts.LCSSeason);
451
+ }
452
+ });
453
+ });
454
+ describe('Test getSinceDate', () => {
455
+ it('getSinceDate from getSinceDateFromAPCs', async () => {
456
+ const history = new Array(...mockData_1.plan1_history);
457
+ const lastAPCId = 'sJbGx1Fpq1v2MmcI';
458
+ const matchDate = new Date('2023-01-17T22:40:07.288Z');
459
+ const config = {};
460
+ const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
461
+ const dc = new data_converter_1.DataConverter(config, mapFileUtil);
462
+ const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
463
+ ppa.getApcHistory = async () => {
464
+ return history;
465
+ };
466
+ const sinceDate = await ppa.getSinceDate('oqIFX3ELRy8sFRd0', lastAPCId, history);
467
+ expect(sinceDate).toEqual(matchDate);
468
+ });
469
+ it('getSinceDate date from config as year', async () => {
470
+ const history = new Array(...mockData_1.plan1_history);
471
+ const lastAPCId = 'sJbGx1Fpq1v2MmcI';
472
+ const matchDate = new Date('2023-01-16T21:50:42.742Z');
473
+ const config = { sinceDate: '2023-01-17' };
474
+ const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
475
+ const dc = new data_converter_1.DataConverter(config, mapFileUtil);
476
+ const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
477
+ ppa.getApcHistory = async () => {
478
+ return history;
479
+ };
480
+ const sinceDate = await ppa.getSinceDate('oqIFX3ELRy8sFRd0', lastAPCId, history);
481
+ expect(sinceDate).toEqual(matchDate);
482
+ });
483
+ it('getSinceDate date from config numberofdays-cross month', async () => {
484
+ const count = 10;
485
+ const history = new Array(...mockData_1.plan1_across_month_DST);
486
+ const lastAPCId = '_mj--7nlyp7mmDrK';
487
+ const matchDate = new Date('2023-02-25T19:13:58.902Z');
488
+ const config = { sinceDate: 'numberofdays:' + count };
489
+ const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
490
+ const dc = new data_converter_1.DataConverter(config, mapFileUtil);
491
+ const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
492
+ const sinceDate = await ppa.getSinceDate('oqIFX3ELRy8sFRd0', lastAPCId, history);
493
+ expect(sinceDate).toEqual(matchDate);
494
+ });
495
+ it('getSinceDate date from config numberofdays-cross DST', async () => {
496
+ const count = 11;
497
+ const history = new Array(...mockData_1.plan1_across_month_DST);
498
+ const lastAPCId = 'sJbGx1Fpq1v2MmcI';
499
+ const matchDate = new Date('2023-03-06T21:50:42.742Z');
500
+ const config = { sinceDate: 'numberofdays:' + count };
501
+ const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
502
+ const dc = new data_converter_1.DataConverter(config, mapFileUtil);
503
+ const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
504
+ const sinceDate = await ppa.getSinceDate('oqIFX3ELRy8sFRd0', lastAPCId, history);
505
+ expect(sinceDate).toEqual(matchDate);
506
+ });
507
+ it('getSinceDate date from config numberofpublishes', async () => {
508
+ const count = 3;
509
+ const history = new Array(...mockData_1.plan1_history);
510
+ const lastAPCId = 'sJbGx1Fpq1v2MmcI';
511
+ const matchDate = new Date('2023-01-17T22:35:20.517Z');
512
+ const config = { sinceDate: 'numberofpublishes:' + count };
513
+ const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
514
+ const dc = new data_converter_1.DataConverter(config, mapFileUtil);
515
+ const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
516
+ const sinceDate = await ppa.getSinceDate('oqIFX3ELRy8sFRd0', lastAPCId, history);
517
+ expect(sinceDate).toEqual(matchDate);
518
+ });
519
+ it('getSinceDate date from config numberofpublishes', async () => {
520
+ const count = 3;
521
+ const history = new Array(...mockData_1.plan1_history);
522
+ const lastAPCId = 'sJbGx1Fpq1v2MmcI';
523
+ const matchDate = new Date('2023-01-17T22:35:20.517Z');
524
+ const config = { sinceDate: 'numberofpublishes:' + count };
525
+ const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
526
+ const dc = new data_converter_1.DataConverter(config, mapFileUtil);
527
+ const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
528
+ ppa.getApcHistory = async () => {
529
+ return history;
530
+ };
531
+ const sinceDate = await ppa.getSinceDate('oqIFX3ELRy8sFRd0', lastAPCId, history);
532
+ expect(sinceDate).toEqual(matchDate);
533
+ });
534
+ });
535
+ describe('getSinceDateFromAPCSpecificDate', () => {
536
+ it('last apc - one day', () => {
537
+ const history = new Array(...mockData_1.plan1_history);
538
+ const lastAPCId = 'sJbGx1Fpq1v2MmcI';
539
+ const matchDate = new Date('2023-01-16T21:50:42.742Z');
540
+ const config = {};
541
+ const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
542
+ const dc = new data_converter_1.DataConverter(config, mapFileUtil);
543
+ const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
544
+ const sinceDate = ppa.getSinceDateFromAPCSpecificDate(history, lastAPCId, new Date('2023-01-17T00:00:00.000Z'));
545
+ expect(sinceDate).toEqual(matchDate);
546
+ });
547
+ it('apc in the middle - one day', () => {
548
+ const history = new Array(...mockData_1.plan1_history);
549
+ const lastAPCId = 'GiT9CZXZGVljoYMR';
550
+ const matchDate = new Date('2023-01-15T19:13:58.902Z');
551
+ const config = {};
552
+ const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
553
+ const dc = new data_converter_1.DataConverter(config, mapFileUtil);
554
+ const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
555
+ const sinceDate = ppa.getSinceDateFromAPCSpecificDate(history, lastAPCId, new Date('2023-01-16T00:00:00.000Z'));
556
+ expect(sinceDate).toEqual(matchDate);
557
+ });
558
+ it('before initial publish', () => {
559
+ const history = new Array(...mockData_1.plan1_history);
560
+ const lastAPCId = 'sJbGx1Fpq1v2MmcI';
561
+ const matchDate = new Date('2023-01-15T19:13:58.902Z');
562
+ const config = {};
563
+ const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
564
+ const dc = new data_converter_1.DataConverter(config, mapFileUtil);
565
+ const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
566
+ const sinceDate = ppa.getSinceDateFromAPCSpecificDate(history, lastAPCId, new Date('2021-01-17T00:00:00.000Z'));
567
+ expect(sinceDate).toEqual(matchDate);
568
+ });
569
+ it('numberofdays at 2 ', () => {
570
+ const history = new Array(...mockData_1.plan1_history);
571
+ const lastAPCId = 'sJbGx1Fpq1v2MmcI';
572
+ const matchDate = new Date('2023-01-15T19:13:58.902Z');
573
+ const config = {};
574
+ const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
575
+ const dc = new data_converter_1.DataConverter(config, mapFileUtil);
576
+ const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
577
+ const sinceDate = ppa.getSinceDateFromAPCSpecificDate(history, lastAPCId, new Date('2023-01-16T00:00:00.000Z'));
578
+ expect(sinceDate).toEqual(matchDate);
579
+ });
580
+ });
581
+ describe('getSinceDateDaysPrevious', () => {
582
+ it('last apc - one day', () => {
583
+ const history = new Array(...mockData_1.plan1_history);
584
+ const lastAPCId = 'sJbGx1Fpq1v2MmcI';
585
+ const matchDate = new Date('2023-01-16T21:50:42.742Z');
586
+ const config = {};
587
+ const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
588
+ const dc = new data_converter_1.DataConverter(config, mapFileUtil);
589
+ const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
590
+ const sinceDate = ppa.getSinceDateDaysPrevious(history, lastAPCId, 1);
591
+ expect(sinceDate).toEqual(matchDate);
592
+ });
593
+ it('apc in the middle - one day', () => {
594
+ const history = new Array(...mockData_1.plan1_history);
595
+ const lastAPCId = 'GiT9CZXZGVljoYMR';
596
+ const matchDate = new Date('2023-01-15T19:13:58.902Z');
597
+ const config = {};
598
+ const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
599
+ const dc = new data_converter_1.DataConverter(config, mapFileUtil);
600
+ const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
601
+ const sinceDate = ppa.getSinceDateDaysPrevious(history, lastAPCId, 1);
602
+ expect(sinceDate).toEqual(matchDate);
603
+ });
604
+ it('numberofdays greater than array size', () => {
605
+ const history = new Array(...mockData_1.plan1_history);
606
+ const lastAPCId = 'sJbGx1Fpq1v2MmcI';
607
+ const matchDate = new Date('2023-01-15T19:13:58.902Z');
608
+ const config = {};
609
+ const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
610
+ const dc = new data_converter_1.DataConverter(config, mapFileUtil);
611
+ const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
612
+ const sinceDate = ppa.getSinceDateDaysPrevious(history, lastAPCId, 5);
613
+ expect(sinceDate).toEqual(matchDate);
614
+ });
615
+ it('numberofdays at 2 ', () => {
616
+ const history = new Array(...mockData_1.plan1_history);
617
+ const lastAPCId = 'sJbGx1Fpq1v2MmcI';
618
+ const matchDate = new Date('2023-01-15T19:13:58.902Z');
619
+ const config = {};
620
+ const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
621
+ const dc = new data_converter_1.DataConverter(config, mapFileUtil);
622
+ const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
623
+ const sinceDate = ppa.getSinceDateDaysPrevious(history, lastAPCId, 2);
624
+ expect(sinceDate).toEqual(matchDate);
625
+ });
626
+ });
627
+ describe('getSinceDateFromAPCs', () => {
628
+ it('first / only apc', () => {
629
+ const history = new Array(...mockData_1.plan1_history).slice(0, 1);
630
+ const lastAPCId = 'v9BKkHo-tpL0wUZN';
631
+ const matchDate = new Date(0);
632
+ const config = {};
633
+ const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
634
+ const dc = new data_converter_1.DataConverter(config, mapFileUtil);
635
+ const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
636
+ const sinceDate = ppa.getSinceDateFromAPCs(history, lastAPCId);
637
+ expect(sinceDate).toEqual(matchDate);
638
+ });
639
+ it('first / multiple apcs in history', () => {
640
+ const history = new Array(...mockData_1.plan1_history).slice(0, 3);
641
+ const lastAPCId = 'v9BKkHo-tpL0wUZN';
642
+ const matchDate = new Date(0);
643
+ const config = {};
644
+ const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
645
+ const dc = new data_converter_1.DataConverter(config, mapFileUtil);
646
+ const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
647
+ const sinceDate = ppa.getSinceDateFromAPCs(history, lastAPCId);
648
+ expect(sinceDate).toEqual(matchDate);
649
+ });
650
+ it('last apc', () => {
651
+ const history = new Array(...mockData_1.plan1_history);
652
+ const lastAPCId = 'sJbGx1Fpq1v2MmcI';
653
+ const matchDate = new Date('2023-01-17T22:40:07.288Z');
654
+ const config = {};
655
+ const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
656
+ const dc = new data_converter_1.DataConverter(config, mapFileUtil);
657
+ const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
658
+ const sinceDate = ppa.getSinceDateFromAPCs(history, lastAPCId);
659
+ expect(sinceDate).toEqual(matchDate);
660
+ });
661
+ it('apc in the middle', () => {
662
+ const history = new Array(...mockData_1.plan1_history);
663
+ const lastAPCId = 'GiT9CZXZGVljoYMR';
664
+ const matchDate = new Date('2023-01-16T21:50:42.742Z');
665
+ const config = {};
666
+ const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
667
+ const dc = new data_converter_1.DataConverter(config, mapFileUtil);
668
+ const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
669
+ const sinceDate = ppa.getSinceDateFromAPCs(history, lastAPCId);
670
+ expect(sinceDate).toEqual(matchDate);
671
+ });
672
+ it('pastPublishCount greater than array size', () => {
673
+ const history = new Array(...mockData_1.plan1_history);
674
+ const lastAPCId = 'sJbGx1Fpq1v2MmcI';
675
+ const matchDate = new Date('2023-01-15T19:13:58.902Z');
676
+ const config = {};
677
+ const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
678
+ const dc = new data_converter_1.DataConverter(config, mapFileUtil);
679
+ const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
680
+ const sinceDate = ppa.getSinceDateFromAPCs(history, lastAPCId, 20);
681
+ expect(sinceDate).toEqual(matchDate);
682
+ });
683
+ it('pastPublishCount at 3 ', () => {
684
+ const history = new Array(...mockData_1.plan1_history);
685
+ const lastAPCId = 'sJbGx1Fpq1v2MmcI';
686
+ const matchDate = new Date('2023-01-17T22:35:20.517Z');
687
+ const config = {};
688
+ const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
689
+ const dc = new data_converter_1.DataConverter(config, mapFileUtil);
690
+ const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
691
+ const sinceDate = ppa.getSinceDateFromAPCs(history, lastAPCId, 3);
692
+ expect(sinceDate).toEqual(matchDate);
693
+ });
694
+ });
695
+ describe('getDeleteChanges', () => {
696
+ const config = {};
697
+ const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
698
+ const dc = new data_converter_1.DataConverter(config, mapFileUtil);
699
+ it('no deletes - 1 apc', async () => {
700
+ const history = new Array(...mockData_1.apc_2bOWR2j9R0QThDVu_delete_history);
701
+ const lastAPCId = 'SYHfQzYWlfXDqK7r';
702
+ const apcIndex = history.findIndex(pc => pc.id === lastAPCId);
703
+ const apc = history[apcIndex];
704
+ const previousApc = (apcIndex > 0)
705
+ ? history[apcIndex - 1]
706
+ : undefined;
707
+ const apcDate = (previousApc) ? new Date(previousApc['createdOn']) : new Date(0);
708
+ const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
709
+ const spy = jest.spyOn(ppa, 'downloadDeleteChanges')
710
+ .mockImplementation(async (assortmentPublishChange) => {
711
+ let deleteChanges = [];
712
+ if (assortmentPublishChange) {
713
+ const apcId = assortmentPublishChange['id'];
714
+ const apc = history.find(apc => apc['id'] === apcId);
715
+ deleteChanges = apc['deleteData'];
716
+ }
717
+ return deleteChanges;
718
+ });
719
+ const deleteChanges = await ppa.getDeleteChanges(apc, history, apc['assortmentBaseline'], apcDate);
720
+ expect(deleteChanges).toEqual([]);
721
+ spy.mockRestore();
722
+ });
723
+ it('1 delete - 1 apc', async () => {
724
+ const history = new Array(...mockData_1.apc_2bOWR2j9R0QThDVu_delete_history);
725
+ const lastAPCId = 'JreGRNvoJ3FsoRZI';
726
+ const apcIndex = history.findIndex(pc => pc.id === lastAPCId);
727
+ const apc = history[apcIndex];
728
+ const previousApc = (apcIndex > 0)
729
+ ? history[apcIndex - 1]
730
+ : undefined;
731
+ const apcDate = (previousApc) ? new Date(previousApc['createdOn']) : new Date(0);
732
+ const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
733
+ const spy = jest.spyOn(ppa, 'downloadDeleteChanges')
734
+ .mockImplementation(async (assortmentPublishChange) => {
735
+ let deleteChanges = [];
736
+ if (assortmentPublishChange) {
737
+ const apcId = assortmentPublishChange['id'];
738
+ const apc = history.find(apc => apc['id'] === apcId);
739
+ deleteChanges = apc['deleteData'];
740
+ }
741
+ return deleteChanges;
742
+ });
743
+ const deleteChanges = await ppa.getDeleteChanges(apc, history, apc['assortmentBaseline'], apcDate);
744
+ expect(deleteChanges).toHaveLength(1);
745
+ spy.mockRestore();
746
+ });
747
+ it('no deletes - testing #3 apc', async () => {
748
+ const history = new Array(...mockData_1.apc_2bOWR2j9R0QThDVu_delete_history);
749
+ const lastAPCId = 'NaPUhAdEzKB-5tQ3';
750
+ const apcIndex = history.findIndex(pc => pc.id === lastAPCId);
751
+ const apc = history[apcIndex];
752
+ const previousApc = (apcIndex > 0)
753
+ ? history[apcIndex - 1]
754
+ : undefined;
755
+ const apcDate = (previousApc) ? new Date(previousApc['createdOn']) : new Date(0);
756
+ const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
757
+ const spy = jest.spyOn(ppa, 'downloadDeleteChanges')
758
+ .mockImplementation(async (assortmentPublishChange) => {
759
+ let deleteChanges = [];
760
+ if (assortmentPublishChange) {
761
+ const apcId = assortmentPublishChange['id'];
762
+ const apc = history.find(apc => apc['id'] === apcId);
763
+ deleteChanges = apc['deleteData'];
764
+ }
765
+ return deleteChanges;
766
+ });
767
+ const deleteChanges = await ppa.getDeleteChanges(apc, history, apc['assortmentBaseline'], apcDate);
768
+ expect(deleteChanges).toEqual([]);
769
+ spy.mockRestore();
770
+ });
771
+ it('1 delete - 1 apc', async () => {
772
+ const history = new Array(...mockData_1.apc_2bOWR2j9R0QThDVu_delete_history);
773
+ const lastAPCId = 'CHGKSCT358qyh1Nu';
774
+ const apcIndex = history.findIndex(pc => pc.id === lastAPCId);
775
+ const apc = history[apcIndex];
776
+ const previousApc = (apcIndex > 0)
777
+ ? history[apcIndex - 1]
778
+ : undefined;
779
+ const apcDate = (previousApc) ? new Date(previousApc['createdOn']) : new Date(0);
780
+ const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
781
+ const spy = jest.spyOn(ppa, 'downloadDeleteChanges')
782
+ .mockImplementation(async (assortmentPublishChange) => {
783
+ let deleteChanges = [];
784
+ if (assortmentPublishChange) {
785
+ const apcId = assortmentPublishChange['id'];
786
+ const apc = history.find(apc => apc['id'] === apcId);
787
+ deleteChanges = apc['deleteData'];
788
+ }
789
+ return deleteChanges;
790
+ });
791
+ const deleteChanges = await ppa.getDeleteChanges(apc, history, apc['assortmentBaseline'], apcDate);
792
+ expect(deleteChanges).toHaveLength(1);
793
+ spy.mockRestore();
794
+ });
795
+ it('1 delete - 2 apc (most recent delete apc, no change earlier apc)', async () => {
796
+ const history = new Array(...mockData_1.apc_2bOWR2j9R0QThDVu_delete_history);
797
+ const lastAPCId = 'CHGKSCT358qyh1Nu';
798
+ const apc = history.find(pc => pc.id === lastAPCId);
799
+ const baseApcId = 'JreGRNvoJ3FsoRZI';
800
+ const baseApc = history.find(pc => pc.id === baseApcId);
801
+ const apcDate = new Date(baseApc['createdOn']);
802
+ const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
803
+ const spy = jest.spyOn(ppa, 'downloadDeleteChanges')
804
+ .mockImplementation(async (assortmentPublishChange) => {
805
+ let deleteChanges = [];
806
+ if (assortmentPublishChange) {
807
+ const apcId = assortmentPublishChange['id'];
808
+ const apc = history.find(apc => apc['id'] === apcId);
809
+ deleteChanges = apc['deleteData'];
810
+ }
811
+ return deleteChanges;
812
+ });
813
+ const deleteChanges = await ppa.getDeleteChanges(apc, history, apc['assortmentBaseline'], apcDate);
814
+ expect(deleteChanges).toHaveLength(1);
815
+ const item = deleteChanges[0];
816
+ expect(item).not.toBeNull();
817
+ expect(item['itemId']).toEqual('qNCQmTFcFxwbT-oG');
818
+ spy.mockRestore();
819
+ });
820
+ it('1 delete - 2 apc (most recent no change, 1 delete earlier apc)', async () => {
821
+ const history = new Array(...mockData_1.apc_2bOWR2j9R0QThDVu_delete_history);
822
+ const lastAPCId = 'NaPUhAdEzKB-5tQ3';
823
+ const apc = history.find(pc => pc.id === lastAPCId);
824
+ const baseApcId = 'SYHfQzYWlfXDqK7r';
825
+ const baseApc = history.find(pc => pc.id === baseApcId);
826
+ const apcDate = new Date(baseApc['createdOn']);
827
+ const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
828
+ const spy = jest.spyOn(ppa, 'downloadDeleteChanges')
829
+ .mockImplementation(async (assortmentPublishChange) => {
830
+ let deleteChanges = [];
831
+ if (assortmentPublishChange) {
832
+ const apcId = assortmentPublishChange['id'];
833
+ const apc = history.find(apc => apc['id'] === apcId);
834
+ deleteChanges = apc['deleteData'];
835
+ }
836
+ return deleteChanges;
837
+ });
838
+ const deleteChanges = await ppa.getDeleteChanges(apc, history, apc['assortmentBaseline'], apcDate);
839
+ expect(deleteChanges).toHaveLength(1);
840
+ const item = deleteChanges[0];
841
+ expect(item).not.toBeNull();
842
+ expect(item['itemId']).toEqual('SfUAZy_Hj631h2Kg');
843
+ spy.mockRestore();
844
+ });
845
+ it('2 delete - 3 apc (most recent delete apc, no change middle apc, 1 delete)', async () => {
846
+ const history = new Array(...mockData_1.apc_2bOWR2j9R0QThDVu_delete_history);
847
+ const lastAPCId = 'CHGKSCT358qyh1Nu';
848
+ const apc = history.find(pc => pc.id === lastAPCId);
849
+ const baseApcId = 'SYHfQzYWlfXDqK7r';
850
+ const baseApc = history.find(pc => pc.id === baseApcId);
851
+ const apcDate = new Date(baseApc['createdOn']);
852
+ const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
853
+ const spy = jest.spyOn(ppa, 'downloadDeleteChanges')
854
+ .mockImplementation(async (assortmentPublishChange) => {
855
+ let deleteChanges = [];
856
+ if (assortmentPublishChange) {
857
+ const apcId = assortmentPublishChange['id'];
858
+ const apc = history.find(apc => apc['id'] === apcId);
859
+ deleteChanges = apc['deleteData'];
860
+ }
861
+ return deleteChanges;
862
+ });
863
+ const deleteChanges = await ppa.getDeleteChanges(apc, history, apc['assortmentBaseline'], apcDate);
864
+ expect(deleteChanges).toHaveLength(2);
865
+ const itemIds = deleteChanges.map(dItem => dItem['itemId']);
866
+ expect(itemIds).toContain('SfUAZy_Hj631h2Kg');
867
+ expect(itemIds).toContain('qNCQmTFcFxwbT-oG');
868
+ spy.mockRestore();
869
+ });
870
+ it('1 delete - 4 apc (most recent re-add, 1 delete, no change middle apc, 1 delete)', async () => {
871
+ console.log('1 delete - 4 apc (most recent re-add, 1 delete, no change middle apc, 1 delete)');
872
+ const history = new Array(...mockData_1.apc_2bOWR2j9R0QThDVu_delete_history);
873
+ const lastAPCId = 'H4L4dHziO6WZRIwa';
874
+ const apc = history.find(pc => pc.id === lastAPCId);
875
+ const baseApcId = 'SYHfQzYWlfXDqK7r';
876
+ const baseApc = history.find(pc => pc.id === baseApcId);
877
+ const apcDate = new Date(baseApc['createdOn']);
878
+ const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
879
+ const spy = jest.spyOn(ppa, 'downloadDeleteChanges')
880
+ .mockImplementation(async (assortmentPublishChange) => {
881
+ let deleteChanges = [];
882
+ if (assortmentPublishChange) {
883
+ const apcId = assortmentPublishChange['id'];
884
+ const apc = history.find(apc => apc['id'] === apcId);
885
+ deleteChanges = apc['deleteData'];
886
+ }
887
+ return deleteChanges;
888
+ });
889
+ const deleteChanges = await ppa.getDeleteChanges(apc, history, apc['assortmentBaseline'], apcDate);
890
+ expect(deleteChanges).toHaveLength(1);
891
+ const itemIds = deleteChanges.map(dItem => dItem['itemId']);
892
+ expect(itemIds).toContain('qNCQmTFcFxwbT-oG');
893
+ spy.mockRestore();
894
+ });
895
+ });
896
+ describe('buildDeleteChanges', () => {
897
+ const config = {};
898
+ const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
899
+ const dc = new data_converter_1.DataConverter(config, mapFileUtil);
900
+ beforeEach(() => {
901
+ jest.clearAllMocks();
902
+ });
903
+ it('apc has valid deleteDataDownloadLink', async () => {
904
+ const returnedDeleteData = [
905
+ {}
906
+ ];
907
+ const apc = {
908
+ deleteDataDownloadLink: 'deleteDataDownloadLink',
909
+ returnedDeleteData
910
+ };
911
+ const previousApc = {};
912
+ const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
913
+ const spy = jest.spyOn(ppa, 'downloadDeleteChanges')
914
+ .mockImplementation(async (assortmentPublishChange) => {
915
+ return assortmentPublishChange['returnedDeleteData'];
916
+ });
917
+ const deleteChanges = await ppa.buildDeleteChanges(apc, previousApc);
918
+ expect(deleteChanges).toHaveLength(returnedDeleteData.length);
919
+ expect(spy).toBeCalledWith(apc);
920
+ spy.mockRestore();
921
+ });
922
+ it('apc no deleteDataDownloadLink, but fullAPC has valid link', async () => {
923
+ const returnedDeleteData = [
924
+ {}
925
+ ];
926
+ const apc = {};
927
+ const fullAPC = {
928
+ deleteDataDownloadLink: 'deleteDataDownloadLink',
929
+ returnedDeleteData
930
+ };
931
+ const previousApc = {};
932
+ const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
933
+ const spy = jest.spyOn(ppa, 'downloadDeleteChanges')
934
+ .mockImplementation(async (assortmentPublishChange) => {
935
+ return assortmentPublishChange['returnedDeleteData'];
936
+ });
937
+ const spy2 = jest.spyOn(ppa, 'downloadAssortmentPublishChange')
938
+ .mockImplementation(async () => {
939
+ return fullAPC;
940
+ });
941
+ const deleteChanges = await ppa.buildDeleteChanges(apc, previousApc);
942
+ expect(deleteChanges).toHaveLength(returnedDeleteData.length);
943
+ expect(spy).toBeCalledWith(fullAPC);
944
+ spy.mockRestore();
945
+ spy2.mockRestore();
946
+ });
947
+ it('apc & fullAPC no deleteDataDownloadLink, error no previousApc', async () => {
948
+ const returnedDeleteData = [
949
+ {}
950
+ ];
951
+ const apc = {};
952
+ const fullAPC = {
953
+ returnedDeleteData
954
+ };
955
+ const previousApc = undefined;
956
+ const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
957
+ const spy2 = jest.spyOn(ppa, 'downloadAssortmentPublishChange')
958
+ .mockImplementation(async () => {
959
+ return fullAPC;
960
+ });
961
+ expect(async () => { await ppa.buildDeleteChanges(apc, previousApc); }).rejects.toThrow(new Error(base_process_publish_assortment_1.BaseProcessPublishAssortment.NOT_ABLE_TO_PROCESS_DELETE_CHANGES));
962
+ spy2.mockRestore();
963
+ });
964
+ it('apc & fullAPC no deleteDataDownloadLink, use previousApc.assortmentBaselineDownloadLink', async () => {
965
+ const assortmentId = '123';
966
+ const apcId = '456';
967
+ const previousApcId = '987';
968
+ const apc = {
969
+ assortmentId,
970
+ id: apcId,
971
+ detail: {
972
+ deletes: [{ id: '1' }, { id: '3' }]
973
+ }
974
+ };
975
+ const fullAPC = {
976
+ assortmentId,
977
+ id: apcId,
978
+ detail: {
979
+ deletes: [{ id: '1' }, { id: '3' }]
980
+ }
981
+ };
982
+ const previousApc = {};
983
+ const fullPreviousApc = {
984
+ id: previousApcId,
985
+ assortmentBaselineDownloadLink: 'assortmentBaselineDownloadLink'
986
+ };
987
+ const previousApcBaseline = {
988
+ assortmentItems: [
989
+ { itemId: '1' },
990
+ { itemId: '2' },
991
+ { itemId: '3' }
992
+ ]
993
+ };
994
+ const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
995
+ const spyDownloadDeleteChanges = jest.spyOn(ppa, 'downloadDeleteChanges')
996
+ .mockImplementation(async (assortmentPublishChange) => {
997
+ return assortmentPublishChange['returnedDeleteData'];
998
+ });
999
+ const spyDownloadAssortmentPublishChange = jest.spyOn(ppa, 'downloadAssortmentPublishChange')
1000
+ .mockImplementation(async (assortmentId, id) => {
1001
+ if (id === apcId) {
1002
+ return fullAPC;
1003
+ }
1004
+ else {
1005
+ return fullPreviousApc;
1006
+ }
1007
+ });
1008
+ const spyDownloadAssortmentBaseline = jest.spyOn(ppa, 'downloadAssortmentBaseline')
1009
+ .mockImplementation(async () => {
1010
+ return previousApcBaseline;
1011
+ });
1012
+ const deleteChanges = await ppa.buildDeleteChanges(apc, previousApc);
1013
+ expect(deleteChanges).toHaveLength(apc.detail.deletes.length);
1014
+ expect(spyDownloadAssortmentBaseline).toBeCalledWith(fullPreviousApc);
1015
+ spyDownloadDeleteChanges.mockRestore();
1016
+ spyDownloadAssortmentPublishChange.mockRestore();
1017
+ spyDownloadAssortmentBaseline.mockRestore();
1018
+ });
1019
+ it('apc & fullAPC no deleteDataDownloadLink, use fullPreviousApc.assortmentBaselineDownloadLink', async () => {
1020
+ const assortmentId = '123';
1021
+ const apcId = '456';
1022
+ const apc = {
1023
+ assortmentId,
1024
+ id: apcId,
1025
+ detail: {
1026
+ deletes: [{ id: '1' }, { id: '3' }]
1027
+ }
1028
+ };
1029
+ const fullAPC = {
1030
+ assortmentId,
1031
+ id: apcId,
1032
+ detail: {
1033
+ deletes: [{ id: '1' }, { id: '3' }]
1034
+ }
1035
+ };
1036
+ const previousApc = {
1037
+ assortmentBaselineDownloadLink: 'assortmentBaselineDownloadLink'
1038
+ };
1039
+ const previousApcBaseline = {
1040
+ assortmentItems: [
1041
+ { itemId: '1' },
1042
+ { itemId: '2' },
1043
+ { itemId: '3' }
1044
+ ]
1045
+ };
1046
+ const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
1047
+ const spyDownloadDeleteChanges = jest.spyOn(ppa, 'downloadDeleteChanges')
1048
+ .mockImplementation(async (assortmentPublishChange) => {
1049
+ return assortmentPublishChange['returnedDeleteData'];
1050
+ });
1051
+ const spyDownloadAssortmentPublishChange = jest.spyOn(ppa, 'downloadAssortmentPublishChange')
1052
+ .mockImplementation(async () => {
1053
+ return fullAPC;
1054
+ });
1055
+ const spyDownloadAssortmentBaseline = jest.spyOn(ppa, 'downloadAssortmentBaseline')
1056
+ .mockImplementation(async () => {
1057
+ return previousApcBaseline;
1058
+ });
1059
+ const deleteChanges = await ppa.buildDeleteChanges(apc, previousApc);
1060
+ expect(deleteChanges).toHaveLength(apc.detail.deletes.length);
1061
+ expect(spyDownloadAssortmentBaseline).toBeCalledWith(previousApc);
1062
+ spyDownloadDeleteChanges.mockRestore();
1063
+ spyDownloadAssortmentPublishChange.mockRestore();
1064
+ spyDownloadAssortmentBaseline.mockRestore();
1065
+ });
1066
+ });
1067
+ describe('getItemFamilyChanges', () => {
1068
+ const filterFullChange = (fullChange, itemFamilyIds) => {
1069
+ const fChange = Object.assign({}, fullChange);
1070
+ fChange['assortmentItems'] = fChange['assortmentItems']
1071
+ .filter(assortItem => itemFamilyIds.includes(assortItem['item']['itemFamilyId']));
1072
+ return fChange;
1073
+ };
1074
+ const filterDeleteChange = (deleteChange, itemFamilyIds) => {
1075
+ let dChange = Array.from(deleteChange);
1076
+ dChange = dChange.filter(assortItem => itemFamilyIds.includes(assortItem['item']['itemFamilyId']));
1077
+ return dChange;
1078
+ };
1079
+ const filterHydratedDetails = (hydratedDetails, itemFamilyIds) => {
1080
+ const hDetails = Object.assign({}, hydratedDetails);
1081
+ hDetails['adds'] = hDetails['adds']
1082
+ .filter(assortItem => itemFamilyIds.includes(assortItem['item']['itemFamilyId']));
1083
+ hDetails['deletes'] = hDetails['deletes']
1084
+ .filter(assortItem => itemFamilyIds.includes(assortItem['item']['itemFamilyId']));
1085
+ hDetails['familyItemsRemoved'] = hDetails['familyItemsRemoved']
1086
+ .filter(assortItem => itemFamilyIds.includes(assortItem['item']['itemFamilyId']));
1087
+ return hDetails;
1088
+ };
1089
+ it('Feb 3 - No Option A', () => {
1090
+ const itemFamilyId = 'kh1Rtb7kie7Vk5vo';
1091
+ const fullChange = filterFullChange(mockData_1.fall_2003_fullChange, [itemFamilyId]);
1092
+ const hydratedDetails = filterHydratedDetails(mockData_1.fall_2003_hydratedDetails, [itemFamilyId]);
1093
+ const seasonFed = {
1094
+ entityReference: 'assortment:' + fullChange['id'],
1095
+ objectClass: 'LCSSeason',
1096
+ federationId: 'VR:...LCSSeason:1'
1097
+ };
1098
+ const itemToFederatedIdMapping = new Map();
1099
+ mockData_1.fall_2003_fedMapping.forEach(mapping => itemToFederatedIdMapping.set(mapping.reference, mapping.mappedReference));
1100
+ const sinceDate = new Date('2023-02-01T00:00:00.000Z');
1101
+ const config = {};
1102
+ const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
1103
+ const dc = new data_converter_1.DataConverter(config, mapFileUtil);
1104
+ const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
1105
+ const assortmentItemFullChangeMap = ppa.getFullChangeAssortmentMap(fullChange);
1106
+ const assortmentItemDeleteMap = new Map();
1107
+ const pcd = new publish_change_data_1.PublishChangeData(fullChange['id'], seasonFed, 'i-OONhGKbJAfRKo-', sinceDate);
1108
+ pcd.itemToFederatedIdMapping = itemToFederatedIdMapping;
1109
+ pcd.releasedForDevelopmentItemIds.push(itemFamilyId);
1110
+ pcd.itemFamilyChanges = ppa.getItemFamilyChanges(pcd, hydratedDetails, assortmentItemFullChangeMap, assortmentItemDeleteMap);
1111
+ const ifcs = pcd.itemFamilyChanges;
1112
+ expect(ifcs.size).toEqual(1);
1113
+ const ifc = ifcs.get(itemFamilyId);
1114
+ expect(ifc.familyAdd).toBe(true);
1115
+ expect(ifc.colorAdds.length).toEqual(0);
1116
+ });
1117
+ it('Feb 3 - 1 Option A', () => {
1118
+ const itemFamilyId = 'U9QryfGVOYMAkBP_';
1119
+ const fullChange = filterFullChange(mockData_1.fall_2003_fullChange, [itemFamilyId]);
1120
+ const hydratedDetails = filterHydratedDetails(mockData_1.fall_2003_hydratedDetails, [itemFamilyId]);
1121
+ const seasonFed = {
1122
+ entityReference: 'assortment:' + fullChange['id'],
1123
+ objectClass: 'LCSSeason',
1124
+ federationId: 'VR:...LCSSeason:1'
1125
+ };
1126
+ const itemToFederatedIdMapping = new Map();
1127
+ mockData_1.fall_2003_fedMapping.forEach(mapping => itemToFederatedIdMapping.set(mapping.reference, mapping.mappedReference));
1128
+ const sinceDate = new Date('2023-02-01T00:00:00.000Z');
1129
+ const config = {};
1130
+ const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
1131
+ const dc = new data_converter_1.DataConverter(config, mapFileUtil);
1132
+ const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
1133
+ const assortmentItemFullChangeMap = ppa.getFullChangeAssortmentMap(fullChange);
1134
+ const assortmentItemDeleteMap = new Map();
1135
+ const pcd = new publish_change_data_1.PublishChangeData(fullChange['id'], seasonFed, 'i-OONhGKbJAfRKo-', sinceDate);
1136
+ pcd.itemToFederatedIdMapping = itemToFederatedIdMapping;
1137
+ pcd.releasedForDevelopmentItemIds.push('jFAp5SmYqhXoX-ZI');
1138
+ pcd.releasedForDevelopmentItemIds.push('U9QryfGVOYMAkBP_');
1139
+ pcd.itemFamilyChanges = ppa.getItemFamilyChanges(pcd, hydratedDetails, assortmentItemFullChangeMap, assortmentItemDeleteMap);
1140
+ const ifcs = pcd.itemFamilyChanges;
1141
+ expect(ifcs.size).toEqual(1);
1142
+ const ifc = ifcs.get(itemFamilyId);
1143
+ expect(ifc.colorAdds.length).toEqual(1);
1144
+ });
1145
+ it('Feb 3 - 2+ Option A', () => {
1146
+ const itemFamilyId = 'tvCyTuL6hF3MwbjJ';
1147
+ const fullChange = filterFullChange(mockData_1.fall_2003_fullChange, [itemFamilyId]);
1148
+ const hydratedDetails = filterHydratedDetails(mockData_1.fall_2003_hydratedDetails, [itemFamilyId]);
1149
+ const seasonFed = {
1150
+ entityReference: 'assortment:' + fullChange['id'],
1151
+ objectClass: 'LCSSeason',
1152
+ federationId: 'VR:...LCSSeason:1'
1153
+ };
1154
+ const itemToFederatedIdMapping = new Map();
1155
+ mockData_1.fall_2003_fedMapping.forEach(mapping => itemToFederatedIdMapping.set(mapping.reference, mapping.mappedReference));
1156
+ const sinceDate = new Date('2023-02-01T00:00:00.000Z');
1157
+ const config = {};
1158
+ const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
1159
+ const dc = new data_converter_1.DataConverter(config, mapFileUtil);
1160
+ const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
1161
+ const assortmentItemFullChangeMap = ppa.getFullChangeAssortmentMap(fullChange);
1162
+ const assortmentItemDeleteMap = new Map();
1163
+ const pcd = new publish_change_data_1.PublishChangeData(fullChange['id'], seasonFed, 'i-OONhGKbJAfRKo-', sinceDate);
1164
+ pcd.itemToFederatedIdMapping = itemToFederatedIdMapping;
1165
+ pcd.releasedForDevelopmentItemIds.push('jezonPsoRUlA52iz');
1166
+ pcd.releasedForDevelopmentItemIds.push('VGo0fWmBBEZoghgk');
1167
+ pcd.releasedForDevelopmentItemIds.push('tvCyTuL6hF3MwbjJ');
1168
+ pcd.itemFamilyChanges = ppa.getItemFamilyChanges(pcd, hydratedDetails, assortmentItemFullChangeMap, assortmentItemDeleteMap);
1169
+ const ifcs = pcd.itemFamilyChanges;
1170
+ expect(ifcs.size).toEqual(1);
1171
+ const ifc = ifcs.get(itemFamilyId);
1172
+ expect(ifc.colorAdds.length).toEqual(2);
1173
+ });
1174
+ it('Feb 3 - 2+ Option A & Feb 3 - 1 Option A', () => {
1175
+ const oneOption_itemFamilyId = 'U9QryfGVOYMAkBP_';
1176
+ const twoOption_itemFamilyId = 'tvCyTuL6hF3MwbjJ';
1177
+ const bothFamilyIds = [oneOption_itemFamilyId, twoOption_itemFamilyId];
1178
+ const fullChange = filterFullChange(mockData_1.fall_2003_fullChange, bothFamilyIds);
1179
+ const hydratedDetails = filterHydratedDetails(mockData_1.fall_2003_hydratedDetails, bothFamilyIds);
1180
+ const seasonFed = {
1181
+ entityReference: 'assortment:' + fullChange['id'],
1182
+ objectClass: 'LCSSeason',
1183
+ federationId: 'VR:...LCSSeason:1'
1184
+ };
1185
+ const itemToFederatedIdMapping = new Map();
1186
+ mockData_1.fall_2003_fedMapping.forEach(mapping => itemToFederatedIdMapping.set(mapping.reference, mapping.mappedReference));
1187
+ const sinceDate = new Date('2023-02-01T00:00:00.000Z');
1188
+ const config = {};
1189
+ const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
1190
+ const dc = new data_converter_1.DataConverter(config, mapFileUtil);
1191
+ const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
1192
+ const assortmentItemFullChangeMap = ppa.getFullChangeAssortmentMap(fullChange);
1193
+ const assortmentItemDeleteMap = new Map();
1194
+ const pcd = new publish_change_data_1.PublishChangeData(fullChange['id'], seasonFed, 'i-OONhGKbJAfRKo-', sinceDate);
1195
+ pcd.itemToFederatedIdMapping = itemToFederatedIdMapping;
1196
+ pcd.releasedForDevelopmentItemIds.push('jFAp5SmYqhXoX-ZI');
1197
+ pcd.releasedForDevelopmentItemIds.push('jezonPsoRUlA52iz');
1198
+ pcd.releasedForDevelopmentItemIds.push('VGo0fWmBBEZoghgk');
1199
+ pcd.releasedForDevelopmentItemIds.push('U9QryfGVOYMAkBP_');
1200
+ pcd.releasedForDevelopmentItemIds.push('tvCyTuL6hF3MwbjJ');
1201
+ pcd.itemFamilyChanges = ppa.getItemFamilyChanges(pcd, hydratedDetails, assortmentItemFullChangeMap, assortmentItemDeleteMap);
1202
+ const ifcs = pcd.itemFamilyChanges;
1203
+ expect(ifcs.size).toEqual(2);
1204
+ let ifc = ifcs.get(oneOption_itemFamilyId);
1205
+ expect(ifc.colorAdds.length).toEqual(1);
1206
+ ifc = ifcs.get(twoOption_itemFamilyId);
1207
+ expect(ifc.colorAdds.length).toEqual(2);
1208
+ });
1209
+ it('Feb 3 - 2+ Option A & Feb 3 - No Option A', () => {
1210
+ const noOption_itemFamilyId = 'kh1Rtb7kie7Vk5vo';
1211
+ const twoOption_itemFamilyId = 'tvCyTuL6hF3MwbjJ';
1212
+ const bothFamilyIds = [noOption_itemFamilyId, twoOption_itemFamilyId];
1213
+ const fullChange = filterFullChange(mockData_1.fall_2003_fullChange, bothFamilyIds);
1214
+ const hydratedDetails = filterHydratedDetails(mockData_1.fall_2003_hydratedDetails, bothFamilyIds);
1215
+ const seasonFed = {
1216
+ entityReference: 'assortment:' + fullChange['id'],
1217
+ objectClass: 'LCSSeason',
1218
+ federationId: 'VR:...LCSSeason:1'
1219
+ };
1220
+ const itemToFederatedIdMapping = new Map();
1221
+ mockData_1.fall_2003_fedMapping.forEach(mapping => itemToFederatedIdMapping.set(mapping.reference, mapping.mappedReference));
1222
+ const sinceDate = new Date('2023-02-01T00:00:00.000Z');
1223
+ const config = {};
1224
+ const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
1225
+ const dc = new data_converter_1.DataConverter(config, mapFileUtil);
1226
+ const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
1227
+ const assortmentItemFullChangeMap = ppa.getFullChangeAssortmentMap(fullChange);
1228
+ const assortmentItemDeleteMap = new Map();
1229
+ const pcd = new publish_change_data_1.PublishChangeData(fullChange['id'], seasonFed, 'i-OONhGKbJAfRKo-', sinceDate);
1230
+ pcd.itemToFederatedIdMapping = itemToFederatedIdMapping;
1231
+ pcd.releasedForDevelopmentItemIds.push(noOption_itemFamilyId);
1232
+ pcd.releasedForDevelopmentItemIds.push('jezonPsoRUlA52iz');
1233
+ pcd.releasedForDevelopmentItemIds.push('VGo0fWmBBEZoghgk');
1234
+ pcd.releasedForDevelopmentItemIds.push('kh1Rtb7kie7Vk5vo');
1235
+ pcd.releasedForDevelopmentItemIds.push('tvCyTuL6hF3MwbjJ');
1236
+ pcd.itemFamilyChanges = ppa.getItemFamilyChanges(pcd, hydratedDetails, assortmentItemFullChangeMap, assortmentItemDeleteMap);
1237
+ const ifcs = pcd.itemFamilyChanges;
1238
+ expect(ifcs.size).toEqual(2);
1239
+ let ifc = ifcs.get(noOption_itemFamilyId);
1240
+ expect(ifc.familyAdd).toBe(true);
1241
+ expect(ifc.colorAdds.length).toEqual(0);
1242
+ ifc = ifcs.get(twoOption_itemFamilyId);
1243
+ expect(ifc.colorAdds.length).toEqual(2);
1244
+ });
1245
+ it('Feb 3 - 1 Option B -remove option - leave family', () => {
1246
+ const itemFamilyId = 'EejAxj-KK_GGr5Kh';
1247
+ const fullChange = filterFullChange(mockData_1.fall_2003_fullChange_run2, [itemFamilyId]);
1248
+ const hydratedDetails = filterHydratedDetails(mockData_1.fall_2003_hydratedDetails_run2, [itemFamilyId]);
1249
+ const deleteChanges = filterDeleteChange(mockData_1.fall_2003_deleteChanges_run2, [itemFamilyId]);
1250
+ const seasonFed = {
1251
+ entityReference: 'assortment:' + fullChange['id'],
1252
+ objectClass: 'LCSSeason',
1253
+ federationId: 'VR:...LCSSeason:1'
1254
+ };
1255
+ const itemToFederatedIdMapping = new Map();
1256
+ mockData_1.fall_2003_fedMapping.forEach(mapping => itemToFederatedIdMapping.set(mapping.reference, mapping.mappedReference));
1257
+ const sinceDate = new Date('2023-02-01T00:00:00.000Z');
1258
+ const config = {};
1259
+ const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
1260
+ const dc = new data_converter_1.DataConverter(config, mapFileUtil);
1261
+ const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
1262
+ const assortmentItemFullChangeMap = ppa.getFullChangeAssortmentMap(fullChange);
1263
+ const assortmentItemDeleteMap = ppa.getDeleteChangesAssortmentMap(deleteChanges);
1264
+ const pcd = new publish_change_data_1.PublishChangeData(fullChange['id'], seasonFed, 'nPxkQJrFlTikr00h', sinceDate);
1265
+ pcd.itemToFederatedIdMapping = itemToFederatedIdMapping;
1266
+ pcd.releasedForDevelopmentItemIds.push(itemFamilyId);
1267
+ pcd.releasedForDevelopmentItemIds.push('yLhrIHYaP7B4nlkh');
1268
+ pcd.itemFamilyChanges = ppa.getItemFamilyChanges(pcd, hydratedDetails, assortmentItemFullChangeMap, assortmentItemDeleteMap);
1269
+ const ifcs = pcd.itemFamilyChanges;
1270
+ expect(ifcs.size).toEqual(1);
1271
+ const ifc = ifcs.get(itemFamilyId);
1272
+ expect(ifc.familyAdd).toBe(true);
1273
+ expect(ifc.colorAdds.length).toEqual(0);
1274
+ expect(ifc.colorDeletes.length).toEqual(1);
1275
+ });
1276
+ it('Feb 3 - 1 Option C -remove family & option', () => {
1277
+ const itemFamilyId = 'JEY86MOuRFv7f9OY';
1278
+ const fullChange = filterFullChange(mockData_1.fall_2003_fullChange_run2, [itemFamilyId]);
1279
+ const hydratedDetails = filterHydratedDetails(mockData_1.fall_2003_hydratedDetails_run2, [itemFamilyId]);
1280
+ const deleteChanges = filterDeleteChange(mockData_1.fall_2003_deleteChanges_run2, [itemFamilyId]);
1281
+ const seasonFed = {
1282
+ entityReference: 'assortment:' + fullChange['id'],
1283
+ objectClass: 'LCSSeason',
1284
+ federationId: 'VR:...LCSSeason:1'
1285
+ };
1286
+ const itemToFederatedIdMapping = new Map();
1287
+ mockData_1.fall_2003_fedMapping.forEach(mapping => itemToFederatedIdMapping.set(mapping.reference, mapping.mappedReference));
1288
+ const sinceDate = new Date('2023-02-01T00:00:00.000Z');
1289
+ const config = {};
1290
+ const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
1291
+ const dc = new data_converter_1.DataConverter(config, mapFileUtil);
1292
+ const ppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
1293
+ const assortmentItemFullChangeMap = ppa.getFullChangeAssortmentMap(fullChange);
1294
+ const assortmentItemDeleteMap = ppa.getDeleteChangesAssortmentMap(deleteChanges);
1295
+ const pcd = new publish_change_data_1.PublishChangeData(fullChange['id'], seasonFed, 'nPxkQJrFlTikr00h', sinceDate);
1296
+ pcd.itemToFederatedIdMapping = itemToFederatedIdMapping;
1297
+ pcd.releasedForDevelopmentItemIds.push(itemFamilyId);
1298
+ pcd.releasedForDevelopmentItemIds.push('eZL2ChJRBlvbu3yG');
1299
+ pcd.itemFamilyChanges = ppa.getItemFamilyChanges(pcd, hydratedDetails, assortmentItemFullChangeMap, assortmentItemDeleteMap);
1300
+ const ifcs = pcd.itemFamilyChanges;
1301
+ expect(ifcs.size).toEqual(1);
1302
+ const ifc = ifcs.get(itemFamilyId);
1303
+ expect(ifc.colorAdds.length).toEqual(0);
1304
+ expect(ifc.colorDeletes.length).toEqual(1);
1305
+ });
1306
+ });
1307
+ describe('getProjectItem', () => {
1308
+ const config = {
1309
+ identifierAtts: {
1310
+ LCSSeason: ['flexPLMSeasonName']
1311
+ }
1312
+ };
1313
+ const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
1314
+ const dc = new data_converter_1.DataConverter(config, mapFileUtil);
1315
+ const bppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
1316
+ it('family assortment item in assortmentItemFullChangeMap', () => {
1317
+ const familyId = 'w43t4';
1318
+ const sinceDate = new Date();
1319
+ const ifc = new item_family_changes_1.ItemFamilyChanges(familyId, sinceDate);
1320
+ const projectItem = {
1321
+ id: '4md02m:' + familyId
1322
+ };
1323
+ ifc.assortmentItemFullChangeMap.set(familyId, {
1324
+ projectItem
1325
+ });
1326
+ const fpi = bppa.getProjectItem(ifc, familyId);
1327
+ expect(fpi).toEqual(projectItem);
1328
+ });
1329
+ it('family assortment item NOT in assortmentItemFullChangeMap', () => {
1330
+ const familyId = 'w43t4';
1331
+ const optionId = 'l3mci2';
1332
+ const sinceDate = new Date();
1333
+ const ifc = new item_family_changes_1.ItemFamilyChanges(familyId, sinceDate);
1334
+ const familyProjectItem = {
1335
+ id: '4md02m:' + familyId
1336
+ };
1337
+ ifc.assortmentItemFullChangeMap.set(optionId, {
1338
+ familyProjectItem
1339
+ });
1340
+ const fpi = bppa.getProjectItem(ifc, familyId);
1341
+ expect(fpi).toEqual(familyProjectItem);
1342
+ });
1343
+ it('option assortment item in assortmentItemFullChangeMap', () => {
1344
+ const familyId = 'w43t4';
1345
+ const optionId = 'l3mci2';
1346
+ const sinceDate = new Date();
1347
+ const ifc = new item_family_changes_1.ItemFamilyChanges(familyId, sinceDate);
1348
+ const projectItem = {
1349
+ id: '4md02m:' + optionId
1350
+ };
1351
+ ifc.assortmentItemFullChangeMap.set(optionId, {
1352
+ projectItem
1353
+ });
1354
+ const fpi = bppa.getProjectItem(ifc, optionId);
1355
+ expect(fpi).toEqual(projectItem);
1356
+ });
1357
+ });
1358
+ describe('getCarriedFromSeason', () => {
1359
+ const config = {
1360
+ identifierAtts: {
1361
+ LCSSeason: ['flexPLMSeasonName']
1362
+ }
1363
+ };
1364
+ const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
1365
+ const dc = new data_converter_1.DataConverter(config, mapFileUtil);
1366
+ const bppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
1367
+ it('cache hit', async () => {
1368
+ const projectItem = {
1369
+ addedFromAssortment: 123
1370
+ };
1371
+ const origGetAssormentEntityFromId = bppa.getAssormentEntityFromId;
1372
+ const origGetSeasonFederationFromAssortment = bppa.getSeasonFederationFromAssortment;
1373
+ try {
1374
+ const assortmentEntity = {};
1375
+ const seasonFed = {
1376
+ entityReference: 'assortment:123',
1377
+ objectClass: 'LCSSeason'
1378
+ };
1379
+ bppa.getAssormentEntityFromId = async (assortmentId) => { return assortmentEntity; };
1380
+ bppa.getSeasonFederationFromAssortment = async (assortment) => { return seasonFed; };
1381
+ const spyGetAssortment = jest.spyOn(bppa, 'getAssormentEntityFromId');
1382
+ const spyGetSeasonFed = jest.spyOn(bppa, 'getSeasonFederationFromAssortment');
1383
+ let sFed = await bppa.getCarriedFromSeason(projectItem);
1384
+ sFed = await bppa.getCarriedFromSeason(projectItem);
1385
+ expect(spyGetAssortment).toHaveBeenCalledTimes(1);
1386
+ expect(spyGetSeasonFed).toHaveBeenCalledTimes(1);
1387
+ }
1388
+ finally {
1389
+ bppa.getAssormentEntityFromId = origGetAssormentEntityFromId;
1390
+ bppa.getSeasonFederationFromAssortment = origGetSeasonFederationFromAssortment;
1391
+ }
1392
+ const sf = await bppa.getCarriedFromSeason(projectItem);
1393
+ });
1394
+ describe('getSeasonFederationFromAssortment', () => {
1395
+ it('Test conversion', async () => {
1396
+ const assortment = {
1397
+ id: '2we4',
1398
+ name: 'Object Name',
1399
+ notTransferred: 'This shouldnt be in the returned object'
1400
+ };
1401
+ const typePath = 'Path';
1402
+ const identifierKeys = ['name'];
1403
+ const informationKeys = [];
1404
+ const mapKey = 'mapKey';
1405
+ const spyTCU_type_path = jest.spyOn(type_conversion_utils_1.TypeConversionUtils, 'getObjectTypePath')
1406
+ .mockImplementation(async () => typePath);
1407
+ const spyDC_get_data = jest.spyOn(dc, 'getFlexPLMObjectData')
1408
+ .mockImplementation(async (data) => data);
1409
+ const spyTCU_id_keys = jest.spyOn(type_conversion_utils_1.TypeConversionUtils, 'getIdentifierProperties')
1410
+ .mockImplementation(async () => identifierKeys);
1411
+ const spyTCU_info_keys = jest.spyOn(type_conversion_utils_1.TypeConversionUtils, 'getInformationalProperties')
1412
+ .mockImplementation(async () => informationKeys);
1413
+ const spyTCU_get_map_key = jest.spyOn(type_conversion_utils_1.TypeConversionUtils, 'getMapKey')
1414
+ .mockImplementation(async () => mapKey);
1415
+ const spyMU_apply_map = jest.spyOn(map_utils_1.MapUtil, 'applyTransformMap')
1416
+ .mockImplementation(async (...args) => args[2]);
1417
+ const results = await bppa.getSeasonFederationFromAssortment(assortment);
1418
+ console.log('Test conversion: ' + JSON.stringify(results));
1419
+ expect(results['entityReference']).toBe('assortment:2we4');
1420
+ expect(results['name']).toBe('Object Name');
1421
+ expect(results['flexPLMTypePath']).toBe('Path');
1422
+ expect(results['objectClass']).toBe('LCSSeason');
1423
+ expect(results).not.toHaveProperty('notTransferred');
1424
+ });
1425
+ });
1426
+ });
1427
+ describe('meetsCriteria', () => {
1428
+ const config = {
1429
+ identifierAtts: {
1430
+ LCSSeason: ['flexPLMSeasonName']
1431
+ },
1432
+ itemPreDevelopmentLifecycleStages: ['concept']
1433
+ };
1434
+ const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
1435
+ const dc = new data_converter_1.DataConverter(config, mapFileUtil);
1436
+ const bppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
1437
+ it('no item', () => {
1438
+ const aItem = {};
1439
+ const results = bppa.meetsCriteria(aItem);
1440
+ expect(results).toBeFalsy();
1441
+ });
1442
+ it('item - no lifecycle stage', () => {
1443
+ const aItem = {
1444
+ item: {
1445
+ lifecycleStage: ''
1446
+ }
1447
+ };
1448
+ const results = bppa.meetsCriteria(aItem);
1449
+ expect(results).toBeFalsy();
1450
+ });
1451
+ it('item - concept lifecycle stage', () => {
1452
+ const aItem = {
1453
+ item: {
1454
+ lifecycleStage: 'concept'
1455
+ }
1456
+ };
1457
+ const results = bppa.meetsCriteria(aItem);
1458
+ expect(results).toBeFalsy();
1459
+ });
1460
+ it('item - delevopment lifecycle stage', () => {
1461
+ const aItem = {
1462
+ item: {
1463
+ lifecycleStage: 'delevopment'
1464
+ }
1465
+ };
1466
+ const results = bppa.meetsCriteria(aItem);
1467
+ expect(results).toBeTruthy();
1468
+ });
1469
+ });
1470
+ describe('getEventsForItemFamilyChanges - conditional eventType', () => {
1471
+ const config = {
1472
+ identifierAtts: {
1473
+ LCSSeason: ['flexPLMSeasonName']
1474
+ },
1475
+ itemPreDevelopmentLifecycleStages: ['concept']
1476
+ };
1477
+ const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
1478
+ const dc = new data_converter_1.DataConverter(config, mapFileUtil);
1479
+ afterEach(() => {
1480
+ jest.restoreAllMocks();
1481
+ });
1482
+ it('should use UPSERT_ON_SEASON for LCSProductSeasonLink when isOutboundCreatableFromEntity returns true', async () => {
1483
+ const bppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
1484
+ const itemFamilyId = 'family123';
1485
+ const prodEntityData = { id: itemFamilyId, identifier: 'FAM-123', itemNumber: 'FAM-123' };
1486
+ const projectItem = { id: 'proj1', updatedOn: '2023-01-15T00:00:00.000Z' };
1487
+ const assortment = { id: 'assort123', name: 'Fall 2023 Assortment', publishToFlexPLM: true };
1488
+ const seasonFed = {
1489
+ entityReference: 'assortment:assort123',
1490
+ objectClass: 'LCSSeason',
1491
+ flexPLMSeasonName: 'Fall 2023'
1492
+ };
1493
+ const itemFamilyChanges = new item_family_changes_1.ItemFamilyChanges(itemFamilyId, new Date('2023-01-01T00:00:00.000Z'));
1494
+ itemFamilyChanges.familyAdd = true;
1495
+ itemFamilyChanges.assortmentItemFullChangeMap.set(itemFamilyId, {
1496
+ item: prodEntityData,
1497
+ projectItem
1498
+ });
1499
+ jest.spyOn(bppa, 'getAssortment').mockResolvedValue(assortment);
1500
+ jest.spyOn(bppa, 'getProjectItem').mockReturnValue(projectItem);
1501
+ jest.spyOn(bppa, 'getSeasonalData').mockResolvedValue({ someData: 'value' });
1502
+ jest.spyOn(map_utils_1.MapUtil, 'applyTransformMap').mockResolvedValue({ transformedData: 'value' });
1503
+ jest.spyOn(type_conversion_utils_1.TypeConversionUtils, 'getIdentifierProperties').mockResolvedValue(['identifier']);
1504
+ jest.spyOn(type_conversion_utils_1.TypeConversionUtils, 'getInformationalProperties').mockResolvedValue([]);
1505
+ jest.spyOn(type_conversion_utils_1.TypeConversionUtils, 'isOutboundCreatableFromEntity').mockResolvedValue(true);
1506
+ const events = await bppa.getEventsForItemFamilyChanges(itemFamilyChanges, 'assort123', seasonFed, new Map());
1507
+ expect(events).toHaveLength(1);
1508
+ expect(events[0].eventType).toBe('UPSERT_ON_SEASON');
1509
+ expect(events[0].objectClass).toBe('LCSProductSeasonLink');
1510
+ expect(type_conversion_utils_1.TypeConversionUtils.isOutboundCreatableFromEntity).toHaveBeenCalledWith(undefined, mapFileUtil, projectItem, { item: prodEntityData, assortment });
1511
+ });
1512
+ it('should use UPDATE_ON_SEASON for LCSProductSeasonLink when isOutboundCreatableFromEntity returns false', async () => {
1513
+ const bppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
1514
+ const itemFamilyId = 'family123';
1515
+ const prodEntityData = { id: itemFamilyId, identifier: 'FAM-123', itemNumber: 'FAM-123' };
1516
+ const projectItem = { id: 'proj1', updatedOn: '2023-01-15T00:00:00.000Z' };
1517
+ const assortment = { id: 'assort123', name: 'Fall 2023 Assortment', publishToFlexPLM: true };
1518
+ const seasonFed = {
1519
+ entityReference: 'assortment:assort123',
1520
+ objectClass: 'LCSSeason',
1521
+ flexPLMSeasonName: 'Fall 2023'
1522
+ };
1523
+ const itemFamilyChanges = new item_family_changes_1.ItemFamilyChanges(itemFamilyId, new Date('2023-01-01T00:00:00.000Z'));
1524
+ itemFamilyChanges.familyUpdate = true;
1525
+ itemFamilyChanges.assortmentItemFullChangeMap.set(itemFamilyId, {
1526
+ item: prodEntityData,
1527
+ projectItem
1528
+ });
1529
+ jest.spyOn(bppa, 'getAssortment').mockResolvedValue(assortment);
1530
+ jest.spyOn(bppa, 'getProjectItem').mockReturnValue(projectItem);
1531
+ jest.spyOn(bppa, 'getSeasonalData').mockResolvedValue({ someData: 'value' });
1532
+ jest.spyOn(map_utils_1.MapUtil, 'applyTransformMap').mockResolvedValue({ transformedData: 'value' });
1533
+ jest.spyOn(type_conversion_utils_1.TypeConversionUtils, 'getIdentifierProperties').mockResolvedValue(['identifier']);
1534
+ jest.spyOn(type_conversion_utils_1.TypeConversionUtils, 'getInformationalProperties').mockResolvedValue([]);
1535
+ jest.spyOn(type_conversion_utils_1.TypeConversionUtils, 'isOutboundCreatableFromEntity').mockResolvedValue(false);
1536
+ const events = await bppa.getEventsForItemFamilyChanges(itemFamilyChanges, 'assort123', seasonFed, new Map());
1537
+ expect(events).toHaveLength(1);
1538
+ expect(events[0].eventType).toBe('UPDATE_ON_SEASON');
1539
+ expect(events[0].objectClass).toBe('LCSProductSeasonLink');
1540
+ expect(type_conversion_utils_1.TypeConversionUtils.isOutboundCreatableFromEntity).toHaveBeenCalledWith(undefined, mapFileUtil, projectItem, { item: prodEntityData, assortment });
1541
+ });
1542
+ it('should use UPSERT_ON_SEASON for LCSSKUSeasonLink when isOutboundCreatableFromEntity returns true', async () => {
1543
+ const bppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
1544
+ const itemFamilyId = 'family123';
1545
+ const colorId = 'color456';
1546
+ const familyItemData = { id: itemFamilyId, identifier: 'FAM-123', itemNumber: 'FAM-123' };
1547
+ const itemData = { id: colorId, identifier: 'COLOR-456', itemNumber: 'COLOR-456' };
1548
+ const familyProjectItem = { id: 'proj0', updatedOn: '2023-01-14T00:00:00.000Z' };
1549
+ const projectItem = { id: 'proj1', updatedOn: '2023-01-15T00:00:00.000Z' };
1550
+ const assortment = { id: 'assort123', name: 'Fall 2023 Assortment', publishToFlexPLM: true };
1551
+ const seasonFed = {
1552
+ entityReference: 'assortment:assort123',
1553
+ objectClass: 'LCSSeason',
1554
+ flexPLMSeasonName: 'Fall 2023'
1555
+ };
1556
+ const itemFamilyChanges = new item_family_changes_1.ItemFamilyChanges(itemFamilyId, new Date('2023-01-01T00:00:00.000Z'));
1557
+ itemFamilyChanges.colorAdds.push(colorId);
1558
+ itemFamilyChanges.assortmentItemFullChangeMap.set(itemFamilyId, {
1559
+ item: familyItemData,
1560
+ projectItem: familyProjectItem
1561
+ });
1562
+ itemFamilyChanges.assortmentItemFullChangeMap.set(colorId, {
1563
+ item: itemData,
1564
+ projectItem
1565
+ });
1566
+ jest.spyOn(bppa, 'getAssortment').mockResolvedValue(assortment);
1567
+ jest.spyOn(bppa, 'getProjectItem')
1568
+ .mockReturnValueOnce(familyProjectItem)
1569
+ .mockReturnValueOnce(projectItem);
1570
+ jest.spyOn(bppa, 'getSeasonalData').mockResolvedValue({ someData: 'value' });
1571
+ jest.spyOn(map_utils_1.MapUtil, 'applyTransformMap').mockResolvedValue({ transformedData: 'value' });
1572
+ jest.spyOn(type_conversion_utils_1.TypeConversionUtils, 'getIdentifierProperties').mockResolvedValue(['identifier']);
1573
+ jest.spyOn(type_conversion_utils_1.TypeConversionUtils, 'getInformationalProperties').mockResolvedValue([]);
1574
+ jest.spyOn(type_conversion_utils_1.TypeConversionUtils, 'isOutboundCreatableFromEntity')
1575
+ .mockResolvedValueOnce(true)
1576
+ .mockResolvedValueOnce(true);
1577
+ const events = await bppa.getEventsForItemFamilyChanges(itemFamilyChanges, 'assort123', seasonFed, new Map());
1578
+ expect(events).toHaveLength(2);
1579
+ const skuEvent = events.find(e => e.objectClass === 'LCSSKUSeasonLink');
1580
+ expect(skuEvent.eventType).toBe('UPSERT_ON_SEASON');
1581
+ expect(type_conversion_utils_1.TypeConversionUtils.isOutboundCreatableFromEntity).toHaveBeenCalledWith(undefined, mapFileUtil, projectItem, { item: itemData, assortment });
1582
+ });
1583
+ it('should use UPDATE_ON_SEASON for LCSSKUSeasonLink when isOutboundCreatableFromEntity returns false', async () => {
1584
+ const bppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
1585
+ const itemFamilyId = 'family123';
1586
+ const colorId = 'color456';
1587
+ const familyItemData = { id: itemFamilyId, identifier: 'FAM-123', itemNumber: 'FAM-123' };
1588
+ const itemData = { id: colorId, identifier: 'COLOR-456', itemNumber: 'COLOR-456' };
1589
+ const familyProjectItem = { id: 'proj0', updatedOn: '2023-01-14T00:00:00.000Z' };
1590
+ const projectItem = { id: 'proj1', updatedOn: '2023-01-15T00:00:00.000Z' };
1591
+ const assortment = { id: 'assort123', name: 'Fall 2023 Assortment', publishToFlexPLM: true };
1592
+ const seasonFed = {
1593
+ entityReference: 'assortment:assort123',
1594
+ objectClass: 'LCSSeason',
1595
+ flexPLMSeasonName: 'Fall 2023'
1596
+ };
1597
+ const itemFamilyChanges = new item_family_changes_1.ItemFamilyChanges(itemFamilyId, new Date('2023-01-01T00:00:00.000Z'));
1598
+ itemFamilyChanges.colorUpdates.push(colorId);
1599
+ itemFamilyChanges.assortmentItemFullChangeMap.set(itemFamilyId, {
1600
+ item: familyItemData,
1601
+ projectItem: familyProjectItem
1602
+ });
1603
+ itemFamilyChanges.assortmentItemFullChangeMap.set(colorId, {
1604
+ item: itemData,
1605
+ projectItem
1606
+ });
1607
+ jest.spyOn(bppa, 'getAssortment').mockResolvedValue(assortment);
1608
+ jest.spyOn(bppa, 'getProjectItem')
1609
+ .mockReturnValueOnce(familyProjectItem)
1610
+ .mockReturnValueOnce(projectItem);
1611
+ jest.spyOn(bppa, 'getSeasonalData').mockResolvedValue({ someData: 'value' });
1612
+ jest.spyOn(map_utils_1.MapUtil, 'applyTransformMap').mockResolvedValue({ transformedData: 'value' });
1613
+ jest.spyOn(type_conversion_utils_1.TypeConversionUtils, 'getIdentifierProperties').mockResolvedValue(['identifier']);
1614
+ jest.spyOn(type_conversion_utils_1.TypeConversionUtils, 'getInformationalProperties').mockResolvedValue([]);
1615
+ jest.spyOn(type_conversion_utils_1.TypeConversionUtils, 'isOutboundCreatableFromEntity')
1616
+ .mockResolvedValueOnce(false)
1617
+ .mockResolvedValueOnce(false);
1618
+ const events = await bppa.getEventsForItemFamilyChanges(itemFamilyChanges, 'assort123', seasonFed, new Map());
1619
+ expect(events).toHaveLength(2);
1620
+ const skuEvent = events.find(e => e.objectClass === 'LCSSKUSeasonLink');
1621
+ expect(skuEvent.eventType).toBe('UPDATE_ON_SEASON');
1622
+ expect(type_conversion_utils_1.TypeConversionUtils.isOutboundCreatableFromEntity).toHaveBeenCalledWith(undefined, mapFileUtil, projectItem, { item: itemData, assortment });
1623
+ });
1624
+ it('should create both product and SKU events with correct eventTypes based on isOutboundCreatableFromEntity', async () => {
1625
+ const bppa = new base_process_publish_assortment_1.BaseProcessPublishAssortment(config, dc, mapFileUtil);
1626
+ const itemFamilyId = 'family123';
1627
+ const colorId = 'color456';
1628
+ const prodEntityData = { id: itemFamilyId, identifier: 'FAM-123', itemNumber: 'FAM-123' };
1629
+ const itemData = { id: colorId, identifier: 'COLOR-456', itemNumber: 'COLOR-456' };
1630
+ const familyProjectItem = { id: 'proj1', updatedOn: '2023-01-15T00:00:00.000Z' };
1631
+ const colorProjectItem = { id: 'proj2', updatedOn: '2023-01-15T00:00:00.000Z' };
1632
+ const assortment = { id: 'assort123', name: 'Fall 2023 Assortment', publishToFlexPLM: true };
1633
+ const seasonFed = {
1634
+ entityReference: 'assortment:assort123',
1635
+ objectClass: 'LCSSeason',
1636
+ flexPLMSeasonName: 'Fall 2023'
1637
+ };
1638
+ const itemFamilyChanges = new item_family_changes_1.ItemFamilyChanges(itemFamilyId, new Date('2023-01-01T00:00:00.000Z'));
1639
+ itemFamilyChanges.familyAdd = true;
1640
+ itemFamilyChanges.colorAdds.push(colorId);
1641
+ itemFamilyChanges.assortmentItemFullChangeMap.set(itemFamilyId, {
1642
+ item: prodEntityData,
1643
+ projectItem: familyProjectItem
1644
+ });
1645
+ itemFamilyChanges.assortmentItemFullChangeMap.set(colorId, {
1646
+ item: itemData,
1647
+ projectItem: colorProjectItem
1648
+ });
1649
+ jest.spyOn(bppa, 'getAssortment').mockResolvedValue(assortment);
1650
+ jest.spyOn(bppa, 'getProjectItem')
1651
+ .mockReturnValueOnce(familyProjectItem)
1652
+ .mockReturnValueOnce(colorProjectItem);
1653
+ jest.spyOn(bppa, 'getSeasonalData').mockResolvedValue({ someData: 'value' });
1654
+ jest.spyOn(map_utils_1.MapUtil, 'applyTransformMap').mockResolvedValue({ transformedData: 'value' });
1655
+ jest.spyOn(type_conversion_utils_1.TypeConversionUtils, 'getIdentifierProperties').mockResolvedValue(['identifier']);
1656
+ jest.spyOn(type_conversion_utils_1.TypeConversionUtils, 'getInformationalProperties').mockResolvedValue([]);
1657
+ jest.spyOn(type_conversion_utils_1.TypeConversionUtils, 'isOutboundCreatableFromEntity')
1658
+ .mockResolvedValueOnce(true)
1659
+ .mockResolvedValueOnce(false);
1660
+ const events = await bppa.getEventsForItemFamilyChanges(itemFamilyChanges, 'assort123', seasonFed, new Map());
1661
+ expect(events).toHaveLength(2);
1662
+ const productEvent = events.find(e => e.objectClass === 'LCSProductSeasonLink');
1663
+ const skuEvent = events.find(e => e.objectClass === 'LCSSKUSeasonLink');
1664
+ expect(productEvent.eventType).toBe('UPSERT_ON_SEASON');
1665
+ expect(skuEvent.eventType).toBe('UPDATE_ON_SEASON');
1666
+ expect(type_conversion_utils_1.TypeConversionUtils.isOutboundCreatableFromEntity).toHaveBeenCalledTimes(2);
1667
+ expect(type_conversion_utils_1.TypeConversionUtils.isOutboundCreatableFromEntity).toHaveBeenNthCalledWith(1, undefined, mapFileUtil, familyProjectItem, { item: prodEntityData, assortment });
1668
+ expect(type_conversion_utils_1.TypeConversionUtils.isOutboundCreatableFromEntity).toHaveBeenNthCalledWith(2, undefined, mapFileUtil, colorProjectItem, { item: itemData, assortment });
1669
+ });
1670
+ });