@contrail/cli 3.6.0-alpha-8-alpha.85a73d5 → 3.6.0-alpha.5ecc188
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/README.md +26 -181
- package/dist/api/types.d.ts +0 -35
- package/dist/api/types.js +1 -49
- package/dist/auth/login.d.ts +4 -0
- package/dist/auth/login.js +136 -56
- package/dist/auth/login.spec.js +117 -3
- package/dist/auth/sign-in-error.d.ts +7 -0
- package/dist/auth/sign-in-error.js +24 -0
- package/dist/auth/sign-in-error.spec.js +22 -0
- package/dist/auth/sso.d.ts +38 -0
- package/dist/auth/sso.js +184 -0
- package/dist/auth/sso.spec.js +191 -0
- package/dist/basecommand.d.ts +3 -0
- package/dist/basecommand.js +10 -3
- package/dist/commands/app/getApiKey.js +2 -2
- package/dist/commands/login.d.ts +12 -0
- package/dist/commands/login.js +25 -0
- package/dist/common.d.ts +1 -4
- package/dist/common.js +1 -18
- package/dist/helpers/config/config.d.ts +3 -3
- package/dist/helpers/config/config.js +3 -3
- package/dist/helpers/file-helpers.d.ts +0 -1
- package/dist/helpers/file-helpers.js +3 -20
- package/dist/logger.js +1 -4
- package/node_modules/@contrail/entity-compare/package.json +3 -6
- package/node_modules/@contrail/loader/lib/common/conditional-columns.js +1 -1
- package/node_modules/@contrail/loader/lib/constants.d.ts +8 -0
- package/node_modules/@contrail/loader/lib/constants.js +9 -1
- package/node_modules/@contrail/loader/lib/entities-v2/linesheet-v2/item-processor.d.ts +4 -0
- package/node_modules/@contrail/loader/lib/entities-v2/linesheet-v2/item-processor.js +57 -0
- package/node_modules/@contrail/loader/lib/entities-v2/linesheet-v2/item-processor.spec.js +492 -34
- package/node_modules/@contrail/loader/lib/pipeline/validate.js +2 -52
- package/node_modules/@contrail/loader/lib/pipeline/validate.spec.js +0 -85
- package/node_modules/@contrail/loader/package.json +2 -2
- package/node_modules/@contrail/sdk/.github/workflows/publish-to-npm.yml +4 -1
- package/node_modules/@contrail/sdk/lib/auth/login.js +1 -1
- package/node_modules/@contrail/sdk/lib/config/config.d.ts +0 -3
- package/node_modules/@contrail/sdk/lib/config/config.js +7 -13
- package/node_modules/@contrail/sdk/lib/core/request.js +2 -6
- package/node_modules/@contrail/sdk/lib/entities/entities.client.d.ts +0 -2
- package/node_modules/@contrail/sdk/lib/entities/entities.client.js +1 -3
- package/node_modules/@contrail/sdk/lib/entities/entity.resource.registry.js +0 -1
- package/node_modules/@contrail/sdk/lib/index.d.ts +0 -1
- package/node_modules/@contrail/sdk/lib/index.js +0 -1
- package/node_modules/@contrail/sdk/package.json +1 -1
- package/oclif.manifest.json +50 -449
- package/package.json +12 -5
- package/dist/commands/entities/create.d.ts +0 -50
- package/dist/commands/entities/create.js +0 -633
- package/dist/commands/entities/create.spec.js +0 -583
- package/dist/commands/entities/delete.d.ts +0 -20
- package/dist/commands/entities/delete.js +0 -140
- package/dist/commands/entities/get.d.ts +0 -25
- package/dist/commands/entities/get.js +0 -269
- package/dist/commands/entities/grammar.spec.js +0 -79
- package/dist/commands/entities/output.spec.d.ts +0 -1
- package/dist/commands/entities/output.spec.js +0 -72
- package/dist/commands/entities/update.d.ts +0 -32
- package/dist/commands/entities/update.js +0 -161
- package/dist/helpers/entities/assortment-items.d.ts +0 -11
- package/dist/helpers/entities/assortment-items.js +0 -76
- package/dist/helpers/entities/batchFetch.d.ts +0 -8
- package/dist/helpers/entities/batchFetch.js +0 -49
- package/dist/helpers/entities/index.d.ts +0 -3
- package/dist/helpers/entities/index.js +0 -6
- package/dist/helpers/entities/items.d.ts +0 -6
- package/dist/helpers/entities/items.js +0 -56
- package/dist/helpers/entities/items.spec.d.ts +0 -1
- package/dist/helpers/entities/items.spec.js +0 -19
- package/dist/helpers/entities/project-items.d.ts +0 -2
- package/dist/helpers/entities/project-items.js +0 -44
- package/dist/helpers/propertySpecifications/dateRanges.d.ts +0 -34
- package/dist/helpers/propertySpecifications/dateRanges.js +0 -83
- package/dist/helpers/propertySpecifications/dateRanges.spec.d.ts +0 -1
- package/dist/helpers/propertySpecifications/dateRanges.spec.js +0 -91
- package/dist/helpers/propertySpecifications/propertySpecifications.d.ts +0 -39
- package/dist/helpers/propertySpecifications/propertySpecifications.js +0 -102
- package/dist/helpers/propertySpecifications/propertySpecifications.spec.d.ts +0 -1
- package/dist/helpers/propertySpecifications/propertySpecifications.spec.js +0 -387
- package/dist/logger.spec.d.ts +0 -1
- package/dist/logger.spec.js +0 -12
- package/node_modules/@contrail/sdk/lib/image-search/image-search.d.ts +0 -34
- package/node_modules/@contrail/sdk/lib/image-search/image-search.js +0 -42
- package/node_modules/@contrail/sdk/lib/image-search/index.d.ts +0 -1
- package/node_modules/@contrail/sdk/lib/image-search/index.js +0 -17
- package/node_modules/@contrail/sdk/scripts/replicate-bug.js +0 -69
- /package/dist/{commands/entities/create.spec.d.ts → auth/sign-in-error.spec.d.ts} +0 -0
- /package/dist/{commands/entities/grammar.spec.d.ts → auth/sso.spec.d.ts} +0 -0
|
@@ -21,56 +21,514 @@ describe('Item Processor', () => {
|
|
|
21
21
|
],
|
|
22
22
|
};
|
|
23
23
|
describe('validateLoadFile', () => {
|
|
24
|
-
it('should
|
|
25
|
-
const
|
|
24
|
+
it('should return general error if loadType is not correct', () => {
|
|
25
|
+
const data = [
|
|
26
26
|
{
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
name: 'item1',
|
|
28
|
+
family_federated_id: 'family_1',
|
|
29
|
+
input_col_1: 'value_1',
|
|
30
|
+
input_col_2: 'value_2',
|
|
31
|
+
typePath: 'item',
|
|
30
32
|
},
|
|
31
33
|
{
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
34
|
+
name: 'item2',
|
|
35
|
+
family_federated_id: 'family_2',
|
|
36
|
+
input_col_1: 'value_3',
|
|
37
|
+
input_col_2: 'value_4',
|
|
38
|
+
typePath: 'item',
|
|
35
39
|
},
|
|
36
40
|
{
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
41
|
+
name: 'item3',
|
|
42
|
+
family_federated_id: 'family_3',
|
|
43
|
+
input_col_1: 'value_5',
|
|
44
|
+
input_col_2: 'value_6',
|
|
45
|
+
typePath: 'item',
|
|
40
46
|
},
|
|
41
47
|
];
|
|
42
48
|
const config = {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
name: 'itemName',
|
|
46
|
-
itemFamilyFederatedId: 'itemFamilyFederatedId',
|
|
47
|
-
},
|
|
49
|
+
...loaderProcess,
|
|
50
|
+
loadType: ['INVALID'],
|
|
48
51
|
};
|
|
49
|
-
const result = item_processor_1.ItemProcessor.validateLoadFile(
|
|
50
|
-
expect(result.
|
|
52
|
+
const result = item_processor_1.ItemProcessor.validateLoadFile(data, config);
|
|
53
|
+
expect(result.generalErrors).toEqual([
|
|
51
54
|
{
|
|
52
|
-
|
|
53
|
-
|
|
55
|
+
message: constants_1.ITEM_PROCESSOR_ERRORS.LOAD_TYPE_INVALID,
|
|
56
|
+
issueType: entity_types_1.IssueType.CONFIG,
|
|
57
|
+
},
|
|
58
|
+
]);
|
|
59
|
+
});
|
|
60
|
+
describe('validate typepath', () => {
|
|
61
|
+
it('should throw general error if typePath is incorrect', () => {
|
|
62
|
+
const data = [
|
|
63
|
+
{
|
|
64
|
+
name: 'item1',
|
|
65
|
+
family_federated_id: 'family_1',
|
|
66
|
+
input_col_1: 'value_1',
|
|
67
|
+
input_col_2: 'value_2',
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
name: 'item2',
|
|
71
|
+
family_federated_id: 'family_2',
|
|
72
|
+
input_col_1: 'value_3',
|
|
73
|
+
input_col_2: 'value_4',
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
name: 'item3',
|
|
77
|
+
family_federated_id: 'family_3',
|
|
78
|
+
input_col_1: 'value_5',
|
|
79
|
+
input_col_2: 'value_6',
|
|
80
|
+
},
|
|
81
|
+
];
|
|
82
|
+
const config = {
|
|
83
|
+
...loaderProcess,
|
|
84
|
+
conditionalColumns: [
|
|
54
85
|
{
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
issueType: entity_types_1.IssueType.DUPLICATE_FEDERATED_ID,
|
|
58
|
-
data: '{"itemName":"foo","itemFamilyFederatedId":"1","itemOptionFederatedId":"11"}',
|
|
86
|
+
toProperty: 'typePath',
|
|
87
|
+
default: 'custom-entity:',
|
|
59
88
|
},
|
|
60
89
|
],
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
90
|
+
};
|
|
91
|
+
const result = item_processor_1.ItemProcessor.validateLoadFile(data, config);
|
|
92
|
+
expect(result.generalErrors).toEqual([
|
|
93
|
+
{
|
|
94
|
+
message: constants_1.ITEM_PROCESSOR_ERRORS.TYPEPATH_INVALID,
|
|
95
|
+
issueType: entity_types_1.IssueType.CONFIG,
|
|
96
|
+
},
|
|
97
|
+
]);
|
|
98
|
+
});
|
|
99
|
+
it('should throw error if typepath is present in the config file but have incorrect typePath', () => {
|
|
100
|
+
const data = [
|
|
101
|
+
{
|
|
102
|
+
name: 'item1',
|
|
103
|
+
family_federated_id: 'family_1',
|
|
104
|
+
input_col_1: 'value_1',
|
|
105
|
+
input_col_2: 'value_2',
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
name: 'item2',
|
|
109
|
+
family_federated_id: 'family_2',
|
|
110
|
+
input_col_1: 'value_3',
|
|
111
|
+
input_col_2: 'value_4',
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
name: 'item3',
|
|
115
|
+
family_federated_id: 'family_3',
|
|
116
|
+
input_col_1: 'value_5',
|
|
117
|
+
input_col_2: 'value_6',
|
|
118
|
+
},
|
|
119
|
+
];
|
|
120
|
+
const config = {
|
|
121
|
+
...loaderProcess,
|
|
122
|
+
conditionalColumns: [
|
|
65
123
|
{
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
issueType: entity_types_1.IssueType.DUPLICATE_FEDERATED_ID,
|
|
69
|
-
data: '{"itemName":"foo","itemFamilyFederatedId":"1","itemOptionFederatedId":"11"}',
|
|
124
|
+
toProperty: 'typePath',
|
|
125
|
+
default: 'custom-entity1',
|
|
70
126
|
},
|
|
71
127
|
],
|
|
72
|
-
}
|
|
73
|
-
|
|
128
|
+
};
|
|
129
|
+
const result = item_processor_1.ItemProcessor.validateLoadFile(data, config);
|
|
130
|
+
expect(result.generalErrors).toEqual([
|
|
131
|
+
{
|
|
132
|
+
message: constants_1.ITEM_PROCESSOR_ERRORS.TYPEPATH_INVALID,
|
|
133
|
+
issueType: entity_types_1.IssueType.CONFIG,
|
|
134
|
+
},
|
|
135
|
+
]);
|
|
136
|
+
});
|
|
137
|
+
it('should throw error if typepath is present in the csv header but have incorrect typePath', () => {
|
|
138
|
+
const data = [
|
|
139
|
+
{
|
|
140
|
+
name: 'item1',
|
|
141
|
+
family_federated_id: 'family_1',
|
|
142
|
+
input_col_1: 'value_1',
|
|
143
|
+
input_col_2: 'value_2',
|
|
144
|
+
typePath: 'custom-entity1',
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
name: 'item2',
|
|
148
|
+
family_federated_id: 'family_2',
|
|
149
|
+
input_col_1: 'value_3',
|
|
150
|
+
input_col_2: 'value_4',
|
|
151
|
+
typePath: 'custom-entity1',
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
name: 'item3',
|
|
155
|
+
family_federated_id: 'family_3',
|
|
156
|
+
input_col_1: 'value_5',
|
|
157
|
+
input_col_2: 'value_6',
|
|
158
|
+
typePath: 'custom-entity1',
|
|
159
|
+
},
|
|
160
|
+
];
|
|
161
|
+
const config = {
|
|
162
|
+
...loaderProcess,
|
|
163
|
+
conditionalColumns: [],
|
|
164
|
+
};
|
|
165
|
+
const result = item_processor_1.ItemProcessor.validateLoadFile(data, config);
|
|
166
|
+
expect(result.generalErrors).toEqual([
|
|
167
|
+
{
|
|
168
|
+
message: constants_1.ITEM_PROCESSOR_ERRORS.TYPEPATH_INVALID,
|
|
169
|
+
issueType: entity_types_1.IssueType.CONFIG,
|
|
170
|
+
},
|
|
171
|
+
]);
|
|
172
|
+
});
|
|
173
|
+
it('should throw error if typepath is not present in csv header', () => {
|
|
174
|
+
const data = [
|
|
175
|
+
{
|
|
176
|
+
name: 'item1',
|
|
177
|
+
family_federated_id: 'family_1',
|
|
178
|
+
input_col_1: 'value_1',
|
|
179
|
+
input_col_2: 'value_2',
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
name: 'item2',
|
|
183
|
+
family_federated_id: 'family_2',
|
|
184
|
+
input_col_1: 'value_3',
|
|
185
|
+
input_col_2: 'value_4',
|
|
186
|
+
},
|
|
187
|
+
{
|
|
188
|
+
name: 'item3',
|
|
189
|
+
family_federated_id: 'family_3',
|
|
190
|
+
input_col_1: 'value_5',
|
|
191
|
+
input_col_2: 'value_6',
|
|
192
|
+
},
|
|
193
|
+
];
|
|
194
|
+
const config = {
|
|
195
|
+
...loaderProcess,
|
|
196
|
+
conditionalColumns: [],
|
|
197
|
+
};
|
|
198
|
+
const result = item_processor_1.ItemProcessor.validateLoadFile(data, config);
|
|
199
|
+
expect(result.generalErrors).toEqual([
|
|
200
|
+
{
|
|
201
|
+
message: constants_1.ITEM_PROCESSOR_ERRORS.TYPEPATH_INVALID,
|
|
202
|
+
issueType: entity_types_1.IssueType.CONFIG,
|
|
203
|
+
},
|
|
204
|
+
]);
|
|
205
|
+
});
|
|
206
|
+
it('should not throw error if every row has a valid typePath', () => {
|
|
207
|
+
const data = [
|
|
208
|
+
{
|
|
209
|
+
name: 'item1',
|
|
210
|
+
family_federated_id: 'family_1',
|
|
211
|
+
input_col_1: 'value_1',
|
|
212
|
+
input_col_2: 'value_2',
|
|
213
|
+
typePath: 'item',
|
|
214
|
+
},
|
|
215
|
+
{
|
|
216
|
+
name: 'item2',
|
|
217
|
+
family_federated_id: 'family_2',
|
|
218
|
+
input_col_1: 'value_3',
|
|
219
|
+
input_col_2: 'value_4',
|
|
220
|
+
typePath: 'item:material:fabric:yarn',
|
|
221
|
+
},
|
|
222
|
+
{
|
|
223
|
+
name: 'item3',
|
|
224
|
+
family_federated_id: 'family_3',
|
|
225
|
+
input_col_1: 'value_5',
|
|
226
|
+
input_col_2: 'value_6',
|
|
227
|
+
typePath: 'item:material:fabric:leather',
|
|
228
|
+
},
|
|
229
|
+
];
|
|
230
|
+
const config = {
|
|
231
|
+
...loaderProcess,
|
|
232
|
+
conditionalColumns: [],
|
|
233
|
+
};
|
|
234
|
+
const result = item_processor_1.ItemProcessor.validateLoadFile(data, config);
|
|
235
|
+
expect(result.generalErrors).toEqual([]);
|
|
236
|
+
});
|
|
237
|
+
});
|
|
238
|
+
describe('validate itemOptionFederatedId', () => {
|
|
239
|
+
it('should validate optionFederatedId in conditional columns', () => {
|
|
240
|
+
const data = [{ name: 'test1', optionName: 'Test Option 1' }];
|
|
241
|
+
const config = {
|
|
242
|
+
...loaderProcess,
|
|
243
|
+
conditionalColumns: [
|
|
244
|
+
{
|
|
245
|
+
toProperty: 'itemFamilyFederatedId',
|
|
246
|
+
default: 'test-{name}',
|
|
247
|
+
},
|
|
248
|
+
{
|
|
249
|
+
toProperty: 'itemOptionFederatedId',
|
|
250
|
+
default: 'test-{optionName}',
|
|
251
|
+
},
|
|
252
|
+
],
|
|
253
|
+
};
|
|
254
|
+
const result = item_processor_1.ItemProcessor.validateLoadFile(data, config);
|
|
255
|
+
expect(result.generalWarnings).not.toContainEqual({
|
|
256
|
+
message: constants_1.ITEM_PROCESSOR_WARNINGS.OPTION_FEDERATED_ID_UNMAPPED,
|
|
257
|
+
issueType: entity_types_1.IssueType.CONFIG,
|
|
258
|
+
});
|
|
259
|
+
});
|
|
260
|
+
it('should validate federatedId in CSV data', () => {
|
|
261
|
+
const data = [
|
|
262
|
+
{
|
|
263
|
+
itemFamilyFederatedId: 'test1',
|
|
264
|
+
itemOptionFederatedId: 'option1',
|
|
265
|
+
name: 'Test 1',
|
|
266
|
+
},
|
|
267
|
+
];
|
|
268
|
+
const result = item_processor_1.ItemProcessor.validateLoadFile(data, loaderProcess);
|
|
269
|
+
expect(result.generalErrors).not.toContainEqual({
|
|
270
|
+
message: constants_1.ITEM_PROCESSOR_WARNINGS.OPTION_FEDERATED_ID_UNMAPPED,
|
|
271
|
+
issueType: entity_types_1.IssueType.CONFIG,
|
|
272
|
+
});
|
|
273
|
+
});
|
|
274
|
+
it('should validate federatedId in federatedMapping', () => {
|
|
275
|
+
const data = [{ code: 'test1', option: 'option1', name: 'Test 1' }];
|
|
276
|
+
const config = {
|
|
277
|
+
...loaderProcess,
|
|
278
|
+
federatedMappings: {
|
|
279
|
+
itemFamilyFederatedId: 'code',
|
|
280
|
+
itemOptionFederatedId: 'option',
|
|
281
|
+
},
|
|
282
|
+
};
|
|
283
|
+
const result = item_processor_1.ItemProcessor.validateLoadFile(data, config);
|
|
284
|
+
expect(result.generalErrors).not.toContainEqual({
|
|
285
|
+
message: constants_1.ITEM_PROCESSOR_WARNINGS.OPTION_FEDERATED_ID_UNMAPPED,
|
|
286
|
+
issueType: entity_types_1.IssueType.CONFIG,
|
|
287
|
+
});
|
|
288
|
+
});
|
|
289
|
+
it('should warning error if itemOptionfederatedId is missing in federatedmapping config, csv header and conditional column', () => {
|
|
290
|
+
const data = [{ name: 'color1', option: 'option1' }];
|
|
291
|
+
const config = {
|
|
292
|
+
id: 'mock-loader-process-id',
|
|
293
|
+
loadFileId: 'mock-load-file-id',
|
|
294
|
+
loadType: [entity_types_1.LoadType.COLOR],
|
|
295
|
+
status: entity_types_1.LoadStatus.COMPLETE,
|
|
296
|
+
conditionalColumns: [
|
|
297
|
+
{
|
|
298
|
+
toProperty: 'typePath',
|
|
299
|
+
default: 'color',
|
|
300
|
+
},
|
|
301
|
+
],
|
|
302
|
+
federatedMappings: {
|
|
303
|
+
name: 'name',
|
|
304
|
+
optionName: 'option',
|
|
305
|
+
},
|
|
306
|
+
};
|
|
307
|
+
const result = item_processor_1.ItemProcessor.validateLoadFile(data, config);
|
|
308
|
+
expect(result.generalWarnings).toEqual([
|
|
309
|
+
{
|
|
310
|
+
message: constants_1.ITEM_PROCESSOR_WARNINGS.OPTION_FEDERATED_ID_UNMAPPED,
|
|
311
|
+
issueType: entity_types_1.IssueType.CONFIG,
|
|
312
|
+
},
|
|
313
|
+
]);
|
|
314
|
+
});
|
|
315
|
+
it('should return error if itemOptionFederatedId is mapped incorrectly in federatedMappings', () => {
|
|
316
|
+
const lineSheetData = [{ header1: 'value1', test1: 'test1' }];
|
|
317
|
+
const config = {
|
|
318
|
+
loadType: ['ITEM'],
|
|
319
|
+
federatedMappings: {
|
|
320
|
+
name: 'header1',
|
|
321
|
+
itemFamilyFederatedId: 'someId',
|
|
322
|
+
optionName: 'test1',
|
|
323
|
+
itemOptionFederatedId: 'test2',
|
|
324
|
+
},
|
|
325
|
+
};
|
|
326
|
+
const result = item_processor_1.ItemProcessor.validateLoadFile(lineSheetData, config);
|
|
327
|
+
expect(result.generalWarnings).toEqual([
|
|
328
|
+
{
|
|
329
|
+
message: constants_1.ITEM_PROCESSOR_WARNINGS.OPTION_FEDERATED_ID_NOT_FOUND('test2'),
|
|
330
|
+
issueType: entity_types_1.IssueType.CONFIG,
|
|
331
|
+
},
|
|
332
|
+
]);
|
|
333
|
+
});
|
|
334
|
+
});
|
|
335
|
+
describe('validate itemOptionName', () => {
|
|
336
|
+
it('should validate optionName in conditional columns', () => {
|
|
337
|
+
const data = [{ federatedId: 'test1' }];
|
|
338
|
+
const config = {
|
|
339
|
+
...loaderProcess,
|
|
340
|
+
federatedMappings: {},
|
|
341
|
+
conditionalColumns: [
|
|
342
|
+
{
|
|
343
|
+
toProperty: 'name',
|
|
344
|
+
default: 'Test {federatedId}',
|
|
345
|
+
},
|
|
346
|
+
{
|
|
347
|
+
toProperty: 'optionName',
|
|
348
|
+
default: 'Test1 {federatedId}',
|
|
349
|
+
},
|
|
350
|
+
],
|
|
351
|
+
};
|
|
352
|
+
const result = item_processor_1.ItemProcessor.validateLoadFile(data, config);
|
|
353
|
+
console.log(JSON.stringify(result, null, 2));
|
|
354
|
+
expect(result.generalWarnings).not.toContainEqual({
|
|
355
|
+
message: constants_1.ITEM_PROCESSOR_WARNINGS.OPTIONNAME_UNMAPPED,
|
|
356
|
+
issueType: entity_types_1.IssueType.CONFIG,
|
|
357
|
+
});
|
|
358
|
+
});
|
|
359
|
+
it('should validate name in CSV data', () => {
|
|
360
|
+
const data = [{ federatedId: 'test1', name: 'Test 1', optionName: 'Option 1' }];
|
|
361
|
+
const result = item_processor_1.ItemProcessor.validateLoadFile(data, loaderProcess);
|
|
362
|
+
expect(result.generalWarnings).not.toContainEqual({
|
|
363
|
+
message: constants_1.ITEM_PROCESSOR_WARNINGS.OPTIONNAME_UNMAPPED,
|
|
364
|
+
issueType: entity_types_1.IssueType.CONFIG,
|
|
365
|
+
});
|
|
366
|
+
});
|
|
367
|
+
it('should return warning if optionName is missing in federatedMappings, config and conditional column', () => {
|
|
368
|
+
const data = [{ id: 'custom-entity1', optionId: 'option1' }];
|
|
369
|
+
const config = {
|
|
370
|
+
...loaderProcess,
|
|
371
|
+
loadType: [entity_types_1.LoadType.CUSTOM_ENTITY],
|
|
372
|
+
federatedMappings: {
|
|
373
|
+
federatedId: 'id',
|
|
374
|
+
itemOptionFederatedId: 'optionId',
|
|
375
|
+
},
|
|
376
|
+
};
|
|
377
|
+
const result = item_processor_1.ItemProcessor.validateLoadFile(data, config);
|
|
378
|
+
expect(result.generalWarnings).toEqual([
|
|
379
|
+
{
|
|
380
|
+
message: constants_1.ITEM_PROCESSOR_WARNINGS.OPTIONNAME_UNMAPPED,
|
|
381
|
+
issueType: entity_types_1.IssueType.CONFIG,
|
|
382
|
+
},
|
|
383
|
+
]);
|
|
384
|
+
});
|
|
385
|
+
it('should validate name in federatedMapping', () => {
|
|
386
|
+
const data = [
|
|
387
|
+
{
|
|
388
|
+
federatedId: 'test1',
|
|
389
|
+
display_name: 'Test 1',
|
|
390
|
+
display_option: 'Option 1',
|
|
391
|
+
},
|
|
392
|
+
];
|
|
393
|
+
const config = {
|
|
394
|
+
...loaderProcess,
|
|
395
|
+
federatedMappings: {
|
|
396
|
+
name: 'display_name',
|
|
397
|
+
optionName: 'display_option',
|
|
398
|
+
},
|
|
399
|
+
};
|
|
400
|
+
const result = item_processor_1.ItemProcessor.validateLoadFile(data, config);
|
|
401
|
+
expect(result.generalWarnings).not.toContainEqual({
|
|
402
|
+
message: constants_1.ITEM_PROCESSOR_WARNINGS.OPTIONNAME_UNMAPPED,
|
|
403
|
+
issueType: entity_types_1.IssueType.CONFIG,
|
|
404
|
+
});
|
|
405
|
+
});
|
|
406
|
+
it('should return a warning if optionName is not mapped in federatedMappings', () => {
|
|
407
|
+
const data = [
|
|
408
|
+
{
|
|
409
|
+
name: 'item1',
|
|
410
|
+
family_federated_id: 'family_1',
|
|
411
|
+
input_col_1: 'value_1',
|
|
412
|
+
input_col_2: 'value_2',
|
|
413
|
+
},
|
|
414
|
+
{
|
|
415
|
+
name: 'item2',
|
|
416
|
+
family_federated_id: 'family_2',
|
|
417
|
+
input_col_1: 'value_3',
|
|
418
|
+
input_col_2: 'value_4',
|
|
419
|
+
},
|
|
420
|
+
{
|
|
421
|
+
name: 'item3',
|
|
422
|
+
family_federated_id: 'family_3',
|
|
423
|
+
input_col_1: 'value_5',
|
|
424
|
+
input_col_2: 'value_6',
|
|
425
|
+
},
|
|
426
|
+
];
|
|
427
|
+
const config = {
|
|
428
|
+
...loaderProcess,
|
|
429
|
+
conditionalColumns: [],
|
|
430
|
+
federatedMappings: {
|
|
431
|
+
itemFamilyFederatedId: 'family_federated_id',
|
|
432
|
+
itemOptionFederatedId: 'input_col_1',
|
|
433
|
+
},
|
|
434
|
+
};
|
|
435
|
+
const result = item_processor_1.ItemProcessor.validateLoadFile(data, config);
|
|
436
|
+
expect(result.generalWarnings).toEqual([
|
|
437
|
+
{
|
|
438
|
+
message: constants_1.ITEM_PROCESSOR_WARNINGS.OPTIONNAME_UNMAPPED,
|
|
439
|
+
issueType: entity_types_1.IssueType.CONFIG,
|
|
440
|
+
},
|
|
441
|
+
]);
|
|
442
|
+
});
|
|
443
|
+
it('should return a warning if optionName is mapped incorrectly in federatedMappings', () => {
|
|
444
|
+
const data = [
|
|
445
|
+
{
|
|
446
|
+
name: 'item1',
|
|
447
|
+
family_federated_id: 'family_1',
|
|
448
|
+
input_col_1: 'value_1',
|
|
449
|
+
input_col_2: 'value_2',
|
|
450
|
+
},
|
|
451
|
+
{
|
|
452
|
+
name: 'item2',
|
|
453
|
+
family_federated_id: 'family_2',
|
|
454
|
+
input_col_1: 'value_3',
|
|
455
|
+
input_col_2: 'value_4',
|
|
456
|
+
},
|
|
457
|
+
{
|
|
458
|
+
name: 'item3',
|
|
459
|
+
family_federated_id: 'family_3',
|
|
460
|
+
input_col_1: 'value_5',
|
|
461
|
+
input_col_2: 'value_6',
|
|
462
|
+
},
|
|
463
|
+
];
|
|
464
|
+
const config = {
|
|
465
|
+
...loaderProcess,
|
|
466
|
+
conditionalColumns: [],
|
|
467
|
+
federatedMappings: {
|
|
468
|
+
itemFamilyFederatedId: 'family_federated_id',
|
|
469
|
+
itemOptionFederatedId: 'input_col_1',
|
|
470
|
+
optionName: 'input_col_3',
|
|
471
|
+
},
|
|
472
|
+
};
|
|
473
|
+
const result = item_processor_1.ItemProcessor.validateLoadFile(data, config);
|
|
474
|
+
expect(result.generalWarnings).toEqual([
|
|
475
|
+
{
|
|
476
|
+
message: '"input_col_3" column not found in the CSV file',
|
|
477
|
+
issueType: entity_types_1.IssueType.CONFIG,
|
|
478
|
+
},
|
|
479
|
+
]);
|
|
480
|
+
});
|
|
481
|
+
it('should throw error for the duplicate itemOptionFederatedId', () => {
|
|
482
|
+
const lineSheetData = [
|
|
483
|
+
{
|
|
484
|
+
itemName: 'foo',
|
|
485
|
+
itemFamilyFederatedId: '1',
|
|
486
|
+
itemOptionFederatedId: '11',
|
|
487
|
+
},
|
|
488
|
+
{
|
|
489
|
+
itemName: 'foo',
|
|
490
|
+
itemFamilyFederatedId: '1',
|
|
491
|
+
itemOptionFederatedId: '11',
|
|
492
|
+
},
|
|
493
|
+
{
|
|
494
|
+
itemName: 'bar',
|
|
495
|
+
itemFamilyFederatedId: '2',
|
|
496
|
+
itemOptionFederatedId: '12',
|
|
497
|
+
},
|
|
498
|
+
];
|
|
499
|
+
const config = {
|
|
500
|
+
loadType: ['ITEM'],
|
|
501
|
+
federatedMappings: {
|
|
502
|
+
name: 'itemName',
|
|
503
|
+
itemFamilyFederatedId: 'itemFamilyFederatedId',
|
|
504
|
+
},
|
|
505
|
+
};
|
|
506
|
+
const result = item_processor_1.ItemProcessor.validateLoadFile(lineSheetData, config);
|
|
507
|
+
expect(result.errors).toEqual([
|
|
508
|
+
{
|
|
509
|
+
rowNumber: 2,
|
|
510
|
+
columnIssues: [
|
|
511
|
+
{
|
|
512
|
+
columnName: 'itemOptionFederatedId',
|
|
513
|
+
message: 'Duplicate federatedId found: 11',
|
|
514
|
+
issueType: entity_types_1.IssueType.DUPLICATE_FEDERATED_ID,
|
|
515
|
+
data: '{"itemName":"foo","itemFamilyFederatedId":"1","itemOptionFederatedId":"11"}',
|
|
516
|
+
},
|
|
517
|
+
],
|
|
518
|
+
},
|
|
519
|
+
{
|
|
520
|
+
rowNumber: 3,
|
|
521
|
+
columnIssues: [
|
|
522
|
+
{
|
|
523
|
+
columnName: 'itemOptionFederatedId',
|
|
524
|
+
message: 'Duplicate federatedId found: 11',
|
|
525
|
+
issueType: entity_types_1.IssueType.DUPLICATE_FEDERATED_ID,
|
|
526
|
+
data: '{"itemName":"foo","itemFamilyFederatedId":"1","itemOptionFederatedId":"11"}',
|
|
527
|
+
},
|
|
528
|
+
],
|
|
529
|
+
},
|
|
530
|
+
]);
|
|
531
|
+
});
|
|
74
532
|
});
|
|
75
533
|
describe('validate duplicate optionName within family', () => {
|
|
76
534
|
it('should return errors when options in the same family have duplicate optionNames', () => {
|
|
@@ -49,8 +49,6 @@ async function validate(rows, config, columnAnalysis, client) {
|
|
|
49
49
|
}
|
|
50
50
|
const processorIssues = runProcessorValidation(rows, config);
|
|
51
51
|
issues.push(...processorIssues);
|
|
52
|
-
const itemTypePathIssues = validateItemTypePath(rows, config);
|
|
53
|
-
issues.push(...itemTypePathIssues);
|
|
54
52
|
const itemNameIssues = validateItemNames(rows, config);
|
|
55
53
|
issues.push(...itemNameIssues);
|
|
56
54
|
const identifierConflictIssues = validateStaticIdentifierConflicts(config);
|
|
@@ -137,7 +135,7 @@ function runProcessorValidation(rows, config) {
|
|
|
137
135
|
for (const error of validationResult?.generalErrors ?? []) {
|
|
138
136
|
issues.push({
|
|
139
137
|
severity: types_2.PreValidationSeverity.ERROR,
|
|
140
|
-
category:
|
|
138
|
+
category: CONFIG_CATEGORY,
|
|
141
139
|
columnName: '',
|
|
142
140
|
propertySlug: '',
|
|
143
141
|
propertyType: '',
|
|
@@ -148,7 +146,7 @@ function runProcessorValidation(rows, config) {
|
|
|
148
146
|
for (const warning of validationResult?.generalWarnings ?? []) {
|
|
149
147
|
issues.push({
|
|
150
148
|
severity: types_2.PreValidationSeverity.WARNING,
|
|
151
|
-
category:
|
|
149
|
+
category: CONFIG_CATEGORY,
|
|
152
150
|
columnName: '',
|
|
153
151
|
propertySlug: '',
|
|
154
152
|
propertyType: '',
|
|
@@ -398,54 +396,6 @@ function validateMultiSelectFormats(rows, typePropertyMaps) {
|
|
|
398
396
|
}
|
|
399
397
|
return issues;
|
|
400
398
|
}
|
|
401
|
-
function validateItemTypePath(rows, config) {
|
|
402
|
-
const isItemCreate = config.loadType.includes(types_2.LoadType.ITEM);
|
|
403
|
-
const isCustomEntity = config.loadType.includes(types_2.LoadType.CUSTOM_ENTITY);
|
|
404
|
-
if (!isItemCreate && !isCustomEntity)
|
|
405
|
-
return [];
|
|
406
|
-
const issues = [];
|
|
407
|
-
if (isItemCreate) {
|
|
408
|
-
const invalidRows = [];
|
|
409
|
-
forEachRow(rows, (row, rowNumber) => {
|
|
410
|
-
const tp = row.typePath;
|
|
411
|
-
const valid = tp === 'item' || (typeof tp === 'string' && tp.startsWith('item:') && tp.split(':')[1]?.length > 0);
|
|
412
|
-
if (!valid)
|
|
413
|
-
invalidRows.push({ row: rowNumber, value: String(tp ?? '') });
|
|
414
|
-
});
|
|
415
|
-
if (invalidRows.length > 0) {
|
|
416
|
-
issues.push({
|
|
417
|
-
severity: types_2.PreValidationSeverity.ERROR,
|
|
418
|
-
category: MISSING_REQUIRED_FIELD_CATEGORY,
|
|
419
|
-
columnName: 'typePath',
|
|
420
|
-
propertySlug: 'typePath',
|
|
421
|
-
propertyType: 'string',
|
|
422
|
-
message: `"typePath" must be "item" or "item:<subtypepath>". ${invalidRows.length} row(s) have an invalid or missing typePath.`,
|
|
423
|
-
affectedRows: invalidRows,
|
|
424
|
-
});
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
if (isCustomEntity) {
|
|
428
|
-
const invalidRows = [];
|
|
429
|
-
forEachRow(rows, (row, rowNumber) => {
|
|
430
|
-
const tp = row.typePath;
|
|
431
|
-
const valid = typeof tp === 'string' && tp.startsWith('custom-entity:') && tp.slice('custom-entity:'.length).length > 0;
|
|
432
|
-
if (!valid)
|
|
433
|
-
invalidRows.push({ row: rowNumber, value: String(tp ?? '') });
|
|
434
|
-
});
|
|
435
|
-
if (invalidRows.length > 0) {
|
|
436
|
-
issues.push({
|
|
437
|
-
severity: types_2.PreValidationSeverity.ERROR,
|
|
438
|
-
category: MISSING_REQUIRED_FIELD_CATEGORY,
|
|
439
|
-
columnName: 'typePath',
|
|
440
|
-
propertySlug: 'typePath',
|
|
441
|
-
propertyType: 'string',
|
|
442
|
-
message: `"typePath" must be "custom-entity:<subtypepath>". ${invalidRows.length} row(s) have an invalid or missing typePath.`,
|
|
443
|
-
affectedRows: invalidRows,
|
|
444
|
-
});
|
|
445
|
-
}
|
|
446
|
-
}
|
|
447
|
-
return issues;
|
|
448
|
-
}
|
|
449
399
|
function validateItemNames(rows, config) {
|
|
450
400
|
const itemBasedLoadTypes = [types_2.LoadType.ITEM, types_2.LoadType.PROJECT_ITEM, types_2.LoadType.ASSORTMENT];
|
|
451
401
|
const isItemBased = config.loadType.some((lt) => itemBasedLoadTypes.includes(lt));
|