@contrail/flexplm 1.3.1-alpha.eae3d9f → 1.3.1-alpha.f54fe36

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 (111) hide show
  1. package/lib/cli/commands/compile.d.ts +1 -0
  2. package/lib/cli/commands/compile.js +71 -0
  3. package/lib/cli/commands/compile.spec.d.ts +1 -0
  4. package/lib/cli/commands/compile.spec.js +80 -0
  5. package/lib/cli/commands/create.d.ts +1 -0
  6. package/lib/cli/commands/create.js +75 -0
  7. package/lib/cli/commands/create.spec.d.ts +1 -0
  8. package/lib/cli/commands/create.spec.js +78 -0
  9. package/lib/cli/commands/upload.d.ts +10 -0
  10. package/lib/cli/commands/upload.js +219 -0
  11. package/lib/cli/commands/upload.spec.d.ts +1 -0
  12. package/lib/cli/commands/upload.spec.js +88 -0
  13. package/lib/cli/index.d.ts +2 -0
  14. package/lib/cli/index.js +64 -0
  15. package/lib/cli/index.spec.d.ts +1 -0
  16. package/lib/cli/index.spec.js +79 -0
  17. package/lib/cli/template/mapping-template.ts.template +18 -0
  18. package/lib/entity-processor/base-entity-processor.d.ts +47 -0
  19. package/lib/entity-processor/base-entity-processor.js +53 -0
  20. package/lib/entity-processor/base-entity-processor.spec.js +1 -0
  21. package/lib/index.d.ts +1 -0
  22. package/lib/index.js +1 -0
  23. package/lib/interfaces/mapping-file.d.ts +429 -0
  24. package/lib/interfaces/mapping-file.js +2 -0
  25. package/lib/publish/base-process-publish-assortment.d.ts +25 -0
  26. package/lib/publish/base-process-publish-assortment.js +60 -6
  27. package/lib/publish/base-process-publish-assortment.spec.js +22 -4
  28. package/lib/publish/mockData.js +5 -0
  29. package/lib/transform/identifier-conversion-spec-mockData.js +34 -6
  30. package/lib/transform/identifier-conversion.d.ts +36 -0
  31. package/lib/transform/identifier-conversion.js +36 -0
  32. package/lib/transform/identifier-conversion.spec.js +4 -0
  33. package/lib/util/config-defaults.js +3 -0
  34. package/lib/util/config-defaults.spec.js +9 -0
  35. package/lib/util/data-converter-spec-mockData.js +17 -3
  36. package/lib/util/data-converter.d.ts +97 -0
  37. package/lib/util/data-converter.js +127 -1
  38. package/lib/util/data-converter.spec.js +2 -0
  39. package/lib/util/error-response-object.d.ts +5 -0
  40. package/lib/util/error-response-object.js +7 -0
  41. package/lib/util/event-short-message-status.js +1 -0
  42. package/lib/util/federation.js +8 -0
  43. package/lib/util/flexplm-connect.d.ts +7 -0
  44. package/lib/util/flexplm-connect.js +14 -0
  45. package/lib/util/logger-config.js +1 -0
  46. package/lib/util/map-util-spec-mockData.js +17 -3
  47. package/lib/util/map-utils.d.ts +27 -0
  48. package/lib/util/map-utils.js +27 -0
  49. package/lib/util/thumbnail-util.d.ts +21 -0
  50. package/lib/util/thumbnail-util.js +28 -1
  51. package/lib/util/thumbnail-util.spec.js +6 -0
  52. package/lib/util/type-conversion-utils-spec-mockData.js +3 -3
  53. package/lib/util/type-conversion-utils.d.ts +140 -0
  54. package/lib/util/type-conversion-utils.js +143 -0
  55. package/lib/util/type-defaults.d.ts +58 -0
  56. package/lib/util/type-defaults.js +58 -0
  57. package/lib/util/type-defaults.spec.js +5 -5
  58. package/lib/util/type-utils.d.ts +21 -0
  59. package/lib/util/type-utils.js +23 -0
  60. package/lib/util/type-utils.spec.js +2 -0
  61. package/package.json +21 -6
  62. package/scripts/copy-template.js +10 -0
  63. package/.github/pull_request_template.md +0 -31
  64. package/.github/workflows/flexplm-lib.yml +0 -27
  65. package/.github/workflows/publish-to-npm.yml +0 -121
  66. package/CHANGELOG.md +0 -32
  67. package/publish.bat +0 -5
  68. package/publish.sh +0 -5
  69. package/src/entity-processor/base-entity-processor.spec.ts +0 -460
  70. package/src/entity-processor/base-entity-processor.ts +0 -515
  71. package/src/flexplm-request.ts +0 -28
  72. package/src/flexplm-utils.spec.ts +0 -27
  73. package/src/flexplm-utils.ts +0 -29
  74. package/src/index.ts +0 -22
  75. package/src/interfaces/interfaces.ts +0 -122
  76. package/src/interfaces/item-family-changes.ts +0 -67
  77. package/src/interfaces/publish-change-data.ts +0 -43
  78. package/src/publish/base-process-publish-assortment-callback.ts +0 -50
  79. package/src/publish/base-process-publish-assortment.spec.ts +0 -1992
  80. package/src/publish/base-process-publish-assortment.ts +0 -1134
  81. package/src/publish/mockData.ts +0 -4561
  82. package/src/transform/identifier-conversion-spec-mockData.ts +0 -496
  83. package/src/transform/identifier-conversion.spec.ts +0 -354
  84. package/src/transform/identifier-conversion.ts +0 -282
  85. package/src/util/config-defaults.spec.ts +0 -350
  86. package/src/util/config-defaults.ts +0 -93
  87. package/src/util/data-converter-spec-mockData.ts +0 -231
  88. package/src/util/data-converter.spec.ts +0 -1041
  89. package/src/util/data-converter.ts +0 -762
  90. package/src/util/error-response-object.spec.ts +0 -116
  91. package/src/util/error-response-object.ts +0 -50
  92. package/src/util/event-short-message-status.ts +0 -22
  93. package/src/util/federation.ts +0 -172
  94. package/src/util/flexplm-connect.spec.ts +0 -132
  95. package/src/util/flexplm-connect.ts +0 -208
  96. package/src/util/logger-config.ts +0 -20
  97. package/src/util/map-util-spec-mockData.ts +0 -231
  98. package/src/util/map-utils.spec.ts +0 -103
  99. package/src/util/map-utils.ts +0 -41
  100. package/src/util/mockData.ts +0 -101
  101. package/src/util/thumbnail-util.spec.ts +0 -508
  102. package/src/util/thumbnail-util.ts +0 -272
  103. package/src/util/type-conversion-utils-spec-mockData.ts +0 -271
  104. package/src/util/type-conversion-utils.spec.ts +0 -968
  105. package/src/util/type-conversion-utils.ts +0 -460
  106. package/src/util/type-defaults.spec.ts +0 -669
  107. package/src/util/type-defaults.ts +0 -281
  108. package/src/util/type-utils.spec.ts +0 -227
  109. package/src/util/type-utils.ts +0 -144
  110. package/tsconfig.json +0 -24
  111. package/tslint.json +0 -57
