@contrail/flexplm 1.2.1 → 1.3.0-alpha.04c91a9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/pull_request_template.md +31 -31
- package/.github/workflows/flexplm-lib.yml +27 -27
- package/.github/workflows/publish-to-npm.yml +131 -0
- package/CHANGELOG.md +10 -0
- package/lib/entity-processor/base-entity-processor.d.ts +42 -42
- package/lib/entity-processor/base-entity-processor.js +385 -363
- package/lib/entity-processor/base-entity-processor.spec.d.ts +1 -1
- package/lib/entity-processor/base-entity-processor.spec.js +397 -302
- 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 +22 -22
- package/lib/index.js +38 -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/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 +93 -93
- package/lib/publish/base-process-publish-assortment.js +944 -944
- package/lib/publish/base-process-publish-assortment.spec.d.ts +1 -1
- package/lib/publish/base-process-publish-assortment.spec.js +1670 -1670
- package/lib/publish/mockData.d.ts +1389 -1389
- package/lib/publish/mockData.js +4519 -4519
- package/lib/transform/identifier-conversion-spec-mockData.js +444 -444
- package/lib/transform/identifier-conversion.d.ts +15 -15
- package/lib/transform/identifier-conversion.js +212 -212
- package/lib/transform/identifier-conversion.spec.d.ts +1 -1
- package/lib/transform/identifier-conversion.spec.js +339 -339
- package/lib/util/config-defaults.d.ts +8 -8
- package/lib/util/config-defaults.js +85 -85
- package/lib/util/config-defaults.spec.d.ts +1 -1
- package/lib/util/config-defaults.spec.js +293 -293
- package/lib/util/data-converter-spec-mockData.js +205 -205
- package/lib/util/data-converter.d.ts +39 -39
- package/lib/util/data-converter.js +592 -592
- package/lib/util/data-converter.spec.d.ts +1 -1
- package/lib/util/data-converter.spec.js +904 -904
- package/lib/util/error-response-object.d.ts +4 -4
- package/lib/util/error-response-object.js +47 -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 -18
- package/lib/util/event-short-message-status.js +23 -22
- package/lib/util/federation.d.ts +15 -15
- package/lib/util/federation.js +149 -149
- package/lib/util/flexplm-connect.d.ts +22 -18
- package/lib/util/flexplm-connect.js +176 -171
- package/lib/util/flexplm-connect.spec.d.ts +1 -0
- package/lib/util/flexplm-connect.spec.js +88 -0
- package/lib/util/logger-config.d.ts +1 -1
- package/lib/util/logger-config.js +26 -26
- package/lib/util/map-util-spec-mockData.js +205 -205
- package/lib/util/map-utils.d.ts +6 -6
- package/lib/util/map-utils.js +15 -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 -79
- package/lib/util/mockData.js +103 -99
- package/lib/util/thumbnail-util.d.ts +34 -19
- package/lib/util/thumbnail-util.js +215 -114
- package/lib/util/thumbnail-util.spec.d.ts +1 -1
- package/lib/util/thumbnail-util.spec.js +434 -242
- package/lib/util/type-conversion-utils-spec-mockData.js +259 -241
- package/lib/util/type-conversion-utils.d.ts +23 -21
- package/lib/util/type-conversion-utils.js +265 -223
- package/lib/util/type-conversion-utils.spec.d.ts +1 -1
- package/lib/util/type-conversion-utils.spec.js +868 -708
- package/lib/util/type-defaults.d.ts +16 -16
- package/lib/util/type-defaults.js +221 -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 +13 -13
- package/lib/util/type-utils.js +114 -114
- package/lib/util/type-utils.spec.d.ts +1 -1
- package/lib/util/type-utils.spec.js +190 -190
- package/package.json +1 -1
- package/publish.bat +4 -4
- package/publish.sh +4 -4
- package/src/entity-processor/base-entity-processor.spec.ts +122 -0
- package/src/entity-processor/base-entity-processor.ts +31 -2
- package/src/flexplm-request.ts +28 -28
- package/src/flexplm-utils.spec.ts +27 -27
- package/src/flexplm-utils.ts +29 -29
- package/src/index.ts +21 -21
- package/src/interfaces/item-family-changes.ts +66 -66
- package/src/interfaces/publish-change-data.ts +42 -42
- package/src/publish/base-process-publish-assortment-callback.ts +50 -50
- package/src/transform/identifier-conversion-spec-mockData.ts +495 -495
- package/src/transform/identifier-conversion.spec.ts +353 -353
- package/src/transform/identifier-conversion.ts +281 -281
- package/src/util/config-defaults.spec.ts +350 -350
- package/src/util/config-defaults.ts +92 -92
- package/src/util/data-converter-spec-mockData.ts +230 -230
- package/src/util/error-response-object.spec.ts +115 -115
- package/src/util/error-response-object.ts +49 -49
- package/src/util/event-short-message-status.ts +1 -0
- package/src/util/federation.ts +172 -172
- package/src/util/flexplm-connect.spec.ts +132 -0
- package/src/util/flexplm-connect.ts +14 -5
- package/src/util/logger-config.ts +19 -19
- package/src/util/map-util-spec-mockData.ts +230 -230
- package/src/util/map-utils.spec.ts +102 -102
- package/src/util/map-utils.ts +40 -40
- package/src/util/mockData.ts +101 -97
- package/src/util/thumbnail-util.spec.ts +239 -0
- package/src/util/thumbnail-util.ts +140 -5
- package/src/util/type-conversion-utils-spec-mockData.ts +18 -0
- package/src/util/type-conversion-utils.spec.ts +184 -0
- package/src/util/type-conversion-utils.ts +75 -1
- package/src/util/type-defaults.spec.ts +668 -668
- package/src/util/type-defaults.ts +280 -280
- package/src/util/type-utils.spec.ts +227 -227
- package/src/util/type-utils.ts +144 -144
- package/tsconfig.json +23 -26
- package/tslint.json +57 -57
- package/.claude/settings.local.json +0 -8
- package/scripts/output.png +0 -0
- package/scripts/test-get-request.ts +0 -35
|
@@ -1,904 +1,904 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const mockObj1234 = {
|
|
4
|
-
id: 1234,
|
|
5
|
-
typePath: 'color'
|
|
6
|
-
};
|
|
7
|
-
const mockObj2222 = {
|
|
8
|
-
id: 2222,
|
|
9
|
-
typePath: 'color'
|
|
10
|
-
};
|
|
11
|
-
const mockGetFunction = jest.fn((options) => {
|
|
12
|
-
return (options?.criteria?.id === 1234)
|
|
13
|
-
? [mockObj1234]
|
|
14
|
-
: [mockObj2222];
|
|
15
|
-
});
|
|
16
|
-
jest.mock('@contrail/sdk', () => {
|
|
17
|
-
const origModule = jest.requireActual('@contrail/sdk');
|
|
18
|
-
return {
|
|
19
|
-
__esModule: true,
|
|
20
|
-
...origModule,
|
|
21
|
-
Entities: class {
|
|
22
|
-
constructor() {
|
|
23
|
-
this.get = mockGetFunction;
|
|
24
|
-
}
|
|
25
|
-
},
|
|
26
|
-
};
|
|
27
|
-
});
|
|
28
|
-
const sdk_1 = require("@contrail/sdk");
|
|
29
|
-
const transform_data_1 = require("@contrail/transform-data");
|
|
30
|
-
const data_converter_1 = require("./data-converter");
|
|
31
|
-
const type_conversion_utils_1 = require("./type-conversion-utils");
|
|
32
|
-
const map_utils_1 = require("./map-utils");
|
|
33
|
-
describe('getFlexPLMValue multi_select', () => {
|
|
34
|
-
const config = {
|
|
35
|
-
apiHost: 'host',
|
|
36
|
-
userName: () => 'user',
|
|
37
|
-
password: () => 'pass',
|
|
38
|
-
urlContext: 'xxx',
|
|
39
|
-
vibeEventEndpoint: '/rfa/vibeiq/vibeEvents',
|
|
40
|
-
csrfEndpoint: '/servlet/rest/security/csrf',
|
|
41
|
-
itemPreDevelopmentLifecycleStages: ['concept']
|
|
42
|
-
};
|
|
43
|
-
const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
|
|
44
|
-
const dc = new data_converter_1.DataConverter(config, mapFileUtil);
|
|
45
|
-
const enumAtt = {
|
|
46
|
-
id: 'cJoZQvoj7dkfCBJq',
|
|
47
|
-
propertyType: 'multi_select',
|
|
48
|
-
slug: 'flexMultiSelect',
|
|
49
|
-
label: 'Flex Multi Select',
|
|
50
|
-
options: [
|
|
51
|
-
{
|
|
52
|
-
value: 'one',
|
|
53
|
-
display: 'One'
|
|
54
|
-
},
|
|
55
|
-
{
|
|
56
|
-
value: 'two',
|
|
57
|
-
display: 'Two'
|
|
58
|
-
},
|
|
59
|
-
{
|
|
60
|
-
value: 'three',
|
|
61
|
-
display: 'Three'
|
|
62
|
-
}
|
|
63
|
-
],
|
|
64
|
-
};
|
|
65
|
-
it('multi_select_null', async () => {
|
|
66
|
-
const newData = {
|
|
67
|
-
flexMultiSelect: null
|
|
68
|
-
};
|
|
69
|
-
const returnValue = await dc.getFlexPLMValue(enumAtt, newData, true);
|
|
70
|
-
expect(returnValue).toEqual([]);
|
|
71
|
-
});
|
|
72
|
-
it('multi_select_no_values', async () => {
|
|
73
|
-
const newData = {
|
|
74
|
-
flexMultiSelect: []
|
|
75
|
-
};
|
|
76
|
-
const returnValue = await dc.getFlexPLMValue(enumAtt, newData, true);
|
|
77
|
-
expect(returnValue).toEqual(newData.flexMultiSelect);
|
|
78
|
-
});
|
|
79
|
-
it('multi_select_two_values', async () => {
|
|
80
|
-
const newData = {
|
|
81
|
-
flexMultiSelect: ['one', 'three']
|
|
82
|
-
};
|
|
83
|
-
const optionValues = [
|
|
84
|
-
{ value: 'one', display: 'One' },
|
|
85
|
-
{ value: 'three', display: 'Three' }
|
|
86
|
-
];
|
|
87
|
-
const returnValue = await dc.getFlexPLMValue(enumAtt, newData, true);
|
|
88
|
-
expect(returnValue).toEqual(optionValues);
|
|
89
|
-
});
|
|
90
|
-
});
|
|
91
|
-
describe('getEnumerationValue', () => {
|
|
92
|
-
const config = {
|
|
93
|
-
apiHost: 'host',
|
|
94
|
-
userName: () => 'user',
|
|
95
|
-
password: () => 'pass',
|
|
96
|
-
urlContext: 'xxx',
|
|
97
|
-
vibeEventEndpoint: '/rfa/vibeiq/vibeEvents',
|
|
98
|
-
csrfEndpoint: '/servlet/rest/security/csrf',
|
|
99
|
-
itemPreDevelopmentLifecycleStages: ['concept']
|
|
100
|
-
};
|
|
101
|
-
const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
|
|
102
|
-
const dc = new data_converter_1.DataConverter(config, mapFileUtil);
|
|
103
|
-
const enumProp = {
|
|
104
|
-
id: 'cJoZQvoj7dkfCBJq',
|
|
105
|
-
propertyType: 'choice',
|
|
106
|
-
slug: 'flexChoice',
|
|
107
|
-
label: 'Flex Choice',
|
|
108
|
-
options: [
|
|
109
|
-
{
|
|
110
|
-
value: 'one',
|
|
111
|
-
display: 'One'
|
|
112
|
-
},
|
|
113
|
-
{
|
|
114
|
-
value: 'two',
|
|
115
|
-
display: 'Two'
|
|
116
|
-
},
|
|
117
|
-
{
|
|
118
|
-
value: 'three',
|
|
119
|
-
display: 'Three'
|
|
120
|
-
}
|
|
121
|
-
],
|
|
122
|
-
};
|
|
123
|
-
const enumPropNoList = {
|
|
124
|
-
id: 'cJoZQvoj7dkfCBJq',
|
|
125
|
-
propertyType: 'choice',
|
|
126
|
-
slug: 'flexChoice',
|
|
127
|
-
label: 'Flex Choice',
|
|
128
|
-
};
|
|
129
|
-
it('match 1 key', () => {
|
|
130
|
-
const nd = 'one';
|
|
131
|
-
const expectedValue = { value: 'one', display: 'One' };
|
|
132
|
-
const returnValue = dc.getEnumerationValue(enumProp, nd);
|
|
133
|
-
expect(returnValue).toEqual(expectedValue);
|
|
134
|
-
});
|
|
135
|
-
it('wrong key', () => {
|
|
136
|
-
const nd = 'one1';
|
|
137
|
-
const expectedValue = {};
|
|
138
|
-
const returnValue = dc.getEnumerationValue(enumProp, nd);
|
|
139
|
-
expect(returnValue).toEqual(expectedValue);
|
|
140
|
-
});
|
|
141
|
-
it('property no list', () => {
|
|
142
|
-
const nd = 'one1';
|
|
143
|
-
const expectedValue = {};
|
|
144
|
-
const returnValue = dc.getEnumerationValue(enumPropNoList, nd);
|
|
145
|
-
expect(returnValue).toEqual(expectedValue);
|
|
146
|
-
});
|
|
147
|
-
});
|
|
148
|
-
describe('getEnumerationValue multi_select', () => {
|
|
149
|
-
const config = {
|
|
150
|
-
apiHost: 'host',
|
|
151
|
-
userName: () => 'user',
|
|
152
|
-
password: () => 'pass',
|
|
153
|
-
urlContext: 'xxx',
|
|
154
|
-
vibeEventEndpoint: '/rfa/vibeiq/vibeEvents',
|
|
155
|
-
csrfEndpoint: '/servlet/rest/security/csrf',
|
|
156
|
-
itemPreDevelopmentLifecycleStages: ['concept']
|
|
157
|
-
};
|
|
158
|
-
const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
|
|
159
|
-
const dc = new data_converter_1.DataConverter(config, mapFileUtil);
|
|
160
|
-
const enumAtt = {
|
|
161
|
-
id: 'cJoZQvoj7dkfCBJq',
|
|
162
|
-
propertyType: 'multi_select',
|
|
163
|
-
slug: 'flexMultiSelect',
|
|
164
|
-
label: 'Flex Multi Select',
|
|
165
|
-
options: [
|
|
166
|
-
{
|
|
167
|
-
value: 'one',
|
|
168
|
-
display: 'One'
|
|
169
|
-
},
|
|
170
|
-
{
|
|
171
|
-
value: 'two',
|
|
172
|
-
display: 'Two'
|
|
173
|
-
},
|
|
174
|
-
{
|
|
175
|
-
value: 'three',
|
|
176
|
-
display: 'Three'
|
|
177
|
-
}
|
|
178
|
-
],
|
|
179
|
-
};
|
|
180
|
-
it('multi_select_null', async () => {
|
|
181
|
-
const nd = null;
|
|
182
|
-
const returnValue = await dc.getEnumerationValue(enumAtt, nd);
|
|
183
|
-
expect(returnValue).toEqual([]);
|
|
184
|
-
});
|
|
185
|
-
it('multi_select_no_values', async () => {
|
|
186
|
-
const nd = [];
|
|
187
|
-
const returnValue = await dc.getEnumerationValue(enumAtt, nd);
|
|
188
|
-
expect(returnValue).toEqual(nd);
|
|
189
|
-
});
|
|
190
|
-
it('multi select one string value', async () => {
|
|
191
|
-
const nd = 'one';
|
|
192
|
-
const optionValues = [
|
|
193
|
-
{ value: 'one', display: 'One' }
|
|
194
|
-
];
|
|
195
|
-
const returnValue = await dc.getEnumerationValue(enumAtt, nd);
|
|
196
|
-
expect(returnValue).toEqual(optionValues);
|
|
197
|
-
});
|
|
198
|
-
it('multi_select_two_values', async () => {
|
|
199
|
-
const nd = ['one', 'three'];
|
|
200
|
-
const optionValues = [
|
|
201
|
-
{ value: 'one', display: 'One' },
|
|
202
|
-
{ value: 'three', display: 'Three' }
|
|
203
|
-
];
|
|
204
|
-
const returnValue = await dc.getEnumerationValue(enumAtt, nd);
|
|
205
|
-
expect(returnValue).toEqual(optionValues);
|
|
206
|
-
});
|
|
207
|
-
});
|
|
208
|
-
describe('getPersistableChanges', () => {
|
|
209
|
-
const config = {
|
|
210
|
-
apiHost: 'host',
|
|
211
|
-
userName: () => 'user',
|
|
212
|
-
password: () => 'pass',
|
|
213
|
-
urlContext: 'xxx',
|
|
214
|
-
vibeEventEndpoint: '/rfa/vibeiq/vibeEvents',
|
|
215
|
-
csrfEndpoint: '/servlet/rest/security/csrf',
|
|
216
|
-
itemPreDevelopmentLifecycleStages: ['concept']
|
|
217
|
-
};
|
|
218
|
-
const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
|
|
219
|
-
const dc = new data_converter_1.DataConverter(config, mapFileUtil);
|
|
220
|
-
it('no changes', () => {
|
|
221
|
-
const entity = {
|
|
222
|
-
num: 1
|
|
223
|
-
};
|
|
224
|
-
const potentialChanges = {};
|
|
225
|
-
const diffs = dc.getPersistableChanges(entity, potentialChanges);
|
|
226
|
-
expect(Object.getOwnPropertyNames(diffs).length).toEqual(0);
|
|
227
|
-
});
|
|
228
|
-
it('same value', () => {
|
|
229
|
-
const entity = {
|
|
230
|
-
str: 'test',
|
|
231
|
-
num: 1
|
|
232
|
-
};
|
|
233
|
-
const potentialChanges = {
|
|
234
|
-
str: 'test',
|
|
235
|
-
num: 1
|
|
236
|
-
};
|
|
237
|
-
const diffs = dc.getPersistableChanges(entity, potentialChanges);
|
|
238
|
-
expect(Object.getOwnPropertyNames(diffs).length).toEqual(0);
|
|
239
|
-
});
|
|
240
|
-
it('diff num value', () => {
|
|
241
|
-
const entity = {
|
|
242
|
-
str: 'option 1 string-Changed',
|
|
243
|
-
num: 12
|
|
244
|
-
};
|
|
245
|
-
const potentialChanges = {
|
|
246
|
-
str: 'option 1 string-Changed',
|
|
247
|
-
num: 1
|
|
248
|
-
};
|
|
249
|
-
const diffs = dc.getPersistableChanges(entity, potentialChanges);
|
|
250
|
-
expect(Object.getOwnPropertyNames(diffs).length).toEqual(1);
|
|
251
|
-
expect(diffs['num']).toEqual(potentialChanges['num']);
|
|
252
|
-
});
|
|
253
|
-
it('zero num value', () => {
|
|
254
|
-
const entity = {
|
|
255
|
-
str: 'option 1 string-Changed',
|
|
256
|
-
num: 12
|
|
257
|
-
};
|
|
258
|
-
const potentialChanges = {
|
|
259
|
-
str: 'option 1 string-Changed',
|
|
260
|
-
num: 0
|
|
261
|
-
};
|
|
262
|
-
const diffs = dc.getPersistableChanges(entity, potentialChanges);
|
|
263
|
-
expect(Object.getOwnPropertyNames(diffs).length).toEqual(1);
|
|
264
|
-
expect(diffs['num']).toEqual(potentialChanges['num']);
|
|
265
|
-
});
|
|
266
|
-
it('diff str value', () => {
|
|
267
|
-
const entity = {
|
|
268
|
-
str: 'test',
|
|
269
|
-
num: 1
|
|
270
|
-
};
|
|
271
|
-
const potentialChanges = {
|
|
272
|
-
str: 'test-1',
|
|
273
|
-
num: 1
|
|
274
|
-
};
|
|
275
|
-
const diffs = dc.getPersistableChanges(entity, potentialChanges);
|
|
276
|
-
expect(Object.getOwnPropertyNames(diffs).length).toEqual(1);
|
|
277
|
-
expect(diffs['str']).toEqual(potentialChanges['str']);
|
|
278
|
-
});
|
|
279
|
-
it('empty str value', () => {
|
|
280
|
-
const entity = {
|
|
281
|
-
str: 'test',
|
|
282
|
-
num: 1
|
|
283
|
-
};
|
|
284
|
-
const potentialChanges = {
|
|
285
|
-
str: '',
|
|
286
|
-
num: 1
|
|
287
|
-
};
|
|
288
|
-
const diffs = dc.getPersistableChanges(entity, potentialChanges);
|
|
289
|
-
expect(Object.getOwnPropertyNames(diffs).length).toEqual(1);
|
|
290
|
-
expect(diffs['str']).toBeNull();
|
|
291
|
-
});
|
|
292
|
-
});
|
|
293
|
-
describe('getObjectReferenceValue cache', () => {
|
|
294
|
-
const config = {
|
|
295
|
-
apiHost: 'host',
|
|
296
|
-
userName: () => 'user',
|
|
297
|
-
password: () => 'pass',
|
|
298
|
-
urlContext: 'xxx',
|
|
299
|
-
vibeEventEndpoint: '/rfa/vibeiq/vibeEvents',
|
|
300
|
-
csrfEndpoint: '/servlet/rest/security/csrf',
|
|
301
|
-
itemPreDevelopmentLifecycleStages: ['concept']
|
|
302
|
-
};
|
|
303
|
-
const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
|
|
304
|
-
const dc = new data_converter_1.DataConverter(config, mapFileUtil);
|
|
305
|
-
const ref1Prop = {
|
|
306
|
-
id: 'cJoZQvoj7dkfCBJq',
|
|
307
|
-
propertyType: 'object_reference',
|
|
308
|
-
slug: 'ref1',
|
|
309
|
-
label: 'Object Ref#1',
|
|
310
|
-
referencedTypeRootSlug: 'color'
|
|
311
|
-
};
|
|
312
|
-
const ref2Prop = {
|
|
313
|
-
id: 'cJoZQvoj7dkfCBJq',
|
|
314
|
-
propertyType: 'object_reference',
|
|
315
|
-
slug: 'ref2',
|
|
316
|
-
label: 'Object Ref#2',
|
|
317
|
-
referencedTypeRootSlug: 'color'
|
|
318
|
-
};
|
|
319
|
-
const ref3Prop = {
|
|
320
|
-
id: 'cJoZQvoj7dkfCBJq',
|
|
321
|
-
propertyType: 'object_reference',
|
|
322
|
-
slug: 'ref3',
|
|
323
|
-
label: 'Object Ref#3',
|
|
324
|
-
referencedTypeRootSlug: 'color'
|
|
325
|
-
};
|
|
326
|
-
const newData = {
|
|
327
|
-
ref1Id: 1234,
|
|
328
|
-
ref2Id: 2222,
|
|
329
|
-
ref3Id: 1234
|
|
330
|
-
};
|
|
331
|
-
it('cache hit', async () => {
|
|
332
|
-
const oobFunction = dc.getFlexPLMObjectData;
|
|
333
|
-
try {
|
|
334
|
-
dc.getFlexPLMObjectData = async (newData) => {
|
|
335
|
-
return newData;
|
|
336
|
-
};
|
|
337
|
-
mockGetFunction.mockClear();
|
|
338
|
-
const r1 = await dc.getObjectReferenceValue(ref1Prop, newData, true);
|
|
339
|
-
const r2 = await dc.getObjectReferenceValue(ref2Prop, newData, true);
|
|
340
|
-
const r3 = await dc.getObjectReferenceValue(ref3Prop, newData, true);
|
|
341
|
-
expect(mockGetFunction).toHaveBeenCalledTimes(2);
|
|
342
|
-
expect(r1).toEqual(mockObj1234);
|
|
343
|
-
expect(r2).toEqual(mockObj2222);
|
|
344
|
-
expect(r3).toEqual(mockObj1234);
|
|
345
|
-
}
|
|
346
|
-
finally {
|
|
347
|
-
dc.getFlexPLMObjectData = oobFunction;
|
|
348
|
-
}
|
|
349
|
-
});
|
|
350
|
-
});
|
|
351
|
-
describe('getObjectReferenceValue bad value', () => {
|
|
352
|
-
const config = {
|
|
353
|
-
apiHost: 'host',
|
|
354
|
-
userName: () => 'user',
|
|
355
|
-
password: () => 'pass',
|
|
356
|
-
urlContext: 'xxx',
|
|
357
|
-
vibeEventEndpoint: '/rfa/vibeiq/vibeEvents',
|
|
358
|
-
csrfEndpoint: '/servlet/rest/security/csrf',
|
|
359
|
-
itemPreDevelopmentLifecycleStages: ['concept']
|
|
360
|
-
};
|
|
361
|
-
const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
|
|
362
|
-
const dc = new data_converter_1.DataConverter(config, mapFileUtil);
|
|
363
|
-
const ref1Prop = {
|
|
364
|
-
id: 'cJoZQvoj7dkfCBJq',
|
|
365
|
-
propertyType: 'object_reference',
|
|
366
|
-
slug: 'ref1',
|
|
367
|
-
label: 'Object Ref#1',
|
|
368
|
-
referencedTypeRootSlug: 'color'
|
|
369
|
-
};
|
|
370
|
-
const ref2Prop = {
|
|
371
|
-
id: 'cJoZQvoj7dkfCBJq',
|
|
372
|
-
propertyType: 'object_reference',
|
|
373
|
-
slug: 'ref2',
|
|
374
|
-
label: 'Object Ref#2',
|
|
375
|
-
referencedTypeRootSlug: 'color'
|
|
376
|
-
};
|
|
377
|
-
const ref3Prop = {
|
|
378
|
-
id: 'cJoZQvoj7dkfCBJq',
|
|
379
|
-
propertyType: 'object_reference',
|
|
380
|
-
slug: 'ref3',
|
|
381
|
-
label: 'Object Ref#3',
|
|
382
|
-
referencedTypeRootSlug: 'color'
|
|
383
|
-
};
|
|
384
|
-
const newData = {
|
|
385
|
-
ref1Id: 1234,
|
|
386
|
-
ref2Id: 2222,
|
|
387
|
-
ref3Id: 1234,
|
|
388
|
-
ref3: 'old value'
|
|
389
|
-
};
|
|
390
|
-
it('old string value', async () => {
|
|
391
|
-
const oobFunction = dc.getFlexPLMObjectData;
|
|
392
|
-
try {
|
|
393
|
-
dc.getFlexPLMObjectData = async (newData) => {
|
|
394
|
-
return newData;
|
|
395
|
-
};
|
|
396
|
-
mockGetFunction.mockClear();
|
|
397
|
-
const r3 = await dc.getObjectReferenceValue(ref3Prop, newData, true);
|
|
398
|
-
expect(r3).toEqual(mockObj1234);
|
|
399
|
-
}
|
|
400
|
-
finally {
|
|
401
|
-
dc.getFlexPLMObjectData = oobFunction;
|
|
402
|
-
}
|
|
403
|
-
});
|
|
404
|
-
it('only id', async () => {
|
|
405
|
-
const oobFunction = dc.getFlexPLMObjectData;
|
|
406
|
-
try {
|
|
407
|
-
dc.getFlexPLMObjectData = async (newData) => {
|
|
408
|
-
return newData;
|
|
409
|
-
};
|
|
410
|
-
mockGetFunction.mockClear();
|
|
411
|
-
const r2 = await dc.getObjectReferenceValue(ref2Prop, newData, true);
|
|
412
|
-
expect(r2).toEqual(mockObj2222);
|
|
413
|
-
}
|
|
414
|
-
finally {
|
|
415
|
-
dc.getFlexPLMObjectData = oobFunction;
|
|
416
|
-
}
|
|
417
|
-
});
|
|
418
|
-
it('already references object', async () => {
|
|
419
|
-
const testData = {
|
|
420
|
-
ref1Id: 1234,
|
|
421
|
-
ref1: mockObj1234,
|
|
422
|
-
ref2Id: 2222,
|
|
423
|
-
ref3Id: 1234,
|
|
424
|
-
ref3: 'old value'
|
|
425
|
-
};
|
|
426
|
-
const oobFunction = dc.getFlexPLMObjectData;
|
|
427
|
-
try {
|
|
428
|
-
dc.getFlexPLMObjectData = async (newData) => {
|
|
429
|
-
return newData;
|
|
430
|
-
};
|
|
431
|
-
mockGetFunction.mockClear();
|
|
432
|
-
const r1 = await dc.getObjectReferenceValue(ref1Prop, testData, true);
|
|
433
|
-
expect(r1).toEqual(mockObj1234);
|
|
434
|
-
}
|
|
435
|
-
finally {
|
|
436
|
-
dc.getFlexPLMObjectData = oobFunction;
|
|
437
|
-
}
|
|
438
|
-
});
|
|
439
|
-
it('old string value, no refId', async () => {
|
|
440
|
-
const testData = {
|
|
441
|
-
ref1: 'old value'
|
|
442
|
-
};
|
|
443
|
-
const oobFunction = dc.getFlexPLMObjectData;
|
|
444
|
-
try {
|
|
445
|
-
dc.getFlexPLMObjectData = async (newData) => {
|
|
446
|
-
return newData;
|
|
447
|
-
};
|
|
448
|
-
mockGetFunction.mockClear();
|
|
449
|
-
const r1 = await dc.getObjectReferenceValue(ref1Prop, testData, true);
|
|
450
|
-
expect(r1).toEqual({});
|
|
451
|
-
}
|
|
452
|
-
finally {
|
|
453
|
-
dc.getFlexPLMObjectData = oobFunction;
|
|
454
|
-
}
|
|
455
|
-
});
|
|
456
|
-
});
|
|
457
|
-
describe('getObjectReferenceValue - use mapping', () => {
|
|
458
|
-
const maps = require('./data-converter-spec-mockData');
|
|
459
|
-
const mapping = maps['mapping'];
|
|
460
|
-
const config = {
|
|
461
|
-
apiHost: 'host',
|
|
462
|
-
userName: () => 'user',
|
|
463
|
-
password: () => 'pass',
|
|
464
|
-
urlContext: 'xxx',
|
|
465
|
-
transformMapFile: 'file1',
|
|
466
|
-
vibeEventEndpoint: '/rfa/vibeiq/vibeEvents',
|
|
467
|
-
csrfEndpoint: '/servlet/rest/security/csrf',
|
|
468
|
-
itemPreDevelopmentLifecycleStages: ['concept']
|
|
469
|
-
};
|
|
470
|
-
const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
|
|
471
|
-
const dc = new data_converter_1.DataConverter(config, mapFileUtil);
|
|
472
|
-
const ref1Prop = {
|
|
473
|
-
id: 'cJoZQvoj7dkfCBJq',
|
|
474
|
-
propertyType: 'object_reference',
|
|
475
|
-
slug: 'ref1',
|
|
476
|
-
label: 'Object Ref#1',
|
|
477
|
-
referencedTypeRootSlug: 'color'
|
|
478
|
-
};
|
|
479
|
-
const ref2Prop = {
|
|
480
|
-
id: 'cJoZQvoj7dkfCBJq',
|
|
481
|
-
propertyType: 'object_reference',
|
|
482
|
-
slug: 'ref2',
|
|
483
|
-
label: 'Object Ref#2',
|
|
484
|
-
referencedTypeRootSlug: 'color'
|
|
485
|
-
};
|
|
486
|
-
const ref3Prop = {
|
|
487
|
-
id: 'cJoZQvoj7dkfCBJq',
|
|
488
|
-
propertyType: 'object_reference',
|
|
489
|
-
slug: 'ref3',
|
|
490
|
-
label: 'Object Ref#3',
|
|
491
|
-
referencedTypeRootSlug: 'color'
|
|
492
|
-
};
|
|
493
|
-
const newData = {
|
|
494
|
-
ref1Id: 1234,
|
|
495
|
-
ref1: mockObj1234,
|
|
496
|
-
ref2Id: 2222,
|
|
497
|
-
ref2: mockObj2222,
|
|
498
|
-
ref3Id: 1234,
|
|
499
|
-
ref3: mockObj1234
|
|
500
|
-
};
|
|
501
|
-
it('mapping test', async () => {
|
|
502
|
-
const oobFunction = dc.getFlexPLMObjectData;
|
|
503
|
-
try {
|
|
504
|
-
dc.getFlexPLMObjectData = async (newData) => {
|
|
505
|
-
return newData;
|
|
506
|
-
};
|
|
507
|
-
mockGetFunction.mockClear();
|
|
508
|
-
let spyGetObjectClass = jest.spyOn(type_conversion_utils_1.TypeConversionUtils, 'getObjectClass')
|
|
509
|
-
.mockImplementation(async () => { return 'LCSColor'; });
|
|
510
|
-
let spyGetObjectTypePath = jest.spyOn(type_conversion_utils_1.TypeConversionUtils, 'getObjectTypePath')
|
|
511
|
-
.mockImplementation(async () => { return 'Color'; });
|
|
512
|
-
let spyGetMapKey = jest.spyOn(type_conversion_utils_1.TypeConversionUtils, 'getMapKey')
|
|
513
|
-
.mockImplementation(async () => { return 'LCSColor'; });
|
|
514
|
-
let spyApplyTransformMap = jest.spyOn(map_utils_1.MapUtil, 'applyTransformMap')
|
|
515
|
-
.mockImplementation(async (...args) => { return args[2]; });
|
|
516
|
-
const r1 = await dc.getObjectReferenceValue(ref1Prop, newData, true);
|
|
517
|
-
const r2 = await dc.getObjectReferenceValue(ref2Prop, newData, true);
|
|
518
|
-
expect(spyGetObjectClass).toHaveBeenCalledTimes(2);
|
|
519
|
-
expect(spyGetObjectTypePath).toHaveBeenCalledTimes(2);
|
|
520
|
-
expect(spyGetMapKey).toHaveBeenCalledTimes(2);
|
|
521
|
-
expect(spyApplyTransformMap).toHaveBeenCalledTimes(2);
|
|
522
|
-
}
|
|
523
|
-
finally {
|
|
524
|
-
dc.getFlexPLMObjectData = oobFunction;
|
|
525
|
-
}
|
|
526
|
-
});
|
|
527
|
-
});
|
|
528
|
-
describe('setEnumerationKeys', () => {
|
|
529
|
-
const config = {
|
|
530
|
-
apiHost: 'host',
|
|
531
|
-
userName: () => 'user',
|
|
532
|
-
password: () => 'pass',
|
|
533
|
-
urlContext: 'xxx',
|
|
534
|
-
vibeEventEndpoint: '/rfa/vibeiq/vibeEvents',
|
|
535
|
-
csrfEndpoint: '/servlet/rest/security/csrf',
|
|
536
|
-
itemPreDevelopmentLifecycleStages: ['concept']
|
|
537
|
-
};
|
|
538
|
-
const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
|
|
539
|
-
const dc = new data_converter_1.DataConverter(config, mapFileUtil);
|
|
540
|
-
const enumProp = {
|
|
541
|
-
id: 'cJoZQvoj7dkfCBJq',
|
|
542
|
-
propertyType: 'multi_select',
|
|
543
|
-
slug: 'flexMultiSelect',
|
|
544
|
-
label: 'Flex Multi Select',
|
|
545
|
-
options: [
|
|
546
|
-
{
|
|
547
|
-
value: 'one',
|
|
548
|
-
display: 'One'
|
|
549
|
-
},
|
|
550
|
-
{
|
|
551
|
-
value: 'two',
|
|
552
|
-
display: 'Two'
|
|
553
|
-
},
|
|
554
|
-
{
|
|
555
|
-
value: 'three',
|
|
556
|
-
display: 'Three'
|
|
557
|
-
}
|
|
558
|
-
],
|
|
559
|
-
};
|
|
560
|
-
const enumPropNoList = {
|
|
561
|
-
id: 'cJoZQvoj7dkfCBJq',
|
|
562
|
-
propertyType: 'multi_select',
|
|
563
|
-
slug: 'flexMultiSelect',
|
|
564
|
-
label: 'Flex Multi Select',
|
|
565
|
-
};
|
|
566
|
-
it('match 1 key', () => {
|
|
567
|
-
const newData = [{ value: 'one', display: 'One' }];
|
|
568
|
-
const returnValue = dc.setEnumerationKeys(enumProp, newData, false);
|
|
569
|
-
expect(returnValue).toEqual(['one']);
|
|
570
|
-
});
|
|
571
|
-
it('match 2 key', () => {
|
|
572
|
-
const newData = [{ value: 'one', display: 'One' }, { value: 'two', display: 'Two' }];
|
|
573
|
-
const returnValue = dc.setEnumerationKeys(enumProp, newData, false);
|
|
574
|
-
expect(returnValue).toEqual(['one', 'two']);
|
|
575
|
-
});
|
|
576
|
-
it('match 1 display', () => {
|
|
577
|
-
const newData = [{ value: 'one', display: 'One' }];
|
|
578
|
-
const returnValue = dc.setEnumerationKeys(enumProp, newData, true);
|
|
579
|
-
expect(returnValue).toEqual(['one']);
|
|
580
|
-
});
|
|
581
|
-
it('match 2 display', () => {
|
|
582
|
-
const newData = [{ value: 'one', display: 'One' }, { value: 'two', display: 'Two' }];
|
|
583
|
-
const returnValue = dc.setEnumerationKeys(enumProp, newData, true);
|
|
584
|
-
expect(returnValue).toEqual(['one', 'two']);
|
|
585
|
-
});
|
|
586
|
-
it('property no list', () => {
|
|
587
|
-
const newData = [{ value: 'one', display: 'One' }, { value: 'two', display: 'Two' }];
|
|
588
|
-
const returnValue = dc.setEnumerationKeys(enumPropNoList, newData, false);
|
|
589
|
-
expect(returnValue).toEqual([]);
|
|
590
|
-
});
|
|
591
|
-
});
|
|
592
|
-
describe('checkKeysAndValues', () => {
|
|
593
|
-
const config = {
|
|
594
|
-
apiHost: 'host',
|
|
595
|
-
userName: () => 'user',
|
|
596
|
-
password: () => 'pass',
|
|
597
|
-
urlContext: 'xxx',
|
|
598
|
-
vibeEventEndpoint: '/rfa/vibeiq/vibeEvents',
|
|
599
|
-
csrfEndpoint: '/servlet/rest/security/csrf',
|
|
600
|
-
itemPreDevelopmentLifecycleStages: ['concept']
|
|
601
|
-
};
|
|
602
|
-
const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
|
|
603
|
-
const dc = new data_converter_1.DataConverter(config, mapFileUtil);
|
|
604
|
-
const groupData = [
|
|
605
|
-
{ name: 'Group 1', typePath: 'custom-entity:grouping' },
|
|
606
|
-
{ name: 'Group 2', typePath: 'custom-entity:grouping' },
|
|
607
|
-
{ name: 'Group 2', typePath: 'custom-entity:grouping' },
|
|
608
|
-
{ name: 'Group 4', typePath: 'custom-entity:grouping' },
|
|
609
|
-
{ name: 'Group 4', typePath: 'custom-entity:grouping:sub' },
|
|
610
|
-
{ name: 'Group 5', typePath: 'custom-entity:grouping:sub' }
|
|
611
|
-
];
|
|
612
|
-
it('Group 1', () => {
|
|
613
|
-
const criteria = {
|
|
614
|
-
name: 'Group 1'
|
|
615
|
-
};
|
|
616
|
-
const typePath = 'custom-entity:grouping';
|
|
617
|
-
const results = dc.checkKeysAndValues(criteria, groupData, typePath);
|
|
618
|
-
expect(results.length).toBe(1);
|
|
619
|
-
});
|
|
620
|
-
it('Group 5 - sub type of typePath', () => {
|
|
621
|
-
const criteria = {
|
|
622
|
-
name: 'Group 5'
|
|
623
|
-
};
|
|
624
|
-
const typePath = 'custom-entity:grouping';
|
|
625
|
-
const results = dc.checkKeysAndValues(criteria, groupData, typePath);
|
|
626
|
-
expect(results.length).toBe(1);
|
|
627
|
-
});
|
|
628
|
-
it('Group 2 - returns the 2 matching', () => {
|
|
629
|
-
const criteria = {
|
|
630
|
-
name: 'Group 2'
|
|
631
|
-
};
|
|
632
|
-
const typePath = 'custom-entity:grouping';
|
|
633
|
-
const results = dc.checkKeysAndValues(criteria, groupData, typePath);
|
|
634
|
-
expect(results.length).toBe(2);
|
|
635
|
-
});
|
|
636
|
-
it('2 Same Name - but 1 is a sub type; returns 2', () => {
|
|
637
|
-
const criteria = {
|
|
638
|
-
name: 'Group 4'
|
|
639
|
-
};
|
|
640
|
-
const typePath = 'custom-entity:grouping';
|
|
641
|
-
const results = dc.checkKeysAndValues(criteria, groupData, typePath);
|
|
642
|
-
expect(results.length).toBe(2);
|
|
643
|
-
});
|
|
644
|
-
it('2 Same Name - but 1 wrong type', () => {
|
|
645
|
-
const criteria = {
|
|
646
|
-
name: 'Group 1'
|
|
647
|
-
};
|
|
648
|
-
const testData = [...groupData];
|
|
649
|
-
testData.push({ name: 'Group 1', typePath: 'custom-entity:label' });
|
|
650
|
-
const typePath = 'custom-entity:grouping';
|
|
651
|
-
const results = dc.checkKeysAndValues(criteria, testData, typePath);
|
|
652
|
-
expect(results.length).toBe(1);
|
|
653
|
-
});
|
|
654
|
-
it('first & last entity have the wrong typePath', () => {
|
|
655
|
-
const criteria = {
|
|
656
|
-
objectId: "2562",
|
|
657
|
-
};
|
|
658
|
-
const typePath = 'custom-entity:group2';
|
|
659
|
-
const testData = [
|
|
660
|
-
{ "typePath": "custom-entity:group1", "name": "BLACK (BK)", "id": "o1v2rh8olgQ78GcL", "objectId": "2562", "entityType": "custom-entity" },
|
|
661
|
-
{ "typePath": "custom-entity:group2", "name": "BLACK (BK)", "id": "t5n22S2gqswe8GcL", "objectId": "2562", "entityType": "custom-entity" },
|
|
662
|
-
{ "typePath": "custom-entity:group1", "name": "BLACK (BK)", "id": "t5rh8o2gqswk3drt", "objectId": "2562", "entityType": "custom-entity" }
|
|
663
|
-
];
|
|
664
|
-
const results = dc.checkKeysAndValues(criteria, testData, typePath);
|
|
665
|
-
expect(results.length).toBe(1);
|
|
666
|
-
});
|
|
667
|
-
});
|
|
668
|
-
describe('filterOutArchivedAndTrashedEntities', () => {
|
|
669
|
-
const config = {
|
|
670
|
-
apiHost: 'host',
|
|
671
|
-
userName: () => 'user',
|
|
672
|
-
password: () => 'pass',
|
|
673
|
-
urlContext: 'xxx',
|
|
674
|
-
vibeEventEndpoint: '/rfa/vibeiq/vibeEvents',
|
|
675
|
-
csrfEndpoint: '/servlet/rest/security/csrf',
|
|
676
|
-
itemPreDevelopmentLifecycleStages: ['concept']
|
|
677
|
-
};
|
|
678
|
-
const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
|
|
679
|
-
const dc = new data_converter_1.DataConverter(config, mapFileUtil);
|
|
680
|
-
it('filter out isArchived and isTrashed entities', () => {
|
|
681
|
-
const entities = [
|
|
682
|
-
{ id: '1', name: 'Entity 1', isArchived: false, isTrashed: false },
|
|
683
|
-
{ id: '2', name: 'Entity 2', isArchived: true, isTrashed: false },
|
|
684
|
-
{ id: '3', name: 'Entity 3', isArchived: false, isTrashed: true },
|
|
685
|
-
{ id: '4', name: 'Entity 4', isArchived: false, isTrashed: false }
|
|
686
|
-
];
|
|
687
|
-
const filteredEntities = dc.filterOutArchivedAndTrashedEntities(entities);
|
|
688
|
-
expect(filteredEntities.length).toBe(2);
|
|
689
|
-
expect(filteredEntities).toEqual([
|
|
690
|
-
{ id: '1', name: 'Entity 1', isArchived: false, isTrashed: false },
|
|
691
|
-
{ id: '4', name: 'Entity 4', isArchived: false, isTrashed: false }
|
|
692
|
-
]);
|
|
693
|
-
});
|
|
694
|
-
it('no entities to filter', () => {
|
|
695
|
-
const entities = [];
|
|
696
|
-
const filteredEntities = dc.filterOutArchivedAndTrashedEntities(entities);
|
|
697
|
-
expect(filteredEntities.length).toBe(0);
|
|
698
|
-
});
|
|
699
|
-
it('all entities are archived or trashed', () => {
|
|
700
|
-
const entities = [
|
|
701
|
-
{ id: '1', name: 'Entity 1', isArchived: true, isTrashed: false },
|
|
702
|
-
{ id: '2', name: 'Entity 2', isArchived: false, isTrashed: true }
|
|
703
|
-
];
|
|
704
|
-
const filteredEntities = dc.filterOutArchivedAndTrashedEntities(entities);
|
|
705
|
-
expect(filteredEntities.length).toBe(0);
|
|
706
|
-
});
|
|
707
|
-
});
|
|
708
|
-
describe('setUserListValue', () => {
|
|
709
|
-
const config = {
|
|
710
|
-
apiHost: 'host',
|
|
711
|
-
userName: () => 'user',
|
|
712
|
-
password: () => 'pass',
|
|
713
|
-
urlContext: 'xxx',
|
|
714
|
-
vibeEventEndpoint: '/rfa/vibeiq/vibeEvents',
|
|
715
|
-
csrfEndpoint: '/servlet/rest/security/csrf',
|
|
716
|
-
itemPreDevelopmentLifecycleStages: ['concept']
|
|
717
|
-
};
|
|
718
|
-
const userListProp1 = {};
|
|
719
|
-
const userEmailMapping = [
|
|
720
|
-
{
|
|
721
|
-
id: "gxgr46kvdeEOn4cH",
|
|
722
|
-
email: "jessica.smith@vibeiq.com"
|
|
723
|
-
},
|
|
724
|
-
{
|
|
725
|
-
id: "Rl5D0sjuAwelScEK",
|
|
726
|
-
email: "adam.smith@vibeiq.com"
|
|
727
|
-
}
|
|
728
|
-
];
|
|
729
|
-
const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
|
|
730
|
-
const dc = new data_converter_1.DataConverter(config, mapFileUtil);
|
|
731
|
-
let spyGetUserByEmail = jest.spyOn(dc, 'getUserByEmail')
|
|
732
|
-
.mockImplementation(async (nd) => {
|
|
733
|
-
let emaildInput = nd?.email.toLowerCase();
|
|
734
|
-
return userEmailMapping.find((user) => user.email === emaildInput);
|
|
735
|
-
});
|
|
736
|
-
let spyProcessGroupMemberCheck = jest.spyOn(dc, 'processGroupMemberCheck')
|
|
737
|
-
.mockImplementation(async (nd) => { return; });
|
|
738
|
-
afterEach(() => {
|
|
739
|
-
spyGetUserByEmail.mockClear();
|
|
740
|
-
spyProcessGroupMemberCheck.mockClear();
|
|
741
|
-
data_converter_1.DataConverter.clearStaticUserCache();
|
|
742
|
-
});
|
|
743
|
-
afterAll(() => {
|
|
744
|
-
spyGetUserByEmail.mockRestore();
|
|
745
|
-
spyProcessGroupMemberCheck.mockRestore();
|
|
746
|
-
});
|
|
747
|
-
it('no value', async () => {
|
|
748
|
-
const newData = {};
|
|
749
|
-
const returnValue = await dc.setUserListValue(userListProp1, newData);
|
|
750
|
-
expect(returnValue).toEqual('');
|
|
751
|
-
});
|
|
752
|
-
it('miss cache', async () => {
|
|
753
|
-
const newData = { email: 'adam.smith@vibeiq.com' };
|
|
754
|
-
const returnValue = await dc.setUserListValue(userListProp1, newData);
|
|
755
|
-
console.log('returnValue', JSON.stringify(returnValue));
|
|
756
|
-
expect(returnValue).toEqual('Rl5D0sjuAwelScEK');
|
|
757
|
-
expect(spyGetUserByEmail).toHaveBeenCalledTimes(1);
|
|
758
|
-
expect(spyProcessGroupMemberCheck).toHaveBeenCalledTimes(1);
|
|
759
|
-
});
|
|
760
|
-
it('miss cache - two different emails', async () => {
|
|
761
|
-
let newData = { email: 'adam.smith@vibeiq.com' };
|
|
762
|
-
let returnValue = await dc.setUserListValue(userListProp1, newData);
|
|
763
|
-
expect(returnValue).toEqual('Rl5D0sjuAwelScEK');
|
|
764
|
-
expect(spyGetUserByEmail).toHaveBeenCalledTimes(1);
|
|
765
|
-
expect(spyProcessGroupMemberCheck).toHaveBeenCalledTimes(1);
|
|
766
|
-
newData = { email: 'jessica.smith@vibeiq.com' };
|
|
767
|
-
returnValue = await dc.setUserListValue(userListProp1, newData);
|
|
768
|
-
expect(spyGetUserByEmail).toHaveBeenCalledTimes(2);
|
|
769
|
-
expect(spyProcessGroupMemberCheck).toHaveBeenCalledTimes(2);
|
|
770
|
-
});
|
|
771
|
-
it('hit cache same email', async () => {
|
|
772
|
-
const newData = { email: 'adam.smith@vibeiq.com' };
|
|
773
|
-
let returnValue = await dc.setUserListValue(userListProp1, newData);
|
|
774
|
-
expect(returnValue).toEqual('Rl5D0sjuAwelScEK');
|
|
775
|
-
expect(spyGetUserByEmail).toHaveBeenCalledTimes(1);
|
|
776
|
-
expect(spyProcessGroupMemberCheck).toHaveBeenCalledTimes(1);
|
|
777
|
-
returnValue = await dc.setUserListValue(userListProp1, newData);
|
|
778
|
-
expect(returnValue).toEqual('Rl5D0sjuAwelScEK');
|
|
779
|
-
expect(spyGetUserByEmail).toHaveBeenCalledTimes(1);
|
|
780
|
-
expect(spyProcessGroupMemberCheck).toHaveBeenCalledTimes(2);
|
|
781
|
-
});
|
|
782
|
-
it('hit cache same email - new DataConverter entity', async () => {
|
|
783
|
-
const newData = { email: 'adam.smith@vibeiq.com' };
|
|
784
|
-
let returnValue = await dc.setUserListValue(userListProp1, newData);
|
|
785
|
-
expect(returnValue).toEqual('Rl5D0sjuAwelScEK');
|
|
786
|
-
expect(spyGetUserByEmail).toHaveBeenCalledTimes(1);
|
|
787
|
-
expect(spyProcessGroupMemberCheck).toHaveBeenCalledTimes(1);
|
|
788
|
-
const dc2 = new data_converter_1.DataConverter(config, mapFileUtil);
|
|
789
|
-
let spyGetUserByEmail2 = jest.spyOn(dc2, 'getUserByEmail')
|
|
790
|
-
.mockImplementation(async (nd) => {
|
|
791
|
-
let emaildInput = nd?.email.toLowerCase();
|
|
792
|
-
return userEmailMapping.find((user) => user.email === emaildInput);
|
|
793
|
-
});
|
|
794
|
-
let spyProcessGroupMemberCheck2 = jest.spyOn(dc2, 'processGroupMemberCheck')
|
|
795
|
-
.mockImplementation(async (nd) => { return; });
|
|
796
|
-
returnValue = await dc2.setUserListValue(userListProp1, newData);
|
|
797
|
-
expect(returnValue).toEqual('Rl5D0sjuAwelScEK');
|
|
798
|
-
expect(spyGetUserByEmail2).toHaveBeenCalledTimes(0);
|
|
799
|
-
expect(spyProcessGroupMemberCheck2).toHaveBeenCalledTimes(1);
|
|
800
|
-
spyGetUserByEmail2.mockRestore();
|
|
801
|
-
spyProcessGroupMemberCheck2.mockRestore();
|
|
802
|
-
});
|
|
803
|
-
});
|
|
804
|
-
describe('getUserListValue', () => {
|
|
805
|
-
const config = {
|
|
806
|
-
apiHost: 'host',
|
|
807
|
-
userName: () => 'user',
|
|
808
|
-
password: () => 'pass',
|
|
809
|
-
urlContext: 'xxx',
|
|
810
|
-
vibeEventEndpoint: '/rfa/vibeiq/vibeEvents',
|
|
811
|
-
csrfEndpoint: '/servlet/rest/security/csrf',
|
|
812
|
-
itemPreDevelopmentLifecycleStages: ['concept']
|
|
813
|
-
};
|
|
814
|
-
const userListProp1 = {
|
|
815
|
-
slug: 'userList1'
|
|
816
|
-
};
|
|
817
|
-
const userEmailMapping = [
|
|
818
|
-
{
|
|
819
|
-
id: "gxgr46kvdeEOn4cH",
|
|
820
|
-
email: "jessica.smith@vibeiq.com",
|
|
821
|
-
first: 'Jessica',
|
|
822
|
-
last: 'Smith'
|
|
823
|
-
},
|
|
824
|
-
{
|
|
825
|
-
id: "Rl5D0sjuAwelScEK",
|
|
826
|
-
email: "adam.smith@vibeiq.com",
|
|
827
|
-
first: 'Adam',
|
|
828
|
-
last: 'Smith'
|
|
829
|
-
}
|
|
830
|
-
];
|
|
831
|
-
const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
|
|
832
|
-
const dc = new data_converter_1.DataConverter(config, mapFileUtil);
|
|
833
|
-
let spyGetUserById = jest.spyOn(dc, 'getUserById')
|
|
834
|
-
.mockImplementation(async (nd) => {
|
|
835
|
-
return userEmailMapping.find((user) => user.id === nd);
|
|
836
|
-
});
|
|
837
|
-
afterEach(() => {
|
|
838
|
-
spyGetUserById.mockClear();
|
|
839
|
-
data_converter_1.DataConverter.clearStaticUserCache();
|
|
840
|
-
});
|
|
841
|
-
afterAll(() => {
|
|
842
|
-
spyGetUserById.mockRestore();
|
|
843
|
-
});
|
|
844
|
-
it('no value', async () => {
|
|
845
|
-
const newData = {};
|
|
846
|
-
const returnValue = await dc.getUserListValue(userListProp1, newData);
|
|
847
|
-
expect(returnValue).toEqual({});
|
|
848
|
-
});
|
|
849
|
-
it('miss cache', async () => {
|
|
850
|
-
const newData = {
|
|
851
|
-
userList1Id: 'gxgr46kvdeEOn4cH'
|
|
852
|
-
};
|
|
853
|
-
const returnValue = await dc.getUserListValue(userListProp1, newData);
|
|
854
|
-
expect(spyGetUserById).toHaveBeenCalledTimes(1);
|
|
855
|
-
expect(returnValue.email).toEqual('jessica.smith@vibeiq.com');
|
|
856
|
-
expect(returnValue.firstName).toEqual('Jessica');
|
|
857
|
-
expect(returnValue.lastName).toEqual('Smith');
|
|
858
|
-
});
|
|
859
|
-
it('miss cache - two different emails', async () => {
|
|
860
|
-
let newData = { userList1Id: 'gxgr46kvdeEOn4cH' };
|
|
861
|
-
let returnValue = await dc.getUserListValue(userListProp1, newData);
|
|
862
|
-
expect(spyGetUserById).toHaveBeenCalledTimes(1);
|
|
863
|
-
expect(returnValue.email).toEqual('jessica.smith@vibeiq.com');
|
|
864
|
-
expect(returnValue.firstName).toEqual('Jessica');
|
|
865
|
-
expect(returnValue.lastName).toEqual('Smith');
|
|
866
|
-
newData = { userList1Id: 'Rl5D0sjuAwelScEK' };
|
|
867
|
-
returnValue = await dc.getUserListValue(userListProp1, newData);
|
|
868
|
-
expect(spyGetUserById).toHaveBeenCalledTimes(2);
|
|
869
|
-
expect(returnValue.email).toEqual('adam.smith@vibeiq.com');
|
|
870
|
-
expect(returnValue.firstName).toEqual('Adam');
|
|
871
|
-
expect(returnValue.lastName).toEqual('Smith');
|
|
872
|
-
});
|
|
873
|
-
it('hit cache same email', async () => {
|
|
874
|
-
const newData = { userList1Id: 'gxgr46kvdeEOn4cH' };
|
|
875
|
-
let returnValue = await dc.getUserListValue(userListProp1, newData);
|
|
876
|
-
expect(spyGetUserById).toHaveBeenCalledTimes(1);
|
|
877
|
-
expect(returnValue.email).toEqual('jessica.smith@vibeiq.com');
|
|
878
|
-
expect(returnValue.firstName).toEqual('Jessica');
|
|
879
|
-
expect(returnValue.lastName).toEqual('Smith');
|
|
880
|
-
returnValue = await dc.getUserListValue(userListProp1, newData);
|
|
881
|
-
expect(spyGetUserById).toHaveBeenCalledTimes(1);
|
|
882
|
-
expect(returnValue.email).toEqual('jessica.smith@vibeiq.com');
|
|
883
|
-
expect(returnValue.firstName).toEqual('Jessica');
|
|
884
|
-
expect(returnValue.lastName).toEqual('Smith');
|
|
885
|
-
});
|
|
886
|
-
it('hit cache same email - new DataConverter entity', async () => {
|
|
887
|
-
const newData = { userList1Id: 'gxgr46kvdeEOn4cH' };
|
|
888
|
-
let returnValue = await dc.getUserListValue(userListProp1, newData);
|
|
889
|
-
expect(spyGetUserById).toHaveBeenCalledTimes(1);
|
|
890
|
-
expect(returnValue.email).toEqual('jessica.smith@vibeiq.com');
|
|
891
|
-
expect(returnValue.firstName).toEqual('Jessica');
|
|
892
|
-
expect(returnValue.lastName).toEqual('Smith');
|
|
893
|
-
const dc2 = new data_converter_1.DataConverter(config, mapFileUtil);
|
|
894
|
-
let spyGetUserById2 = jest.spyOn(dc2, 'getUserById')
|
|
895
|
-
.mockImplementation(async (nd) => {
|
|
896
|
-
return userEmailMapping.find((user) => user.id === nd);
|
|
897
|
-
});
|
|
898
|
-
returnValue = await dc2.getUserListValue(userListProp1, newData);
|
|
899
|
-
expect(spyGetUserById2).toHaveBeenCalledTimes(0);
|
|
900
|
-
expect(returnValue.email).toEqual('jessica.smith@vibeiq.com');
|
|
901
|
-
expect(returnValue.firstName).toEqual('Jessica');
|
|
902
|
-
expect(returnValue.lastName).toEqual('Smith');
|
|
903
|
-
});
|
|
904
|
-
});
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const mockObj1234 = {
|
|
4
|
+
id: 1234,
|
|
5
|
+
typePath: 'color'
|
|
6
|
+
};
|
|
7
|
+
const mockObj2222 = {
|
|
8
|
+
id: 2222,
|
|
9
|
+
typePath: 'color'
|
|
10
|
+
};
|
|
11
|
+
const mockGetFunction = jest.fn((options) => {
|
|
12
|
+
return (options?.criteria?.id === 1234)
|
|
13
|
+
? [mockObj1234]
|
|
14
|
+
: [mockObj2222];
|
|
15
|
+
});
|
|
16
|
+
jest.mock('@contrail/sdk', () => {
|
|
17
|
+
const origModule = jest.requireActual('@contrail/sdk');
|
|
18
|
+
return {
|
|
19
|
+
__esModule: true,
|
|
20
|
+
...origModule,
|
|
21
|
+
Entities: class {
|
|
22
|
+
constructor() {
|
|
23
|
+
this.get = mockGetFunction;
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
});
|
|
28
|
+
const sdk_1 = require("@contrail/sdk");
|
|
29
|
+
const transform_data_1 = require("@contrail/transform-data");
|
|
30
|
+
const data_converter_1 = require("./data-converter");
|
|
31
|
+
const type_conversion_utils_1 = require("./type-conversion-utils");
|
|
32
|
+
const map_utils_1 = require("./map-utils");
|
|
33
|
+
describe('getFlexPLMValue multi_select', () => {
|
|
34
|
+
const config = {
|
|
35
|
+
apiHost: 'host',
|
|
36
|
+
userName: () => 'user',
|
|
37
|
+
password: () => 'pass',
|
|
38
|
+
urlContext: 'xxx',
|
|
39
|
+
vibeEventEndpoint: '/rfa/vibeiq/vibeEvents',
|
|
40
|
+
csrfEndpoint: '/servlet/rest/security/csrf',
|
|
41
|
+
itemPreDevelopmentLifecycleStages: ['concept']
|
|
42
|
+
};
|
|
43
|
+
const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
|
|
44
|
+
const dc = new data_converter_1.DataConverter(config, mapFileUtil);
|
|
45
|
+
const enumAtt = {
|
|
46
|
+
id: 'cJoZQvoj7dkfCBJq',
|
|
47
|
+
propertyType: 'multi_select',
|
|
48
|
+
slug: 'flexMultiSelect',
|
|
49
|
+
label: 'Flex Multi Select',
|
|
50
|
+
options: [
|
|
51
|
+
{
|
|
52
|
+
value: 'one',
|
|
53
|
+
display: 'One'
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
value: 'two',
|
|
57
|
+
display: 'Two'
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
value: 'three',
|
|
61
|
+
display: 'Three'
|
|
62
|
+
}
|
|
63
|
+
],
|
|
64
|
+
};
|
|
65
|
+
it('multi_select_null', async () => {
|
|
66
|
+
const newData = {
|
|
67
|
+
flexMultiSelect: null
|
|
68
|
+
};
|
|
69
|
+
const returnValue = await dc.getFlexPLMValue(enumAtt, newData, true);
|
|
70
|
+
expect(returnValue).toEqual([]);
|
|
71
|
+
});
|
|
72
|
+
it('multi_select_no_values', async () => {
|
|
73
|
+
const newData = {
|
|
74
|
+
flexMultiSelect: []
|
|
75
|
+
};
|
|
76
|
+
const returnValue = await dc.getFlexPLMValue(enumAtt, newData, true);
|
|
77
|
+
expect(returnValue).toEqual(newData.flexMultiSelect);
|
|
78
|
+
});
|
|
79
|
+
it('multi_select_two_values', async () => {
|
|
80
|
+
const newData = {
|
|
81
|
+
flexMultiSelect: ['one', 'three']
|
|
82
|
+
};
|
|
83
|
+
const optionValues = [
|
|
84
|
+
{ value: 'one', display: 'One' },
|
|
85
|
+
{ value: 'three', display: 'Three' }
|
|
86
|
+
];
|
|
87
|
+
const returnValue = await dc.getFlexPLMValue(enumAtt, newData, true);
|
|
88
|
+
expect(returnValue).toEqual(optionValues);
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
describe('getEnumerationValue', () => {
|
|
92
|
+
const config = {
|
|
93
|
+
apiHost: 'host',
|
|
94
|
+
userName: () => 'user',
|
|
95
|
+
password: () => 'pass',
|
|
96
|
+
urlContext: 'xxx',
|
|
97
|
+
vibeEventEndpoint: '/rfa/vibeiq/vibeEvents',
|
|
98
|
+
csrfEndpoint: '/servlet/rest/security/csrf',
|
|
99
|
+
itemPreDevelopmentLifecycleStages: ['concept']
|
|
100
|
+
};
|
|
101
|
+
const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
|
|
102
|
+
const dc = new data_converter_1.DataConverter(config, mapFileUtil);
|
|
103
|
+
const enumProp = {
|
|
104
|
+
id: 'cJoZQvoj7dkfCBJq',
|
|
105
|
+
propertyType: 'choice',
|
|
106
|
+
slug: 'flexChoice',
|
|
107
|
+
label: 'Flex Choice',
|
|
108
|
+
options: [
|
|
109
|
+
{
|
|
110
|
+
value: 'one',
|
|
111
|
+
display: 'One'
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
value: 'two',
|
|
115
|
+
display: 'Two'
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
value: 'three',
|
|
119
|
+
display: 'Three'
|
|
120
|
+
}
|
|
121
|
+
],
|
|
122
|
+
};
|
|
123
|
+
const enumPropNoList = {
|
|
124
|
+
id: 'cJoZQvoj7dkfCBJq',
|
|
125
|
+
propertyType: 'choice',
|
|
126
|
+
slug: 'flexChoice',
|
|
127
|
+
label: 'Flex Choice',
|
|
128
|
+
};
|
|
129
|
+
it('match 1 key', () => {
|
|
130
|
+
const nd = 'one';
|
|
131
|
+
const expectedValue = { value: 'one', display: 'One' };
|
|
132
|
+
const returnValue = dc.getEnumerationValue(enumProp, nd);
|
|
133
|
+
expect(returnValue).toEqual(expectedValue);
|
|
134
|
+
});
|
|
135
|
+
it('wrong key', () => {
|
|
136
|
+
const nd = 'one1';
|
|
137
|
+
const expectedValue = {};
|
|
138
|
+
const returnValue = dc.getEnumerationValue(enumProp, nd);
|
|
139
|
+
expect(returnValue).toEqual(expectedValue);
|
|
140
|
+
});
|
|
141
|
+
it('property no list', () => {
|
|
142
|
+
const nd = 'one1';
|
|
143
|
+
const expectedValue = {};
|
|
144
|
+
const returnValue = dc.getEnumerationValue(enumPropNoList, nd);
|
|
145
|
+
expect(returnValue).toEqual(expectedValue);
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
describe('getEnumerationValue multi_select', () => {
|
|
149
|
+
const config = {
|
|
150
|
+
apiHost: 'host',
|
|
151
|
+
userName: () => 'user',
|
|
152
|
+
password: () => 'pass',
|
|
153
|
+
urlContext: 'xxx',
|
|
154
|
+
vibeEventEndpoint: '/rfa/vibeiq/vibeEvents',
|
|
155
|
+
csrfEndpoint: '/servlet/rest/security/csrf',
|
|
156
|
+
itemPreDevelopmentLifecycleStages: ['concept']
|
|
157
|
+
};
|
|
158
|
+
const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
|
|
159
|
+
const dc = new data_converter_1.DataConverter(config, mapFileUtil);
|
|
160
|
+
const enumAtt = {
|
|
161
|
+
id: 'cJoZQvoj7dkfCBJq',
|
|
162
|
+
propertyType: 'multi_select',
|
|
163
|
+
slug: 'flexMultiSelect',
|
|
164
|
+
label: 'Flex Multi Select',
|
|
165
|
+
options: [
|
|
166
|
+
{
|
|
167
|
+
value: 'one',
|
|
168
|
+
display: 'One'
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
value: 'two',
|
|
172
|
+
display: 'Two'
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
value: 'three',
|
|
176
|
+
display: 'Three'
|
|
177
|
+
}
|
|
178
|
+
],
|
|
179
|
+
};
|
|
180
|
+
it('multi_select_null', async () => {
|
|
181
|
+
const nd = null;
|
|
182
|
+
const returnValue = await dc.getEnumerationValue(enumAtt, nd);
|
|
183
|
+
expect(returnValue).toEqual([]);
|
|
184
|
+
});
|
|
185
|
+
it('multi_select_no_values', async () => {
|
|
186
|
+
const nd = [];
|
|
187
|
+
const returnValue = await dc.getEnumerationValue(enumAtt, nd);
|
|
188
|
+
expect(returnValue).toEqual(nd);
|
|
189
|
+
});
|
|
190
|
+
it('multi select one string value', async () => {
|
|
191
|
+
const nd = 'one';
|
|
192
|
+
const optionValues = [
|
|
193
|
+
{ value: 'one', display: 'One' }
|
|
194
|
+
];
|
|
195
|
+
const returnValue = await dc.getEnumerationValue(enumAtt, nd);
|
|
196
|
+
expect(returnValue).toEqual(optionValues);
|
|
197
|
+
});
|
|
198
|
+
it('multi_select_two_values', async () => {
|
|
199
|
+
const nd = ['one', 'three'];
|
|
200
|
+
const optionValues = [
|
|
201
|
+
{ value: 'one', display: 'One' },
|
|
202
|
+
{ value: 'three', display: 'Three' }
|
|
203
|
+
];
|
|
204
|
+
const returnValue = await dc.getEnumerationValue(enumAtt, nd);
|
|
205
|
+
expect(returnValue).toEqual(optionValues);
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
describe('getPersistableChanges', () => {
|
|
209
|
+
const config = {
|
|
210
|
+
apiHost: 'host',
|
|
211
|
+
userName: () => 'user',
|
|
212
|
+
password: () => 'pass',
|
|
213
|
+
urlContext: 'xxx',
|
|
214
|
+
vibeEventEndpoint: '/rfa/vibeiq/vibeEvents',
|
|
215
|
+
csrfEndpoint: '/servlet/rest/security/csrf',
|
|
216
|
+
itemPreDevelopmentLifecycleStages: ['concept']
|
|
217
|
+
};
|
|
218
|
+
const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
|
|
219
|
+
const dc = new data_converter_1.DataConverter(config, mapFileUtil);
|
|
220
|
+
it('no changes', () => {
|
|
221
|
+
const entity = {
|
|
222
|
+
num: 1
|
|
223
|
+
};
|
|
224
|
+
const potentialChanges = {};
|
|
225
|
+
const diffs = dc.getPersistableChanges(entity, potentialChanges);
|
|
226
|
+
expect(Object.getOwnPropertyNames(diffs).length).toEqual(0);
|
|
227
|
+
});
|
|
228
|
+
it('same value', () => {
|
|
229
|
+
const entity = {
|
|
230
|
+
str: 'test',
|
|
231
|
+
num: 1
|
|
232
|
+
};
|
|
233
|
+
const potentialChanges = {
|
|
234
|
+
str: 'test',
|
|
235
|
+
num: 1
|
|
236
|
+
};
|
|
237
|
+
const diffs = dc.getPersistableChanges(entity, potentialChanges);
|
|
238
|
+
expect(Object.getOwnPropertyNames(diffs).length).toEqual(0);
|
|
239
|
+
});
|
|
240
|
+
it('diff num value', () => {
|
|
241
|
+
const entity = {
|
|
242
|
+
str: 'option 1 string-Changed',
|
|
243
|
+
num: 12
|
|
244
|
+
};
|
|
245
|
+
const potentialChanges = {
|
|
246
|
+
str: 'option 1 string-Changed',
|
|
247
|
+
num: 1
|
|
248
|
+
};
|
|
249
|
+
const diffs = dc.getPersistableChanges(entity, potentialChanges);
|
|
250
|
+
expect(Object.getOwnPropertyNames(diffs).length).toEqual(1);
|
|
251
|
+
expect(diffs['num']).toEqual(potentialChanges['num']);
|
|
252
|
+
});
|
|
253
|
+
it('zero num value', () => {
|
|
254
|
+
const entity = {
|
|
255
|
+
str: 'option 1 string-Changed',
|
|
256
|
+
num: 12
|
|
257
|
+
};
|
|
258
|
+
const potentialChanges = {
|
|
259
|
+
str: 'option 1 string-Changed',
|
|
260
|
+
num: 0
|
|
261
|
+
};
|
|
262
|
+
const diffs = dc.getPersistableChanges(entity, potentialChanges);
|
|
263
|
+
expect(Object.getOwnPropertyNames(diffs).length).toEqual(1);
|
|
264
|
+
expect(diffs['num']).toEqual(potentialChanges['num']);
|
|
265
|
+
});
|
|
266
|
+
it('diff str value', () => {
|
|
267
|
+
const entity = {
|
|
268
|
+
str: 'test',
|
|
269
|
+
num: 1
|
|
270
|
+
};
|
|
271
|
+
const potentialChanges = {
|
|
272
|
+
str: 'test-1',
|
|
273
|
+
num: 1
|
|
274
|
+
};
|
|
275
|
+
const diffs = dc.getPersistableChanges(entity, potentialChanges);
|
|
276
|
+
expect(Object.getOwnPropertyNames(diffs).length).toEqual(1);
|
|
277
|
+
expect(diffs['str']).toEqual(potentialChanges['str']);
|
|
278
|
+
});
|
|
279
|
+
it('empty str value', () => {
|
|
280
|
+
const entity = {
|
|
281
|
+
str: 'test',
|
|
282
|
+
num: 1
|
|
283
|
+
};
|
|
284
|
+
const potentialChanges = {
|
|
285
|
+
str: '',
|
|
286
|
+
num: 1
|
|
287
|
+
};
|
|
288
|
+
const diffs = dc.getPersistableChanges(entity, potentialChanges);
|
|
289
|
+
expect(Object.getOwnPropertyNames(diffs).length).toEqual(1);
|
|
290
|
+
expect(diffs['str']).toBeNull();
|
|
291
|
+
});
|
|
292
|
+
});
|
|
293
|
+
describe('getObjectReferenceValue cache', () => {
|
|
294
|
+
const config = {
|
|
295
|
+
apiHost: 'host',
|
|
296
|
+
userName: () => 'user',
|
|
297
|
+
password: () => 'pass',
|
|
298
|
+
urlContext: 'xxx',
|
|
299
|
+
vibeEventEndpoint: '/rfa/vibeiq/vibeEvents',
|
|
300
|
+
csrfEndpoint: '/servlet/rest/security/csrf',
|
|
301
|
+
itemPreDevelopmentLifecycleStages: ['concept']
|
|
302
|
+
};
|
|
303
|
+
const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
|
|
304
|
+
const dc = new data_converter_1.DataConverter(config, mapFileUtil);
|
|
305
|
+
const ref1Prop = {
|
|
306
|
+
id: 'cJoZQvoj7dkfCBJq',
|
|
307
|
+
propertyType: 'object_reference',
|
|
308
|
+
slug: 'ref1',
|
|
309
|
+
label: 'Object Ref#1',
|
|
310
|
+
referencedTypeRootSlug: 'color'
|
|
311
|
+
};
|
|
312
|
+
const ref2Prop = {
|
|
313
|
+
id: 'cJoZQvoj7dkfCBJq',
|
|
314
|
+
propertyType: 'object_reference',
|
|
315
|
+
slug: 'ref2',
|
|
316
|
+
label: 'Object Ref#2',
|
|
317
|
+
referencedTypeRootSlug: 'color'
|
|
318
|
+
};
|
|
319
|
+
const ref3Prop = {
|
|
320
|
+
id: 'cJoZQvoj7dkfCBJq',
|
|
321
|
+
propertyType: 'object_reference',
|
|
322
|
+
slug: 'ref3',
|
|
323
|
+
label: 'Object Ref#3',
|
|
324
|
+
referencedTypeRootSlug: 'color'
|
|
325
|
+
};
|
|
326
|
+
const newData = {
|
|
327
|
+
ref1Id: 1234,
|
|
328
|
+
ref2Id: 2222,
|
|
329
|
+
ref3Id: 1234
|
|
330
|
+
};
|
|
331
|
+
it('cache hit', async () => {
|
|
332
|
+
const oobFunction = dc.getFlexPLMObjectData;
|
|
333
|
+
try {
|
|
334
|
+
dc.getFlexPLMObjectData = async (newData) => {
|
|
335
|
+
return newData;
|
|
336
|
+
};
|
|
337
|
+
mockGetFunction.mockClear();
|
|
338
|
+
const r1 = await dc.getObjectReferenceValue(ref1Prop, newData, true);
|
|
339
|
+
const r2 = await dc.getObjectReferenceValue(ref2Prop, newData, true);
|
|
340
|
+
const r3 = await dc.getObjectReferenceValue(ref3Prop, newData, true);
|
|
341
|
+
expect(mockGetFunction).toHaveBeenCalledTimes(2);
|
|
342
|
+
expect(r1).toEqual(mockObj1234);
|
|
343
|
+
expect(r2).toEqual(mockObj2222);
|
|
344
|
+
expect(r3).toEqual(mockObj1234);
|
|
345
|
+
}
|
|
346
|
+
finally {
|
|
347
|
+
dc.getFlexPLMObjectData = oobFunction;
|
|
348
|
+
}
|
|
349
|
+
});
|
|
350
|
+
});
|
|
351
|
+
describe('getObjectReferenceValue bad value', () => {
|
|
352
|
+
const config = {
|
|
353
|
+
apiHost: 'host',
|
|
354
|
+
userName: () => 'user',
|
|
355
|
+
password: () => 'pass',
|
|
356
|
+
urlContext: 'xxx',
|
|
357
|
+
vibeEventEndpoint: '/rfa/vibeiq/vibeEvents',
|
|
358
|
+
csrfEndpoint: '/servlet/rest/security/csrf',
|
|
359
|
+
itemPreDevelopmentLifecycleStages: ['concept']
|
|
360
|
+
};
|
|
361
|
+
const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
|
|
362
|
+
const dc = new data_converter_1.DataConverter(config, mapFileUtil);
|
|
363
|
+
const ref1Prop = {
|
|
364
|
+
id: 'cJoZQvoj7dkfCBJq',
|
|
365
|
+
propertyType: 'object_reference',
|
|
366
|
+
slug: 'ref1',
|
|
367
|
+
label: 'Object Ref#1',
|
|
368
|
+
referencedTypeRootSlug: 'color'
|
|
369
|
+
};
|
|
370
|
+
const ref2Prop = {
|
|
371
|
+
id: 'cJoZQvoj7dkfCBJq',
|
|
372
|
+
propertyType: 'object_reference',
|
|
373
|
+
slug: 'ref2',
|
|
374
|
+
label: 'Object Ref#2',
|
|
375
|
+
referencedTypeRootSlug: 'color'
|
|
376
|
+
};
|
|
377
|
+
const ref3Prop = {
|
|
378
|
+
id: 'cJoZQvoj7dkfCBJq',
|
|
379
|
+
propertyType: 'object_reference',
|
|
380
|
+
slug: 'ref3',
|
|
381
|
+
label: 'Object Ref#3',
|
|
382
|
+
referencedTypeRootSlug: 'color'
|
|
383
|
+
};
|
|
384
|
+
const newData = {
|
|
385
|
+
ref1Id: 1234,
|
|
386
|
+
ref2Id: 2222,
|
|
387
|
+
ref3Id: 1234,
|
|
388
|
+
ref3: 'old value'
|
|
389
|
+
};
|
|
390
|
+
it('old string value', async () => {
|
|
391
|
+
const oobFunction = dc.getFlexPLMObjectData;
|
|
392
|
+
try {
|
|
393
|
+
dc.getFlexPLMObjectData = async (newData) => {
|
|
394
|
+
return newData;
|
|
395
|
+
};
|
|
396
|
+
mockGetFunction.mockClear();
|
|
397
|
+
const r3 = await dc.getObjectReferenceValue(ref3Prop, newData, true);
|
|
398
|
+
expect(r3).toEqual(mockObj1234);
|
|
399
|
+
}
|
|
400
|
+
finally {
|
|
401
|
+
dc.getFlexPLMObjectData = oobFunction;
|
|
402
|
+
}
|
|
403
|
+
});
|
|
404
|
+
it('only id', async () => {
|
|
405
|
+
const oobFunction = dc.getFlexPLMObjectData;
|
|
406
|
+
try {
|
|
407
|
+
dc.getFlexPLMObjectData = async (newData) => {
|
|
408
|
+
return newData;
|
|
409
|
+
};
|
|
410
|
+
mockGetFunction.mockClear();
|
|
411
|
+
const r2 = await dc.getObjectReferenceValue(ref2Prop, newData, true);
|
|
412
|
+
expect(r2).toEqual(mockObj2222);
|
|
413
|
+
}
|
|
414
|
+
finally {
|
|
415
|
+
dc.getFlexPLMObjectData = oobFunction;
|
|
416
|
+
}
|
|
417
|
+
});
|
|
418
|
+
it('already references object', async () => {
|
|
419
|
+
const testData = {
|
|
420
|
+
ref1Id: 1234,
|
|
421
|
+
ref1: mockObj1234,
|
|
422
|
+
ref2Id: 2222,
|
|
423
|
+
ref3Id: 1234,
|
|
424
|
+
ref3: 'old value'
|
|
425
|
+
};
|
|
426
|
+
const oobFunction = dc.getFlexPLMObjectData;
|
|
427
|
+
try {
|
|
428
|
+
dc.getFlexPLMObjectData = async (newData) => {
|
|
429
|
+
return newData;
|
|
430
|
+
};
|
|
431
|
+
mockGetFunction.mockClear();
|
|
432
|
+
const r1 = await dc.getObjectReferenceValue(ref1Prop, testData, true);
|
|
433
|
+
expect(r1).toEqual(mockObj1234);
|
|
434
|
+
}
|
|
435
|
+
finally {
|
|
436
|
+
dc.getFlexPLMObjectData = oobFunction;
|
|
437
|
+
}
|
|
438
|
+
});
|
|
439
|
+
it('old string value, no refId', async () => {
|
|
440
|
+
const testData = {
|
|
441
|
+
ref1: 'old value'
|
|
442
|
+
};
|
|
443
|
+
const oobFunction = dc.getFlexPLMObjectData;
|
|
444
|
+
try {
|
|
445
|
+
dc.getFlexPLMObjectData = async (newData) => {
|
|
446
|
+
return newData;
|
|
447
|
+
};
|
|
448
|
+
mockGetFunction.mockClear();
|
|
449
|
+
const r1 = await dc.getObjectReferenceValue(ref1Prop, testData, true);
|
|
450
|
+
expect(r1).toEqual({});
|
|
451
|
+
}
|
|
452
|
+
finally {
|
|
453
|
+
dc.getFlexPLMObjectData = oobFunction;
|
|
454
|
+
}
|
|
455
|
+
});
|
|
456
|
+
});
|
|
457
|
+
describe('getObjectReferenceValue - use mapping', () => {
|
|
458
|
+
const maps = require('./data-converter-spec-mockData');
|
|
459
|
+
const mapping = maps['mapping'];
|
|
460
|
+
const config = {
|
|
461
|
+
apiHost: 'host',
|
|
462
|
+
userName: () => 'user',
|
|
463
|
+
password: () => 'pass',
|
|
464
|
+
urlContext: 'xxx',
|
|
465
|
+
transformMapFile: 'file1',
|
|
466
|
+
vibeEventEndpoint: '/rfa/vibeiq/vibeEvents',
|
|
467
|
+
csrfEndpoint: '/servlet/rest/security/csrf',
|
|
468
|
+
itemPreDevelopmentLifecycleStages: ['concept']
|
|
469
|
+
};
|
|
470
|
+
const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
|
|
471
|
+
const dc = new data_converter_1.DataConverter(config, mapFileUtil);
|
|
472
|
+
const ref1Prop = {
|
|
473
|
+
id: 'cJoZQvoj7dkfCBJq',
|
|
474
|
+
propertyType: 'object_reference',
|
|
475
|
+
slug: 'ref1',
|
|
476
|
+
label: 'Object Ref#1',
|
|
477
|
+
referencedTypeRootSlug: 'color'
|
|
478
|
+
};
|
|
479
|
+
const ref2Prop = {
|
|
480
|
+
id: 'cJoZQvoj7dkfCBJq',
|
|
481
|
+
propertyType: 'object_reference',
|
|
482
|
+
slug: 'ref2',
|
|
483
|
+
label: 'Object Ref#2',
|
|
484
|
+
referencedTypeRootSlug: 'color'
|
|
485
|
+
};
|
|
486
|
+
const ref3Prop = {
|
|
487
|
+
id: 'cJoZQvoj7dkfCBJq',
|
|
488
|
+
propertyType: 'object_reference',
|
|
489
|
+
slug: 'ref3',
|
|
490
|
+
label: 'Object Ref#3',
|
|
491
|
+
referencedTypeRootSlug: 'color'
|
|
492
|
+
};
|
|
493
|
+
const newData = {
|
|
494
|
+
ref1Id: 1234,
|
|
495
|
+
ref1: mockObj1234,
|
|
496
|
+
ref2Id: 2222,
|
|
497
|
+
ref2: mockObj2222,
|
|
498
|
+
ref3Id: 1234,
|
|
499
|
+
ref3: mockObj1234
|
|
500
|
+
};
|
|
501
|
+
it('mapping test', async () => {
|
|
502
|
+
const oobFunction = dc.getFlexPLMObjectData;
|
|
503
|
+
try {
|
|
504
|
+
dc.getFlexPLMObjectData = async (newData) => {
|
|
505
|
+
return newData;
|
|
506
|
+
};
|
|
507
|
+
mockGetFunction.mockClear();
|
|
508
|
+
let spyGetObjectClass = jest.spyOn(type_conversion_utils_1.TypeConversionUtils, 'getObjectClass')
|
|
509
|
+
.mockImplementation(async () => { return 'LCSColor'; });
|
|
510
|
+
let spyGetObjectTypePath = jest.spyOn(type_conversion_utils_1.TypeConversionUtils, 'getObjectTypePath')
|
|
511
|
+
.mockImplementation(async () => { return 'Color'; });
|
|
512
|
+
let spyGetMapKey = jest.spyOn(type_conversion_utils_1.TypeConversionUtils, 'getMapKey')
|
|
513
|
+
.mockImplementation(async () => { return 'LCSColor'; });
|
|
514
|
+
let spyApplyTransformMap = jest.spyOn(map_utils_1.MapUtil, 'applyTransformMap')
|
|
515
|
+
.mockImplementation(async (...args) => { return args[2]; });
|
|
516
|
+
const r1 = await dc.getObjectReferenceValue(ref1Prop, newData, true);
|
|
517
|
+
const r2 = await dc.getObjectReferenceValue(ref2Prop, newData, true);
|
|
518
|
+
expect(spyGetObjectClass).toHaveBeenCalledTimes(2);
|
|
519
|
+
expect(spyGetObjectTypePath).toHaveBeenCalledTimes(2);
|
|
520
|
+
expect(spyGetMapKey).toHaveBeenCalledTimes(2);
|
|
521
|
+
expect(spyApplyTransformMap).toHaveBeenCalledTimes(2);
|
|
522
|
+
}
|
|
523
|
+
finally {
|
|
524
|
+
dc.getFlexPLMObjectData = oobFunction;
|
|
525
|
+
}
|
|
526
|
+
});
|
|
527
|
+
});
|
|
528
|
+
describe('setEnumerationKeys', () => {
|
|
529
|
+
const config = {
|
|
530
|
+
apiHost: 'host',
|
|
531
|
+
userName: () => 'user',
|
|
532
|
+
password: () => 'pass',
|
|
533
|
+
urlContext: 'xxx',
|
|
534
|
+
vibeEventEndpoint: '/rfa/vibeiq/vibeEvents',
|
|
535
|
+
csrfEndpoint: '/servlet/rest/security/csrf',
|
|
536
|
+
itemPreDevelopmentLifecycleStages: ['concept']
|
|
537
|
+
};
|
|
538
|
+
const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
|
|
539
|
+
const dc = new data_converter_1.DataConverter(config, mapFileUtil);
|
|
540
|
+
const enumProp = {
|
|
541
|
+
id: 'cJoZQvoj7dkfCBJq',
|
|
542
|
+
propertyType: 'multi_select',
|
|
543
|
+
slug: 'flexMultiSelect',
|
|
544
|
+
label: 'Flex Multi Select',
|
|
545
|
+
options: [
|
|
546
|
+
{
|
|
547
|
+
value: 'one',
|
|
548
|
+
display: 'One'
|
|
549
|
+
},
|
|
550
|
+
{
|
|
551
|
+
value: 'two',
|
|
552
|
+
display: 'Two'
|
|
553
|
+
},
|
|
554
|
+
{
|
|
555
|
+
value: 'three',
|
|
556
|
+
display: 'Three'
|
|
557
|
+
}
|
|
558
|
+
],
|
|
559
|
+
};
|
|
560
|
+
const enumPropNoList = {
|
|
561
|
+
id: 'cJoZQvoj7dkfCBJq',
|
|
562
|
+
propertyType: 'multi_select',
|
|
563
|
+
slug: 'flexMultiSelect',
|
|
564
|
+
label: 'Flex Multi Select',
|
|
565
|
+
};
|
|
566
|
+
it('match 1 key', () => {
|
|
567
|
+
const newData = [{ value: 'one', display: 'One' }];
|
|
568
|
+
const returnValue = dc.setEnumerationKeys(enumProp, newData, false);
|
|
569
|
+
expect(returnValue).toEqual(['one']);
|
|
570
|
+
});
|
|
571
|
+
it('match 2 key', () => {
|
|
572
|
+
const newData = [{ value: 'one', display: 'One' }, { value: 'two', display: 'Two' }];
|
|
573
|
+
const returnValue = dc.setEnumerationKeys(enumProp, newData, false);
|
|
574
|
+
expect(returnValue).toEqual(['one', 'two']);
|
|
575
|
+
});
|
|
576
|
+
it('match 1 display', () => {
|
|
577
|
+
const newData = [{ value: 'one', display: 'One' }];
|
|
578
|
+
const returnValue = dc.setEnumerationKeys(enumProp, newData, true);
|
|
579
|
+
expect(returnValue).toEqual(['one']);
|
|
580
|
+
});
|
|
581
|
+
it('match 2 display', () => {
|
|
582
|
+
const newData = [{ value: 'one', display: 'One' }, { value: 'two', display: 'Two' }];
|
|
583
|
+
const returnValue = dc.setEnumerationKeys(enumProp, newData, true);
|
|
584
|
+
expect(returnValue).toEqual(['one', 'two']);
|
|
585
|
+
});
|
|
586
|
+
it('property no list', () => {
|
|
587
|
+
const newData = [{ value: 'one', display: 'One' }, { value: 'two', display: 'Two' }];
|
|
588
|
+
const returnValue = dc.setEnumerationKeys(enumPropNoList, newData, false);
|
|
589
|
+
expect(returnValue).toEqual([]);
|
|
590
|
+
});
|
|
591
|
+
});
|
|
592
|
+
describe('checkKeysAndValues', () => {
|
|
593
|
+
const config = {
|
|
594
|
+
apiHost: 'host',
|
|
595
|
+
userName: () => 'user',
|
|
596
|
+
password: () => 'pass',
|
|
597
|
+
urlContext: 'xxx',
|
|
598
|
+
vibeEventEndpoint: '/rfa/vibeiq/vibeEvents',
|
|
599
|
+
csrfEndpoint: '/servlet/rest/security/csrf',
|
|
600
|
+
itemPreDevelopmentLifecycleStages: ['concept']
|
|
601
|
+
};
|
|
602
|
+
const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
|
|
603
|
+
const dc = new data_converter_1.DataConverter(config, mapFileUtil);
|
|
604
|
+
const groupData = [
|
|
605
|
+
{ name: 'Group 1', typePath: 'custom-entity:grouping' },
|
|
606
|
+
{ name: 'Group 2', typePath: 'custom-entity:grouping' },
|
|
607
|
+
{ name: 'Group 2', typePath: 'custom-entity:grouping' },
|
|
608
|
+
{ name: 'Group 4', typePath: 'custom-entity:grouping' },
|
|
609
|
+
{ name: 'Group 4', typePath: 'custom-entity:grouping:sub' },
|
|
610
|
+
{ name: 'Group 5', typePath: 'custom-entity:grouping:sub' }
|
|
611
|
+
];
|
|
612
|
+
it('Group 1', () => {
|
|
613
|
+
const criteria = {
|
|
614
|
+
name: 'Group 1'
|
|
615
|
+
};
|
|
616
|
+
const typePath = 'custom-entity:grouping';
|
|
617
|
+
const results = dc.checkKeysAndValues(criteria, groupData, typePath);
|
|
618
|
+
expect(results.length).toBe(1);
|
|
619
|
+
});
|
|
620
|
+
it('Group 5 - sub type of typePath', () => {
|
|
621
|
+
const criteria = {
|
|
622
|
+
name: 'Group 5'
|
|
623
|
+
};
|
|
624
|
+
const typePath = 'custom-entity:grouping';
|
|
625
|
+
const results = dc.checkKeysAndValues(criteria, groupData, typePath);
|
|
626
|
+
expect(results.length).toBe(1);
|
|
627
|
+
});
|
|
628
|
+
it('Group 2 - returns the 2 matching', () => {
|
|
629
|
+
const criteria = {
|
|
630
|
+
name: 'Group 2'
|
|
631
|
+
};
|
|
632
|
+
const typePath = 'custom-entity:grouping';
|
|
633
|
+
const results = dc.checkKeysAndValues(criteria, groupData, typePath);
|
|
634
|
+
expect(results.length).toBe(2);
|
|
635
|
+
});
|
|
636
|
+
it('2 Same Name - but 1 is a sub type; returns 2', () => {
|
|
637
|
+
const criteria = {
|
|
638
|
+
name: 'Group 4'
|
|
639
|
+
};
|
|
640
|
+
const typePath = 'custom-entity:grouping';
|
|
641
|
+
const results = dc.checkKeysAndValues(criteria, groupData, typePath);
|
|
642
|
+
expect(results.length).toBe(2);
|
|
643
|
+
});
|
|
644
|
+
it('2 Same Name - but 1 wrong type', () => {
|
|
645
|
+
const criteria = {
|
|
646
|
+
name: 'Group 1'
|
|
647
|
+
};
|
|
648
|
+
const testData = [...groupData];
|
|
649
|
+
testData.push({ name: 'Group 1', typePath: 'custom-entity:label' });
|
|
650
|
+
const typePath = 'custom-entity:grouping';
|
|
651
|
+
const results = dc.checkKeysAndValues(criteria, testData, typePath);
|
|
652
|
+
expect(results.length).toBe(1);
|
|
653
|
+
});
|
|
654
|
+
it('first & last entity have the wrong typePath', () => {
|
|
655
|
+
const criteria = {
|
|
656
|
+
objectId: "2562",
|
|
657
|
+
};
|
|
658
|
+
const typePath = 'custom-entity:group2';
|
|
659
|
+
const testData = [
|
|
660
|
+
{ "typePath": "custom-entity:group1", "name": "BLACK (BK)", "id": "o1v2rh8olgQ78GcL", "objectId": "2562", "entityType": "custom-entity" },
|
|
661
|
+
{ "typePath": "custom-entity:group2", "name": "BLACK (BK)", "id": "t5n22S2gqswe8GcL", "objectId": "2562", "entityType": "custom-entity" },
|
|
662
|
+
{ "typePath": "custom-entity:group1", "name": "BLACK (BK)", "id": "t5rh8o2gqswk3drt", "objectId": "2562", "entityType": "custom-entity" }
|
|
663
|
+
];
|
|
664
|
+
const results = dc.checkKeysAndValues(criteria, testData, typePath);
|
|
665
|
+
expect(results.length).toBe(1);
|
|
666
|
+
});
|
|
667
|
+
});
|
|
668
|
+
describe('filterOutArchivedAndTrashedEntities', () => {
|
|
669
|
+
const config = {
|
|
670
|
+
apiHost: 'host',
|
|
671
|
+
userName: () => 'user',
|
|
672
|
+
password: () => 'pass',
|
|
673
|
+
urlContext: 'xxx',
|
|
674
|
+
vibeEventEndpoint: '/rfa/vibeiq/vibeEvents',
|
|
675
|
+
csrfEndpoint: '/servlet/rest/security/csrf',
|
|
676
|
+
itemPreDevelopmentLifecycleStages: ['concept']
|
|
677
|
+
};
|
|
678
|
+
const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
|
|
679
|
+
const dc = new data_converter_1.DataConverter(config, mapFileUtil);
|
|
680
|
+
it('filter out isArchived and isTrashed entities', () => {
|
|
681
|
+
const entities = [
|
|
682
|
+
{ id: '1', name: 'Entity 1', isArchived: false, isTrashed: false },
|
|
683
|
+
{ id: '2', name: 'Entity 2', isArchived: true, isTrashed: false },
|
|
684
|
+
{ id: '3', name: 'Entity 3', isArchived: false, isTrashed: true },
|
|
685
|
+
{ id: '4', name: 'Entity 4', isArchived: false, isTrashed: false }
|
|
686
|
+
];
|
|
687
|
+
const filteredEntities = dc.filterOutArchivedAndTrashedEntities(entities);
|
|
688
|
+
expect(filteredEntities.length).toBe(2);
|
|
689
|
+
expect(filteredEntities).toEqual([
|
|
690
|
+
{ id: '1', name: 'Entity 1', isArchived: false, isTrashed: false },
|
|
691
|
+
{ id: '4', name: 'Entity 4', isArchived: false, isTrashed: false }
|
|
692
|
+
]);
|
|
693
|
+
});
|
|
694
|
+
it('no entities to filter', () => {
|
|
695
|
+
const entities = [];
|
|
696
|
+
const filteredEntities = dc.filterOutArchivedAndTrashedEntities(entities);
|
|
697
|
+
expect(filteredEntities.length).toBe(0);
|
|
698
|
+
});
|
|
699
|
+
it('all entities are archived or trashed', () => {
|
|
700
|
+
const entities = [
|
|
701
|
+
{ id: '1', name: 'Entity 1', isArchived: true, isTrashed: false },
|
|
702
|
+
{ id: '2', name: 'Entity 2', isArchived: false, isTrashed: true }
|
|
703
|
+
];
|
|
704
|
+
const filteredEntities = dc.filterOutArchivedAndTrashedEntities(entities);
|
|
705
|
+
expect(filteredEntities.length).toBe(0);
|
|
706
|
+
});
|
|
707
|
+
});
|
|
708
|
+
describe('setUserListValue', () => {
|
|
709
|
+
const config = {
|
|
710
|
+
apiHost: 'host',
|
|
711
|
+
userName: () => 'user',
|
|
712
|
+
password: () => 'pass',
|
|
713
|
+
urlContext: 'xxx',
|
|
714
|
+
vibeEventEndpoint: '/rfa/vibeiq/vibeEvents',
|
|
715
|
+
csrfEndpoint: '/servlet/rest/security/csrf',
|
|
716
|
+
itemPreDevelopmentLifecycleStages: ['concept']
|
|
717
|
+
};
|
|
718
|
+
const userListProp1 = {};
|
|
719
|
+
const userEmailMapping = [
|
|
720
|
+
{
|
|
721
|
+
id: "gxgr46kvdeEOn4cH",
|
|
722
|
+
email: "jessica.smith@vibeiq.com"
|
|
723
|
+
},
|
|
724
|
+
{
|
|
725
|
+
id: "Rl5D0sjuAwelScEK",
|
|
726
|
+
email: "adam.smith@vibeiq.com"
|
|
727
|
+
}
|
|
728
|
+
];
|
|
729
|
+
const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
|
|
730
|
+
const dc = new data_converter_1.DataConverter(config, mapFileUtil);
|
|
731
|
+
let spyGetUserByEmail = jest.spyOn(dc, 'getUserByEmail')
|
|
732
|
+
.mockImplementation(async (nd) => {
|
|
733
|
+
let emaildInput = nd?.email.toLowerCase();
|
|
734
|
+
return userEmailMapping.find((user) => user.email === emaildInput);
|
|
735
|
+
});
|
|
736
|
+
let spyProcessGroupMemberCheck = jest.spyOn(dc, 'processGroupMemberCheck')
|
|
737
|
+
.mockImplementation(async (nd) => { return; });
|
|
738
|
+
afterEach(() => {
|
|
739
|
+
spyGetUserByEmail.mockClear();
|
|
740
|
+
spyProcessGroupMemberCheck.mockClear();
|
|
741
|
+
data_converter_1.DataConverter.clearStaticUserCache();
|
|
742
|
+
});
|
|
743
|
+
afterAll(() => {
|
|
744
|
+
spyGetUserByEmail.mockRestore();
|
|
745
|
+
spyProcessGroupMemberCheck.mockRestore();
|
|
746
|
+
});
|
|
747
|
+
it('no value', async () => {
|
|
748
|
+
const newData = {};
|
|
749
|
+
const returnValue = await dc.setUserListValue(userListProp1, newData);
|
|
750
|
+
expect(returnValue).toEqual('');
|
|
751
|
+
});
|
|
752
|
+
it('miss cache', async () => {
|
|
753
|
+
const newData = { email: 'adam.smith@vibeiq.com' };
|
|
754
|
+
const returnValue = await dc.setUserListValue(userListProp1, newData);
|
|
755
|
+
console.log('returnValue', JSON.stringify(returnValue));
|
|
756
|
+
expect(returnValue).toEqual('Rl5D0sjuAwelScEK');
|
|
757
|
+
expect(spyGetUserByEmail).toHaveBeenCalledTimes(1);
|
|
758
|
+
expect(spyProcessGroupMemberCheck).toHaveBeenCalledTimes(1);
|
|
759
|
+
});
|
|
760
|
+
it('miss cache - two different emails', async () => {
|
|
761
|
+
let newData = { email: 'adam.smith@vibeiq.com' };
|
|
762
|
+
let returnValue = await dc.setUserListValue(userListProp1, newData);
|
|
763
|
+
expect(returnValue).toEqual('Rl5D0sjuAwelScEK');
|
|
764
|
+
expect(spyGetUserByEmail).toHaveBeenCalledTimes(1);
|
|
765
|
+
expect(spyProcessGroupMemberCheck).toHaveBeenCalledTimes(1);
|
|
766
|
+
newData = { email: 'jessica.smith@vibeiq.com' };
|
|
767
|
+
returnValue = await dc.setUserListValue(userListProp1, newData);
|
|
768
|
+
expect(spyGetUserByEmail).toHaveBeenCalledTimes(2);
|
|
769
|
+
expect(spyProcessGroupMemberCheck).toHaveBeenCalledTimes(2);
|
|
770
|
+
});
|
|
771
|
+
it('hit cache same email', async () => {
|
|
772
|
+
const newData = { email: 'adam.smith@vibeiq.com' };
|
|
773
|
+
let returnValue = await dc.setUserListValue(userListProp1, newData);
|
|
774
|
+
expect(returnValue).toEqual('Rl5D0sjuAwelScEK');
|
|
775
|
+
expect(spyGetUserByEmail).toHaveBeenCalledTimes(1);
|
|
776
|
+
expect(spyProcessGroupMemberCheck).toHaveBeenCalledTimes(1);
|
|
777
|
+
returnValue = await dc.setUserListValue(userListProp1, newData);
|
|
778
|
+
expect(returnValue).toEqual('Rl5D0sjuAwelScEK');
|
|
779
|
+
expect(spyGetUserByEmail).toHaveBeenCalledTimes(1);
|
|
780
|
+
expect(spyProcessGroupMemberCheck).toHaveBeenCalledTimes(2);
|
|
781
|
+
});
|
|
782
|
+
it('hit cache same email - new DataConverter entity', async () => {
|
|
783
|
+
const newData = { email: 'adam.smith@vibeiq.com' };
|
|
784
|
+
let returnValue = await dc.setUserListValue(userListProp1, newData);
|
|
785
|
+
expect(returnValue).toEqual('Rl5D0sjuAwelScEK');
|
|
786
|
+
expect(spyGetUserByEmail).toHaveBeenCalledTimes(1);
|
|
787
|
+
expect(spyProcessGroupMemberCheck).toHaveBeenCalledTimes(1);
|
|
788
|
+
const dc2 = new data_converter_1.DataConverter(config, mapFileUtil);
|
|
789
|
+
let spyGetUserByEmail2 = jest.spyOn(dc2, 'getUserByEmail')
|
|
790
|
+
.mockImplementation(async (nd) => {
|
|
791
|
+
let emaildInput = nd?.email.toLowerCase();
|
|
792
|
+
return userEmailMapping.find((user) => user.email === emaildInput);
|
|
793
|
+
});
|
|
794
|
+
let spyProcessGroupMemberCheck2 = jest.spyOn(dc2, 'processGroupMemberCheck')
|
|
795
|
+
.mockImplementation(async (nd) => { return; });
|
|
796
|
+
returnValue = await dc2.setUserListValue(userListProp1, newData);
|
|
797
|
+
expect(returnValue).toEqual('Rl5D0sjuAwelScEK');
|
|
798
|
+
expect(spyGetUserByEmail2).toHaveBeenCalledTimes(0);
|
|
799
|
+
expect(spyProcessGroupMemberCheck2).toHaveBeenCalledTimes(1);
|
|
800
|
+
spyGetUserByEmail2.mockRestore();
|
|
801
|
+
spyProcessGroupMemberCheck2.mockRestore();
|
|
802
|
+
});
|
|
803
|
+
});
|
|
804
|
+
describe('getUserListValue', () => {
|
|
805
|
+
const config = {
|
|
806
|
+
apiHost: 'host',
|
|
807
|
+
userName: () => 'user',
|
|
808
|
+
password: () => 'pass',
|
|
809
|
+
urlContext: 'xxx',
|
|
810
|
+
vibeEventEndpoint: '/rfa/vibeiq/vibeEvents',
|
|
811
|
+
csrfEndpoint: '/servlet/rest/security/csrf',
|
|
812
|
+
itemPreDevelopmentLifecycleStages: ['concept']
|
|
813
|
+
};
|
|
814
|
+
const userListProp1 = {
|
|
815
|
+
slug: 'userList1'
|
|
816
|
+
};
|
|
817
|
+
const userEmailMapping = [
|
|
818
|
+
{
|
|
819
|
+
id: "gxgr46kvdeEOn4cH",
|
|
820
|
+
email: "jessica.smith@vibeiq.com",
|
|
821
|
+
first: 'Jessica',
|
|
822
|
+
last: 'Smith'
|
|
823
|
+
},
|
|
824
|
+
{
|
|
825
|
+
id: "Rl5D0sjuAwelScEK",
|
|
826
|
+
email: "adam.smith@vibeiq.com",
|
|
827
|
+
first: 'Adam',
|
|
828
|
+
last: 'Smith'
|
|
829
|
+
}
|
|
830
|
+
];
|
|
831
|
+
const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
|
|
832
|
+
const dc = new data_converter_1.DataConverter(config, mapFileUtil);
|
|
833
|
+
let spyGetUserById = jest.spyOn(dc, 'getUserById')
|
|
834
|
+
.mockImplementation(async (nd) => {
|
|
835
|
+
return userEmailMapping.find((user) => user.id === nd);
|
|
836
|
+
});
|
|
837
|
+
afterEach(() => {
|
|
838
|
+
spyGetUserById.mockClear();
|
|
839
|
+
data_converter_1.DataConverter.clearStaticUserCache();
|
|
840
|
+
});
|
|
841
|
+
afterAll(() => {
|
|
842
|
+
spyGetUserById.mockRestore();
|
|
843
|
+
});
|
|
844
|
+
it('no value', async () => {
|
|
845
|
+
const newData = {};
|
|
846
|
+
const returnValue = await dc.getUserListValue(userListProp1, newData);
|
|
847
|
+
expect(returnValue).toEqual({});
|
|
848
|
+
});
|
|
849
|
+
it('miss cache', async () => {
|
|
850
|
+
const newData = {
|
|
851
|
+
userList1Id: 'gxgr46kvdeEOn4cH'
|
|
852
|
+
};
|
|
853
|
+
const returnValue = await dc.getUserListValue(userListProp1, newData);
|
|
854
|
+
expect(spyGetUserById).toHaveBeenCalledTimes(1);
|
|
855
|
+
expect(returnValue.email).toEqual('jessica.smith@vibeiq.com');
|
|
856
|
+
expect(returnValue.firstName).toEqual('Jessica');
|
|
857
|
+
expect(returnValue.lastName).toEqual('Smith');
|
|
858
|
+
});
|
|
859
|
+
it('miss cache - two different emails', async () => {
|
|
860
|
+
let newData = { userList1Id: 'gxgr46kvdeEOn4cH' };
|
|
861
|
+
let returnValue = await dc.getUserListValue(userListProp1, newData);
|
|
862
|
+
expect(spyGetUserById).toHaveBeenCalledTimes(1);
|
|
863
|
+
expect(returnValue.email).toEqual('jessica.smith@vibeiq.com');
|
|
864
|
+
expect(returnValue.firstName).toEqual('Jessica');
|
|
865
|
+
expect(returnValue.lastName).toEqual('Smith');
|
|
866
|
+
newData = { userList1Id: 'Rl5D0sjuAwelScEK' };
|
|
867
|
+
returnValue = await dc.getUserListValue(userListProp1, newData);
|
|
868
|
+
expect(spyGetUserById).toHaveBeenCalledTimes(2);
|
|
869
|
+
expect(returnValue.email).toEqual('adam.smith@vibeiq.com');
|
|
870
|
+
expect(returnValue.firstName).toEqual('Adam');
|
|
871
|
+
expect(returnValue.lastName).toEqual('Smith');
|
|
872
|
+
});
|
|
873
|
+
it('hit cache same email', async () => {
|
|
874
|
+
const newData = { userList1Id: 'gxgr46kvdeEOn4cH' };
|
|
875
|
+
let returnValue = await dc.getUserListValue(userListProp1, newData);
|
|
876
|
+
expect(spyGetUserById).toHaveBeenCalledTimes(1);
|
|
877
|
+
expect(returnValue.email).toEqual('jessica.smith@vibeiq.com');
|
|
878
|
+
expect(returnValue.firstName).toEqual('Jessica');
|
|
879
|
+
expect(returnValue.lastName).toEqual('Smith');
|
|
880
|
+
returnValue = await dc.getUserListValue(userListProp1, newData);
|
|
881
|
+
expect(spyGetUserById).toHaveBeenCalledTimes(1);
|
|
882
|
+
expect(returnValue.email).toEqual('jessica.smith@vibeiq.com');
|
|
883
|
+
expect(returnValue.firstName).toEqual('Jessica');
|
|
884
|
+
expect(returnValue.lastName).toEqual('Smith');
|
|
885
|
+
});
|
|
886
|
+
it('hit cache same email - new DataConverter entity', async () => {
|
|
887
|
+
const newData = { userList1Id: 'gxgr46kvdeEOn4cH' };
|
|
888
|
+
let returnValue = await dc.getUserListValue(userListProp1, newData);
|
|
889
|
+
expect(spyGetUserById).toHaveBeenCalledTimes(1);
|
|
890
|
+
expect(returnValue.email).toEqual('jessica.smith@vibeiq.com');
|
|
891
|
+
expect(returnValue.firstName).toEqual('Jessica');
|
|
892
|
+
expect(returnValue.lastName).toEqual('Smith');
|
|
893
|
+
const dc2 = new data_converter_1.DataConverter(config, mapFileUtil);
|
|
894
|
+
let spyGetUserById2 = jest.spyOn(dc2, 'getUserById')
|
|
895
|
+
.mockImplementation(async (nd) => {
|
|
896
|
+
return userEmailMapping.find((user) => user.id === nd);
|
|
897
|
+
});
|
|
898
|
+
returnValue = await dc2.getUserListValue(userListProp1, newData);
|
|
899
|
+
expect(spyGetUserById2).toHaveBeenCalledTimes(0);
|
|
900
|
+
expect(returnValue.email).toEqual('jessica.smith@vibeiq.com');
|
|
901
|
+
expect(returnValue.firstName).toEqual('Jessica');
|
|
902
|
+
expect(returnValue.lastName).toEqual('Smith');
|
|
903
|
+
});
|
|
904
|
+
});
|