@contrail/flexplm 1.4.0 → 1.5.0-alpha.14a4f1b

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 (112) hide show
  1. package/lib/cli/commands/compile.d.ts +4 -0
  2. package/lib/cli/commands/compile.js +73 -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 +5 -0
  6. package/lib/cli/commands/create.js +77 -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 +17 -0
  10. package/lib/cli/commands/upload.js +228 -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 +5 -0
  14. package/lib/cli/index.js +70 -0
  15. package/lib/cli/index.spec.d.ts +1 -0
  16. package/lib/cli/index.spec.js +85 -0
  17. package/lib/cli/template/mapping-template.ts.template +62 -0
  18. package/lib/entity-processor/base-entity-processor.d.ts +65 -0
  19. package/lib/entity-processor/base-entity-processor.js +71 -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 +460 -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 +37 -1
  32. package/lib/transform/identifier-conversion.spec.js +35 -0
  33. package/lib/util/config-defaults.d.ts +18 -0
  34. package/lib/util/config-defaults.js +25 -15
  35. package/lib/util/config-defaults.spec.js +56 -0
  36. package/lib/util/data-converter-spec-mockData.js +17 -3
  37. package/lib/util/data-converter.d.ts +102 -0
  38. package/lib/util/data-converter.js +195 -34
  39. package/lib/util/data-converter.spec.js +430 -0
  40. package/lib/util/error-response-object.d.ts +5 -0
  41. package/lib/util/error-response-object.js +7 -0
  42. package/lib/util/event-short-message-status.js +1 -0
  43. package/lib/util/federation.js +8 -0
  44. package/lib/util/flexplm-connect.d.ts +7 -0
  45. package/lib/util/flexplm-connect.js +14 -0
  46. package/lib/util/logger-config.js +1 -0
  47. package/lib/util/map-util-spec-mockData.js +17 -3
  48. package/lib/util/map-utils.d.ts +27 -0
  49. package/lib/util/map-utils.js +27 -0
  50. package/lib/util/thumbnail-util.d.ts +21 -0
  51. package/lib/util/thumbnail-util.js +28 -1
  52. package/lib/util/thumbnail-util.spec.js +6 -0
  53. package/lib/util/type-conversion-utils-spec-mockData.js +3 -3
  54. package/lib/util/type-conversion-utils.d.ts +151 -0
  55. package/lib/util/type-conversion-utils.js +154 -0
  56. package/lib/util/type-defaults.d.ts +69 -0
  57. package/lib/util/type-defaults.js +98 -4
  58. package/lib/util/type-defaults.spec.js +114 -4
  59. package/lib/util/type-utils.d.ts +21 -0
  60. package/lib/util/type-utils.js +23 -0
  61. package/lib/util/type-utils.spec.js +2 -0
  62. package/package.json +21 -6
  63. package/scripts/copy-template.js +10 -0
  64. package/.github/pull_request_template.md +0 -31
  65. package/.github/workflows/flexplm-lib.yml +0 -27
  66. package/.github/workflows/publish-to-npm.yml +0 -121
  67. package/CHANGELOG.md +0 -40
  68. package/publish.bat +0 -5
  69. package/publish.sh +0 -5
  70. package/src/entity-processor/base-entity-processor.spec.ts +0 -689
  71. package/src/entity-processor/base-entity-processor.ts +0 -583
  72. package/src/flexplm-request.ts +0 -28
  73. package/src/flexplm-utils.spec.ts +0 -27
  74. package/src/flexplm-utils.ts +0 -29
  75. package/src/index.ts +0 -22
  76. package/src/interfaces/interfaces.ts +0 -122
  77. package/src/interfaces/item-family-changes.ts +0 -67
  78. package/src/interfaces/publish-change-data.ts +0 -43
  79. package/src/publish/base-process-publish-assortment-callback.ts +0 -50
  80. package/src/publish/base-process-publish-assortment.spec.ts +0 -1992
  81. package/src/publish/base-process-publish-assortment.ts +0 -1134
  82. package/src/publish/mockData.ts +0 -4561
  83. package/src/transform/identifier-conversion-spec-mockData.ts +0 -496
  84. package/src/transform/identifier-conversion.spec.ts +0 -354
  85. package/src/transform/identifier-conversion.ts +0 -282
  86. package/src/util/config-defaults.spec.ts +0 -392
  87. package/src/util/config-defaults.ts +0 -97
  88. package/src/util/data-converter-spec-mockData.ts +0 -231
  89. package/src/util/data-converter.spec.ts +0 -1120
  90. package/src/util/data-converter.ts +0 -766
  91. package/src/util/error-response-object.spec.ts +0 -116
  92. package/src/util/error-response-object.ts +0 -50
  93. package/src/util/event-short-message-status.ts +0 -22
  94. package/src/util/federation.ts +0 -172
  95. package/src/util/flexplm-connect.spec.ts +0 -132
  96. package/src/util/flexplm-connect.ts +0 -208
  97. package/src/util/logger-config.ts +0 -20
  98. package/src/util/map-util-spec-mockData.ts +0 -231
  99. package/src/util/map-utils.spec.ts +0 -103
  100. package/src/util/map-utils.ts +0 -41
  101. package/src/util/mockData.ts +0 -101
  102. package/src/util/thumbnail-util.spec.ts +0 -508
  103. package/src/util/thumbnail-util.ts +0 -272
  104. package/src/util/type-conversion-utils-spec-mockData.ts +0 -272
  105. package/src/util/type-conversion-utils.spec.ts +0 -1031
  106. package/src/util/type-conversion-utils.ts +0 -490
  107. package/src/util/type-defaults.spec.ts +0 -669
  108. package/src/util/type-defaults.ts +0 -281
  109. package/src/util/type-utils.spec.ts +0 -227
  110. package/src/util/type-utils.ts +0 -144
  111. package/tsconfig.json +0 -24
  112. package/tslint.json +0 -57
