@contrail/flexplm 1.1.61 → 1.1.62

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