definition-generator-framework 1.12.3 → 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,173 @@
|
|
|
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
|
+
exports.AssetComponentName = void 0;
|
|
7
|
+
const joi_1 = __importDefault(require("joi"));
|
|
8
|
+
const joi_custom_validators_1 = require("../joi-custom-validators");
|
|
9
|
+
const mocks_1 = require("../../../_mocks/mocks");
|
|
10
|
+
const raw_definition_helper_1 = require("../../raw-definition-helper/raw-definition.helper");
|
|
11
|
+
const custom_validator_helper_1 = require("./custom-validator.helper");
|
|
12
|
+
const context_1 = require("../../../framework/context");
|
|
13
|
+
const definition_store_1 = require("../../../framework/definition-store");
|
|
14
|
+
joi_custom_validators_1.JoiCustomValidators.decorate(joi_1.default, { existsSync: (path) => path !== 'D:/test/false/path.png' });
|
|
15
|
+
exports.AssetComponentName = 'ASSET';
|
|
16
|
+
class Asset {
|
|
17
|
+
static { this.$meta = {
|
|
18
|
+
componentName: exports.AssetComponentName
|
|
19
|
+
}; }
|
|
20
|
+
async process() { }
|
|
21
|
+
}
|
|
22
|
+
class AssetGroup {
|
|
23
|
+
static { this.$meta = {
|
|
24
|
+
componentName: 'ASSET-GROUP'
|
|
25
|
+
}; }
|
|
26
|
+
async process() { }
|
|
27
|
+
}
|
|
28
|
+
function getSimpleRawDefinition(value, offset = 1) {
|
|
29
|
+
return {
|
|
30
|
+
componentName: exports.AssetComponentName,
|
|
31
|
+
location: mocks_1.SampleLocation1,
|
|
32
|
+
parsedStructure: {
|
|
33
|
+
line: mocks_1.SampleLocation1.line + offset,
|
|
34
|
+
rawData: {
|
|
35
|
+
value: {
|
|
36
|
+
rawData: value,
|
|
37
|
+
line: mocks_1.SampleLocation1.line + offset
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
function getFlatRawDefinition(value, offset = 1) {
|
|
44
|
+
return {
|
|
45
|
+
componentName: exports.AssetComponentName,
|
|
46
|
+
location: mocks_1.SampleLocation1,
|
|
47
|
+
parsedStructure: {
|
|
48
|
+
line: mocks_1.SampleLocation1.line + offset,
|
|
49
|
+
rawData: value
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
describe('JOI CUSTOM VALIDATORS', () => {
|
|
54
|
+
beforeEach(() => {
|
|
55
|
+
context_1.Context.config.projectRoot = 'D:/';
|
|
56
|
+
custom_validator_helper_1.CustomValidatorHelper['duplicateHelpers'] = new Map();
|
|
57
|
+
});
|
|
58
|
+
describe('Variable Name', () => {
|
|
59
|
+
let schema = joi_1.default.object().keys({
|
|
60
|
+
value: joi_1.default.string().required()
|
|
61
|
+
});
|
|
62
|
+
test('valid data', () => {
|
|
63
|
+
let rawDefinition = getSimpleRawDefinition('test');
|
|
64
|
+
let { value, error } = schema.validate(raw_definition_helper_1.RawDefinitionHelper.flatten(rawDefinition), {
|
|
65
|
+
abortEarly: false,
|
|
66
|
+
context: rawDefinition
|
|
67
|
+
});
|
|
68
|
+
expect(value).toEqual({ value: 'test' });
|
|
69
|
+
expect(error).toEqual(undefined);
|
|
70
|
+
});
|
|
71
|
+
test('different groups should not create duplicates', () => {
|
|
72
|
+
let schema2 = joi_1.default.object().keys({
|
|
73
|
+
value: joi_1.default.string().required()
|
|
74
|
+
});
|
|
75
|
+
let rawDefinition1 = getSimpleRawDefinition('test', 1);
|
|
76
|
+
let rawDefinition2 = getSimpleRawDefinition('test', 2);
|
|
77
|
+
schema.validate(raw_definition_helper_1.RawDefinitionHelper.flatten(rawDefinition1), { abortEarly: false, context: rawDefinition1 });
|
|
78
|
+
schema2.validate(raw_definition_helper_1.RawDefinitionHelper.flatten(rawDefinition2), { abortEarly: false, context: rawDefinition2 });
|
|
79
|
+
(0, mocks_1.resetContext)();
|
|
80
|
+
custom_validator_helper_1.CustomValidatorHelper.logDuplicates();
|
|
81
|
+
expect(context_1.Context.errorLogs).toStrictEqual([]);
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
describe('Reference', () => {
|
|
85
|
+
let schema = joi_1.default.object().keys({
|
|
86
|
+
value: joi_1.default.string().reference(Asset).required()
|
|
87
|
+
});
|
|
88
|
+
let multipleSchema = joi_1.default.object().keys({
|
|
89
|
+
value: joi_1.default.string().reference([AssetGroup, Asset]).required()
|
|
90
|
+
});
|
|
91
|
+
test('valid data', () => {
|
|
92
|
+
let rawDefinition = getSimpleRawDefinition('test');
|
|
93
|
+
definition_store_1.DefinitionStore['setRawDefinition'](Asset, 'test', rawDefinition);
|
|
94
|
+
let { value, error } = schema.validate(raw_definition_helper_1.RawDefinitionHelper.flatten(rawDefinition), {
|
|
95
|
+
abortEarly: false,
|
|
96
|
+
context: rawDefinition
|
|
97
|
+
});
|
|
98
|
+
expect(value).toEqual({ value: 'test' });
|
|
99
|
+
expect(error).toEqual(undefined);
|
|
100
|
+
});
|
|
101
|
+
test('multiple reference', () => {
|
|
102
|
+
let rawDefinition = getSimpleRawDefinition('test');
|
|
103
|
+
definition_store_1.DefinitionStore['setRawDefinition'](Asset, 'test', rawDefinition);
|
|
104
|
+
let { value, error } = multipleSchema.validate(raw_definition_helper_1.RawDefinitionHelper.flatten(rawDefinition), {
|
|
105
|
+
abortEarly: false,
|
|
106
|
+
context: rawDefinition
|
|
107
|
+
});
|
|
108
|
+
expect(value).toEqual({ value: 'test' });
|
|
109
|
+
expect(error).toEqual(undefined);
|
|
110
|
+
});
|
|
111
|
+
test('primitive valid data', () => {
|
|
112
|
+
let rawDefinition = getFlatRawDefinition('test');
|
|
113
|
+
let primitiveSchema = joi_1.default.string().reference(Asset).required();
|
|
114
|
+
definition_store_1.DefinitionStore['setRawDefinition'](Asset, 'test', rawDefinition);
|
|
115
|
+
let { value, error } = primitiveSchema.validate(raw_definition_helper_1.RawDefinitionHelper.flatten(rawDefinition), {
|
|
116
|
+
abortEarly: false,
|
|
117
|
+
context: rawDefinition
|
|
118
|
+
});
|
|
119
|
+
expect(value).toEqual('test');
|
|
120
|
+
expect(error).toEqual(undefined);
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
describe('Path', () => {
|
|
124
|
+
let schema = joi_1.default.object().keys({
|
|
125
|
+
value: joi_1.default.string().path().required()
|
|
126
|
+
});
|
|
127
|
+
test('valid data', () => {
|
|
128
|
+
let rawDefinition = getSimpleRawDefinition('images/test.png');
|
|
129
|
+
let { value, error } = schema.validate(raw_definition_helper_1.RawDefinitionHelper.flatten(rawDefinition), {
|
|
130
|
+
abortEarly: false,
|
|
131
|
+
context: rawDefinition
|
|
132
|
+
});
|
|
133
|
+
expect(value).toEqual({ value: '.test/images/test.png' });
|
|
134
|
+
expect(error).toEqual(undefined);
|
|
135
|
+
});
|
|
136
|
+
test('should detect files not existing, invalid url', () => {
|
|
137
|
+
let rawDefinition = getSimpleRawDefinition('invalid data');
|
|
138
|
+
let { error } = schema.validate(raw_definition_helper_1.RawDefinitionHelper.flatten(rawDefinition), { abortEarly: false, context: rawDefinition });
|
|
139
|
+
expect(error?.details).toStrictEqual([
|
|
140
|
+
{
|
|
141
|
+
message: '"value" with value "invalid data" fails to match the required pattern: /^[\\S]+$/',
|
|
142
|
+
path: ['value'],
|
|
143
|
+
type: 'string.pattern.base',
|
|
144
|
+
context: {
|
|
145
|
+
name: undefined,
|
|
146
|
+
regex: /^[\S]+$/,
|
|
147
|
+
value: 'invalid data',
|
|
148
|
+
label: 'value',
|
|
149
|
+
key: 'value'
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
]);
|
|
153
|
+
});
|
|
154
|
+
test('should detect files not existing, missing file', () => {
|
|
155
|
+
let rawDefinition = getSimpleRawDefinition('false/path.png');
|
|
156
|
+
let { error } = schema.validate(raw_definition_helper_1.RawDefinitionHelper.flatten(rawDefinition), { abortEarly: false, context: rawDefinition });
|
|
157
|
+
expect(error?.details).toStrictEqual([
|
|
158
|
+
{
|
|
159
|
+
message: '"value" failed custom validation because No file is found in the path: "D:/test/false/path.png"',
|
|
160
|
+
path: ['value'],
|
|
161
|
+
type: 'any.custom',
|
|
162
|
+
context: {
|
|
163
|
+
error: new Error('No file is found in the path: "D:/test/false/path.png"'),
|
|
164
|
+
label: 'value',
|
|
165
|
+
value: 'false/path.png',
|
|
166
|
+
key: 'value'
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
]);
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
//# sourceMappingURL=custom-validator.helper.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
const Joi = __importStar(require("joi"));
|
|
27
|
+
const joi_custom_validators_1 = require("./joi-custom-validators");
|
|
28
|
+
const mocks_1 = require("../../_mocks/mocks");
|
|
29
|
+
const raw_definition_helper_1 = require("../raw-definition-helper/raw-definition.helper");
|
|
30
|
+
joi_custom_validators_1.JoiCustomValidators.decorate({ existsSync: (path) => path !== 'D:/test/false/path.png' });
|
|
31
|
+
const DefinitionType = 'ASSET';
|
|
32
|
+
class Asset {
|
|
33
|
+
static { this.$meta = {
|
|
34
|
+
definitionName: DefinitionType
|
|
35
|
+
}; }
|
|
36
|
+
async process() { }
|
|
37
|
+
}
|
|
38
|
+
class AssetGroup {
|
|
39
|
+
static { this.$meta = {
|
|
40
|
+
definitionName: 'ASSET-GROUP'
|
|
41
|
+
}; }
|
|
42
|
+
async process() { }
|
|
43
|
+
}
|
|
44
|
+
function getSimpleRawDefinition(value, offset = 1) {
|
|
45
|
+
return {
|
|
46
|
+
type: DefinitionType,
|
|
47
|
+
location: mocks_1.SampleLocation1,
|
|
48
|
+
parsedStructure: {
|
|
49
|
+
line: mocks_1.SampleLocation1.line + offset,
|
|
50
|
+
rawData: {
|
|
51
|
+
value: {
|
|
52
|
+
rawData: value,
|
|
53
|
+
line: mocks_1.SampleLocation1.line + offset
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
function getFlatRawDefinition(value, offset = 1) {
|
|
60
|
+
return {
|
|
61
|
+
type: DefinitionType,
|
|
62
|
+
location: mocks_1.SampleLocation1,
|
|
63
|
+
parsedStructure: {
|
|
64
|
+
line: mocks_1.SampleLocation1.line + offset,
|
|
65
|
+
rawData: value
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
describe('JOI CUSTOM VALIDATORS', () => {
|
|
70
|
+
beforeEach(() => {
|
|
71
|
+
let validators = joi_custom_validators_1.JoiCustomValidators;
|
|
72
|
+
validators.rootDirectory = 'D:/';
|
|
73
|
+
validators.definitionNames = new Map();
|
|
74
|
+
validators.duplicateHelpers = new Map();
|
|
75
|
+
});
|
|
76
|
+
describe('Variable Name', () => {
|
|
77
|
+
let schema = Joi.object().keys({
|
|
78
|
+
value: Joi.string().uniqueNameGroup(Asset).required()
|
|
79
|
+
});
|
|
80
|
+
test('valid data', () => {
|
|
81
|
+
let rawDefinition = getSimpleRawDefinition('test');
|
|
82
|
+
let { value, error } = schema.validate(raw_definition_helper_1.RawDefinitionHelper.flatten(rawDefinition), {
|
|
83
|
+
abortEarly: false,
|
|
84
|
+
context: rawDefinition
|
|
85
|
+
});
|
|
86
|
+
expect(value).toEqual({ value: 'assetTest' });
|
|
87
|
+
expect(error).toEqual(undefined);
|
|
88
|
+
});
|
|
89
|
+
test('invalid data', () => {
|
|
90
|
+
let rawDefinition = getSimpleRawDefinition('invalid data');
|
|
91
|
+
let { error } = schema.validate(raw_definition_helper_1.RawDefinitionHelper.flatten(rawDefinition), { abortEarly: false, context: rawDefinition });
|
|
92
|
+
expect(error?.details).toStrictEqual([
|
|
93
|
+
{
|
|
94
|
+
message: '"value" with value "invalid data" fails to match the required pattern: /^[a-z]+([a-zA-Z0-9]+)*$/',
|
|
95
|
+
path: [],
|
|
96
|
+
type: 'string.pattern.base',
|
|
97
|
+
context: {
|
|
98
|
+
name: undefined,
|
|
99
|
+
regex: /^[a-z]+([a-zA-Z0-9]+)*$/,
|
|
100
|
+
value: 'invalid data',
|
|
101
|
+
label: 'value',
|
|
102
|
+
key: 'value'
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
]);
|
|
106
|
+
});
|
|
107
|
+
test('should detect duplicate variable names', () => {
|
|
108
|
+
let rawDefinition1 = getSimpleRawDefinition('test', 1);
|
|
109
|
+
let rawDefinition2 = getSimpleRawDefinition('test', 2);
|
|
110
|
+
schema.validate(raw_definition_helper_1.RawDefinitionHelper.flatten(rawDefinition1), { abortEarly: false, context: rawDefinition1 });
|
|
111
|
+
schema.validate(raw_definition_helper_1.RawDefinitionHelper.flatten(rawDefinition2), { abortEarly: false, context: rawDefinition2 });
|
|
112
|
+
let context = (0, mocks_1.getMockContext)();
|
|
113
|
+
joi_custom_validators_1.JoiCustomValidators.logDuplicates(context);
|
|
114
|
+
expect(context.errorLogs).toStrictEqual([
|
|
115
|
+
{
|
|
116
|
+
description: 'Value should be singular! Group: "ASSET", Value: "test"',
|
|
117
|
+
location: { line: mocks_1.SampleLocation1.line + 1, path: 'D:/test/file-1.md' }
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
description: 'Value should be singular! Group: "ASSET", Value: "test"',
|
|
121
|
+
location: { line: mocks_1.SampleLocation1.line + 2, path: 'D:/test/file-1.md' }
|
|
122
|
+
}
|
|
123
|
+
]);
|
|
124
|
+
});
|
|
125
|
+
test('different groups should not create duplicates', () => {
|
|
126
|
+
let schema2 = Joi.object().keys({
|
|
127
|
+
value: Joi.string().uniqueNameGroup(AssetGroup).required()
|
|
128
|
+
});
|
|
129
|
+
let rawDefinition1 = getSimpleRawDefinition('test', 1);
|
|
130
|
+
let rawDefinition2 = getSimpleRawDefinition('test', 2);
|
|
131
|
+
schema.validate(raw_definition_helper_1.RawDefinitionHelper.flatten(rawDefinition1), { abortEarly: false, context: rawDefinition1 });
|
|
132
|
+
schema2.validate(raw_definition_helper_1.RawDefinitionHelper.flatten(rawDefinition2), { abortEarly: false, context: rawDefinition2 });
|
|
133
|
+
let context = (0, mocks_1.getMockContext)();
|
|
134
|
+
joi_custom_validators_1.JoiCustomValidators.logDuplicates(context);
|
|
135
|
+
expect(context.errorLogs).toStrictEqual([]);
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
describe('Reference', () => {
|
|
139
|
+
let schema = Joi.object().keys({
|
|
140
|
+
value: Joi.string().reference(Asset).required()
|
|
141
|
+
});
|
|
142
|
+
let multipleSchema = Joi.object().keys({
|
|
143
|
+
value: Joi.string().reference([AssetGroup, Asset]).required()
|
|
144
|
+
});
|
|
145
|
+
test('valid data', () => {
|
|
146
|
+
let rawDefinition = getSimpleRawDefinition('test');
|
|
147
|
+
let validators = joi_custom_validators_1.JoiCustomValidators;
|
|
148
|
+
validators.getDefinitionNames(DefinitionType).add('test');
|
|
149
|
+
let { value, error } = schema.validate(raw_definition_helper_1.RawDefinitionHelper.flatten(rawDefinition), {
|
|
150
|
+
abortEarly: false,
|
|
151
|
+
context: rawDefinition
|
|
152
|
+
});
|
|
153
|
+
expect(value).toEqual({ value: 'assetTest' });
|
|
154
|
+
expect(error).toEqual(undefined);
|
|
155
|
+
});
|
|
156
|
+
test('multiple reference', () => {
|
|
157
|
+
let rawDefinition = getSimpleRawDefinition('test');
|
|
158
|
+
let validators = joi_custom_validators_1.JoiCustomValidators;
|
|
159
|
+
validators.getDefinitionNames(DefinitionType).add('test');
|
|
160
|
+
let { value, error } = multipleSchema.validate(raw_definition_helper_1.RawDefinitionHelper.flatten(rawDefinition), {
|
|
161
|
+
abortEarly: false,
|
|
162
|
+
context: rawDefinition
|
|
163
|
+
});
|
|
164
|
+
expect(value).toEqual({ value: 'assetTest' });
|
|
165
|
+
expect(error).toEqual(undefined);
|
|
166
|
+
});
|
|
167
|
+
test('primitive valid data', () => {
|
|
168
|
+
let rawDefinition = getFlatRawDefinition('test');
|
|
169
|
+
let primitiveSchema = Joi.string().reference(Asset).required();
|
|
170
|
+
let validators = joi_custom_validators_1.JoiCustomValidators;
|
|
171
|
+
validators.getDefinitionNames(DefinitionType).add('test');
|
|
172
|
+
let { value, error } = primitiveSchema.validate(raw_definition_helper_1.RawDefinitionHelper.flatten(rawDefinition), {
|
|
173
|
+
abortEarly: false,
|
|
174
|
+
context: rawDefinition
|
|
175
|
+
});
|
|
176
|
+
expect(value).toEqual('assetTest');
|
|
177
|
+
expect(error).toEqual(undefined);
|
|
178
|
+
});
|
|
179
|
+
test('should detect non existing references', () => {
|
|
180
|
+
let rawDefinition = getSimpleRawDefinition('test');
|
|
181
|
+
let { error } = schema.validate(raw_definition_helper_1.RawDefinitionHelper.flatten(rawDefinition), { abortEarly: false, context: rawDefinition });
|
|
182
|
+
expect(error?.details).toEqual([
|
|
183
|
+
{
|
|
184
|
+
context: {
|
|
185
|
+
key: 'value',
|
|
186
|
+
label: 'value',
|
|
187
|
+
value: 'test'
|
|
188
|
+
},
|
|
189
|
+
message: 'There is no definition found for "test" in name field: "ASSET"',
|
|
190
|
+
path: ['value'],
|
|
191
|
+
type: 'any.custom'
|
|
192
|
+
}
|
|
193
|
+
]);
|
|
194
|
+
});
|
|
195
|
+
test('should detect non existing multiple references', () => {
|
|
196
|
+
let rawDefinition = getSimpleRawDefinition('test');
|
|
197
|
+
let { error } = multipleSchema.validate(raw_definition_helper_1.RawDefinitionHelper.flatten(rawDefinition), {
|
|
198
|
+
abortEarly: false,
|
|
199
|
+
context: rawDefinition
|
|
200
|
+
});
|
|
201
|
+
expect(error?.details).toEqual([
|
|
202
|
+
{
|
|
203
|
+
context: {
|
|
204
|
+
key: 'value',
|
|
205
|
+
label: 'value',
|
|
206
|
+
value: 'test'
|
|
207
|
+
},
|
|
208
|
+
message: 'There is no definition found for "test" in name field: "ASSET-GROUP, ASSET"',
|
|
209
|
+
path: ['value'],
|
|
210
|
+
type: 'any.custom'
|
|
211
|
+
}
|
|
212
|
+
]);
|
|
213
|
+
});
|
|
214
|
+
});
|
|
215
|
+
describe('Path', () => {
|
|
216
|
+
let schema = Joi.object().keys({
|
|
217
|
+
value: Joi.string().path().required()
|
|
218
|
+
});
|
|
219
|
+
test('valid data', () => {
|
|
220
|
+
let rawDefinition = getSimpleRawDefinition('images/test.png');
|
|
221
|
+
let { value, error } = schema.validate(raw_definition_helper_1.RawDefinitionHelper.flatten(rawDefinition), {
|
|
222
|
+
abortEarly: false,
|
|
223
|
+
context: rawDefinition
|
|
224
|
+
});
|
|
225
|
+
expect(value).toEqual({ value: '.test/images/test.png' });
|
|
226
|
+
expect(error).toEqual(undefined);
|
|
227
|
+
});
|
|
228
|
+
test('should detect files not existing', () => {
|
|
229
|
+
let rawDefinition = getSimpleRawDefinition('invalid data');
|
|
230
|
+
let { error } = schema.validate(raw_definition_helper_1.RawDefinitionHelper.flatten(rawDefinition), { abortEarly: false, context: rawDefinition });
|
|
231
|
+
expect(error?.details).toStrictEqual([
|
|
232
|
+
{
|
|
233
|
+
message: '"value" with value "invalid data" fails to match the required pattern: /^[\\S]+$/',
|
|
234
|
+
path: ['value'],
|
|
235
|
+
type: 'string.pattern.base',
|
|
236
|
+
context: {
|
|
237
|
+
name: undefined,
|
|
238
|
+
regex: /^[\S]+$/,
|
|
239
|
+
value: 'invalid data',
|
|
240
|
+
label: 'value',
|
|
241
|
+
key: 'value'
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
]);
|
|
245
|
+
});
|
|
246
|
+
test('should detect files not existing', () => {
|
|
247
|
+
let rawDefinition = getSimpleRawDefinition('false/path.png');
|
|
248
|
+
let { error } = schema.validate(raw_definition_helper_1.RawDefinitionHelper.flatten(rawDefinition), { abortEarly: false, context: rawDefinition });
|
|
249
|
+
expect(error?.details).toStrictEqual([
|
|
250
|
+
{
|
|
251
|
+
message: 'No file is found in the path: "false/path.png"',
|
|
252
|
+
path: ['value'],
|
|
253
|
+
type: 'any.custom',
|
|
254
|
+
context: { label: 'value', value: 'false/path.png', key: 'value' }
|
|
255
|
+
}
|
|
256
|
+
]);
|
|
257
|
+
});
|
|
258
|
+
});
|
|
259
|
+
});
|
|
260
|
+
//# sourceMappingURL=joi-custom-validators.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|