definition-generator-framework 1.12.4 → 1.12.5
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/helpers/common-functions/common-functions.spec.d.ts +1 -0
- package/dist/helpers/common-functions/common-functions.spec.js +50 -0
- package/dist/helpers/duplicate-helper/duplicate-helper.spec.d.ts +1 -0
- package/dist/helpers/duplicate-helper/duplicate-helper.spec.js +54 -0
- package/dist/helpers/output-helper/output-helper.spec.d.ts +24 -0
- package/dist/helpers/output-helper/output-helper.spec.js +249 -0
- package/dist/helpers/raw-definition-helper/raw-definition.helper.spec.d.ts +1 -0
- package/dist/helpers/raw-definition-helper/raw-definition.helper.spec.js +135 -0
- package/dist/helpers/validator/custom-validator-helper/custom-validator.helper.spec.d.ts +1 -0
- package/dist/helpers/validator/custom-validator-helper/custom-validator.helper.spec.js +173 -0
- package/dist/helpers/validator/joi-custom-validators.spec.d.ts +1 -0
- package/dist/helpers/validator/joi-custom-validators.spec.js +260 -0
- package/dist/helpers/validator/validator.spec.d.ts +1 -0
- package/dist/helpers/validator/validator.spec.js +322 -0
- package/dist/pipeline/1-select-definitions.spec.d.ts +1 -0
- package/dist/pipeline/1-select-definitions.spec.js +140 -0
- package/dist/pipeline/2-structure-parser.helper.spec.d.ts +1 -0
- package/dist/pipeline/2-structure-parser.helper.spec.js +280 -0
- package/dist/pipeline/parsers/array-parser.spec.d.ts +1 -0
- package/dist/pipeline/parsers/array-parser.spec.js +125 -0
- package/dist/pipeline/parsers/object-parser.spec.d.ts +1 -0
- package/dist/pipeline/parsers/object-parser.spec.js +173 -0
- package/dist/pipeline/parsers/primitive-parser.spec.d.ts +1 -0
- package/dist/pipeline/parsers/primitive-parser.spec.js +79 -0
- package/package.json +8 -3
- package/.eslintrc.js +0 -212
- package/.vscode/launch.json +0 -15
- package/.vscode/settings.json +0 -25
- package/coverage/clover.xml +0 -503
- package/coverage/coverage-final.json +0 -16
- package/coverage/lcov-report/_mocks/index.html +0 -116
- package/coverage/lcov-report/_mocks/mocks.ts.html +0 -223
- package/coverage/lcov-report/base.css +0 -224
- package/coverage/lcov-report/block-navigation.js +0 -87
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/framework/framework.data.ts.html +0 -109
- package/coverage/lcov-report/framework/index.html +0 -116
- package/coverage/lcov-report/helpers/common-functions/common-functions.ts.html +0 -178
- package/coverage/lcov-report/helpers/common-functions/index.html +0 -116
- package/coverage/lcov-report/helpers/duplicate-helper/duplicate-helper.ts.html +0 -196
- package/coverage/lcov-report/helpers/duplicate-helper/index.html +0 -116
- package/coverage/lcov-report/helpers/output-helper/index.html +0 -116
- package/coverage/lcov-report/helpers/output-helper/output-helper.ts.html +0 -277
- package/coverage/lcov-report/helpers/raw-definition-helper/index.html +0 -116
- package/coverage/lcov-report/helpers/raw-definition-helper/raw-definition.helper.ts.html +0 -256
- package/coverage/lcov-report/helpers/validator/index.html +0 -131
- package/coverage/lcov-report/helpers/validator/joi-custom-validators.ts.html +0 -643
- package/coverage/lcov-report/helpers/validator/validator.ts.html +0 -310
- package/coverage/lcov-report/index.html +0 -251
- package/coverage/lcov-report/pipeline/1-select-definitions-helper.ts.html +0 -358
- package/coverage/lcov-report/pipeline/2-structure-parser.helper.ts.html +0 -301
- package/coverage/lcov-report/pipeline/3-config.ts.html +0 -178
- package/coverage/lcov-report/pipeline/_mocks/index.html +0 -116
- package/coverage/lcov-report/pipeline/_mocks/index.ts.html +0 -229
- package/coverage/lcov-report/pipeline/index.html +0 -146
- package/coverage/lcov-report/pipeline/parsers/array-parser.ts.html +0 -271
- package/coverage/lcov-report/pipeline/parsers/index.html +0 -146
- package/coverage/lcov-report/pipeline/parsers/object-parser.ts.html +0 -439
- package/coverage/lcov-report/pipeline/parsers/primitive-parser.ts.html +0 -370
- package/coverage/lcov-report/prettify.css +0 -1
- package/coverage/lcov-report/prettify.js +0 -2
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +0 -196
- package/coverage/lcov.info +0 -911
- package/dist/_mocks/mocks.js.map +0 -1
- package/dist/decorators/definition-component.js.map +0 -1
- package/dist/decorators/definition-generator.js.map +0 -1
- package/dist/framework/context.js.map +0 -1
- package/dist/framework/definition-component.js.map +0 -1
- package/dist/framework/definition-generator.js.map +0 -1
- package/dist/framework/definition-store.js.map +0 -1
- package/dist/framework/file-content-generator/file-content-generator.js.map +0 -1
- package/dist/framework/file-content-generator/file-content-generator.test.js.map +0 -1
- package/dist/framework/framework.data.js.map +0 -1
- package/dist/framework/framework.js.map +0 -1
- package/dist/framework/framework.model.js.map +0 -1
- package/dist/framework/index-file-generator/index-file-generator.js.map +0 -1
- package/dist/framework/interfaces.js.map +0 -1
- package/dist/framework/kernel.js.map +0 -1
- package/dist/helpers/common-functions/common-functions.js.map +0 -1
- package/dist/helpers/common-functions/common-functions.spec.js.map +0 -1
- package/dist/helpers/common-functions/common-functions.test.js.map +0 -1
- package/dist/helpers/duplicate-helper/duplicate-helper.js.map +0 -1
- package/dist/helpers/duplicate-helper/duplicate-helper.spec.js.map +0 -1
- package/dist/helpers/duplicate-helper/duplicate-helper.test.js.map +0 -1
- package/dist/helpers/output-helper/output-helper.js.map +0 -1
- package/dist/helpers/output-helper/output-helper.spec.js.map +0 -1
- package/dist/helpers/output-helper/output-helper.test.js.map +0 -1
- package/dist/helpers/raw-definition-helper/raw-definition.helper.js.map +0 -1
- package/dist/helpers/raw-definition-helper/raw-definition.helper.spec.js.map +0 -1
- package/dist/helpers/raw-definition-helper/raw-definition.helper.test.js.map +0 -1
- package/dist/helpers/validator/custom-validator-helper/custom-validator.helper.js.map +0 -1
- package/dist/helpers/validator/custom-validator-helper/custom-validator.helper.spec.js.map +0 -1
- package/dist/helpers/validator/custom-validator-helper/custom-validator.helper.test.js.map +0 -1
- package/dist/helpers/validator/custom-validators/helpers/sprite-validation.helper.js.map +0 -1
- package/dist/helpers/validator/custom-validators/helpers/sprite-validation.helper.test.js.map +0 -1
- package/dist/helpers/validator/custom-validators/image.custom-validator.js.map +0 -1
- package/dist/helpers/validator/custom-validators/path.custom-validator.js.map +0 -1
- package/dist/helpers/validator/custom-validators/position-on-sprite.js.map +0 -1
- package/dist/helpers/validator/custom-validators/reference.custom-validator.js.map +0 -1
- package/dist/helpers/validator/custom-validators/sprite.custom-validator.js.map +0 -1
- package/dist/helpers/validator/custom-validators/unique-name-group.custom-validator.js.map +0 -1
- package/dist/helpers/validator/custom-validators/unique.custom-validator.js.map +0 -1
- package/dist/helpers/validator/joi-custom-validators.js.map +0 -1
- package/dist/helpers/validator/joi-custom-validators.spec.js.map +0 -1
- package/dist/helpers/validator/validator.js.map +0 -1
- package/dist/helpers/validator/validator.spec.js.map +0 -1
- package/dist/helpers/validator/validator.test.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/pipeline/1-select-definitions-helper.js.map +0 -1
- package/dist/pipeline/1-select-definitions.helper.js.map +0 -1
- package/dist/pipeline/1-select-definitions.helper.test.js.map +0 -1
- package/dist/pipeline/1-select-definitions.spec.js.map +0 -1
- package/dist/pipeline/2-structure-parser.helper.js.map +0 -1
- package/dist/pipeline/2-structure-parser.helper.spec.js.map +0 -1
- package/dist/pipeline/2-structure-parser.helper.test.js.map +0 -1
- package/dist/pipeline/3-config.js.map +0 -1
- package/dist/pipeline/_mocks/index.js.map +0 -1
- package/dist/pipeline/parsers/array-parser.js.map +0 -1
- package/dist/pipeline/parsers/array-parser.spec.js.map +0 -1
- package/dist/pipeline/parsers/array-parser.test.js.map +0 -1
- package/dist/pipeline/parsers/object-parser.js.map +0 -1
- package/dist/pipeline/parsers/object-parser.spec.js.map +0 -1
- package/dist/pipeline/parsers/object-parser.test.js.map +0 -1
- package/dist/pipeline/parsers/primitive-parser.js.map +0 -1
- package/dist/pipeline/parsers/primitive-parser.spec.js.map +0 -1
- package/dist/pipeline/parsers/primitive-parser.test.js.map +0 -1
- package/dist/pipeline/raw-data-parser.js.map +0 -1
- package/dist/pre-made-components/_validators/shape-validators.js.map +0 -1
- package/dist/pre-made-components/_validators/sprite-validators.js.map +0 -1
- package/dist/pre-made-components/assets/1-sprite.js.map +0 -1
- package/dist/pre-made-components/assets/2-sprite-group.js.map +0 -1
- package/dist/pre-made-components/assets/3-font.js.map +0 -1
- package/dist/pre-made-components/events/1-event.js.map +0 -1
- package/dist/pre-made-components/events/1-script.js.map +0 -1
- package/dist/pre-made-components/events/2-event-test.js.map +0 -1
- package/dist/pre-made-components/events/2-script-test.js.map +0 -1
- package/dist/pre-made-components/events/3-event.js.map +0 -1
- package/dist/pre-made-components/events/4-event-test.js.map +0 -1
- package/dist/pre-made-components/events/event-setup.js.map +0 -1
- package/dist/pre-made-components/events/helpers/quotes-to-tags.helper.js.map +0 -1
- package/dist/pre-made-components/events/helpers/quotes-to-tags.helper.test.js.map +0 -1
- package/dist/pre-made-components/events/helpers/script-testing.helper.js.map +0 -1
- package/dist/pre-made-components/events/script-setup.js.map +0 -1
- package/dist/pre-made-components/events/scripting-setup.js.map +0 -1
- package/dist/pre-made-components/events/validators.js.map +0 -1
- package/dist/setup.js.map +0 -1
- package/package.json.bak +0 -60
- package/scripts/prepare-package-json.ts +0 -23
- package/tsconfig.json +0 -24
- package/vitest.config.ts +0 -1
|
@@ -0,0 +1,322 @@
|
|
|
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' });
|
|
14
|
+
const ComponentType = 'ASSET';
|
|
15
|
+
class Asset {
|
|
16
|
+
static { this.$meta = {
|
|
17
|
+
componentName: ComponentType
|
|
18
|
+
}; }
|
|
19
|
+
async process() { }
|
|
20
|
+
}
|
|
21
|
+
const TestSchema = joi_1.default.object().keys({
|
|
22
|
+
str1: joi_1.default.string().required(),
|
|
23
|
+
str2: joi_1.default.string().path().optional()
|
|
24
|
+
});
|
|
25
|
+
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 = {
|
|
46
|
+
componentName: ComponentType,
|
|
47
|
+
location: mocks_1.SampleLocation1,
|
|
48
|
+
parsedStructure: {
|
|
49
|
+
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
|
+
]
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
describe('VALIDATOR', () => {
|
|
69
|
+
beforeEach(() => {
|
|
70
|
+
(0, mocks_1.resetContext)();
|
|
71
|
+
custom_validator_helper_1.CustomValidatorHelper['duplicateHelpers'] = new Map();
|
|
72
|
+
});
|
|
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
|
+
});
|
|
139
|
+
});
|
|
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
|
+
});
|
|
185
|
+
});
|
|
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
|
+
});
|
|
320
|
+
});
|
|
321
|
+
});
|
|
322
|
+
//# sourceMappingURL=validator.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const _1_select_definitions_helper_1 = require("./1-select-definitions-helper");
|
|
4
|
+
const mocks_1 = require("../_mocks/mocks");
|
|
5
|
+
const custom_validator_helper_spec_1 = require("../helpers/validator/custom-validator-helper/custom-validator.helper.spec");
|
|
6
|
+
const definition_store_1 = require("../framework/definition-store");
|
|
7
|
+
definition_store_1.DefinitionStore['definitionsMap'].set(custom_validator_helper_spec_1.AssetComponentName, new Map());
|
|
8
|
+
describe('SELECT DEFINITIONS HELPER', () => {
|
|
9
|
+
let selectDefinitionsHelper;
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
selectDefinitionsHelper = new _1_select_definitions_helper_1.SelectDefinitionsHelper();
|
|
12
|
+
});
|
|
13
|
+
test('should handle empty files', () => {
|
|
14
|
+
let content = ``;
|
|
15
|
+
let fileInfo = (0, mocks_1.getMockFileInfo)(content);
|
|
16
|
+
let result = selectDefinitionsHelper.process(fileInfo);
|
|
17
|
+
expect(result.definitionPlaneTexts).toStrictEqual([]);
|
|
18
|
+
expect(result.errorLogs).toStrictEqual([]);
|
|
19
|
+
});
|
|
20
|
+
test('should handle files without definitions', () => {
|
|
21
|
+
let content = `
|
|
22
|
+
Explanation
|
|
23
|
+
|
|
24
|
+
### ASSET
|
|
25
|
+
Name: singular name
|
|
26
|
+
Path: path to file
|
|
27
|
+
`;
|
|
28
|
+
let fileInfo = (0, mocks_1.getMockFileInfo)(content);
|
|
29
|
+
let result = selectDefinitionsHelper.process(fileInfo);
|
|
30
|
+
expect(result.definitionPlaneTexts).toStrictEqual([]);
|
|
31
|
+
expect(result.errorLogs).toStrictEqual([]);
|
|
32
|
+
});
|
|
33
|
+
test('should select definitions', () => {
|
|
34
|
+
let content = `
|
|
35
|
+
# DEFINITIONS
|
|
36
|
+
### ASSET
|
|
37
|
+
Name: test
|
|
38
|
+
Path: test.png
|
|
39
|
+
`;
|
|
40
|
+
let fileInfo = (0, mocks_1.getMockFileInfo)(content);
|
|
41
|
+
let result = selectDefinitionsHelper.process(fileInfo);
|
|
42
|
+
expect(result.definitionPlaneTexts).toStrictEqual([
|
|
43
|
+
{
|
|
44
|
+
type: 'ASSET',
|
|
45
|
+
content: [' Name: test', ' Path: test.png'],
|
|
46
|
+
location: { line: 3, path: fileInfo.path }
|
|
47
|
+
}
|
|
48
|
+
]);
|
|
49
|
+
expect(result.errorLogs).toStrictEqual([]);
|
|
50
|
+
});
|
|
51
|
+
test('should ignore comments', () => {
|
|
52
|
+
let content = `
|
|
53
|
+
# DEFINITIONS
|
|
54
|
+
### ASSET
|
|
55
|
+
Name: test // comment
|
|
56
|
+
Path: test.png // comment
|
|
57
|
+
// ----comment----\r
|
|
58
|
+
`;
|
|
59
|
+
let fileInfo = (0, mocks_1.getMockFileInfo)(content);
|
|
60
|
+
let result = selectDefinitionsHelper.process(fileInfo);
|
|
61
|
+
expect(result.definitionPlaneTexts).toStrictEqual([
|
|
62
|
+
{
|
|
63
|
+
type: 'ASSET',
|
|
64
|
+
content: [' Name: test', ' Path: test.png'],
|
|
65
|
+
location: { line: 3, path: fileInfo.path }
|
|
66
|
+
}
|
|
67
|
+
]);
|
|
68
|
+
expect(result.errorLogs).toStrictEqual([]);
|
|
69
|
+
});
|
|
70
|
+
test('should not allow empty definitions', () => {
|
|
71
|
+
let content = `
|
|
72
|
+
# DEFINITIONS
|
|
73
|
+
### ASSET
|
|
74
|
+
`;
|
|
75
|
+
let fileInfo = (0, mocks_1.getMockFileInfo)(content);
|
|
76
|
+
let result = selectDefinitionsHelper.process(fileInfo);
|
|
77
|
+
expect(result.definitionPlaneTexts).toStrictEqual([]);
|
|
78
|
+
expect(result.errorLogs).toStrictEqual([
|
|
79
|
+
{
|
|
80
|
+
description: 'Definitions cannot be empty!',
|
|
81
|
+
location: { line: 3, path: fileInfo.path }
|
|
82
|
+
}
|
|
83
|
+
]);
|
|
84
|
+
});
|
|
85
|
+
test('should not allow unknown definition header after the first valid definition', () => {
|
|
86
|
+
let content = `
|
|
87
|
+
# DEFINITIONS
|
|
88
|
+
### ASSET
|
|
89
|
+
Name: test
|
|
90
|
+
Path: test.png
|
|
91
|
+
|
|
92
|
+
### Some text
|
|
93
|
+
some text
|
|
94
|
+
`;
|
|
95
|
+
let fileInfo = (0, mocks_1.getMockFileInfo)(content);
|
|
96
|
+
let result = selectDefinitionsHelper.process(fileInfo);
|
|
97
|
+
expect(result.errorLogs).toStrictEqual([
|
|
98
|
+
{
|
|
99
|
+
description: 'Invalid definition header: "### Some text"',
|
|
100
|
+
location: { line: 7, path: fileInfo.path }
|
|
101
|
+
}
|
|
102
|
+
]);
|
|
103
|
+
});
|
|
104
|
+
test('invalid definitions should not corrupt other definitions', () => {
|
|
105
|
+
let content = `
|
|
106
|
+
# DEFINITIONS
|
|
107
|
+
### ASSET
|
|
108
|
+
Name: test
|
|
109
|
+
Path: test.png
|
|
110
|
+
|
|
111
|
+
### Some text
|
|
112
|
+
some text
|
|
113
|
+
|
|
114
|
+
### ASSET
|
|
115
|
+
Name: test2
|
|
116
|
+
Path: test2.png
|
|
117
|
+
`;
|
|
118
|
+
let fileInfo = (0, mocks_1.getMockFileInfo)(content);
|
|
119
|
+
let result = selectDefinitionsHelper.process(fileInfo);
|
|
120
|
+
expect(result.definitionPlaneTexts).toStrictEqual([
|
|
121
|
+
{
|
|
122
|
+
type: 'ASSET',
|
|
123
|
+
content: [' Name: test', ' Path: test.png'],
|
|
124
|
+
location: { line: 3, path: fileInfo.path }
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
type: 'ASSET',
|
|
128
|
+
content: [' Name: test2', ' Path: test2.png'],
|
|
129
|
+
location: { line: 10, path: fileInfo.path }
|
|
130
|
+
}
|
|
131
|
+
]);
|
|
132
|
+
expect(result.errorLogs).toStrictEqual([
|
|
133
|
+
{
|
|
134
|
+
description: 'Invalid definition header: "### Some text"',
|
|
135
|
+
location: { line: 7, path: fileInfo.path }
|
|
136
|
+
}
|
|
137
|
+
]);
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
//# sourceMappingURL=1-select-definitions.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|