@contrail/flexplm 1.3.0 → 1.3.1-alpha.56221f6

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 (149) 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 +89 -42
  19. package/lib/entity-processor/base-entity-processor.js +438 -385
  20. package/lib/entity-processor/base-entity-processor.spec.d.ts +1 -1
  21. package/lib/entity-processor/base-entity-processor.spec.js +398 -397
  22. package/lib/flexplm-request.d.ts +3 -3
  23. package/lib/flexplm-request.js +34 -34
  24. package/lib/flexplm-utils.d.ts +5 -5
  25. package/lib/flexplm-utils.js +33 -33
  26. package/lib/flexplm-utils.spec.d.ts +1 -1
  27. package/lib/flexplm-utils.spec.js +26 -26
  28. package/lib/index.d.ts +23 -22
  29. package/lib/index.js +39 -38
  30. package/lib/interfaces/interfaces.d.ts +105 -105
  31. package/lib/interfaces/interfaces.js +2 -2
  32. package/lib/interfaces/item-family-changes.d.ts +20 -20
  33. package/lib/interfaces/item-family-changes.js +56 -56
  34. package/lib/interfaces/mapping-file.d.ts +429 -0
  35. package/lib/interfaces/mapping-file.js +2 -0
  36. package/lib/interfaces/publish-change-data.d.ts +19 -19
  37. package/lib/interfaces/publish-change-data.js +32 -32
  38. package/lib/publish/base-process-publish-assortment-callback.d.ts +9 -9
  39. package/lib/publish/base-process-publish-assortment-callback.js +38 -38
  40. package/lib/publish/base-process-publish-assortment.d.ts +118 -93
  41. package/lib/publish/base-process-publish-assortment.js +998 -944
  42. package/lib/publish/base-process-publish-assortment.spec.d.ts +1 -1
  43. package/lib/publish/base-process-publish-assortment.spec.js +1688 -1670
  44. package/lib/publish/mockData.d.ts +1389 -1389
  45. package/lib/publish/mockData.js +4524 -4519
  46. package/lib/transform/identifier-conversion-spec-mockData.js +472 -444
  47. package/lib/transform/identifier-conversion.d.ts +51 -15
  48. package/lib/transform/identifier-conversion.js +248 -212
  49. package/lib/transform/identifier-conversion.spec.d.ts +1 -1
  50. package/lib/transform/identifier-conversion.spec.js +343 -339
  51. package/lib/util/config-defaults.d.ts +8 -8
  52. package/lib/util/config-defaults.js +88 -85
  53. package/lib/util/config-defaults.spec.d.ts +1 -1
  54. package/lib/util/config-defaults.spec.js +302 -293
  55. package/lib/util/data-converter-spec-mockData.js +219 -205
  56. package/lib/util/data-converter.d.ts +136 -39
  57. package/lib/util/data-converter.js +718 -592
  58. package/lib/util/data-converter.spec.d.ts +1 -1
  59. package/lib/util/data-converter.spec.js +906 -904
  60. package/lib/util/error-response-object.d.ts +9 -4
  61. package/lib/util/error-response-object.js +54 -47
  62. package/lib/util/error-response-object.spec.d.ts +1 -1
  63. package/lib/util/error-response-object.spec.js +99 -99
  64. package/lib/util/event-short-message-status.d.ts +19 -19
  65. package/lib/util/event-short-message-status.js +24 -23
  66. package/lib/util/federation.d.ts +15 -15
  67. package/lib/util/federation.js +157 -149
  68. package/lib/util/flexplm-connect.d.ts +29 -22
  69. package/lib/util/flexplm-connect.js +190 -176
  70. package/lib/util/flexplm-connect.spec.d.ts +1 -1
  71. package/lib/util/flexplm-connect.spec.js +88 -88
  72. package/lib/util/logger-config.d.ts +1 -1
  73. package/lib/util/logger-config.js +27 -26
  74. package/lib/util/map-util-spec-mockData.js +219 -205
  75. package/lib/util/map-utils.d.ts +33 -6
  76. package/lib/util/map-utils.js +42 -15
  77. package/lib/util/map-utils.spec.d.ts +1 -1
  78. package/lib/util/map-utils.spec.js +89 -89
  79. package/lib/util/mockData.d.ts +80 -80
  80. package/lib/util/mockData.js +103 -103
  81. package/lib/util/thumbnail-util.d.ts +55 -34
  82. package/lib/util/thumbnail-util.js +242 -215
  83. package/lib/util/thumbnail-util.spec.d.ts +1 -1
  84. package/lib/util/thumbnail-util.spec.js +440 -434
  85. package/lib/util/type-conversion-utils-spec-mockData.js +259 -259
  86. package/lib/util/type-conversion-utils.d.ts +163 -23
  87. package/lib/util/type-conversion-utils.js +408 -265
  88. package/lib/util/type-conversion-utils.spec.d.ts +1 -1
  89. package/lib/util/type-conversion-utils.spec.js +868 -868
  90. package/lib/util/type-defaults.d.ts +74 -16
  91. package/lib/util/type-defaults.js +279 -221
  92. package/lib/util/type-defaults.spec.d.ts +1 -1
  93. package/lib/util/type-defaults.spec.js +516 -516
  94. package/lib/util/type-utils.d.ts +34 -13
  95. package/lib/util/type-utils.js +137 -114
  96. package/lib/util/type-utils.spec.d.ts +1 -1
  97. package/lib/util/type-utils.spec.js +192 -190
  98. package/package.json +21 -6
  99. package/scripts/copy-template.js +10 -0
  100. package/.claude/settings.local.json +0 -8
  101. package/.github/pull_request_template.md +0 -31
  102. package/.github/workflows/flexplm-lib.yml +0 -27
  103. package/.github/workflows/publish-to-npm.yml +0 -124
  104. package/CHANGELOG.md +0 -32
  105. package/publish.bat +0 -5
  106. package/publish.sh +0 -5
  107. package/src/entity-processor/base-entity-processor.spec.ts +0 -460
  108. package/src/entity-processor/base-entity-processor.ts +0 -515
  109. package/src/flexplm-request.ts +0 -28
  110. package/src/flexplm-utils.spec.ts +0 -27
  111. package/src/flexplm-utils.ts +0 -29
  112. package/src/index.ts +0 -22
  113. package/src/interfaces/interfaces.ts +0 -122
  114. package/src/interfaces/item-family-changes.ts +0 -67
  115. package/src/interfaces/publish-change-data.ts +0 -43
  116. package/src/publish/base-process-publish-assortment-callback.ts +0 -50
  117. package/src/publish/base-process-publish-assortment.spec.ts +0 -1992
  118. package/src/publish/base-process-publish-assortment.ts +0 -1134
  119. package/src/publish/mockData.ts +0 -4561
  120. package/src/transform/identifier-conversion-spec-mockData.ts +0 -496
  121. package/src/transform/identifier-conversion.spec.ts +0 -354
  122. package/src/transform/identifier-conversion.ts +0 -282
  123. package/src/util/config-defaults.spec.ts +0 -350
  124. package/src/util/config-defaults.ts +0 -93
  125. package/src/util/data-converter-spec-mockData.ts +0 -231
  126. package/src/util/data-converter.spec.ts +0 -1041
  127. package/src/util/data-converter.ts +0 -762
  128. package/src/util/error-response-object.spec.ts +0 -116
  129. package/src/util/error-response-object.ts +0 -50
  130. package/src/util/event-short-message-status.ts +0 -22
  131. package/src/util/federation.ts +0 -172
  132. package/src/util/flexplm-connect.spec.ts +0 -132
  133. package/src/util/flexplm-connect.ts +0 -208
  134. package/src/util/logger-config.ts +0 -20
  135. package/src/util/map-util-spec-mockData.ts +0 -231
  136. package/src/util/map-utils.spec.ts +0 -103
  137. package/src/util/map-utils.ts +0 -41
  138. package/src/util/mockData.ts +0 -101
  139. package/src/util/thumbnail-util.spec.ts +0 -508
  140. package/src/util/thumbnail-util.ts +0 -272
  141. package/src/util/type-conversion-utils-spec-mockData.ts +0 -271
  142. package/src/util/type-conversion-utils.spec.ts +0 -968
  143. package/src/util/type-conversion-utils.ts +0 -460
  144. package/src/util/type-defaults.spec.ts +0 -669
  145. package/src/util/type-defaults.ts +0 -281
  146. package/src/util/type-utils.spec.ts +0 -227
  147. package/src/util/type-utils.ts +0 -144
  148. package/tsconfig.json +0 -29
  149. package/tslint.json +0 -57
package/publish.bat DELETED
@@ -1,5 +0,0 @@
1
- rd /s /q lib
2
- call npm install
3
- call npm run build
4
- call npm version patch
5
- call npm publish
package/publish.sh DELETED
@@ -1,5 +0,0 @@
1
- rm -rf lib;
2
- npm install;
3
- npm run build;
4
- npm version patch;
5
- npm publish;
@@ -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
- });