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