@contrail/flexplm 1.3.0-alpha.5 → 1.3.0-alpha.7cd23d9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/.github/workflows/flexplm-lib.yml +1 -1
  2. package/.github/workflows/publish-to-npm.yml +118 -0
  3. package/CHANGELOG.md +1 -1
  4. package/lib/entity-processor/base-entity-processor.d.ts +42 -42
  5. package/lib/entity-processor/base-entity-processor.js +385 -385
  6. package/lib/entity-processor/base-entity-processor.spec.d.ts +1 -1
  7. package/lib/entity-processor/base-entity-processor.spec.js +397 -397
  8. package/lib/flexplm-request.d.ts +3 -3
  9. package/lib/flexplm-request.js +34 -34
  10. package/lib/flexplm-utils.d.ts +5 -5
  11. package/lib/flexplm-utils.js +33 -33
  12. package/lib/flexplm-utils.spec.d.ts +1 -1
  13. package/lib/flexplm-utils.spec.js +26 -26
  14. package/lib/index.d.ts +22 -22
  15. package/lib/index.js +38 -38
  16. package/lib/interfaces/interfaces.d.ts +105 -105
  17. package/lib/interfaces/interfaces.js +2 -2
  18. package/lib/interfaces/item-family-changes.d.ts +20 -20
  19. package/lib/interfaces/item-family-changes.js +56 -56
  20. package/lib/interfaces/publish-change-data.d.ts +19 -19
  21. package/lib/interfaces/publish-change-data.js +32 -32
  22. package/lib/publish/base-process-publish-assortment-callback.d.ts +9 -9
  23. package/lib/publish/base-process-publish-assortment-callback.js +38 -38
  24. package/lib/publish/base-process-publish-assortment.d.ts +93 -93
  25. package/lib/publish/base-process-publish-assortment.js +944 -944
  26. package/lib/publish/base-process-publish-assortment.spec.d.ts +1 -1
  27. package/lib/publish/base-process-publish-assortment.spec.js +1670 -1670
  28. package/lib/publish/mockData.d.ts +1389 -1389
  29. package/lib/publish/mockData.js +4519 -4519
  30. package/lib/transform/identifier-conversion-spec-mockData.js +444 -444
  31. package/lib/transform/identifier-conversion.d.ts +15 -15
  32. package/lib/transform/identifier-conversion.js +212 -212
  33. package/lib/transform/identifier-conversion.spec.d.ts +1 -1
  34. package/lib/transform/identifier-conversion.spec.js +339 -339
  35. package/lib/util/config-defaults.d.ts +8 -8
  36. package/lib/util/config-defaults.js +85 -85
  37. package/lib/util/config-defaults.spec.d.ts +1 -1
  38. package/lib/util/config-defaults.spec.js +293 -293
  39. package/lib/util/data-converter-spec-mockData.js +205 -205
  40. package/lib/util/data-converter.d.ts +39 -39
  41. package/lib/util/data-converter.js +592 -592
  42. package/lib/util/data-converter.spec.d.ts +1 -1
  43. package/lib/util/data-converter.spec.js +904 -904
  44. package/lib/util/error-response-object.d.ts +4 -4
  45. package/lib/util/error-response-object.js +47 -47
  46. package/lib/util/error-response-object.spec.d.ts +1 -1
  47. package/lib/util/error-response-object.spec.js +99 -99
  48. package/lib/util/event-short-message-status.d.ts +19 -19
  49. package/lib/util/event-short-message-status.js +23 -23
  50. package/lib/util/federation.d.ts +15 -15
  51. package/lib/util/federation.js +149 -149
  52. package/lib/util/flexplm-connect.d.ts +22 -22
  53. package/lib/util/flexplm-connect.js +176 -176
  54. package/lib/util/flexplm-connect.spec.d.ts +1 -1
  55. package/lib/util/flexplm-connect.spec.js +88 -88
  56. package/lib/util/logger-config.d.ts +1 -1
  57. package/lib/util/logger-config.js +26 -26
  58. package/lib/util/map-util-spec-mockData.js +205 -205
  59. package/lib/util/map-utils.d.ts +6 -6
  60. package/lib/util/map-utils.js +15 -15
  61. package/lib/util/map-utils.spec.d.ts +1 -1
  62. package/lib/util/map-utils.spec.js +89 -89
  63. package/lib/util/mockData.d.ts +80 -80
  64. package/lib/util/mockData.js +103 -103
  65. package/lib/util/thumbnail-util.d.ts +34 -34
  66. package/lib/util/thumbnail-util.js +215 -214
  67. package/lib/util/thumbnail-util.spec.d.ts +1 -1
  68. package/lib/util/thumbnail-util.spec.js +434 -394
  69. package/lib/util/type-conversion-utils-spec-mockData.js +259 -259
  70. package/lib/util/type-conversion-utils.d.ts +23 -23
  71. package/lib/util/type-conversion-utils.js +265 -265
  72. package/lib/util/type-conversion-utils.spec.d.ts +1 -1
  73. package/lib/util/type-conversion-utils.spec.js +868 -868
  74. package/lib/util/type-defaults.d.ts +16 -16
  75. package/lib/util/type-defaults.js +221 -221
  76. package/lib/util/type-defaults.spec.d.ts +1 -1
  77. package/lib/util/type-defaults.spec.js +516 -516
  78. package/lib/util/type-utils.d.ts +13 -13
  79. package/lib/util/type-utils.js +114 -114
  80. package/lib/util/type-utils.spec.d.ts +1 -1
  81. package/lib/util/type-utils.spec.js +190 -190
  82. package/package.json +1 -1
  83. package/publish.sh +0 -0
  84. package/src/util/thumbnail-util.spec.ts +50 -0
  85. package/src/util/thumbnail-util.ts +5 -4
  86. package/tsconfig.json +1 -6
  87. package/.claude/settings.local.json +0 -8