@@ -1,689 +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
- describe('getIdentityEntity', () => {
461
- const config = {} as FCConfig;
462
- const mapFileUtil = new MapFileUtil(new Entities());
463
- const dc = new DataConverter(config, mapFileUtil);
464
- let btep: TestBaseEntityProcessor;
465
- let mockEntitiesGet: jest.Mock;
466
-
467
- beforeEach(() => {
468
- btep = new TestBaseEntityProcessor(config, dc, mapFileUtil, 'item');
469
- mockEntitiesGet = jest.fn();
470
- (btep as any).entities = { get: mockEntitiesGet };
471
- });
472
-
473
- it('should throw error when poolKey is missing', async () => {
474
- await expect(btep.getIdentityEntity({
475
- poolKey: '',
476
- propertyName: 'itemNumber',
477
- propertyValue: '12345'
478
- })).rejects.toThrow('poolKey, propertyName, and propertyValue must be defined');
479
- });
480
-
481
- it('should throw error when propertyName is missing', async () => {
482
- await expect(btep.getIdentityEntity({
483
- poolKey: 'item',
484
- propertyName: '',
485
- propertyValue: '12345'
486
- })).rejects.toThrow('poolKey, propertyName, and propertyValue must be defined');
487
- });
488
-
489
- it('should throw error when propertyValue is missing', async () => {
490
- await expect(btep.getIdentityEntity({
491
- poolKey: 'item',
492
- propertyName: 'itemNumber',
493
- propertyValue: ''
494
- })).rejects.toThrow('poolKey, propertyName, and propertyValue must be defined');
495
- });
496
-
497
- it('should return undefined when no identity entities are found (empty array)', async () => {
498
- mockEntitiesGet.mockResolvedValue([]);
499
-
500
- const result = await btep.getIdentityEntity({
501
- poolKey: 'item',
502
- propertyName: 'itemNumber',
503
- propertyValue: '12345'
504
- });
505
-
506
- expect(result).toBeUndefined();
507
- expect(mockEntitiesGet).toHaveBeenCalledWith({
508
- entityName: 'identity',
509
- criteria: { poolKey: 'item', propertyName: 'itemNumber', propertyValue: '12345' }
510
- });
511
- });
512
-
513
- it('should return undefined when identity entities result is null', async () => {
514
- mockEntitiesGet.mockResolvedValue(null);
515
-
516
- const result = await btep.getIdentityEntity({
517
- poolKey: 'item',
518
- propertyName: 'itemNumber',
519
- propertyValue: '12345'
520
- });
521
-
522
- expect(result).toBeUndefined();
523
- });
524
-
525
- it('should throw error when multiple identity entities are found', async () => {
526
- mockEntitiesGet.mockResolvedValue([
527
- { entityReference: 'item:1' },
528
- { entityReference: 'item:2' }
529
- ]);
530
-
531
- await expect(btep.getIdentityEntity({
532
- poolKey: 'item',
533
- propertyName: 'itemNumber',
534
- propertyValue: '12345'
535
- })).rejects.toThrow('Multiple identity entities found for poolKey: item, itemNumber: 12345');
536
- });
537
-
538
- it('should return the identity entity when one is found (array)', async () => {
539
- const identityEntity = { entityReference: 'item:1' };
540
- mockEntitiesGet.mockResolvedValue([identityEntity]);
541
-
542
- const result = await btep.getIdentityEntity({
543
- poolKey: 'item',
544
- propertyName: 'itemNumber',
545
- propertyValue: '12345'
546
- });
547
-
548
- expect(result).toEqual(identityEntity);
549
- expect(mockEntitiesGet).toHaveBeenCalledTimes(1);
550
- });
551
-
552
- it('should return the identity entity when result is a single object (not array)', async () => {
553
- const identityEntity = { entityReference: 'item:5' };
554
- mockEntitiesGet.mockResolvedValue(identityEntity);
555
-
556
- const result = await btep.getIdentityEntity({
557
- poolKey: 'item:material',
558
- propertyName: 'materialNumber',
559
- propertyValue: 'MAT-001'
560
- });
561
-
562
- expect(result).toEqual(identityEntity);
563
- expect(mockEntitiesGet).toHaveBeenCalledTimes(1);
564
- });
565
- });
566
-
567
- describe('getEntityUsingIdentityService', () => {
568
- const config = {} as FCConfig;
569
- const mapFileUtil = new MapFileUtil(new Entities());
570
- const dc = new DataConverter(config, mapFileUtil);
571
- let btep: TestBaseEntityProcessor;
572
- let mockEntitiesGet: jest.Mock;
573
-
574
- beforeEach(() => {
575
- btep = new TestBaseEntityProcessor(config, dc, mapFileUtil, 'item');
576
- mockEntitiesGet = jest.fn();
577
- (btep as any).entities = { get: mockEntitiesGet };
578
- });
579
-
580
- it('should throw error when poolKey is missing', async () => {
581
- await expect(btep.getEntityUsingIdentityService({
582
- poolKey: '',
583
- propertyName: 'itemNumber',
584
- propertyValue: '12345'
585
- })).rejects.toThrow('poolKey, propertyName, and propertyValue must be defined');
586
- });
587
-
588
- it('should throw error when propertyName is missing', async () => {
589
- await expect(btep.getEntityUsingIdentityService({
590
- poolKey: 'item',
591
- propertyName: '',
592
- propertyValue: '12345'
593
- })).rejects.toThrow('poolKey, propertyName, and propertyValue must be defined');
594
- });
595
-
596
- it('should throw error when propertyValue is missing', async () => {
597
- await expect(btep.getEntityUsingIdentityService({
598
- poolKey: 'item',
599
- propertyName: 'itemNumber',
600
- propertyValue: ''
601
- })).rejects.toThrow('poolKey, propertyName, and propertyValue must be defined');
602
- });
603
-
604
- it('should return undefined when no identity entities are found (empty array)', async () => {
605
- mockEntitiesGet.mockResolvedValue([]);
606
-
607
- const result = await btep.getEntityUsingIdentityService({
608
- poolKey: 'item',
609
- propertyName: 'itemNumber',
610
- propertyValue: '12345'
611
- });
612
-
613
- expect(result).toBeUndefined();
614
- expect(mockEntitiesGet).toHaveBeenCalledWith({
615
- entityName: 'identity',
616
- criteria: { poolKey: 'item', propertyName: 'itemNumber', propertyValue: '12345' }
617
- });
618
- });
619
-
620
- it('should return undefined when identity entities result is null', async () => {
621
- mockEntitiesGet.mockResolvedValue(null);
622
-
623
- const result = await btep.getEntityUsingIdentityService({
624
- poolKey: 'item',
625
- propertyName: 'itemNumber',
626
- propertyValue: '12345'
627
- });
628
-
629
- expect(result).toBeUndefined();
630
- });
631
-
632
- it('should throw error when multiple identity entities are found', async () => {
633
- mockEntitiesGet.mockResolvedValue([
634
- { entityReference: 'item:1' },
635
- { entityReference: 'item:2' }
636
- ]);
637
-
638
- await expect(btep.getEntityUsingIdentityService({
639
- poolKey: 'item',
640
- propertyName: 'itemNumber',
641
- propertyValue: '12345'
642
- })).rejects.toThrow('Multiple identity entities found for poolKey: item, itemNumber: 12345');
643
- });
644
-
645
- it('should return the entity when one identity entity is found (array)', async () => {
646
- const mockEntity = { id: '1', name: 'Test Item' };
647
- mockEntitiesGet
648
- .mockResolvedValueOnce([{ entityReference: 'item:1' }])
649
- .mockResolvedValueOnce(mockEntity);
650
-
651
- const result = await btep.getEntityUsingIdentityService({
652
- poolKey: 'item',
653
- propertyName: 'itemNumber',
654
- propertyValue: '12345'
655
- });
656
-
657
- expect(result).toEqual(mockEntity);
658
- expect(mockEntitiesGet).toHaveBeenCalledTimes(2);
659
- expect(mockEntitiesGet).toHaveBeenNthCalledWith(1, {
660
- entityName: 'identity',
661
- criteria: { poolKey: 'item', propertyName: 'itemNumber', propertyValue: '12345' }
662
- });
663
- expect(mockEntitiesGet).toHaveBeenNthCalledWith(2, {
664
- entityName: 'item',
665
- id: '1'
666
- });
667
- });
668
-
669
- it('should return the entity when identity result is a single object (not array)', async () => {
670
- const mockEntity = { id: '5', name: 'Test Material' };
671
- mockEntitiesGet
672
- .mockResolvedValueOnce({ entityReference: 'item:5' })
673
- .mockResolvedValueOnce(mockEntity);
674
-
675
- const result = await btep.getEntityUsingIdentityService({
676
- poolKey: 'item:material',
677
- propertyName: 'materialNumber',
678
- propertyValue: 'MAT-001'
679
- });
680
-
681
- expect(result).toEqual(mockEntity);
682
- expect(mockEntitiesGet).toHaveBeenNthCalledWith(2, {
683
- entityName: 'item',
684
- id: '5'
685
- });
686
- });
687
- });
688
-
689
- });