@@ -1,460 +0,0 @@
1
- import { Entities, TypeClientOptions } from "@contrail/sdk";
2
- import { MapFileUtil } from "@contrail/transform-data";
3
- import { EntityPayloadType, FCConfig } from "../interfaces/interfaces";
4
- import { DataConverter } from "../util/data-converter";
5
- import { BaseEntityProcessor, IncomingEntityResponse } from "./base-entity-processor";
6
- import { TypeConversionUtils } from "../util/type-conversion-utils";
7
- import { ThumbnailUtil } from "../util/thumbnail-util";
8
-
9
- const mockRootType = {
10
- typeProperties: [
11
- { slug: 'rootText' }
12
- ]
13
- };
14
- const mockTypeUtilGetByRootAndPath = jest.fn((options: TypeClientOptions) => {
15
- return Promise.resolve(mockRootType);
16
- });
17
-
18
- jest.mock('@contrail/sdk', () => {
19
- const origModule = jest.requireActual('@contrail/sdk');
20
- return {
21
- __esModule: true,
22
- ...origModule,
23
- Types: jest.fn().mockImplementation(() => {
24
- return {
25
- getByRootAndPath: mockTypeUtilGetByRootAndPath
26
- };
27
- })
28
- };
29
- });
30
-
31
- class TestBaseEntityProcessor extends BaseEntityProcessor {
32
- protected getIncomingEntity(event: any, inboundData: any): Promise<IncomingEntityResponse> {
33
- throw new Error("Method not implemented.");
34
- }
35
- protected getCreateEntity(inboundData: any): Promise<IncomingEntityResponse> {
36
- throw new Error("Method not implemented.");
37
- }
38
- protected getOutgoingUpsertPayload(entityType: any, event: any): Promise<EntityPayloadType> {
39
- throw new Error("Method not implemented.");
40
- }
41
-
42
- }
43
- describe('BaseEntityProcessor', () =>{
44
- describe('getOutboundEntityUpdates', () =>{
45
-
46
- const config = {} as FCConfig;
47
- const mapFileUtil = new MapFileUtil(new Entities());
48
- const dc = new DataConverter(config, mapFileUtil);
49
- it('no payload', async () =>{
50
- const btep = new TestBaseEntityProcessor(config, dc, mapFileUtil, 'test');
51
- const event = {};
52
- const flexResponse = {};
53
-
54
- const updates = await btep.getOutboundEntityUpdates(event, flexResponse);
55
- expect(updates).toBeUndefined();
56
- });
57
-
58
- it('flexPayload.status === OK', async () =>{
59
- const btep = new TestBaseEntityProcessor(config, dc, mapFileUtil, 'test');
60
- const event = {};
61
- const flexResponse = {
62
- data: {
63
- payload: [
64
- {
65
- status: 'OK'
66
- }
67
- ]
68
- }
69
- };
70
- const getTransformedDataSpy = jest.spyOn(btep, 'getTransformedData').mockReturnValue(Promise.resolve({}));
71
- const returnValue = {
72
- name: 'Test'
73
- };
74
- const getUpdatesForEntitySpy = jest.spyOn(btep, 'getUpdatesForEntity').mockReturnValue(Promise.resolve(returnValue));
75
- const updates = await btep.getOutboundEntityUpdates(event, flexResponse);
76
- expect(getTransformedDataSpy).toBeCalledTimes(1);
77
- expect(getUpdatesForEntitySpy).toBeCalledTimes(1);
78
- expect(updates).toBe(returnValue);
79
- });
80
-
81
- it('flexPayload.status === FAIL', async () =>{
82
- const btep = new TestBaseEntityProcessor(config, dc, mapFileUtil, 'test');
83
- const event = {};
84
- const flexResponse = {
85
- data: {
86
- payload: [
87
- {
88
- status: 'FAIL'
89
- }
90
- ]
91
- }
92
- };
93
- const getTransformedDataSpy = jest.spyOn(btep, 'getTransformedData').mockReturnValue(Promise.resolve({}));
94
- const returnValue = {
95
- name: 'Test'
96
- };
97
- const getUpdatesForEntitySpy = jest.spyOn(btep, 'getUpdatesForEntity').mockReturnValue(Promise.resolve(returnValue));
98
- const updates = await btep.getOutboundEntityUpdates(event, flexResponse);
99
- expect(getTransformedDataSpy).toBeCalledTimes(0);
100
- expect(getUpdatesForEntitySpy).toBeCalledTimes(0);
101
- expect(updates).toBeUndefined();
102
- });
103
-
104
- it('should set flexPLMObjectClass when data exists but flexPLMObjectClass is missing', async () =>{
105
- const btep = new TestBaseEntityProcessor(config, dc, mapFileUtil, 'test');
106
- const event = { newData: { id: '123' } };
107
- const flexResponse = {
108
- data: {
109
- payload: [
110
- {
111
- status: 'OK',
112
- objectClass: 'Material',
113
- data: {
114
- name: 'Test Material'
115
- }
116
- }
117
- ]
118
- }
119
- };
120
- const getTransformedDataSpy = jest.spyOn(btep, 'getTransformedData').mockReturnValue(Promise.resolve({}));
121
- const returnValue = {
122
- name: 'Test'
123
- };
124
- const getUpdatesForEntitySpy = jest.spyOn(btep, 'getUpdatesForEntity').mockReturnValue(Promise.resolve(returnValue));
125
-
126
- await btep.getOutboundEntityUpdates(event, flexResponse);
127
-
128
- expect(flexResponse.data.payload[0].data['flexPLMObjectClass']).toBe('Material');
129
- expect(getTransformedDataSpy).toBeCalledTimes(1);
130
- expect(getTransformedDataSpy).toBeCalledWith(flexResponse.data.payload[0]);
131
- expect(getUpdatesForEntitySpy).toBeCalledTimes(1);
132
- });
133
-
134
- it('should not override existing flexPLMObjectClass', async () =>{
135
- const btep = new TestBaseEntityProcessor(config, dc, mapFileUtil, 'test');
136
- const event = { newData: { id: '123' } };
137
- const flexResponse = {
138
- data: {
139
- payload: [
140
- {
141
- status: 'OK',
142
- objectClass: 'Material',
143
- data: {
144
- name: 'Test Material',
145
- flexPLMObjectClass: 'ExistingClass'
146
- }
147
- }
148
- ]
149
- }
150
- };
151
- const getTransformedDataSpy = jest.spyOn(btep, 'getTransformedData').mockReturnValue(Promise.resolve({}));
152
- const returnValue = {
153
- name: 'Test'
154
- };
155
- const getUpdatesForEntitySpy = jest.spyOn(btep, 'getUpdatesForEntity').mockReturnValue(Promise.resolve(returnValue));
156
-
157
- await btep.getOutboundEntityUpdates(event, flexResponse);
158
-
159
- expect(flexResponse.data.payload[0].data.flexPLMObjectClass).toBe('ExistingClass');
160
- expect(getTransformedDataSpy).toBeCalledTimes(1);
161
- expect(getTransformedDataSpy).toBeCalledWith(flexResponse.data.payload[0]);
162
- expect(getUpdatesForEntitySpy).toBeCalledTimes(1);
163
- });
164
-
165
- it('should skip setting flexPLMObjectClass when data is null or undefined', async () =>{
166
- const btep = new TestBaseEntityProcessor(config, dc, mapFileUtil, 'test');
167
- const event = { newData: { id: '123' } };
168
- const flexResponse = {
169
- data: {
170
- payload: [
171
- {
172
- status: 'OK',
173
- objectClass: 'Material',
174
- data: null
175
- }
176
- ]
177
- }
178
- };
179
- const getTransformedDataSpy = jest.spyOn(btep, 'getTransformedData').mockReturnValue(Promise.resolve({}));
180
- const returnValue = {
181
- name: 'Test'
182
- };
183
- const getUpdatesForEntitySpy = jest.spyOn(btep, 'getUpdatesForEntity').mockReturnValue(Promise.resolve(returnValue));
184
-
185
- await btep.getOutboundEntityUpdates(event, flexResponse);
186
-
187
- expect(getTransformedDataSpy).toBeCalledTimes(1);
188
- expect(getTransformedDataSpy).toBeCalledWith(flexResponse.data.payload[0]);
189
- expect(getUpdatesForEntitySpy).toBeCalledTimes(1);
190
- });
191
-
192
- });
193
-
194
- describe('queryEntityWithSubType', () =>{
195
- const config = {} as FCConfig;
196
- const mapFileUtil = new MapFileUtil(new Entities());
197
- beforeEach(() =>{
198
- jest.clearAllMocks();
199
- });
200
- it('entity parameter not set', async () =>{
201
- const btep = new TestBaseEntityProcessor({} as FCConfig, {} as DataConverter, {} as MapFileUtil, 'test');
202
- const entity = '';
203
- const subType = 'test';
204
- const propertyCriteria = {a:'val'};
205
- expect(async () => {await btep.queryEntityWithSubTypeCriteria(entity, subType, propertyCriteria)}).rejects.toThrow();
206
- });
207
- it('entityTypePath not set', async () =>{
208
- const btep = new TestBaseEntityProcessor({} as FCConfig, {} as DataConverter, {} as MapFileUtil, 'test');
209
- const entity = 'test';
210
- const subType = '';
211
- const propertyCriteria = {};
212
- expect(async () => {await btep.queryEntityWithSubTypeCriteria(entity, subType, propertyCriteria)}).rejects.toThrow();
213
-
214
- });
215
- it('propertyCriteria not set', async () =>{
216
- const btep = new TestBaseEntityProcessor({} as FCConfig, {} as DataConverter, {} as MapFileUtil, 'test');
217
- const entity = 'test';
218
- const subType = 'test';
219
- const propertyCriteria = {};
220
- expect(async () => {await btep.queryEntityWithSubTypeCriteria(entity, subType, propertyCriteria)}).rejects.toThrow();
221
- });
222
-
223
- it('basic queryEntityWithSubTypeCriteria test', async () =>{
224
- const dc = new DataConverter(config, mapFileUtil);
225
- const btep = new TestBaseEntityProcessor(config, dc, mapFileUtil, 'test');
226
- const entityType = 'custom-entity';
227
- const entityTypePath = 'custom-entity:sample';
228
- const rootCriteria = {
229
- rootText: 'root'
230
- };
231
- const subCriteria = {
232
- sampleText: 'sample',
233
- typePath: entityTypePath
234
- };
235
- const propertyCriteria = Object.assign({}, rootCriteria, subCriteria);
236
- const rootCriteriaResults = Object.assign({}, rootCriteria);
237
-
238
- const mockGetByRootTypeProperties = jest.spyOn(btep, 'getRootTypePropertyKeys').mockReturnValue(['rootText']);
239
- const mockDCgetAllObjectReferences = jest.spyOn(dc, 'getAllObjectReferences').mockReturnValue(Promise.resolve([]));
240
-
241
- const results = await btep.queryEntityWithSubTypeCriteria(entityType, entityTypePath, propertyCriteria);
242
- expect(results).toEqual([]);
243
- expect(mockTypeUtilGetByRootAndPath).toBeCalledTimes(1);
244
- expect(mockTypeUtilGetByRootAndPath).toBeCalledWith({ root: entityType});
245
- expect(mockGetByRootTypeProperties).toBeCalledTimes(1);
246
- expect(mockGetByRootTypeProperties).toBeCalledWith(mockRootType, propertyCriteria);
247
-
248
- expect(mockDCgetAllObjectReferences).toBeCalledTimes(1);
249
- expect(mockDCgetAllObjectReferences).toBeCalledWith(entityType, rootCriteriaResults, subCriteria);
250
- });
251
-
252
- });
253
-
254
- describe('getCriteriaForEntity', () =>{
255
- const config = {} as FCConfig;
256
- const mapFileUtil = new MapFileUtil(new Entities());
257
- beforeEach(() =>{
258
- jest.clearAllMocks();
259
- });
260
- it('entity parameter not set', async () =>{
261
- const btep = new TestBaseEntityProcessor({} as FCConfig, {} as DataConverter, {} as MapFileUtil, 'test');
262
- const entity = '';
263
- const subType = 'test';
264
- const propertyCriteria = {a:'val'};
265
- expect(async () => {await btep.getCriteriaForEntity(entity, subType, propertyCriteria)}).rejects.toThrow();
266
- });
267
- it('entityTypePath not set', async () =>{
268
- const btep = new TestBaseEntityProcessor({} as FCConfig, {} as DataConverter, {} as MapFileUtil, 'test');
269
- const entity = 'test';
270
- const subType = '';
271
- const propertyCriteria = {};
272
- expect(async () => {await btep.getCriteriaForEntity(entity, subType, propertyCriteria)}).rejects.toThrow();
273
-
274
- });
275
- it('propertyCriteria not set', async () =>{
276
- const btep = new TestBaseEntityProcessor({} as FCConfig, {} as DataConverter, {} as MapFileUtil, 'test');
277
- const entity = 'test';
278
- const subType = 'test';
279
- const propertyCriteria = {};
280
- expect(async () => {await btep.getCriteriaForEntity(entity, subType, propertyCriteria)}).rejects.toThrow();
281
- });
282
-
283
- it('basic getCriteriaForEntity test', async () =>{
284
- const dc = new DataConverter(config, mapFileUtil);
285
- const btep = new TestBaseEntityProcessor(config, dc, mapFileUtil, 'test');
286
- const entityType = 'custom-entity';
287
- const entityTypePath = 'custom-entity:sample';
288
- const rootCriteria = {
289
- rootText: 'root'
290
- };
291
- const subCriteria = {
292
- sampleText: 'sample',
293
- typePath: entityTypePath
294
- };
295
- const propertyCriteria = Object.assign({}, rootCriteria, subCriteria);
296
- const rootCriteriaResults = Object.assign({}, rootCriteria);
297
- const subCriteriaResults = Object.assign({}, subCriteria);
298
-
299
- const mockGetByRootTypeProperties = jest.spyOn(btep, 'getRootTypePropertyKeys').mockReturnValue(['rootText']);
300
- // const mockDCgetAllObjectReferences = jest.spyOn(dc, 'getAllObjectReferences').mockReturnValue(Promise.resolve([]));
301
-
302
- const {rootTypeCriteria, subTypeCriteria} = await btep.getCriteriaForEntity(entityType, entityTypePath, propertyCriteria);
303
- expect(mockTypeUtilGetByRootAndPath).toBeCalledTimes(1);
304
- expect(mockTypeUtilGetByRootAndPath).toBeCalledWith({ root: entityType});
305
- expect(mockGetByRootTypeProperties).toBeCalledTimes(1);
306
- expect(mockGetByRootTypeProperties).toBeCalledWith(mockRootType, propertyCriteria);
307
- expect(rootTypeCriteria).toEqual(rootCriteriaResults);
308
- expect(subTypeCriteria).toEqual(subCriteriaResults);
309
-
310
- });
311
- });
312
-
313
- describe('getRootTypePropertyKeys', () =>{
314
- it('rootType parameter not set', async () =>{
315
- const btep = new TestBaseEntityProcessor({} as FCConfig, {} as DataConverter, {} as MapFileUtil, 'test');
316
- const rootType = '';
317
- expect(async () => {await btep.getRootTypePropertyKeys(rootType)}).rejects.toThrow();
318
- });
319
-
320
- it('get keys from rootType.typeProperties', async () =>{
321
- const btep = new TestBaseEntityProcessor({} as FCConfig, {} as DataConverter, {} as MapFileUtil, 'test');
322
- const rootType = {
323
- typeProperties: ['a', 'b']
324
- };
325
- const keys = await btep.getRootTypePropertyKeys(rootType);
326
- expect(keys).not.toEqual(['a', 'b']);
327
- });
328
-
329
- it('get keys from rootType.typeProperties', async () =>{
330
- const btep = new TestBaseEntityProcessor({} as FCConfig, {} as DataConverter, {} as MapFileUtil, 'test');
331
- const rootType = {
332
- typeProperties: [{ slug: 'a'},{slug: 'b'}]
333
- };
334
- const keys = await btep.getRootTypePropertyKeys(rootType);
335
- expect(keys).toEqual(['a', 'b']);
336
- });
337
-
338
- });
339
-
340
- describe('handleIncomingUpsert - inbound image sync', () =>{
341
- const config = {} as FCConfig;
342
- const mapFileUtil = new MapFileUtil(new Entities());
343
- const dc = new DataConverter(config, mapFileUtil);
344
- const mockEvent = { objectClass: 'TestClass', federatedId: 'fed-123', data: { name: 'test' }, entityReference: 'ref-1', eventType: 'PERSIST' } as EntityPayloadType;
345
- const mockInboundData = { name: 'transformed-test' };
346
- const mockCreatedEntity = { id: 'created-1', name: 'created', primaryViewableId: 'pv-created' };
347
- const mockUpdatedEntity = { id: 'updated-1', name: 'updated', primaryViewableId: 'pv-updated' };
348
- const mockExistingEntity = { id: 'existing-1', name: 'existing', typeId: 'type-1', roles: [] };
349
-
350
- let btep: TestBaseEntityProcessor;
351
- let syncInboundImagesSpy: jest.SpyInstance;
352
- let syncThumbnailSpy: jest.SpyInstance;
353
-
354
- beforeEach(() =>{
355
- jest.clearAllMocks();
356
- btep = new TestBaseEntityProcessor(config, dc, mapFileUtil, 'test');
357
- jest.spyOn(btep, 'getTransformedData').mockResolvedValue(mockInboundData);
358
- syncInboundImagesSpy = jest.spyOn(TypeConversionUtils, 'syncInboundImages');
359
- syncThumbnailSpy = jest.spyOn(ThumbnailUtil.prototype, 'syncThumbnailToVibeIQ').mockResolvedValue(undefined);
360
- });
361
-
362
- it('should call syncThumbnailToVibeIQ with entity after create when syncInboundImages returns true', async () =>{
363
- jest.spyOn(btep, 'getIncomingEntity' as any).mockResolvedValue({ entity: null });
364
- jest.spyOn(btep, 'getCreateEntity' as any).mockResolvedValue({ entity: { name: 'new' } });
365
- jest.spyOn(btep, 'createEntity').mockResolvedValue(mockCreatedEntity);
366
- syncInboundImagesSpy.mockResolvedValue(true);
367
-
368
- const result = await btep.handleIncomingUpsert(mockEvent);
369
-
370
- expect(syncThumbnailSpy).toBeCalledTimes(1);
371
- expect(syncThumbnailSpy).toBeCalledWith({ entityId: 'created-1', primaryViewableId: 'pv-created', event: mockEvent, entityName: 'test' });
372
- expect(result).toBe(mockCreatedEntity);
373
- });
374
-
375
- it('should not sync images after create when syncInboundImages returns false', async () =>{
376
- jest.spyOn(btep, 'getIncomingEntity' as any).mockResolvedValue({ entity: null });
377
- jest.spyOn(btep, 'getCreateEntity' as any).mockResolvedValue({ entity: { name: 'new' } });
378
- jest.spyOn(btep, 'createEntity').mockResolvedValue(mockCreatedEntity);
379
- syncInboundImagesSpy.mockResolvedValue(false);
380
-
381
- const result = await btep.handleIncomingUpsert(mockEvent);
382
-
383
- expect(syncInboundImagesSpy).toBeCalledTimes(1);
384
- expect(syncThumbnailSpy).toBeCalledTimes(0);
385
- expect(result).toBe(mockCreatedEntity);
386
- });
387
-
388
- it('should call syncThumbnailToVibeIQ with entity and update with property diffs on update', async () =>{
389
- jest.spyOn(btep, 'getIncomingEntity' as any).mockResolvedValue({ entity: mockExistingEntity });
390
- jest.spyOn(btep, 'getUpdatesForEntity').mockResolvedValue({ name: 'changed' });
391
- const updateEntitySpy = jest.spyOn(btep, 'updateEntity').mockResolvedValue(mockUpdatedEntity);
392
- syncInboundImagesSpy.mockResolvedValue(true);
393
-
394
- const result = await btep.handleIncomingUpsert(mockEvent);
395
-
396
- expect(syncThumbnailSpy).toBeCalledTimes(1);
397
- expect(syncThumbnailSpy).toBeCalledWith({ entityId: 'existing-1', primaryViewableId: undefined, event: mockEvent, entityName: 'test' });
398
- expect(updateEntitySpy).toBeCalledWith('test', mockExistingEntity, { name: 'changed' });
399
- expect(result).toBe(mockUpdatedEntity);
400
- });
401
-
402
- it('should not sync images on update when syncInboundImages returns false', async () =>{
403
- jest.spyOn(btep, 'getIncomingEntity' as any).mockResolvedValue({ entity: mockExistingEntity });
404
- jest.spyOn(btep, 'getUpdatesForEntity').mockResolvedValue({ name: 'changed' });
405
- jest.spyOn(btep, 'updateEntity').mockResolvedValue(mockUpdatedEntity);
406
- syncInboundImagesSpy.mockResolvedValue(false);
407
-
408
- const result = await btep.handleIncomingUpsert(mockEvent);
409
-
410
- expect(syncInboundImagesSpy).toBeCalledTimes(1);
411
- expect(syncThumbnailSpy).toBeCalledTimes(0);
412
- expect(result).toBe(mockUpdatedEntity);
413
- });
414
-
415
- it('should not sync images on early return from getIncomingEntity', async () =>{
416
- jest.spyOn(btep, 'getIncomingEntity' as any).mockResolvedValue({
417
- earlyReturn: { status: 400, data: { message: 'error' }, shortStatusMessage: 'FAIL' }
418
- });
419
-
420
- await btep.handleIncomingUpsert(mockEvent);
421
-
422
- expect(syncInboundImagesSpy).toBeCalledTimes(0);
423
- expect(syncThumbnailSpy).toBeCalledTimes(0);
424
- });
425
-
426
- it('should not sync images on early return from getCreateEntity', async () =>{
427
- jest.spyOn(btep, 'getIncomingEntity' as any).mockResolvedValue({ entity: null });
428
- jest.spyOn(btep, 'getCreateEntity' as any).mockResolvedValue({
429
- earlyReturn: { status: 400, data: { message: 'not creatable' }, shortStatusMessage: 'NOT_CREATABLE' }
430
- });
431
-
432
- await btep.handleIncomingUpsert(mockEvent);
433
-
434
- expect(syncInboundImagesSpy).toBeCalledTimes(0);
435
- expect(syncThumbnailSpy).toBeCalledTimes(0);
436
- });
437
-
438
- it('should return no changes when no property diffs and no thumbnail updates', async () =>{
439
- jest.spyOn(btep, 'getIncomingEntity' as any).mockResolvedValue({ entity: mockExistingEntity });
440
- jest.spyOn(btep, 'getUpdatesForEntity').mockResolvedValue({});
441
- syncInboundImagesSpy.mockResolvedValue(true);
442
- syncThumbnailSpy.mockResolvedValue(undefined);
443
-
444
- const result = await btep.handleIncomingUpsert(mockEvent);
445
-
446
- expect(result).toEqual({ status: 200, data: { message: 'No Changes to persist for entity: existing-1' } });
447
- });
448
-
449
- it('should return no changes when syncInboundImages is false and no property diffs', async () =>{
450
- jest.spyOn(btep, 'getIncomingEntity' as any).mockResolvedValue({ entity: mockExistingEntity });
451
- jest.spyOn(btep, 'getUpdatesForEntity').mockResolvedValue({});
452
- syncInboundImagesSpy.mockResolvedValue(false);
453
-
454
- const result = await btep.handleIncomingUpsert(mockEvent);
455
-
456
- expect(result).toEqual({ status: 200, data: { message: 'No Changes to persist for entity: existing-1' } });
457
- });
458
- });
459
-
460
- });