definition-generator-framework 1.12.5 → 1.12.7
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/dist/framework/definition-component.d.ts +11 -9
- package/dist/framework/definition-component.js +18 -18
- package/dist/framework/definition-generator.d.ts +6 -5
- package/dist/framework/definition-generator.js +16 -18
- package/dist/framework/file-content-generator/file-content-generator.js +1 -1
- package/dist/framework/file-content-generator/file-content-generator.test.js +49 -49
- package/dist/framework/framework.d.ts +14 -13
- package/dist/framework/framework.data.d.ts +3 -3
- package/dist/framework/framework.data.js +13 -7
- package/dist/framework/framework.js +36 -33
- package/dist/framework/framework.model.d.ts +15 -15
- package/dist/framework/framework.model.js +3 -3
- package/dist/framework/index-file-generator/index-file-generator.js +2 -4
- package/dist/helpers/common-functions/common-functions.js +1 -1
- package/dist/helpers/common-functions/common-functions.spec.js +48 -48
- package/dist/helpers/duplicate-helper/duplicate-helper.spec.js +52 -52
- package/dist/helpers/output-helper/output-helper.d.ts +26 -26
- package/dist/helpers/output-helper/output-helper.js +127 -107
- package/dist/helpers/output-helper/output-helper.spec.d.ts +22 -22
- package/dist/helpers/output-helper/output-helper.spec.js +223 -211
- package/dist/helpers/output-helper/output-helper.test.d.ts +22 -22
- package/dist/helpers/output-helper/output-helper.test.js +224 -212
- package/dist/helpers/raw-definition-helper/raw-definition.helper.spec.js +133 -125
- package/dist/helpers/validator/custom-validator-helper/custom-validator.helper.spec.d.ts +1 -1
- package/dist/helpers/validator/custom-validator-helper/custom-validator.helper.spec.js +174 -156
- package/dist/helpers/validator/custom-validators/image.custom-validator.d.ts +6 -6
- package/dist/helpers/validator/custom-validators/image.custom-validator.js +40 -39
- package/dist/helpers/validator/custom-validators/unique-name-group.custom-validator.d.ts +4 -4
- package/dist/helpers/validator/custom-validators/unique-name-group.custom-validator.js +29 -29
- package/dist/helpers/validator/joi-custom-validators.spec.js +284 -240
- package/dist/helpers/validator/validator.spec.js +313 -303
- package/dist/pipeline/1-select-definitions-helper.d.ts +13 -13
- package/dist/pipeline/1-select-definitions-helper.js +68 -72
- package/dist/pipeline/1-select-definitions.helper.test.js +40 -40
- package/dist/pipeline/1-select-definitions.spec.js +131 -131
- package/dist/pipeline/2-structure-parser.helper.spec.js +266 -266
- package/dist/pipeline/parsers/array-parser.spec.js +116 -113
- package/dist/pipeline/parsers/object-parser.spec.js +159 -153
- package/dist/pipeline/parsers/primitive-parser.spec.js +67 -67
- package/dist/pre-made-components/assets/3-font.js +4 -4
- package/dist/pre-made-components/events/1-event.d.ts +1 -1
- package/dist/pre-made-components/events/1-event.js +157 -125
- package/dist/pre-made-components/events/2-event-test.d.ts +8 -8
- package/dist/pre-made-components/events/2-event-test.js +156 -119
- package/dist/pre-made-components/events/2-script-test.js +0 -1
- package/dist/pre-made-components/events/event-setup.d.ts +10 -5
- package/dist/pre-made-components/events/event-setup.js +15 -15
- package/dist/pre-made-components/events/script-setup.d.ts +5 -3
- package/dist/pre-made-components/events/script-setup.js +11 -11
- package/package.json +5 -10
|
@@ -1,322 +1,332 @@
|
|
|
1
|
-
|
|
2
|
-
var __importDefault =
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
var __importDefault =
|
|
3
|
+
(this && this.__importDefault) ||
|
|
4
|
+
function (mod) {
|
|
5
|
+
return mod && mod.__esModule ? mod : { default: mod };
|
|
6
|
+
};
|
|
7
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
8
|
+
const joi_1 = __importDefault(require('joi'));
|
|
9
|
+
const validator_1 = require('./validator');
|
|
10
|
+
const joi_custom_validators_1 = require('./joi-custom-validators');
|
|
11
|
+
const mocks_1 = require('../../_mocks/mocks');
|
|
12
|
+
const custom_validator_helper_1 = require('./custom-validator-helper/custom-validator.helper');
|
|
13
|
+
const context_1 = require('../../framework/context');
|
|
14
|
+
const definition_store_1 = require('../../framework/definition-store');
|
|
15
|
+
joi_custom_validators_1.JoiCustomValidators.decorate(joi_1.default, { existsSync: path => path !== 'D:/test/false/path.png' });
|
|
14
16
|
const ComponentType = 'ASSET';
|
|
15
17
|
class Asset {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
static {
|
|
19
|
+
this.$meta = {
|
|
20
|
+
componentName: ComponentType
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
async process() {}
|
|
20
24
|
}
|
|
21
25
|
const TestSchema = joi_1.default.object().keys({
|
|
22
|
-
|
|
23
|
-
|
|
26
|
+
str1: joi_1.default.string().required(),
|
|
27
|
+
str2: joi_1.default.string().path().optional()
|
|
24
28
|
});
|
|
25
29
|
function getSampleRawDefinition(str, pathString) {
|
|
26
|
-
|
|
27
|
-
componentName: ComponentType,
|
|
28
|
-
location: mocks_1.SampleLocation1,
|
|
29
|
-
parsedStructure: {
|
|
30
|
-
line: mocks_1.SampleLocation1.line + 1,
|
|
31
|
-
rawData: {
|
|
32
|
-
str1: {
|
|
33
|
-
rawData: str,
|
|
34
|
-
line: mocks_1.SampleLocation1.line + 1
|
|
35
|
-
},
|
|
36
|
-
str2: {
|
|
37
|
-
rawData: pathString,
|
|
38
|
-
line: mocks_1.SampleLocation1.line + 2
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
return rawDefinition;
|
|
44
|
-
}
|
|
45
|
-
const SampleNestedRawDefinition = {
|
|
30
|
+
let rawDefinition = {
|
|
46
31
|
componentName: ComponentType,
|
|
47
32
|
location: mocks_1.SampleLocation1,
|
|
48
33
|
parsedStructure: {
|
|
34
|
+
line: mocks_1.SampleLocation1.line + 1,
|
|
35
|
+
rawData: {
|
|
36
|
+
str1: {
|
|
37
|
+
rawData: str,
|
|
38
|
+
line: mocks_1.SampleLocation1.line + 1
|
|
39
|
+
},
|
|
40
|
+
str2: {
|
|
41
|
+
rawData: pathString,
|
|
42
|
+
line: mocks_1.SampleLocation1.line + 2
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
return rawDefinition;
|
|
48
|
+
}
|
|
49
|
+
const SampleNestedRawDefinition = {
|
|
50
|
+
componentName: ComponentType,
|
|
51
|
+
location: mocks_1.SampleLocation1,
|
|
52
|
+
parsedStructure: {
|
|
53
|
+
line: mocks_1.SampleLocation1.line + 1,
|
|
54
|
+
rawData: {
|
|
55
|
+
obj1: {
|
|
49
56
|
line: mocks_1.SampleLocation1.line + 1,
|
|
50
|
-
rawData:
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
line: mocks_1.SampleLocation1.line + 2,
|
|
59
|
-
rawData: 'test data'
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
]
|
|
57
|
+
rawData: [
|
|
58
|
+
{
|
|
59
|
+
line: mocks_1.SampleLocation1.line + 2,
|
|
60
|
+
rawData: {
|
|
61
|
+
obj2: {
|
|
62
|
+
line: mocks_1.SampleLocation1.line + 2,
|
|
63
|
+
rawData: 'test data'
|
|
64
|
+
}
|
|
64
65
|
}
|
|
65
|
-
|
|
66
|
+
}
|
|
67
|
+
]
|
|
68
|
+
}
|
|
66
69
|
}
|
|
70
|
+
}
|
|
67
71
|
};
|
|
68
72
|
describe('VALIDATOR', () => {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
73
|
+
beforeEach(() => {
|
|
74
|
+
(0, mocks_1.resetContext)();
|
|
75
|
+
custom_validator_helper_1.CustomValidatorHelper['duplicateHelpers'] = new Map();
|
|
76
|
+
});
|
|
77
|
+
describe('Convert', () => {
|
|
78
|
+
test('valid definition', () => {
|
|
79
|
+
context_1.Context.rawDefinitions.push(getSampleRawDefinition('str1', 'images/test.png'));
|
|
80
|
+
let definitions = validator_1.Validator.validateAndConvert(ComponentType, TestSchema);
|
|
81
|
+
custom_validator_helper_1.CustomValidatorHelper.logDuplicates();
|
|
82
|
+
expect(context_1.Context.errorLogs).toStrictEqual([]);
|
|
83
|
+
expect(definitions).toStrictEqual([{ str1: 'str1', str2: '.test/images/test.png' }]);
|
|
72
84
|
});
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
expect(definitions).toStrictEqual([{ str1: 'str1', str2: '.test/images/test.png' }]);
|
|
80
|
-
});
|
|
81
|
-
test('singular definition', () => {
|
|
82
|
-
context_1.Context.rawDefinitions.push(getSampleRawDefinition('str1', 'images/test.png'));
|
|
83
|
-
let definitions = validator_1.Validator.validateAndConvert(ComponentType, TestSchema);
|
|
84
|
-
custom_validator_helper_1.CustomValidatorHelper.logDuplicates();
|
|
85
|
-
expect(context_1.Context.errorLogs).toStrictEqual([]);
|
|
86
|
-
expect(definitions).toStrictEqual([{ str1: 'str1', str2: '.test/images/test.png' }]);
|
|
87
|
-
});
|
|
88
|
-
test('should allow references in the same namespace', () => {
|
|
89
|
-
let rawDefinition1 = {
|
|
90
|
-
componentName: ComponentType,
|
|
91
|
-
location: mocks_1.SampleLocation1,
|
|
92
|
-
parsedStructure: {
|
|
93
|
-
line: mocks_1.SampleLocation1.line + 1,
|
|
94
|
-
rawData: {
|
|
95
|
-
name: {
|
|
96
|
-
rawData: 'asset2',
|
|
97
|
-
line: mocks_1.SampleLocation1.line + 1
|
|
98
|
-
},
|
|
99
|
-
ref: {
|
|
100
|
-
rawData: 'asset1',
|
|
101
|
-
line: mocks_1.SampleLocation1.line + 2
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
};
|
|
106
|
-
let rawDefinition2 = {
|
|
107
|
-
componentName: ComponentType,
|
|
108
|
-
location: mocks_1.SampleLocation1,
|
|
109
|
-
parsedStructure: {
|
|
110
|
-
line: mocks_1.SampleLocation1.line + 1,
|
|
111
|
-
rawData: {
|
|
112
|
-
name: {
|
|
113
|
-
rawData: 'asset1',
|
|
114
|
-
line: mocks_1.SampleLocation1.line + 1
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
};
|
|
119
|
-
context_1.Context.rawDefinitions.push(rawDefinition1);
|
|
120
|
-
context_1.Context.rawDefinitions.push(rawDefinition2);
|
|
121
|
-
let schema = joi_1.default.object().keys({
|
|
122
|
-
name: joi_1.default.string().required(),
|
|
123
|
-
ref: joi_1.default.string().reference(Asset).optional()
|
|
124
|
-
});
|
|
125
|
-
definition_store_1.DefinitionStore['setRawDefinition'](Asset, 'asset1', rawDefinition2);
|
|
126
|
-
let definitions = validator_1.Validator.validateAndConvert(ComponentType, schema);
|
|
127
|
-
custom_validator_helper_1.CustomValidatorHelper.logDuplicates();
|
|
128
|
-
expect(context_1.Context.errorLogs).toStrictEqual([]);
|
|
129
|
-
expect(definitions).toStrictEqual([
|
|
130
|
-
{
|
|
131
|
-
name: 'asset2',
|
|
132
|
-
ref: 'asset1'
|
|
133
|
-
},
|
|
134
|
-
{
|
|
135
|
-
name: 'asset1'
|
|
136
|
-
}
|
|
137
|
-
]);
|
|
138
|
-
});
|
|
85
|
+
test('singular definition', () => {
|
|
86
|
+
context_1.Context.rawDefinitions.push(getSampleRawDefinition('str1', 'images/test.png'));
|
|
87
|
+
let definitions = validator_1.Validator.validateAndConvert(ComponentType, TestSchema);
|
|
88
|
+
custom_validator_helper_1.CustomValidatorHelper.logDuplicates();
|
|
89
|
+
expect(context_1.Context.errorLogs).toStrictEqual([]);
|
|
90
|
+
expect(definitions).toStrictEqual([{ str1: 'str1', str2: '.test/images/test.png' }]);
|
|
139
91
|
});
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
92
|
+
test('should allow references in the same namespace', () => {
|
|
93
|
+
let rawDefinition1 = {
|
|
94
|
+
componentName: ComponentType,
|
|
95
|
+
location: mocks_1.SampleLocation1,
|
|
96
|
+
parsedStructure: {
|
|
97
|
+
line: mocks_1.SampleLocation1.line + 1,
|
|
98
|
+
rawData: {
|
|
99
|
+
name: {
|
|
100
|
+
rawData: 'asset2',
|
|
101
|
+
line: mocks_1.SampleLocation1.line + 1
|
|
102
|
+
},
|
|
103
|
+
ref: {
|
|
104
|
+
rawData: 'asset1',
|
|
105
|
+
line: mocks_1.SampleLocation1.line + 2
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
let rawDefinition2 = {
|
|
111
|
+
componentName: ComponentType,
|
|
112
|
+
location: mocks_1.SampleLocation1,
|
|
113
|
+
parsedStructure: {
|
|
114
|
+
line: mocks_1.SampleLocation1.line + 1,
|
|
115
|
+
rawData: {
|
|
116
|
+
name: {
|
|
117
|
+
rawData: 'asset1',
|
|
118
|
+
line: mocks_1.SampleLocation1.line + 1
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
context_1.Context.rawDefinitions.push(rawDefinition1);
|
|
124
|
+
context_1.Context.rawDefinitions.push(rawDefinition2);
|
|
125
|
+
let schema = joi_1.default.object().keys({
|
|
126
|
+
name: joi_1.default.string().required(),
|
|
127
|
+
ref: joi_1.default.string().reference(Asset).optional()
|
|
128
|
+
});
|
|
129
|
+
definition_store_1.DefinitionStore['setRawDefinition'](Asset, 'asset1', rawDefinition2);
|
|
130
|
+
let definitions = validator_1.Validator.validateAndConvert(ComponentType, schema);
|
|
131
|
+
custom_validator_helper_1.CustomValidatorHelper.logDuplicates();
|
|
132
|
+
expect(context_1.Context.errorLogs).toStrictEqual([]);
|
|
133
|
+
expect(definitions).toStrictEqual([
|
|
134
|
+
{
|
|
135
|
+
name: 'asset2',
|
|
136
|
+
ref: 'asset1'
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
name: 'asset1'
|
|
140
|
+
}
|
|
141
|
+
]);
|
|
185
142
|
});
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
143
|
+
});
|
|
144
|
+
describe('Convert Singular', () => {
|
|
145
|
+
test('valid definition', () => {
|
|
146
|
+
context_1.Context.rawDefinitions.push(getSampleRawDefinition('str1', 'images/test.png'));
|
|
147
|
+
let definition = validator_1.Validator.validateAndConvertSingular(ComponentType, TestSchema);
|
|
148
|
+
custom_validator_helper_1.CustomValidatorHelper.logDuplicates();
|
|
149
|
+
expect(context_1.Context.errorLogs).toStrictEqual([]);
|
|
150
|
+
expect(definition).toStrictEqual({ str1: 'str1', str2: '.test/images/test.png' });
|
|
151
|
+
});
|
|
152
|
+
test('should log error for no definition', () => {
|
|
153
|
+
let definition = validator_1.Validator.validateAndConvertSingular(ComponentType, TestSchema);
|
|
154
|
+
custom_validator_helper_1.CustomValidatorHelper.logDuplicates();
|
|
155
|
+
expect(definition).toStrictEqual(undefined);
|
|
156
|
+
expect(context_1.Context.errorLogs).toStrictEqual([
|
|
157
|
+
{
|
|
158
|
+
description: 'Singleton definition has no declared entry "ASSET"',
|
|
159
|
+
location: {
|
|
160
|
+
line: 0,
|
|
161
|
+
path: '*'
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
]);
|
|
165
|
+
});
|
|
166
|
+
test('should log error for multiple definitions', () => {
|
|
167
|
+
context_1.Context.rawDefinitions.push(getSampleRawDefinition('str1', 'images/test.png'));
|
|
168
|
+
context_1.Context.rawDefinitions.push(getSampleRawDefinition('str2', 'images/test.png'));
|
|
169
|
+
let definition = validator_1.Validator.validateAndConvertSingular(ComponentType, TestSchema);
|
|
170
|
+
custom_validator_helper_1.CustomValidatorHelper.logDuplicates();
|
|
171
|
+
expect(definition).toStrictEqual(undefined);
|
|
172
|
+
expect(context_1.Context.errorLogs).toStrictEqual([
|
|
173
|
+
{
|
|
174
|
+
description: 'Only one definition can be defined for "ASSET"',
|
|
175
|
+
location: {
|
|
176
|
+
line: 2,
|
|
177
|
+
path: 'D:/test/file-1.md'
|
|
178
|
+
}
|
|
179
|
+
},
|
|
180
|
+
{
|
|
181
|
+
description: 'Only one definition can be defined for "ASSET"',
|
|
182
|
+
location: {
|
|
183
|
+
line: 2,
|
|
184
|
+
path: 'D:/test/file-1.md'
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
]);
|
|
188
|
+
});
|
|
189
|
+
});
|
|
190
|
+
describe('Validate', () => {
|
|
191
|
+
test('should handle valid raw definition', () => {
|
|
192
|
+
let rawDefinition = getSampleRawDefinition('a', 'images/test.png');
|
|
193
|
+
let value = validator_1.Validator['validate'](rawDefinition, TestSchema);
|
|
194
|
+
custom_validator_helper_1.CustomValidatorHelper.logDuplicates();
|
|
195
|
+
expect(value).toStrictEqual({ str1: 'a', str2: '.test/images/test.png' });
|
|
196
|
+
expect(context_1.Context.errorLogs).toStrictEqual([]);
|
|
197
|
+
});
|
|
198
|
+
test('should log error for required fields', () => {
|
|
199
|
+
let rawDefinition = getSampleRawDefinition(undefined, 'images/test.png');
|
|
200
|
+
let value = validator_1.Validator['validate'](rawDefinition, TestSchema);
|
|
201
|
+
custom_validator_helper_1.CustomValidatorHelper.logDuplicates();
|
|
202
|
+
expect(value).toStrictEqual(undefined);
|
|
203
|
+
expect(context_1.Context.errorLogs).toStrictEqual([
|
|
204
|
+
{
|
|
205
|
+
description: '"str1" is required',
|
|
206
|
+
location: {
|
|
207
|
+
line: mocks_1.SampleLocation1.line + 1,
|
|
208
|
+
path: mocks_1.SampleLocation1.path
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
]);
|
|
212
|
+
});
|
|
213
|
+
test('should log error for invalid flag attribute value', () => {
|
|
214
|
+
let rawDefinition = getSampleRawDefinition('a', 'wrong text');
|
|
215
|
+
let value = validator_1.Validator['validate'](rawDefinition, TestSchema);
|
|
216
|
+
custom_validator_helper_1.CustomValidatorHelper.logDuplicates();
|
|
217
|
+
expect(value).toStrictEqual(undefined);
|
|
218
|
+
expect(context_1.Context.errorLogs).toStrictEqual([
|
|
219
|
+
{
|
|
220
|
+
description: `"str2" with value "wrong text" fails to match the required pattern: /^[\\S]+$/`,
|
|
221
|
+
location: {
|
|
222
|
+
line: mocks_1.SampleLocation1.line + 2,
|
|
223
|
+
path: mocks_1.SampleLocation1.path
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
]);
|
|
227
|
+
});
|
|
228
|
+
test('should log error for non matching pattern', () => {
|
|
229
|
+
let schema = joi_1.default.object().keys({
|
|
230
|
+
str1: joi_1.default
|
|
231
|
+
.string()
|
|
232
|
+
.regex(/^[a-z]+([a-zA-Z0-9]+)*$/)
|
|
233
|
+
.required(),
|
|
234
|
+
str2: joi_1.default
|
|
235
|
+
.string()
|
|
236
|
+
.regex(/^[a-z]+([a-zA-Z0-9]+)*$/)
|
|
237
|
+
.required()
|
|
238
|
+
});
|
|
239
|
+
let rawDefinition = getSampleRawDefinition('1a', 'wrong string');
|
|
240
|
+
let value = validator_1.Validator['validate'](rawDefinition, schema);
|
|
241
|
+
custom_validator_helper_1.CustomValidatorHelper.logDuplicates();
|
|
242
|
+
expect(value).toStrictEqual(undefined);
|
|
243
|
+
expect(context_1.Context.errorLogs).toStrictEqual([
|
|
244
|
+
{
|
|
245
|
+
description: `"str1" with value "1a" fails to match the required pattern: /^[a-z]+([a-zA-Z0-9]+)*$/`,
|
|
246
|
+
location: {
|
|
247
|
+
line: mocks_1.SampleLocation1.line + 1,
|
|
248
|
+
path: mocks_1.SampleLocation1.path
|
|
249
|
+
}
|
|
250
|
+
},
|
|
251
|
+
{
|
|
252
|
+
description: `"str2" with value "wrong string" fails to match the required pattern: /^[a-z]+([a-zA-Z0-9]+)*$/`,
|
|
253
|
+
location: {
|
|
254
|
+
line: mocks_1.SampleLocation1.line + 2,
|
|
255
|
+
path: mocks_1.SampleLocation1.path
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
]);
|
|
259
|
+
});
|
|
260
|
+
test('should validate primitive definition', () => {
|
|
261
|
+
let rawDefinition = {
|
|
262
|
+
componentName: ComponentType,
|
|
263
|
+
location: mocks_1.SampleLocation1,
|
|
264
|
+
parsedStructure: {
|
|
265
|
+
line: mocks_1.SampleLocation1.line + 1,
|
|
266
|
+
rawData: 'test'
|
|
267
|
+
}
|
|
268
|
+
};
|
|
269
|
+
let value = validator_1.Validator['validate'](rawDefinition, joi_1.default.string());
|
|
270
|
+
custom_validator_helper_1.CustomValidatorHelper.logDuplicates();
|
|
271
|
+
expect(value).toStrictEqual('test');
|
|
272
|
+
expect(context_1.Context.errorLogs).toStrictEqual([]);
|
|
273
|
+
});
|
|
274
|
+
test('should log error for primitive definition', () => {
|
|
275
|
+
let rawDefinition = {
|
|
276
|
+
componentName: ComponentType,
|
|
277
|
+
location: mocks_1.SampleLocation1,
|
|
278
|
+
parsedStructure: {
|
|
279
|
+
line: mocks_1.SampleLocation1.line + 1,
|
|
280
|
+
rawData: 'test'
|
|
281
|
+
}
|
|
282
|
+
};
|
|
283
|
+
let value = validator_1.Validator['validate'](rawDefinition, joi_1.default.string().valid('only'));
|
|
284
|
+
custom_validator_helper_1.CustomValidatorHelper.logDuplicates();
|
|
285
|
+
expect(value).toStrictEqual(undefined);
|
|
286
|
+
expect(context_1.Context.errorLogs).toStrictEqual([
|
|
287
|
+
{
|
|
288
|
+
description: '"value" must be [only]',
|
|
289
|
+
location: {
|
|
290
|
+
line: mocks_1.SampleLocation1.line + 1,
|
|
291
|
+
path: mocks_1.SampleLocation1.path
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
]);
|
|
295
|
+
});
|
|
296
|
+
test('should validate nested object', () => {
|
|
297
|
+
let schema = joi_1.default.object().keys({
|
|
298
|
+
obj1: joi_1.default.array().items(
|
|
299
|
+
joi_1.default.object().keys({
|
|
300
|
+
obj2: joi_1.default.string()
|
|
301
|
+
})
|
|
302
|
+
)
|
|
303
|
+
});
|
|
304
|
+
let value = validator_1.Validator['validate'](SampleNestedRawDefinition, schema);
|
|
305
|
+
custom_validator_helper_1.CustomValidatorHelper.logDuplicates();
|
|
306
|
+
expect(value).toStrictEqual({ obj1: [{ obj2: 'test data' }] });
|
|
307
|
+
expect(context_1.Context.errorLogs).toStrictEqual([]);
|
|
308
|
+
});
|
|
309
|
+
test('should log error for nested object', () => {
|
|
310
|
+
let schema = joi_1.default.object().keys({
|
|
311
|
+
obj1: joi_1.default.array().items(
|
|
312
|
+
joi_1.default.object().keys({
|
|
313
|
+
obj2: joi_1.default.string().valid('only')
|
|
314
|
+
})
|
|
315
|
+
)
|
|
316
|
+
});
|
|
317
|
+
let value = validator_1.Validator['validate'](SampleNestedRawDefinition, schema);
|
|
318
|
+
custom_validator_helper_1.CustomValidatorHelper.logDuplicates();
|
|
319
|
+
expect(value).toStrictEqual(undefined);
|
|
320
|
+
expect(context_1.Context.errorLogs).toStrictEqual([
|
|
321
|
+
{
|
|
322
|
+
description: '"obj1[0].obj2" must be [only]',
|
|
323
|
+
location: {
|
|
324
|
+
line: mocks_1.SampleLocation1.line + 2,
|
|
325
|
+
path: 'D:/test/file-1.md'
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
]);
|
|
320
329
|
});
|
|
330
|
+
});
|
|
321
331
|
});
|
|
322
|
-
//# sourceMappingURL=validator.spec.js.map
|
|
332
|
+
//# sourceMappingURL=validator.spec.js.map
|