@@ -1,394 +1,434 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const thumbnail_util_1 = require("./thumbnail-util");
4
- const mockData_1 = require("./mockData");
5
- const mockEntitiesGet = jest.fn();
6
- const mockEntitiesUpdate = jest.fn();
7
- const mockEntitiesDelete = jest.fn();
8
- const mockContentCreate = jest.fn();
9
- jest.mock('@contrail/sdk', () => {
10
- return {
11
- Entities: jest.fn().mockImplementation(() => ({
12
- get: mockEntitiesGet,
13
- update: mockEntitiesUpdate,
14
- delete: mockEntitiesDelete,
15
- })),
16
- Content: jest.fn().mockImplementation(() => ({
17
- create: mockContentCreate,
18
- })),
19
- };
20
- });
21
- const mockGetRequest = jest.fn();
22
- jest.mock('./flexplm-connect', () => {
23
- return {
24
- FlexPLMConnect: jest.fn().mockImplementation(() => ({
25
- getRequest: mockGetRequest,
26
- })),
27
- };
28
- });
29
- describe('ThumbnailUtil Tests', () => {
30
- const config = {};
31
- describe('setOutboundThumbnail()', () => {
32
- const tu = new thumbnail_util_1.ThumbnailUtil(config);
33
- beforeEach(() => {
34
- jest.clearAllMocks();
35
- });
36
- it('no data', async () => {
37
- const data = {};
38
- const event = {};
39
- const results = await tu.setOutboundThumbnail(data, event);
40
- const keys = Object.keys(results);
41
- expect(results).toEqual(data);
42
- expect(keys.length).toEqual(0);
43
- });
44
- it('remove thumbnail', async () => {
45
- const data = {};
46
- const event = {
47
- propertyDiffs: {
48
- largeViewableDownloadUrl: {
49
- oldValue: '123',
50
- newValue: null
51
- }
52
- }
53
- };
54
- const results = await tu.setOutboundThumbnail(data, event);
55
- const keys = Object.keys(results);
56
- expect(keys.length).toEqual(1);
57
- expect(keys[0]).toEqual(thumbnail_util_1.ThumbnailUtil.NEW_THUMBNAIL_ID);
58
- expect(results[thumbnail_util_1.ThumbnailUtil.NEW_THUMBNAIL_ID]).toEqual(thumbnail_util_1.ThumbnailUtil.REMOVE_THUMBNAIL);
59
- });
60
- it('calling getFileId - new thumbnail', async () => {
61
- const data = {};
62
- const newDownloadUrl = 'https://api.vibeiq.com/dev/api/files/downloadUrl/w3ckfeGAD8ViOZj-%2Fcontent:E1iBQuWbr74lcdcw%2F9e30ds9o-d34b-451e-ae59-b4km36018d5a.png';
63
- const oldDownloadUrl = 'xxx';
64
- const thumbnailId = 'Eey3ZOiqdrUA84F8';
65
- const event = {
66
- newData: {
67
- primaryViewableId: 'm5bJa4RtTLUtKBP5',
68
- largeViewableDownloadUrl: newDownloadUrl
69
- },
70
- propertyDiffs: {
71
- largeViewableDownloadUrl: {
72
- newValue: newDownloadUrl,
73
- oldValue: oldDownloadUrl
74
- }
75
- }
76
- };
77
- const spyCustomSizes = jest.spyOn(tu, 'getCustomSizes');
78
- spyCustomSizes.mockReturnValue(Promise.resolve(mockData_1.empty_custom_sizes));
79
- const spyGetFileId = jest.spyOn(tu, 'getFileId');
80
- spyGetFileId.mockReturnValue(Promise.resolve(thumbnailId));
81
- const results = await tu.setOutboundThumbnail(data, event);
82
- const keys = Object.keys(results);
83
- expect(keys.length).toEqual(1);
84
- expect(keys[0]).toEqual(thumbnail_util_1.ThumbnailUtil.NEW_THUMBNAIL_ID);
85
- const thumbnailValue = results[thumbnail_util_1.ThumbnailUtil.NEW_THUMBNAIL_ID];
86
- expect(thumbnailValue).toEqual(thumbnailId);
87
- });
88
- it('calling getFileId - existing thumbnail', async () => {
89
- const data = {};
90
- const newDownloadUrl = 'https://api.vibeiq.com/dev/api/files/downloadUrl/w3ckfeGAD8ViOZj-%2Fcontent:E1iBQuWbr74lcdcw%2F9e30ds9o-d34b-451e-ae59-b4km36018d5a.png';
91
- const thumbnailId = 'Eey3ZOiqdrUA84F8';
92
- const event = {
93
- newData: {
94
- primaryViewableId: 'm5bJa4RtTLUtKBP5',
95
- largeViewableDownloadUrl: newDownloadUrl
96
- },
97
- propertyDiffs: {}
98
- };
99
- const spyCustomSizes = jest.spyOn(tu, 'getCustomSizes');
100
- spyCustomSizes.mockReturnValue(Promise.resolve(mockData_1.empty_custom_sizes));
101
- const spyGetFileId = jest.spyOn(tu, 'getFileId');
102
- spyGetFileId.mockReturnValue(Promise.resolve(thumbnailId));
103
- const results = await tu.setOutboundThumbnail(data, event);
104
- const keys = Object.keys(results);
105
- expect(keys.length).toEqual(1);
106
- expect(keys[0]).toEqual(thumbnail_util_1.ThumbnailUtil.EXISTING_THUMBNAIL_ID);
107
- const thumbnailValue = results[thumbnail_util_1.ThumbnailUtil.EXISTING_THUMBNAIL_ID];
108
- expect(thumbnailValue).toEqual(thumbnailId);
109
- });
110
- });
111
- describe('getFileId', () => {
112
- const primaryFileId = 'yn2d5oHD4rXHRzyB';
113
- beforeEach(() => {
114
- jest.clearAllMocks();
115
- });
116
- it('no custom sizes, default max_thumbnail_size - result large', async () => {
117
- const tu = new thumbnail_util_1.ThumbnailUtil(config);
118
- const spyCustomSizes = jest.spyOn(tu, 'getCustomSizes');
119
- spyCustomSizes.mockReturnValue(Promise.resolve(mockData_1.empty_custom_sizes));
120
- const spyContentEntity = jest.spyOn(tu, 'getContentEntity');
121
- const content = JSON.parse(JSON.stringify(mockData_1.thumbnail_content_entity));
122
- spyContentEntity.mockReturnValue(Promise.resolve(content));
123
- const results = await tu.getFileId(primaryFileId);
124
- expect(results).toEqual('vo4N4mCd-tFrw101');
125
- });
126
- it('no custom sizes, 750 * 1_024 max_thumbnail_size - result medium', async () => {
127
- const config1 = {
128
- max_thumbnail_size: 750 * 1024
129
- };
130
- const tu = new thumbnail_util_1.ThumbnailUtil(config1);
131
- const spyCustomSizes = jest.spyOn(tu, 'getCustomSizes');
132
- spyCustomSizes.mockReturnValue(Promise.resolve(mockData_1.empty_custom_sizes));
133
- const spyContentEntity = jest.spyOn(tu, 'getContentEntity');
134
- const content = mockData_1.thumbnail_content_entity;
135
- spyContentEntity.mockReturnValue(Promise.resolve(content));
136
- const results = await tu.getFileId(primaryFileId);
137
- expect(results).toEqual('AsRvJenpeqxksUNW');
138
- });
139
- it('custom sizes, 750 * 1_024 max_thumbnail_size - result CS_500Id', async () => {
140
- const config1 = {
141
- max_thumbnail_size: 750 * 1024
142
- };
143
- const tu = new thumbnail_util_1.ThumbnailUtil(config1);
144
- const spyCustomSizes = jest.spyOn(tu, 'getCustomSizes');
145
- spyCustomSizes.mockReturnValue(Promise.resolve(mockData_1.four_custom_sizes));
146
- const spyContentEntity = jest.spyOn(tu, 'getContentEntity');
147
- const content = mockData_1.thumbnail_content_entity;
148
- spyContentEntity.mockReturnValue(Promise.resolve(content));
149
- const results = await tu.getFileId(primaryFileId);
150
- expect(results).toEqual('rBaHc1J2xdOWdbhI');
151
- });
152
- });
153
- describe('Test isThumbnailNew', () => {
154
- const tu = new thumbnail_util_1.ThumbnailUtil(config);
155
- it('no propertyDiffs', () => {
156
- const event = {
157
- newData: {
158
- name: 'Test'
159
- },
160
- oldData: {
161
- name: 'Test'
162
- }
163
- };
164
- const results = tu.isThumbnailNew(event, undefined);
165
- expect(results).toBeFalsy();
166
- });
167
- it('empty propertyDiffs', () => {
168
- const event = {
169
- newData: {
170
- name: 'Test'
171
- },
172
- oldData: {
173
- name: 'Test'
174
- },
175
- propertyDiffs: {}
176
- };
177
- const results = tu.isThumbnailNew(event, undefined);
178
- expect(results).toBeFalsy();
179
- });
180
- it('propertyDiffs diff property', () => {
181
- const event = {
182
- newData: {
183
- name: 'Test1'
184
- },
185
- oldData: {
186
- name: 'Test'
187
- },
188
- propertyDiffs: {
189
- name: {
190
- propertyName: 'name',
191
- oldValue: 'Test',
192
- newValue: 'Test1'
193
- }
194
- }
195
- };
196
- const results = tu.isThumbnailNew(event, undefined);
197
- expect(results).toBeFalsy();
198
- });
199
- it('propertyDiffs OOB property', () => {
200
- const event = {
201
- newData: {
202
- name: 'Test1'
203
- },
204
- oldData: {
205
- name: 'Test'
206
- },
207
- propertyDiffs: {
208
- mediumLargeViewableDownloadUrl: {
209
- propertyName: 'mediumLargeViewableDownloadUrl',
210
- oldValue: '',
211
- newValue: 'Test1'
212
- }
213
- }
214
- };
215
- const results = tu.isThumbnailNew(event, undefined);
216
- expect(results).toBeTruthy();
217
- });
218
- it('propertyDiffs custom property', () => {
219
- const event = {
220
- newData: {
221
- name: 'Test1'
222
- },
223
- oldData: {
224
- name: 'Test'
225
- },
226
- propertyDiffs: {
227
- RL_1000Url: {
228
- propertyName: 'RL_1000Url',
229
- oldValue: '',
230
- newValue: 'Test1'
231
- }
232
- }
233
- };
234
- const results = tu.isThumbnailNew(event, [{ slug: 'RL_1000' }]);
235
- expect(results).toBeTruthy();
236
- });
237
- });
238
- describe('logContentResults', () => {
239
- it('no content - doesnt error', () => {
240
- const tu = new thumbnail_util_1.ThumbnailUtil(config);
241
- const content = undefined;
242
- const relations = [];
243
- tu.logContentResults(content, relations);
244
- });
245
- it('no relations - doesnt error', () => {
246
- const tu = new thumbnail_util_1.ThumbnailUtil(config);
247
- const content = undefined;
248
- const relations = undefined;
249
- tu.logContentResults(content, relations);
250
- });
251
- it('content and relations - logs', () => {
252
- const tu = new thumbnail_util_1.ThumbnailUtil(config);
253
- const content = {
254
- id: '123',
255
- name: 'Test',
256
- primaryFile: { id: 'file123' }
257
- };
258
- const relations = ['primaryFile'];
259
- tu.logContentResults(content, relations);
260
- expect(Object.keys(content)).toHaveLength(3);
261
- expect(content).toHaveProperty('primaryFile');
262
- expect(content.primaryFile).toHaveProperty('id');
263
- expect(content.primaryFile.id).toEqual('file123');
264
- });
265
- });
266
- describe('syncThumbnailToVibeIQ', () => {
267
- let tu;
268
- beforeEach(() => {
269
- jest.clearAllMocks();
270
- tu = new thumbnail_util_1.ThumbnailUtil(config);
271
- mockEntitiesGet.mockImplementation((opts) => {
272
- if (opts.entityName === 'content-custom-size')
273
- return Promise.resolve([]);
274
- return Promise.resolve({});
275
- });
276
- mockEntitiesUpdate.mockImplementation((opts) => Promise.resolve({ id: opts.id }));
277
- mockEntitiesDelete.mockImplementation((opts) => Promise.resolve({ id: opts.id }));
278
- });
279
- it('does not update when no thumbnail IDs in event data', async () => {
280
- const event = { data: {} };
281
- await tu.syncThumbnailToVibeIQ({ entityId: 'entity1', event, entityName: 'color' });
282
- expect(mockEntitiesUpdate).not.toHaveBeenCalled();
283
- expect(mockEntitiesDelete).not.toHaveBeenCalled();
284
- expect(mockContentCreate).not.toHaveBeenCalled();
285
- });
286
- it('does not update when event.data is undefined', async () => {
287
- const event = {};
288
- await tu.syncThumbnailToVibeIQ({ entityId: 'entity1', event, entityName: 'color' });
289
- expect(mockEntitiesUpdate).not.toHaveBeenCalled();
290
- expect(mockEntitiesDelete).not.toHaveBeenCalled();
291
- });
292
- it('REMOVE_THUMBNAIL with existing primaryViewableId deletes content and updates entity', async () => {
293
- const event = { data: { [thumbnail_util_1.ThumbnailUtil.NEW_THUMBNAIL_ID]: thumbnail_util_1.ThumbnailUtil.REMOVE_THUMBNAIL } };
294
- await tu.syncThumbnailToVibeIQ({ entityId: 'entity1', primaryViewableId: 'pv1', event, entityName: 'color' });
295
- expect(mockEntitiesDelete).toHaveBeenCalledWith({ entityName: 'content', id: 'pv1' });
296
- expect(mockEntitiesUpdate).toHaveBeenCalledWith(expect.objectContaining({ entityName: 'color', id: 'entity1' }));
297
- });
298
- it('REMOVE_THUMBNAIL with no primaryViewableId updates entity without deleting', async () => {
299
- const event = { data: { [thumbnail_util_1.ThumbnailUtil.NEW_THUMBNAIL_ID]: thumbnail_util_1.ThumbnailUtil.REMOVE_THUMBNAIL } };
300
- await tu.syncThumbnailToVibeIQ({ entityId: 'entity1', event, entityName: 'item' });
301
- expect(mockEntitiesDelete).not.toHaveBeenCalled();
302
- expect(mockEntitiesUpdate).toHaveBeenCalledWith(expect.objectContaining({ entityName: 'item', id: 'entity1' }));
303
- });
304
- it('creates new content when no primaryViewableId exists and updates entity', async () => {
305
- const mockResponse = {
306
- arrayBuffer: jest.fn().mockResolvedValue(new ArrayBuffer(8)),
307
- headers: { get: jest.fn().mockReturnValue('image/png') },
308
- };
309
- mockGetRequest.mockResolvedValue(mockResponse);
310
- const createdContent = {
311
- id: 'newContent1',
312
- contentType: 'image/png',
313
- fileName: 'thumb.png',
314
- primaryFileUrl: 'https://files/primary.png',
315
- largeViewableUrl: 'https://files/large.png',
316
- mediumLargeViewableUrl: null,
317
- mediumViewableUrl: null,
318
- smallViewableUrl: null,
319
- tinyViewableUrl: null,
320
- };
321
- mockContentCreate.mockResolvedValue(createdContent);
322
- const event = { data: { [thumbnail_util_1.ThumbnailUtil.NEW_THUMBNAIL_ID]: '/rest/thumbnail/thumb.png' } };
323
- await tu.syncThumbnailToVibeIQ({ entityId: 'entity1', event, entityName: 'color' });
324
- expect(mockGetRequest).toHaveBeenCalledWith({ urlPath: '/rest/thumbnail/thumb.png', includeUrlContext: false, returnFullResponse: true });
325
- expect(mockContentCreate).toHaveBeenCalledWith(expect.objectContaining({
326
- fileName: 'thumb.png',
327
- contentType: 'image/png',
328
- contentHolderReference: 'color:entity1',
329
- }));
330
- expect(mockEntitiesUpdate).toHaveBeenCalledWith(expect.objectContaining({
331
- entityName: 'content',
332
- id: 'newContent1',
333
- object: { flexplmThumbnailUrl: '/rest/thumbnail/thumb.png' },
334
- }));
335
- expect(mockEntitiesUpdate).toHaveBeenCalledWith(expect.objectContaining({
336
- entityName: 'color',
337
- id: 'entity1',
338
- }));
339
- });
340
- it('replaces content when primaryViewable.flexplmThumbnailUrl differs and updates entity', async () => {
341
- mockEntitiesGet.mockImplementation((opts) => {
342
- if (opts.entityName === 'content-custom-size')
343
- return Promise.resolve([]);
344
- if (opts.entityName === 'content' && opts.id === 'oldPv') {
345
- return Promise.resolve({ id: 'oldPv', flexplmThumbnailUrl: '/rest/thumbnail/old.png' });
346
- }
347
- return Promise.resolve({});
348
- });
349
- const mockResponse = {
350
- arrayBuffer: jest.fn().mockResolvedValue(new ArrayBuffer(8)),
351
- headers: { get: jest.fn().mockReturnValue('image/jpeg') },
352
- };
353
- mockGetRequest.mockResolvedValue(mockResponse);
354
- const createdContent = {
355
- id: 'newContent2',
356
- contentType: 'image/jpeg',
357
- fileName: 'new.jpg',
358
- primaryFileUrl: 'https://files/new-primary.jpg',
359
- largeViewableUrl: null,
360
- mediumLargeViewableUrl: null,
361
- mediumViewableUrl: null,
362
- smallViewableUrl: null,
363
- tinyViewableUrl: null,
364
- };
365
- mockContentCreate.mockResolvedValue(createdContent);
366
- const event = { data: { [thumbnail_util_1.ThumbnailUtil.NEW_THUMBNAIL_ID]: '/rest/thumbnail/new.jpg' } };
367
- await tu.syncThumbnailToVibeIQ({ entityId: 'entity1', primaryViewableId: 'oldPv', event, entityName: 'item' });
368
- expect(mockContentCreate).toHaveBeenCalled();
369
- expect(mockEntitiesUpdate).toHaveBeenCalledWith(expect.objectContaining({
370
- entityName: 'content',
371
- id: 'newContent2',
372
- object: { flexplmThumbnailUrl: '/rest/thumbnail/new.jpg' },
373
- }));
374
- expect(mockEntitiesUpdate).toHaveBeenCalledWith(expect.objectContaining({ entityName: 'item', id: 'entity1' }));
375
- expect(mockEntitiesDelete).toHaveBeenCalledWith({ entityName: 'content', id: 'oldPv' });
376
- });
377
- it('does not update when primaryViewable.flexplmThumbnailUrl matches', async () => {
378
- const thumbnailUrl = '/rest/thumbnail/same.png';
379
- mockEntitiesGet.mockImplementation((opts) => {
380
- if (opts.entityName === 'content-custom-size')
381
- return Promise.resolve([]);
382
- if (opts.entityName === 'content' && opts.id === 'pv1') {
383
- return Promise.resolve({ id: 'pv1', flexplmThumbnailUrl: thumbnailUrl });
384
- }
385
- return Promise.resolve({});
386
- });
387
- const event = { data: { [thumbnail_util_1.ThumbnailUtil.EXISTING_THUMBNAIL_ID]: thumbnailUrl } };
388
- await tu.syncThumbnailToVibeIQ({ entityId: 'entity1', primaryViewableId: 'pv1', event, entityName: 'color' });
389
- expect(mockContentCreate).not.toHaveBeenCalled();
390
- expect(mockEntitiesUpdate).not.toHaveBeenCalled();
391
- expect(mockEntitiesDelete).not.toHaveBeenCalled();
392
- });
393
- });
394
- });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const thumbnail_util_1 = require("./thumbnail-util");
4
+ const mockData_1 = require("./mockData");
5
+ const mockEntitiesGet = jest.fn();
6
+ const mockEntitiesUpdate = jest.fn();
7
+ const mockEntitiesDelete = jest.fn();
8
+ const mockContentCreate = jest.fn();
9
+ jest.mock('@contrail/sdk', () => {
10
+ return {
11
+ Entities: jest.fn().mockImplementation(() => ({
12
+ get: mockEntitiesGet,
13
+ update: mockEntitiesUpdate,
14
+ delete: mockEntitiesDelete,
15
+ })),
16
+ Content: jest.fn().mockImplementation(() => ({
17
+ create: mockContentCreate,
18
+ })),
19
+ };
20
+ });
21
+ const mockGetRequest = jest.fn();
22
+ jest.mock('./flexplm-connect', () => {
23
+ return {
24
+ FlexPLMConnect: jest.fn().mockImplementation(() => ({
25
+ getRequest: mockGetRequest,
26
+ })),
27
+ };
28
+ });
29
+ describe('ThumbnailUtil Tests', () => {
30
+ const config = {};
31
+ describe('setOutboundThumbnail()', () => {
32
+ const tu = new thumbnail_util_1.ThumbnailUtil(config);
33
+ beforeEach(() => {
34
+ jest.clearAllMocks();
35
+ });
36
+ it('no data', async () => {
37
+ const data = {};
38
+ const event = {};
39
+ const results = await tu.setOutboundThumbnail(data, event);
40
+ const keys = Object.keys(results);
41
+ expect(results).toEqual(data);
42
+ expect(keys.length).toEqual(0);
43
+ });
44
+ it('remove thumbnail', async () => {
45
+ const data = {};
46
+ const event = {
47
+ propertyDiffs: {
48
+ largeViewableDownloadUrl: {
49
+ oldValue: '123',
50
+ newValue: null
51
+ }
52
+ }
53
+ };
54
+ const results = await tu.setOutboundThumbnail(data, event);
55
+ const keys = Object.keys(results);
56
+ expect(keys.length).toEqual(1);
57
+ expect(keys[0]).toEqual(thumbnail_util_1.ThumbnailUtil.NEW_THUMBNAIL_ID);
58
+ expect(results[thumbnail_util_1.ThumbnailUtil.NEW_THUMBNAIL_ID]).toEqual(thumbnail_util_1.ThumbnailUtil.REMOVE_THUMBNAIL);
59
+ });
60
+ it('calling getFileId - new thumbnail', async () => {
61
+ const data = {};
62
+ const newDownloadUrl = 'https://api.vibeiq.com/dev/api/files/downloadUrl/w3ckfeGAD8ViOZj-%2Fcontent:E1iBQuWbr74lcdcw%2F9e30ds9o-d34b-451e-ae59-b4km36018d5a.png';
63
+ const oldDownloadUrl = 'xxx';
64
+ const thumbnailId = 'Eey3ZOiqdrUA84F8';
65
+ const event = {
66
+ newData: {
67
+ primaryViewableId: 'm5bJa4RtTLUtKBP5',
68
+ largeViewableDownloadUrl: newDownloadUrl
69
+ },
70
+ propertyDiffs: {
71
+ largeViewableDownloadUrl: {
72
+ newValue: newDownloadUrl,
73
+ oldValue: oldDownloadUrl
74
+ }
75
+ }
76
+ };
77
+ const spyCustomSizes = jest.spyOn(tu, 'getCustomSizes');
78
+ spyCustomSizes.mockReturnValue(Promise.resolve(mockData_1.empty_custom_sizes));
79
+ const spyGetFileId = jest.spyOn(tu, 'getFileId');
80
+ spyGetFileId.mockReturnValue(Promise.resolve(thumbnailId));
81
+ const results = await tu.setOutboundThumbnail(data, event);
82
+ const keys = Object.keys(results);
83
+ expect(keys.length).toEqual(1);
84
+ expect(keys[0]).toEqual(thumbnail_util_1.ThumbnailUtil.NEW_THUMBNAIL_ID);
85
+ const thumbnailValue = results[thumbnail_util_1.ThumbnailUtil.NEW_THUMBNAIL_ID];
86
+ expect(thumbnailValue).toEqual(thumbnailId);
87
+ });
88
+ it('calling getFileId - existing thumbnail', async () => {
89
+ const data = {};
90
+ const newDownloadUrl = 'https://api.vibeiq.com/dev/api/files/downloadUrl/w3ckfeGAD8ViOZj-%2Fcontent:E1iBQuWbr74lcdcw%2F9e30ds9o-d34b-451e-ae59-b4km36018d5a.png';
91
+ const thumbnailId = 'Eey3ZOiqdrUA84F8';
92
+ const event = {
93
+ newData: {
94
+ primaryViewableId: 'm5bJa4RtTLUtKBP5',
95
+ largeViewableDownloadUrl: newDownloadUrl
96
+ },
97
+ propertyDiffs: {}
98
+ };
99
+ const spyCustomSizes = jest.spyOn(tu, 'getCustomSizes');
100
+ spyCustomSizes.mockReturnValue(Promise.resolve(mockData_1.empty_custom_sizes));
101
+ const spyGetFileId = jest.spyOn(tu, 'getFileId');
102
+ spyGetFileId.mockReturnValue(Promise.resolve(thumbnailId));
103
+ const results = await tu.setOutboundThumbnail(data, event);
104
+ const keys = Object.keys(results);
105
+ expect(keys.length).toEqual(1);
106
+ expect(keys[0]).toEqual(thumbnail_util_1.ThumbnailUtil.EXISTING_THUMBNAIL_ID);
107
+ const thumbnailValue = results[thumbnail_util_1.ThumbnailUtil.EXISTING_THUMBNAIL_ID];
108
+ expect(thumbnailValue).toEqual(thumbnailId);
109
+ });
110
+ });
111
+ describe('getFileId', () => {
112
+ const primaryFileId = 'yn2d5oHD4rXHRzyB';
113
+ beforeEach(() => {
114
+ jest.clearAllMocks();
115
+ });
116
+ it('no custom sizes, default max_thumbnail_size - result large', async () => {
117
+ const tu = new thumbnail_util_1.ThumbnailUtil(config);
118
+ const spyCustomSizes = jest.spyOn(tu, 'getCustomSizes');
119
+ spyCustomSizes.mockReturnValue(Promise.resolve(mockData_1.empty_custom_sizes));
120
+ const spyContentEntity = jest.spyOn(tu, 'getContentEntity');
121
+ const content = JSON.parse(JSON.stringify(mockData_1.thumbnail_content_entity));
122
+ spyContentEntity.mockReturnValue(Promise.resolve(content));
123
+ const results = await tu.getFileId(primaryFileId);
124
+ expect(results).toEqual('vo4N4mCd-tFrw101');
125
+ });
126
+ it('no custom sizes, 750 * 1_024 max_thumbnail_size - result medium', async () => {
127
+ const config1 = {
128
+ max_thumbnail_size: 750 * 1024
129
+ };
130
+ const tu = new thumbnail_util_1.ThumbnailUtil(config1);
131
+ const spyCustomSizes = jest.spyOn(tu, 'getCustomSizes');
132
+ spyCustomSizes.mockReturnValue(Promise.resolve(mockData_1.empty_custom_sizes));
133
+ const spyContentEntity = jest.spyOn(tu, 'getContentEntity');
134
+ const content = mockData_1.thumbnail_content_entity;
135
+ spyContentEntity.mockReturnValue(Promise.resolve(content));
136
+ const results = await tu.getFileId(primaryFileId);
137
+ expect(results).toEqual('AsRvJenpeqxksUNW');
138
+ });
139
+ it('custom sizes, 750 * 1_024 max_thumbnail_size - result CS_500Id', async () => {
140
+ const config1 = {
141
+ max_thumbnail_size: 750 * 1024
142
+ };
143
+ const tu = new thumbnail_util_1.ThumbnailUtil(config1);
144
+ const spyCustomSizes = jest.spyOn(tu, 'getCustomSizes');
145
+ spyCustomSizes.mockReturnValue(Promise.resolve(mockData_1.four_custom_sizes));
146
+ const spyContentEntity = jest.spyOn(tu, 'getContentEntity');
147
+ const content = mockData_1.thumbnail_content_entity;
148
+ spyContentEntity.mockReturnValue(Promise.resolve(content));
149
+ const results = await tu.getFileId(primaryFileId);
150
+ expect(results).toEqual('rBaHc1J2xdOWdbhI');
151
+ });
152
+ });
153
+ describe('Test isThumbnailNew', () => {
154
+ const tu = new thumbnail_util_1.ThumbnailUtil(config);
155
+ it('no propertyDiffs', () => {
156
+ const event = {
157
+ newData: {
158
+ name: 'Test'
159
+ },
160
+ oldData: {
161
+ name: 'Test'
162
+ }
163
+ };
164
+ const results = tu.isThumbnailNew(event, undefined);
165
+ expect(results).toBeFalsy();
166
+ });
167
+ it('empty propertyDiffs', () => {
168
+ const event = {
169
+ newData: {
170
+ name: 'Test'
171
+ },
172
+ oldData: {
173
+ name: 'Test'
174
+ },
175
+ propertyDiffs: {}
176
+ };
177
+ const results = tu.isThumbnailNew(event, undefined);
178
+ expect(results).toBeFalsy();
179
+ });
180
+ it('propertyDiffs diff property', () => {
181
+ const event = {
182
+ newData: {
183
+ name: 'Test1'
184
+ },
185
+ oldData: {
186
+ name: 'Test'
187
+ },
188
+ propertyDiffs: {
189
+ name: {
190
+ propertyName: 'name',
191
+ oldValue: 'Test',
192
+ newValue: 'Test1'
193
+ }
194
+ }
195
+ };
196
+ const results = tu.isThumbnailNew(event, undefined);
197
+ expect(results).toBeFalsy();
198
+ });
199
+ it('propertyDiffs OOB property', () => {
200
+ const event = {
201
+ newData: {
202
+ name: 'Test1'
203
+ },
204
+ oldData: {
205
+ name: 'Test'
206
+ },
207
+ propertyDiffs: {
208
+ mediumLargeViewableDownloadUrl: {
209
+ propertyName: 'mediumLargeViewableDownloadUrl',
210
+ oldValue: '',
211
+ newValue: 'Test1'
212
+ }
213
+ }
214
+ };
215
+ const results = tu.isThumbnailNew(event, undefined);
216
+ expect(results).toBeTruthy();
217
+ });
218
+ it('propertyDiffs custom property', () => {
219
+ const event = {
220
+ newData: {
221
+ name: 'Test1'
222
+ },
223
+ oldData: {
224
+ name: 'Test'
225
+ },
226
+ propertyDiffs: {
227
+ RL_1000Url: {
228
+ propertyName: 'RL_1000Url',
229
+ oldValue: '',
230
+ newValue: 'Test1'
231
+ }
232
+ }
233
+ };
234
+ const results = tu.isThumbnailNew(event, [{ slug: 'RL_1000' }]);
235
+ expect(results).toBeTruthy();
236
+ });
237
+ });
238
+ describe('logContentResults', () => {
239
+ it('no content - doesnt error', () => {
240
+ const tu = new thumbnail_util_1.ThumbnailUtil(config);
241
+ const content = undefined;
242
+ const relations = [];
243
+ tu.logContentResults(content, relations);
244
+ });
245
+ it('no relations - doesnt error', () => {
246
+ const tu = new thumbnail_util_1.ThumbnailUtil(config);
247
+ const content = undefined;
248
+ const relations = undefined;
249
+ tu.logContentResults(content, relations);
250
+ });
251
+ it('content and relations - logs', () => {
252
+ const tu = new thumbnail_util_1.ThumbnailUtil(config);
253
+ const content = {
254
+ id: '123',
255
+ name: 'Test',
256
+ primaryFile: { id: 'file123' }
257
+ };
258
+ const relations = ['primaryFile'];
259
+ tu.logContentResults(content, relations);
260
+ expect(Object.keys(content)).toHaveLength(3);
261
+ expect(content).toHaveProperty('primaryFile');
262
+ expect(content.primaryFile).toHaveProperty('id');
263
+ expect(content.primaryFile.id).toEqual('file123');
264
+ });
265
+ });
266
+ describe('syncThumbnailToVibeIQ', () => {
267
+ let tu;
268
+ beforeEach(() => {
269
+ jest.clearAllMocks();
270
+ tu = new thumbnail_util_1.ThumbnailUtil(config);
271
+ mockEntitiesGet.mockImplementation((opts) => {
272
+ if (opts.entityName === 'content-custom-size')
273
+ return Promise.resolve([]);
274
+ return Promise.resolve({});
275
+ });
276
+ mockEntitiesUpdate.mockImplementation((opts) => Promise.resolve({ id: opts.id }));
277
+ mockEntitiesDelete.mockImplementation((opts) => Promise.resolve({ id: opts.id }));
278
+ });
279
+ it('does not update when no thumbnail IDs in event data', async () => {
280
+ const event = { data: {} };
281
+ await tu.syncThumbnailToVibeIQ({ entityId: 'entity1', event, entityName: 'color' });
282
+ expect(mockEntitiesUpdate).not.toHaveBeenCalled();
283
+ expect(mockEntitiesDelete).not.toHaveBeenCalled();
284
+ expect(mockContentCreate).not.toHaveBeenCalled();
285
+ });
286
+ it('does not update when event.data is undefined', async () => {
287
+ const event = {};
288
+ await tu.syncThumbnailToVibeIQ({ entityId: 'entity1', event, entityName: 'color' });
289
+ expect(mockEntitiesUpdate).not.toHaveBeenCalled();
290
+ expect(mockEntitiesDelete).not.toHaveBeenCalled();
291
+ });
292
+ it('REMOVE_THUMBNAIL with existing primaryViewableId deletes content and updates entity', async () => {
293
+ const event = { data: { [thumbnail_util_1.ThumbnailUtil.NEW_THUMBNAIL_ID]: thumbnail_util_1.ThumbnailUtil.REMOVE_THUMBNAIL } };
294
+ await tu.syncThumbnailToVibeIQ({ entityId: 'entity1', primaryViewableId: 'pv1', event, entityName: 'color' });
295
+ expect(mockEntitiesDelete).toHaveBeenCalledWith({ entityName: 'content', id: 'pv1' });
296
+ expect(mockEntitiesUpdate).toHaveBeenCalledWith(expect.objectContaining({ entityName: 'color', id: 'entity1' }));
297
+ });
298
+ it('REMOVE_THUMBNAIL with no primaryViewableId updates entity without deleting', async () => {
299
+ const event = { data: { [thumbnail_util_1.ThumbnailUtil.NEW_THUMBNAIL_ID]: thumbnail_util_1.ThumbnailUtil.REMOVE_THUMBNAIL } };
300
+ await tu.syncThumbnailToVibeIQ({ entityId: 'entity1', event, entityName: 'item' });
301
+ expect(mockEntitiesDelete).not.toHaveBeenCalled();
302
+ expect(mockEntitiesUpdate).toHaveBeenCalledWith(expect.objectContaining({ entityName: 'item', id: 'entity1' }));
303
+ });
304
+ it('creates new content when no primaryViewableId exists and updates entity', async () => {
305
+ const mockResponse = {
306
+ arrayBuffer: jest.fn().mockResolvedValue(new ArrayBuffer(8)),
307
+ headers: { get: jest.fn().mockReturnValue('image/png') },
308
+ };
309
+ mockGetRequest.mockResolvedValue(mockResponse);
310
+ const createdContent = {
311
+ id: 'newContent1',
312
+ contentType: 'image/png',
313
+ fileName: 'thumb.png',
314
+ primaryFileUrl: 'https://files/primary.png',
315
+ largeViewableUrl: 'https://files/large.png',
316
+ mediumLargeViewableUrl: null,
317
+ mediumViewableUrl: null,
318
+ smallViewableUrl: null,
319
+ tinyViewableUrl: null,
320
+ };
321
+ mockContentCreate.mockResolvedValue(createdContent);
322
+ const event = { data: { [thumbnail_util_1.ThumbnailUtil.NEW_THUMBNAIL_ID]: '/rest/thumbnail/thumb.png' } };
323
+ await tu.syncThumbnailToVibeIQ({ entityId: 'entity1', event, entityName: 'color' });
324
+ expect(mockGetRequest).toHaveBeenCalledWith({ urlPath: '/rest/thumbnail/thumb.png', includeUrlContext: false, returnFullResponse: true });
325
+ expect(mockContentCreate).toHaveBeenCalledWith(expect.objectContaining({
326
+ fileName: 'thumb.png',
327
+ contentType: 'image/png',
328
+ contentHolderReference: 'color:entity1',
329
+ }));
330
+ expect(mockEntitiesUpdate).toHaveBeenCalledWith(expect.objectContaining({
331
+ entityName: 'content',
332
+ id: 'newContent1',
333
+ object: { flexplmThumbnailUrl: '/rest/thumbnail/thumb.png' },
334
+ }));
335
+ expect(mockEntitiesUpdate).toHaveBeenCalledWith(expect.objectContaining({
336
+ entityName: 'color',
337
+ id: 'entity1',
338
+ }));
339
+ });
340
+ it('encodes URL path segments with special characters', async () => {
341
+ const mockResponse = {
342
+ arrayBuffer: jest.fn().mockResolvedValue(new ArrayBuffer(8)),
343
+ headers: { get: jest.fn().mockReturnValue('image/png') },
344
+ };
345
+ mockGetRequest.mockResolvedValue(mockResponse);
346
+ mockContentCreate.mockResolvedValue({
347
+ id: 'c1', contentType: 'image/png', fileName: 'my image.png',
348
+ primaryFileUrl: 'https://files/primary.png', largeViewableUrl: null,
349
+ mediumLargeViewableUrl: null, mediumViewableUrl: null, smallViewableUrl: null, tinyViewableUrl: null,
350
+ });
351
+ const event = { data: { [thumbnail_util_1.ThumbnailUtil.NEW_THUMBNAIL_ID]: '/rest/thumbnail/my image.png' } };
352
+ await tu.syncThumbnailToVibeIQ({ entityId: 'entity1', event, entityName: 'color' });
353
+ expect(mockGetRequest).toHaveBeenCalledWith({
354
+ urlPath: '/rest/thumbnail/my%20image.png',
355
+ includeUrlContext: false,
356
+ returnFullResponse: true,
357
+ });
358
+ expect(mockContentCreate).toHaveBeenCalledWith(expect.objectContaining({ fileName: 'my image.png' }));
359
+ });
360
+ it('encodes URL path segments with unicode characters', async () => {
361
+ const mockResponse = {
362
+ arrayBuffer: jest.fn().mockResolvedValue(new ArrayBuffer(8)),
363
+ headers: { get: jest.fn().mockReturnValue('image/jpeg') },
364
+ };
365
+ mockGetRequest.mockResolvedValue(mockResponse);
366
+ mockContentCreate.mockResolvedValue({
367
+ id: 'c2', contentType: 'image/jpeg', fileName: 'café-logo.jpg',
368
+ primaryFileUrl: 'https://files/primary.jpg', largeViewableUrl: null,
369
+ mediumLargeViewableUrl: null, mediumViewableUrl: null, smallViewableUrl: null, tinyViewableUrl: null,
370
+ });
371
+ const event = { data: { [thumbnail_util_1.ThumbnailUtil.NEW_THUMBNAIL_ID]: '/rest/thumbnail/café-logo.jpg' } };
372
+ await tu.syncThumbnailToVibeIQ({ entityId: 'entity1', event, entityName: 'item' });
373
+ expect(mockGetRequest).toHaveBeenCalledWith({
374
+ urlPath: '/rest/thumbnail/caf%C3%A9-logo.jpg',
375
+ includeUrlContext: false,
376
+ returnFullResponse: true,
377
+ });
378
+ expect(mockContentCreate).toHaveBeenCalledWith(expect.objectContaining({ fileName: 'café-logo.jpg' }));
379
+ });
380
+ it('replaces content when primaryViewable.flexplmThumbnailUrl differs and updates entity', async () => {
381
+ mockEntitiesGet.mockImplementation((opts) => {
382
+ if (opts.entityName === 'content-custom-size')
383
+ return Promise.resolve([]);
384
+ if (opts.entityName === 'content' && opts.id === 'oldPv') {
385
+ return Promise.resolve({ id: 'oldPv', flexplmThumbnailUrl: '/rest/thumbnail/old.png' });
386
+ }
387
+ return Promise.resolve({});
388
+ });
389
+ const mockResponse = {
390
+ arrayBuffer: jest.fn().mockResolvedValue(new ArrayBuffer(8)),
391
+ headers: { get: jest.fn().mockReturnValue('image/jpeg') },
392
+ };
393
+ mockGetRequest.mockResolvedValue(mockResponse);
394
+ const createdContent = {
395
+ id: 'newContent2',
396
+ contentType: 'image/jpeg',
397
+ fileName: 'new.jpg',
398
+ primaryFileUrl: 'https://files/new-primary.jpg',
399
+ largeViewableUrl: null,
400
+ mediumLargeViewableUrl: null,
401
+ mediumViewableUrl: null,
402
+ smallViewableUrl: null,
403
+ tinyViewableUrl: null,
404
+ };
405
+ mockContentCreate.mockResolvedValue(createdContent);
406
+ const event = { data: { [thumbnail_util_1.ThumbnailUtil.NEW_THUMBNAIL_ID]: '/rest/thumbnail/new.jpg' } };
407
+ await tu.syncThumbnailToVibeIQ({ entityId: 'entity1', primaryViewableId: 'oldPv', event, entityName: 'item' });
408
+ expect(mockContentCreate).toHaveBeenCalled();
409
+ expect(mockEntitiesUpdate).toHaveBeenCalledWith(expect.objectContaining({
410
+ entityName: 'content',
411
+ id: 'newContent2',
412
+ object: { flexplmThumbnailUrl: '/rest/thumbnail/new.jpg' },
413
+ }));
414
+ expect(mockEntitiesUpdate).toHaveBeenCalledWith(expect.objectContaining({ entityName: 'item', id: 'entity1' }));
415
+ expect(mockEntitiesDelete).toHaveBeenCalledWith({ entityName: 'content', id: 'oldPv' });
416
+ });
417
+ it('does not update when primaryViewable.flexplmThumbnailUrl matches', async () => {
418
+ const thumbnailUrl = '/rest/thumbnail/same.png';
419
+ mockEntitiesGet.mockImplementation((opts) => {
420
+ if (opts.entityName === 'content-custom-size')
421
+ return Promise.resolve([]);
422
+ if (opts.entityName === 'content' && opts.id === 'pv1') {
423
+ return Promise.resolve({ id: 'pv1', flexplmThumbnailUrl: thumbnailUrl });
424
+ }
425
+ return Promise.resolve({});
426
+ });
427
+ const event = { data: { [thumbnail_util_1.ThumbnailUtil.EXISTING_THUMBNAIL_ID]: thumbnailUrl } };
428
+ await tu.syncThumbnailToVibeIQ({ entityId: 'entity1', primaryViewableId: 'pv1', event, entityName: 'color' });
429
+ expect(mockContentCreate).not.toHaveBeenCalled();
430
+ expect(mockEntitiesUpdate).not.toHaveBeenCalled();
431
+ expect(mockEntitiesDelete).not.toHaveBeenCalled();
432
+ });
433
+ });
434
+ });