@contrail/flexplm 1.2.1 → 1.3.0-alpha.04c91a9

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 (125) hide show
  1. package/.github/pull_request_template.md +31 -31
  2. package/.github/workflows/flexplm-lib.yml +27 -27
  3. package/.github/workflows/publish-to-npm.yml +131 -0
  4. package/CHANGELOG.md +10 -0
  5. package/lib/entity-processor/base-entity-processor.d.ts +42 -42
  6. package/lib/entity-processor/base-entity-processor.js +385 -363
  7. package/lib/entity-processor/base-entity-processor.spec.d.ts +1 -1
  8. package/lib/entity-processor/base-entity-processor.spec.js +397 -302
  9. package/lib/flexplm-request.d.ts +3 -3
  10. package/lib/flexplm-request.js +34 -34
  11. package/lib/flexplm-utils.d.ts +5 -5
  12. package/lib/flexplm-utils.js +33 -33
  13. package/lib/flexplm-utils.spec.d.ts +1 -1
  14. package/lib/flexplm-utils.spec.js +26 -26
  15. package/lib/index.d.ts +22 -22
  16. package/lib/index.js +38 -38
  17. package/lib/interfaces/interfaces.d.ts +105 -105
  18. package/lib/interfaces/interfaces.js +2 -2
  19. package/lib/interfaces/item-family-changes.d.ts +20 -20
  20. package/lib/interfaces/item-family-changes.js +56 -56
  21. package/lib/interfaces/publish-change-data.d.ts +19 -19
  22. package/lib/interfaces/publish-change-data.js +32 -32
  23. package/lib/publish/base-process-publish-assortment-callback.d.ts +9 -9
  24. package/lib/publish/base-process-publish-assortment-callback.js +38 -38
  25. package/lib/publish/base-process-publish-assortment.d.ts +93 -93
  26. package/lib/publish/base-process-publish-assortment.js +944 -944
  27. package/lib/publish/base-process-publish-assortment.spec.d.ts +1 -1
  28. package/lib/publish/base-process-publish-assortment.spec.js +1670 -1670
  29. package/lib/publish/mockData.d.ts +1389 -1389
  30. package/lib/publish/mockData.js +4519 -4519
  31. package/lib/transform/identifier-conversion-spec-mockData.js +444 -444
  32. package/lib/transform/identifier-conversion.d.ts +15 -15
  33. package/lib/transform/identifier-conversion.js +212 -212
  34. package/lib/transform/identifier-conversion.spec.d.ts +1 -1
  35. package/lib/transform/identifier-conversion.spec.js +339 -339
  36. package/lib/util/config-defaults.d.ts +8 -8
  37. package/lib/util/config-defaults.js +85 -85
  38. package/lib/util/config-defaults.spec.d.ts +1 -1
  39. package/lib/util/config-defaults.spec.js +293 -293
  40. package/lib/util/data-converter-spec-mockData.js +205 -205
  41. package/lib/util/data-converter.d.ts +39 -39
  42. package/lib/util/data-converter.js +592 -592
  43. package/lib/util/data-converter.spec.d.ts +1 -1
  44. package/lib/util/data-converter.spec.js +904 -904
  45. package/lib/util/error-response-object.d.ts +4 -4
  46. package/lib/util/error-response-object.js +47 -47
  47. package/lib/util/error-response-object.spec.d.ts +1 -1
  48. package/lib/util/error-response-object.spec.js +99 -99
  49. package/lib/util/event-short-message-status.d.ts +19 -18
  50. package/lib/util/event-short-message-status.js +23 -22
  51. package/lib/util/federation.d.ts +15 -15
  52. package/lib/util/federation.js +149 -149
  53. package/lib/util/flexplm-connect.d.ts +22 -18
  54. package/lib/util/flexplm-connect.js +176 -171
  55. package/lib/util/flexplm-connect.spec.d.ts +1 -0
  56. package/lib/util/flexplm-connect.spec.js +88 -0
  57. package/lib/util/logger-config.d.ts +1 -1
  58. package/lib/util/logger-config.js +26 -26
  59. package/lib/util/map-util-spec-mockData.js +205 -205
  60. package/lib/util/map-utils.d.ts +6 -6
  61. package/lib/util/map-utils.js +15 -15
  62. package/lib/util/map-utils.spec.d.ts +1 -1
  63. package/lib/util/map-utils.spec.js +89 -89
  64. package/lib/util/mockData.d.ts +80 -79
  65. package/lib/util/mockData.js +103 -99
  66. package/lib/util/thumbnail-util.d.ts +34 -19
  67. package/lib/util/thumbnail-util.js +215 -114
  68. package/lib/util/thumbnail-util.spec.d.ts +1 -1
  69. package/lib/util/thumbnail-util.spec.js +434 -242
  70. package/lib/util/type-conversion-utils-spec-mockData.js +259 -241
  71. package/lib/util/type-conversion-utils.d.ts +23 -21
  72. package/lib/util/type-conversion-utils.js +265 -223
  73. package/lib/util/type-conversion-utils.spec.d.ts +1 -1
  74. package/lib/util/type-conversion-utils.spec.js +868 -708
  75. package/lib/util/type-defaults.d.ts +16 -16
  76. package/lib/util/type-defaults.js +221 -221
  77. package/lib/util/type-defaults.spec.d.ts +1 -1
  78. package/lib/util/type-defaults.spec.js +516 -516
  79. package/lib/util/type-utils.d.ts +13 -13
  80. package/lib/util/type-utils.js +114 -114
  81. package/lib/util/type-utils.spec.d.ts +1 -1
  82. package/lib/util/type-utils.spec.js +190 -190
  83. package/package.json +1 -1
  84. package/publish.bat +4 -4
  85. package/publish.sh +4 -4
  86. package/src/entity-processor/base-entity-processor.spec.ts +122 -0
  87. package/src/entity-processor/base-entity-processor.ts +31 -2
  88. package/src/flexplm-request.ts +28 -28
  89. package/src/flexplm-utils.spec.ts +27 -27
  90. package/src/flexplm-utils.ts +29 -29
  91. package/src/index.ts +21 -21
  92. package/src/interfaces/item-family-changes.ts +66 -66
  93. package/src/interfaces/publish-change-data.ts +42 -42
  94. package/src/publish/base-process-publish-assortment-callback.ts +50 -50
  95. package/src/transform/identifier-conversion-spec-mockData.ts +495 -495
  96. package/src/transform/identifier-conversion.spec.ts +353 -353
  97. package/src/transform/identifier-conversion.ts +281 -281
  98. package/src/util/config-defaults.spec.ts +350 -350
  99. package/src/util/config-defaults.ts +92 -92
  100. package/src/util/data-converter-spec-mockData.ts +230 -230
  101. package/src/util/error-response-object.spec.ts +115 -115
  102. package/src/util/error-response-object.ts +49 -49
  103. package/src/util/event-short-message-status.ts +1 -0
  104. package/src/util/federation.ts +172 -172
  105. package/src/util/flexplm-connect.spec.ts +132 -0
  106. package/src/util/flexplm-connect.ts +14 -5
  107. package/src/util/logger-config.ts +19 -19
  108. package/src/util/map-util-spec-mockData.ts +230 -230
  109. package/src/util/map-utils.spec.ts +102 -102
  110. package/src/util/map-utils.ts +40 -40
  111. package/src/util/mockData.ts +101 -97
  112. package/src/util/thumbnail-util.spec.ts +239 -0
  113. package/src/util/thumbnail-util.ts +140 -5
  114. package/src/util/type-conversion-utils-spec-mockData.ts +18 -0
  115. package/src/util/type-conversion-utils.spec.ts +184 -0
  116. package/src/util/type-conversion-utils.ts +75 -1
  117. package/src/util/type-defaults.spec.ts +668 -668
  118. package/src/util/type-defaults.ts +280 -280
  119. package/src/util/type-utils.spec.ts +227 -227
  120. package/src/util/type-utils.ts +144 -144
  121. package/tsconfig.json +23 -26
  122. package/tslint.json +57 -57
  123. package/.claude/settings.local.json +0 -8
  124. package/scripts/output.png +0 -0
  125. package/scripts/test-get-request.ts +0 -35
