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