@@ -1,242 +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
- describe('ThumbnailUtil Tests', () => {
6
- const config = {};
7
- describe('setOutboundThumbnail()', () => {
8
- const tu = new thumbnail_util_1.ThumbnailUtil(config);
9
- beforeEach(() => {
10
- jest.clearAllMocks();
11
- });
12
- it('no data', async () => {
13
- const data = {};
14
- const event = {};
15
- const results = await tu.setOutboundThumbnail(data, event);
16
- const keys = Object.keys(results);
17
- expect(results).toEqual(data);
18
- expect(keys.length).toEqual(0);
19
- });
20
- it('remove thumbnail', async () => {
21
- const data = {};
22
- const event = {
23
- propertyDiffs: {
24
- largeViewableDownloadUrl: {
25
- oldValue: '123',
26
- newValue: null
27
- }
28
- }
29
- };
30
- const results = await tu.setOutboundThumbnail(data, event);
31
- const keys = Object.keys(results);
32
- expect(keys.length).toEqual(1);
33
- expect(keys[0]).toEqual(thumbnail_util_1.ThumbnailUtil.NEW_THUMBNAIL_ID);
34
- expect(results[thumbnail_util_1.ThumbnailUtil.NEW_THUMBNAIL_ID]).toEqual(thumbnail_util_1.ThumbnailUtil.REMOVE_THUMBNAIL);
35
- });
36
- it('calling getFileId - new thumbnail', async () => {
37
- const data = {};
38
- const newDownloadUrl = 'https://api.vibeiq.com/dev/api/files/downloadUrl/w3ckfeGAD8ViOZj-%2Fcontent:E1iBQuWbr74lcdcw%2F9e30ds9o-d34b-451e-ae59-b4km36018d5a.png';
39
- const oldDownloadUrl = 'xxx';
40
- const thumbnailId = 'Eey3ZOiqdrUA84F8';
41
- const event = {
42
- newData: {
43
- primaryViewableId: 'm5bJa4RtTLUtKBP5',
44
- largeViewableDownloadUrl: newDownloadUrl
45
- },
46
- propertyDiffs: {
47
- largeViewableDownloadUrl: {
48
- newValue: newDownloadUrl,
49
- oldValue: oldDownloadUrl
50
- }
51
- }
52
- };
53
- const spyCustomSizes = jest.spyOn(tu, 'getCustomSizes');
54
- spyCustomSizes.mockReturnValue(Promise.resolve(mockData_1.empty_custom_sizes));
55
- const spyGetFileId = jest.spyOn(tu, 'getFileId');
56
- spyGetFileId.mockReturnValue(Promise.resolve(thumbnailId));
57
- const results = await tu.setOutboundThumbnail(data, event);
58
- const keys = Object.keys(results);
59
- expect(keys.length).toEqual(1);
60
- expect(keys[0]).toEqual(thumbnail_util_1.ThumbnailUtil.NEW_THUMBNAIL_ID);
61
- const thumbnailValue = results[thumbnail_util_1.ThumbnailUtil.NEW_THUMBNAIL_ID];
62
- expect(thumbnailValue).toEqual(thumbnailId);
63
- });
64
- it('calling getFileId - existing thumbnail', async () => {
65
- const data = {};
66
- const newDownloadUrl = 'https://api.vibeiq.com/dev/api/files/downloadUrl/w3ckfeGAD8ViOZj-%2Fcontent:E1iBQuWbr74lcdcw%2F9e30ds9o-d34b-451e-ae59-b4km36018d5a.png';
67
- const thumbnailId = 'Eey3ZOiqdrUA84F8';
68
- const event = {
69
- newData: {
70
- primaryViewableId: 'm5bJa4RtTLUtKBP5',
71
- largeViewableDownloadUrl: newDownloadUrl
72
- },
73
- propertyDiffs: {}
74
- };
75
- const spyCustomSizes = jest.spyOn(tu, 'getCustomSizes');
76
- spyCustomSizes.mockReturnValue(Promise.resolve(mockData_1.empty_custom_sizes));
77
- const spyGetFileId = jest.spyOn(tu, 'getFileId');
78
- spyGetFileId.mockReturnValue(Promise.resolve(thumbnailId));
79
- const results = await tu.setOutboundThumbnail(data, event);
80
- const keys = Object.keys(results);
81
- expect(keys.length).toEqual(1);
82
- expect(keys[0]).toEqual(thumbnail_util_1.ThumbnailUtil.EXISTING_THUMBNAIL_ID);
83
- const thumbnailValue = results[thumbnail_util_1.ThumbnailUtil.EXISTING_THUMBNAIL_ID];
84
- expect(thumbnailValue).toEqual(thumbnailId);
85
- });
86
- });
87
- describe('getFileId', () => {
88
- const primaryFileId = 'yn2d5oHD4rXHRzyB';
89
- beforeEach(() => {
90
- jest.clearAllMocks();
91
- });
92
- it('no custom sizes, default max_thumbnail_size - result large', async () => {
93
- const tu = new thumbnail_util_1.ThumbnailUtil(config);
94
- const spyCustomSizes = jest.spyOn(tu, 'getCustomSizes');
95
- spyCustomSizes.mockReturnValue(Promise.resolve(mockData_1.empty_custom_sizes));
96
- const spyContentEntity = jest.spyOn(tu, 'getContentEntity');
97
- const content = JSON.parse(JSON.stringify(mockData_1.thumbnail_content_entity));
98
- spyContentEntity.mockReturnValue(Promise.resolve(content));
99
- const results = await tu.getFileId(primaryFileId);
100
- expect(results).toEqual('vo4N4mCd-tFrw101');
101
- });
102
- it('no custom sizes, 750 * 1_024 max_thumbnail_size - result medium', async () => {
103
- const config1 = {
104
- max_thumbnail_size: 750 * 1024
105
- };
106
- const tu = new thumbnail_util_1.ThumbnailUtil(config1);
107
- const spyCustomSizes = jest.spyOn(tu, 'getCustomSizes');
108
- spyCustomSizes.mockReturnValue(Promise.resolve(mockData_1.empty_custom_sizes));
109
- const spyContentEntity = jest.spyOn(tu, 'getContentEntity');
110
- const content = mockData_1.thumbnail_content_entity;
111
- spyContentEntity.mockReturnValue(Promise.resolve(content));
112
- const results = await tu.getFileId(primaryFileId);
113
- expect(results).toEqual('AsRvJenpeqxksUNW');
114
- });
115
- it('custom sizes, 750 * 1_024 max_thumbnail_size - result CS_500Id', async () => {
116
- const config1 = {
117
- max_thumbnail_size: 750 * 1024
118
- };
119
- const tu = new thumbnail_util_1.ThumbnailUtil(config1);
120
- const spyCustomSizes = jest.spyOn(tu, 'getCustomSizes');
121
- spyCustomSizes.mockReturnValue(Promise.resolve(mockData_1.four_custom_sizes));
122
- const spyContentEntity = jest.spyOn(tu, 'getContentEntity');
123
- const content = mockData_1.thumbnail_content_entity;
124
- spyContentEntity.mockReturnValue(Promise.resolve(content));
125
- const results = await tu.getFileId(primaryFileId);
126
- expect(results).toEqual('rBaHc1J2xdOWdbhI');
127
- });
128
- });
129
- describe('Test isThumbnailNew', () => {
130
- const tu = new thumbnail_util_1.ThumbnailUtil(config);
131
- it('no propertyDiffs', () => {
132
- const event = {
133
- newData: {
134
- name: 'Test'
135
- },
136
- oldData: {
137
- name: 'Test'
138
- }
139
- };
140
- const results = tu.isThumbnailNew(event, undefined);
141
- expect(results).toBeFalsy();
142
- });
143
- it('empty propertyDiffs', () => {
144
- const event = {
145
- newData: {
146
- name: 'Test'
147
- },
148
- oldData: {
149
- name: 'Test'
150
- },
151
- propertyDiffs: {}
152
- };
153
- const results = tu.isThumbnailNew(event, undefined);
154
- expect(results).toBeFalsy();
155
- });
156
- it('propertyDiffs diff property', () => {
157
- const event = {
158
- newData: {
159
- name: 'Test1'
160
- },
161
- oldData: {
162
- name: 'Test'
163
- },
164
- propertyDiffs: {
165
- name: {
166
- propertyName: 'name',
167
- oldValue: 'Test',
168
- newValue: 'Test1'
169
- }
170
- }
171
- };
172
- const results = tu.isThumbnailNew(event, undefined);
173
- expect(results).toBeFalsy();
174
- });
175
- it('propertyDiffs OOB property', () => {
176
- const event = {
177
- newData: {
178
- name: 'Test1'
179
- },
180
- oldData: {
181
- name: 'Test'
182
- },
183
- propertyDiffs: {
184
- mediumLargeViewableDownloadUrl: {
185
- propertyName: 'mediumLargeViewableDownloadUrl',
186
- oldValue: '',
187
- newValue: 'Test1'
188
- }
189
- }
190
- };
191
- const results = tu.isThumbnailNew(event, undefined);
192
- expect(results).toBeTruthy();
193
- });
194
- it('propertyDiffs custom property', () => {
195
- const event = {
196
- newData: {
197
- name: 'Test1'
198
- },
199
- oldData: {
200
- name: 'Test'
201
- },
202
- propertyDiffs: {
203
- RL_1000Url: {
204
- propertyName: 'RL_1000Url',
205
- oldValue: '',
206
- newValue: 'Test1'
207
- }
208
- }
209
- };
210
- const results = tu.isThumbnailNew(event, [{ slug: 'RL_1000' }]);
211
- expect(results).toBeTruthy();
212
- });
213
- });
214
- describe('logContentResults', () => {
215
- it('no content - doesnt error', () => {
216
- const tu = new thumbnail_util_1.ThumbnailUtil(config);
217
- const content = undefined;
218
- const relations = [];
219
- tu.logContentResults(content, relations);
220
- });
221
- it('no relations - doesnt error', () => {
222
- const tu = new thumbnail_util_1.ThumbnailUtil(config);
223
- const content = undefined;
224
- const relations = undefined;
225
- tu.logContentResults(content, relations);
226
- });
227
- it('content and relations - logs', () => {
228
- const tu = new thumbnail_util_1.ThumbnailUtil(config);
229
- const content = {
230
- id: '123',
231
- name: 'Test',
232
- primaryFile: { id: 'file123' }
233
- };
234
- const relations = ['primaryFile'];
235
- tu.logContentResults(content, relations);
236
- expect(Object.keys(content)).toHaveLength(3);
237
- expect(content).toHaveProperty('primaryFile');
238
- expect(content.primaryFile).toHaveProperty('id');
239
- expect(content.primaryFile.id).toEqual('file123');
240
- });
241
- });
242
- });
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
+ });