@redocly/openapi-core 1.0.0-beta.102 → 1.0.0-beta.105
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/__tests__/utils.ts +3 -1
- package/lib/config/config.d.ts +4 -3
- package/lib/config/config.js +23 -16
- package/lib/config/load.d.ts +1 -1
- package/lib/config/load.js +15 -3
- package/lib/config/rules.d.ts +1 -1
- package/lib/config/types.d.ts +4 -2
- package/lib/decorators/common/filters/filter-helper.d.ts +3 -0
- package/lib/decorators/common/filters/filter-helper.js +67 -0
- package/lib/decorators/common/filters/filter-in.d.ts +2 -0
- package/lib/decorators/common/filters/filter-in.js +17 -0
- package/lib/decorators/common/filters/filter-out.d.ts +2 -0
- package/lib/decorators/common/filters/filter-out.js +17 -0
- package/lib/decorators/oas2/index.d.ts +2 -0
- package/lib/decorators/oas2/index.js +5 -1
- package/lib/decorators/oas3/index.d.ts +2 -0
- package/lib/decorators/oas3/index.js +5 -1
- package/lib/index.d.ts +2 -2
- package/lib/index.js +2 -1
- package/lib/lint.d.ts +2 -0
- package/lib/lint.js +2 -2
- package/lib/redocly/registry-api-types.d.ts +2 -0
- package/lib/redocly/registry-api.d.ts +1 -1
- package/lib/redocly/registry-api.js +3 -1
- package/lib/rules/ajv.d.ts +1 -1
- package/lib/rules/ajv.js +1 -1
- package/lib/rules/common/assertions/asserts.d.ts +6 -1
- package/lib/rules/common/assertions/asserts.js +81 -51
- package/lib/rules/common/assertions/utils.d.ts +2 -1
- package/lib/rules/common/assertions/utils.js +27 -8
- package/lib/types/redocly-yaml.js +317 -27
- package/lib/utils.d.ts +5 -3
- package/lib/utils.js +15 -2
- package/lib/walk.d.ts +4 -14
- package/lib/walk.js +35 -26
- package/package.json +3 -2
- package/src/__tests__/fixtures/.redocly.lint-ignore.yaml +5 -0
- package/src/__tests__/lint.test.ts +70 -10
- package/src/__tests__/utils.test.ts +42 -1
- package/src/config/__tests__/load.test.ts +8 -2
- package/src/config/config.ts +31 -27
- package/src/config/load.ts +29 -9
- package/src/config/types.ts +6 -5
- package/src/decorators/__tests__/filter-in.test.ts +310 -0
- package/src/decorators/__tests__/filter-out.test.ts +331 -0
- package/src/decorators/common/filters/filter-helper.ts +72 -0
- package/src/decorators/common/filters/filter-in.ts +18 -0
- package/src/decorators/common/filters/filter-out.ts +18 -0
- package/src/decorators/oas2/index.ts +5 -1
- package/src/decorators/oas3/index.ts +5 -1
- package/src/index.ts +2 -1
- package/src/lint.ts +4 -3
- package/src/redocly/registry-api-types.ts +2 -0
- package/src/redocly/registry-api.ts +4 -0
- package/src/rules/ajv.ts +4 -4
- package/src/rules/common/assertions/__tests__/asserts.test.ts +149 -146
- package/src/rules/common/assertions/asserts.ts +97 -52
- package/src/rules/common/assertions/utils.ts +41 -16
- package/src/types/redocly-yaml.ts +322 -34
- package/src/utils.ts +28 -15
- package/src/walk.ts +59 -47
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Oas2Decorator, Oas3Decorator } from '../../../visitors';
|
|
2
|
+
import { checkIfMatchByStrategy, filter } from './filter-helper';
|
|
3
|
+
|
|
4
|
+
const DEFAULT_STRATEGY = 'any';
|
|
5
|
+
|
|
6
|
+
export const FilterIn: Oas3Decorator | Oas2Decorator = ({ property, value, matchStrategy }) => {
|
|
7
|
+
const strategy = matchStrategy || DEFAULT_STRATEGY;
|
|
8
|
+
const filterInCriteria = (item: any) =>
|
|
9
|
+
item?.[property] && !checkIfMatchByStrategy(item?.[property], value, strategy);
|
|
10
|
+
|
|
11
|
+
return {
|
|
12
|
+
any: {
|
|
13
|
+
enter: (node, ctx) => {
|
|
14
|
+
filter(node, ctx, filterInCriteria);
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Oas2Decorator, Oas3Decorator } from '../../../visitors';
|
|
2
|
+
import { checkIfMatchByStrategy, filter } from './filter-helper';
|
|
3
|
+
|
|
4
|
+
const DEFAULT_STRATEGY = 'any';
|
|
5
|
+
|
|
6
|
+
export const FilterOut: Oas3Decorator | Oas2Decorator = ({ property, value, matchStrategy }) => {
|
|
7
|
+
const strategy = matchStrategy || DEFAULT_STRATEGY;
|
|
8
|
+
const filterOutCriteria = (item: any) =>
|
|
9
|
+
checkIfMatchByStrategy(item?.[property], value, strategy);
|
|
10
|
+
|
|
11
|
+
return {
|
|
12
|
+
any: {
|
|
13
|
+
enter: (node, ctx) => {
|
|
14
|
+
filter(node, ctx, filterOutCriteria);
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
};
|
|
@@ -4,11 +4,15 @@ import { OperationDescriptionOverride } from '../common/operation-description-ov
|
|
|
4
4
|
import { TagDescriptionOverride } from '../common/tag-description-override';
|
|
5
5
|
import { InfoDescriptionOverride } from '../common/info-description-override';
|
|
6
6
|
import { RemoveXInternal } from '../common/remove-x-internal';
|
|
7
|
+
import { FilterIn } from '../common/filters/filter-in';
|
|
8
|
+
import { FilterOut } from '../common/filters/filter-out';
|
|
7
9
|
|
|
8
10
|
export const decorators = {
|
|
9
11
|
'registry-dependencies': RegistryDependencies as Oas2Decorator,
|
|
10
12
|
'operation-description-override': OperationDescriptionOverride as Oas2Decorator,
|
|
11
13
|
'tag-description-override': TagDescriptionOverride as Oas2Decorator,
|
|
12
14
|
'info-description-override': InfoDescriptionOverride as Oas2Decorator,
|
|
13
|
-
'remove-x-internal': RemoveXInternal as Oas2Decorator
|
|
15
|
+
'remove-x-internal': RemoveXInternal as Oas2Decorator,
|
|
16
|
+
'filter-in': FilterIn as Oas2Decorator,
|
|
17
|
+
'filter-out': FilterOut as Oas2Decorator,
|
|
14
18
|
};
|
|
@@ -4,11 +4,15 @@ import { OperationDescriptionOverride } from '../common/operation-description-ov
|
|
|
4
4
|
import { TagDescriptionOverride } from '../common/tag-description-override';
|
|
5
5
|
import { InfoDescriptionOverride } from '../common/info-description-override';
|
|
6
6
|
import { RemoveXInternal } from '../common/remove-x-internal';
|
|
7
|
+
import { FilterIn } from '../common/filters/filter-in';
|
|
8
|
+
import { FilterOut } from '../common/filters/filter-out';
|
|
7
9
|
|
|
8
10
|
export const decorators = {
|
|
9
11
|
'registry-dependencies': RegistryDependencies as Oas3Decorator,
|
|
10
12
|
'operation-description-override': OperationDescriptionOverride as Oas3Decorator,
|
|
11
13
|
'tag-description-override': TagDescriptionOverride as Oas3Decorator,
|
|
12
14
|
'info-description-override': InfoDescriptionOverride as Oas3Decorator,
|
|
13
|
-
'remove-x-internal': RemoveXInternal as Oas3Decorator
|
|
15
|
+
'remove-x-internal': RemoveXInternal as Oas3Decorator,
|
|
16
|
+
'filter-in': FilterIn as Oas3Decorator,
|
|
17
|
+
'filter-out': FilterOut as Oas3Decorator,
|
|
14
18
|
};
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { BundleOutputFormat, readFileFromUrl, slash } from './utils';
|
|
1
|
+
export { BundleOutputFormat, readFileFromUrl, slash, doesYamlFileExist } from './utils';
|
|
2
2
|
export { Oas3_1Types } from './types/oas3_1';
|
|
3
3
|
export { Oas3Types } from './types/oas3';
|
|
4
4
|
export { Oas2Types } from './types/oas2';
|
|
@@ -33,6 +33,7 @@ export {
|
|
|
33
33
|
getConfig,
|
|
34
34
|
findConfig,
|
|
35
35
|
CONFIG_FILE_NAMES,
|
|
36
|
+
RuleSeverity
|
|
36
37
|
} from './config';
|
|
37
38
|
|
|
38
39
|
|
package/src/lint.ts
CHANGED
|
@@ -94,9 +94,10 @@ export async function lintDocument(opts: {
|
|
|
94
94
|
}
|
|
95
95
|
|
|
96
96
|
export async function lintConfig(opts: {
|
|
97
|
-
document: Document
|
|
97
|
+
document: Document
|
|
98
|
+
severity?: ProblemSeverity
|
|
98
99
|
}) {
|
|
99
|
-
const { document } = opts;
|
|
100
|
+
const { document, severity } = opts;
|
|
100
101
|
|
|
101
102
|
const ctx: WalkContext = {
|
|
102
103
|
problems: [],
|
|
@@ -110,7 +111,7 @@ export async function lintConfig(opts: {
|
|
|
110
111
|
});
|
|
111
112
|
|
|
112
113
|
const types = normalizeTypes(ConfigTypes, config);
|
|
113
|
-
const rules = [{ severity: 'error'
|
|
114
|
+
const rules = [{ severity: severity || 'error', ruleId: 'configuration spec', visitor: OasSpec({ severity: 'error' }) }];
|
|
114
115
|
const normalizedVisitors = normalizeVisitors(rules, types);
|
|
115
116
|
|
|
116
117
|
walkDocument({
|
|
@@ -105,6 +105,8 @@ export class RegistryApi {
|
|
|
105
105
|
branch,
|
|
106
106
|
isUpsert,
|
|
107
107
|
isPublic,
|
|
108
|
+
batchId,
|
|
109
|
+
batchSize
|
|
108
110
|
}: RegistryApiTypes.PushApiParams) {
|
|
109
111
|
const response = await this.request(
|
|
110
112
|
`/${organizationId}/${name}/${version}`,
|
|
@@ -120,6 +122,8 @@ export class RegistryApi {
|
|
|
120
122
|
branch,
|
|
121
123
|
isUpsert,
|
|
122
124
|
isPublic,
|
|
125
|
+
batchId,
|
|
126
|
+
batchSize
|
|
123
127
|
}),
|
|
124
128
|
},
|
|
125
129
|
this.region,
|
package/src/rules/ajv.ts
CHANGED
|
@@ -8,7 +8,7 @@ export function releaseAjvInstance() {
|
|
|
8
8
|
ajvInstance = null;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
function getAjv(resolve: ResolveFn
|
|
11
|
+
function getAjv(resolve: ResolveFn, disallowAdditionalProperties: boolean) {
|
|
12
12
|
if (!ajvInstance) {
|
|
13
13
|
ajvInstance = new Ajv({
|
|
14
14
|
schemaId: '$id',
|
|
@@ -23,7 +23,7 @@ function getAjv(resolve: ResolveFn<any>, disallowAdditionalProperties: boolean)
|
|
|
23
23
|
defaultAdditionalProperties: !disallowAdditionalProperties,
|
|
24
24
|
loadSchemaSync(base: string, $ref: string) {
|
|
25
25
|
const resolvedRef = resolve({ $ref }, base.split('#')[0]);
|
|
26
|
-
if (!resolvedRef || !resolvedRef.location) return
|
|
26
|
+
if (!resolvedRef || !resolvedRef.location) return false;
|
|
27
27
|
return { $id: resolvedRef.location.absolutePointer, ...resolvedRef.node };
|
|
28
28
|
},
|
|
29
29
|
logger: false,
|
|
@@ -35,7 +35,7 @@ function getAjv(resolve: ResolveFn<any>, disallowAdditionalProperties: boolean)
|
|
|
35
35
|
function getAjvValidator(
|
|
36
36
|
schema: any,
|
|
37
37
|
loc: Location,
|
|
38
|
-
resolve: ResolveFn
|
|
38
|
+
resolve: ResolveFn,
|
|
39
39
|
disallowAdditionalProperties: boolean,
|
|
40
40
|
): ValidateFunction | undefined {
|
|
41
41
|
const ajv = getAjv(resolve, disallowAdditionalProperties);
|
|
@@ -52,7 +52,7 @@ export function validateJsonSchema(
|
|
|
52
52
|
schema: any,
|
|
53
53
|
schemaLoc: Location,
|
|
54
54
|
instancePath: string,
|
|
55
|
-
resolve: ResolveFn
|
|
55
|
+
resolve: ResolveFn,
|
|
56
56
|
disallowAdditionalProperties: boolean,
|
|
57
57
|
): { valid: boolean; errors: (ErrorObject & { suggest?: string[] })[] } {
|
|
58
58
|
const validate = getAjvValidator(schema, schemaLoc, resolve, disallowAdditionalProperties);
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+
import { Location } from '../../../../ref-utils';
|
|
2
|
+
import { Source } from '../../../../resolve';
|
|
1
3
|
import { asserts } from '../asserts';
|
|
2
4
|
|
|
5
|
+
let baseLocation = new Location(jest.fn() as any as Source, 'pointer');
|
|
6
|
+
|
|
3
7
|
describe('oas3 assertions', () => {
|
|
4
8
|
describe('generic rules', () => {
|
|
5
9
|
const fakeNode = {
|
|
@@ -10,232 +14,231 @@ describe('oas3 assertions', () => {
|
|
|
10
14
|
|
|
11
15
|
describe('pattern', () => {
|
|
12
16
|
it('value should match regex pattern', () => {
|
|
13
|
-
expect(asserts.pattern('test string', '/test/')).
|
|
14
|
-
expect(asserts.pattern('test string', '/test me/')).
|
|
15
|
-
expect(asserts.pattern(['test string', 'test me'], '/test/')).
|
|
16
|
-
expect(asserts.pattern(['test string', 'test me'], '/test me/')).
|
|
17
|
+
expect(asserts.pattern('test string', '/test/', baseLocation)).toEqual({ isValid: true });
|
|
18
|
+
expect(asserts.pattern('test string', '/test me/', baseLocation)).toEqual({ isValid: false, location: baseLocation });
|
|
19
|
+
expect(asserts.pattern(['test string', 'test me'], '/test/', baseLocation)).toEqual({ isValid: true });
|
|
20
|
+
expect(asserts.pattern(['test string', 'test me'], '/test me/', baseLocation)).toEqual({ isValid: false, location: baseLocation.key() });
|
|
21
|
+
expect(asserts.pattern('./components/smth/test.yaml', '/^(./)?components/.*.yaml$/', baseLocation)).toEqual({ isValid: true });
|
|
22
|
+
expect(asserts.pattern('./other.yaml', '/^(./)?components/.*.yaml$/', baseLocation)).toEqual({ isValid: false, location: baseLocation });
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
describe('ref', () => {
|
|
27
|
+
it('value should have ref', () => {
|
|
28
|
+
expect(asserts.ref({ $ref: 'text' }, true, baseLocation, { $ref: 'text' })).toEqual({ isValid: true, location: baseLocation });
|
|
29
|
+
expect(asserts.ref({}, true, baseLocation, {})).toEqual({ isValid: false, location: baseLocation.key() });
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('value should not have ref', () => {
|
|
33
|
+
expect(asserts.ref({ $ref: 'text' }, false, baseLocation, { $ref: 'text' })).toEqual({ isValid: false, location: baseLocation });
|
|
34
|
+
expect(asserts.ref({}, false, baseLocation, {})).toEqual({ isValid: true, location: baseLocation.key() });
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('value should match regex pattern', () => {
|
|
38
|
+
expect(asserts.ref({ $ref: 'test string' }, '/test/', baseLocation, { $ref: 'test string' })).toEqual({ isValid: true, location: baseLocation });
|
|
39
|
+
expect(asserts.ref({ $ref: 'test string' }, '/test me/', baseLocation, { $ref: 'test string' })).toEqual({ isValid: false, location: baseLocation });
|
|
40
|
+
expect(asserts.ref({ $ref: './components/smth/test.yaml' }, '/^(./)?components/.*.yaml$/', baseLocation, { $ref: './components/smth/test.yaml' })).toEqual({ isValid: true, location: baseLocation });
|
|
41
|
+
expect(asserts.ref({ $ref: './paths/smth/test.yaml' }, '/^(./)?components/.*.yaml$/', baseLocation, { $ref: './paths/smth/test.yaml' })).toEqual({ isValid: false, location: baseLocation });
|
|
17
42
|
});
|
|
18
43
|
});
|
|
19
44
|
|
|
20
45
|
describe('enum', () => {
|
|
21
46
|
it('value should be among predefined keys', () => {
|
|
22
|
-
expect(asserts.enum('test', ['test', 'example'])).
|
|
23
|
-
expect(asserts.enum(['test'], ['test', 'example'])).
|
|
24
|
-
expect(asserts.enum(['test', 'example'], ['test', 'example'])).
|
|
25
|
-
expect(asserts.enum(['test', 'example', 'foo'], ['test', 'example'])).
|
|
26
|
-
expect(asserts.enum('test', ['foo', 'example'])).
|
|
27
|
-
expect(asserts.enum(['test', 'foo'], ['test', 'example'])).
|
|
47
|
+
expect(asserts.enum('test', ['test', 'example'], baseLocation)).toEqual({ isValid: true });
|
|
48
|
+
expect(asserts.enum(['test'], ['test', 'example'], baseLocation)).toEqual({ isValid: true });
|
|
49
|
+
expect(asserts.enum(['test', 'example'], ['test', 'example'], baseLocation)).toEqual({ isValid: true });
|
|
50
|
+
expect(asserts.enum(['test', 'example', 'foo'], ['test', 'example'], baseLocation)).toEqual({ isValid: false, location: baseLocation.child('foo').key() });
|
|
51
|
+
expect(asserts.enum('test', ['foo', 'example'], baseLocation)).toEqual({ isValid: false, location: baseLocation });
|
|
52
|
+
expect(asserts.enum(['test', 'foo'], ['test', 'example'], baseLocation)).toEqual({ isValid: false, location: baseLocation.child('foo').key() });
|
|
28
53
|
});
|
|
29
54
|
});
|
|
30
55
|
|
|
31
56
|
describe('defined', () => {
|
|
32
57
|
it('value should be defined', () => {
|
|
33
|
-
expect(asserts.defined('test', true)).
|
|
34
|
-
expect(asserts.defined(undefined, true)).
|
|
58
|
+
expect(asserts.defined('test', true, baseLocation)).toEqual({ isValid: true, location: baseLocation });
|
|
59
|
+
expect(asserts.defined(undefined, true, baseLocation)).toEqual({ isValid: false, location: baseLocation });
|
|
35
60
|
});
|
|
36
61
|
it('value should be undefined', () => {
|
|
37
|
-
expect(asserts.defined(undefined, false)).
|
|
38
|
-
expect(asserts.defined('test', false)).
|
|
62
|
+
expect(asserts.defined(undefined, false, baseLocation)).toEqual({ isValid: true, location: baseLocation });
|
|
63
|
+
expect(asserts.defined('test', false, baseLocation)).toEqual({ isValid: false, location: baseLocation });
|
|
39
64
|
});
|
|
40
65
|
});
|
|
41
66
|
|
|
42
67
|
describe('undefined', () => {
|
|
43
68
|
it('value should be undefined', () => {
|
|
44
|
-
expect(asserts.undefined(undefined, true)).
|
|
45
|
-
expect(asserts.undefined('test', true)).
|
|
69
|
+
expect(asserts.undefined(undefined, true, baseLocation)).toEqual({ isValid: true, location: baseLocation });
|
|
70
|
+
expect(asserts.undefined('test', true, baseLocation)).toEqual({ isValid: false, location: baseLocation });
|
|
46
71
|
});
|
|
47
72
|
it('value should be defined', () => {
|
|
48
|
-
expect(asserts.undefined('test', false)).
|
|
49
|
-
expect(asserts.undefined(undefined, false)).
|
|
73
|
+
expect(asserts.undefined('test', false, baseLocation)).toEqual({ isValid: true, location: baseLocation });
|
|
74
|
+
expect(asserts.undefined(undefined, false, baseLocation)).toEqual({ isValid: false, location: baseLocation });
|
|
50
75
|
});
|
|
51
76
|
});
|
|
52
77
|
|
|
53
78
|
describe('required', () => {
|
|
54
79
|
it('values should be required', () => {
|
|
55
|
-
expect(asserts.required(['one', 'two', 'three'], ['one', 'two'])).
|
|
56
|
-
expect(asserts.required(['one', 'two'], ['one', 'two', 'three'])).
|
|
80
|
+
expect(asserts.required(['one', 'two', 'three'], ['one', 'two'], baseLocation)).toEqual({ isValid: true });
|
|
81
|
+
expect(asserts.required(['one', 'two'], ['one', 'two', 'three'], baseLocation)).toEqual({ isValid: false, location: baseLocation.key() });
|
|
57
82
|
});
|
|
58
83
|
});
|
|
59
84
|
|
|
60
85
|
describe('nonEmpty', () => {
|
|
61
86
|
it('value should not be empty', () => {
|
|
62
|
-
expect(asserts.nonEmpty('test', true)).
|
|
63
|
-
expect(asserts.nonEmpty('', true)).
|
|
64
|
-
expect(asserts.nonEmpty(null, true)).
|
|
65
|
-
expect(asserts.nonEmpty(undefined, true)).
|
|
87
|
+
expect(asserts.nonEmpty('test', true, baseLocation)).toEqual({ isValid: true, location: baseLocation });
|
|
88
|
+
expect(asserts.nonEmpty('', true, baseLocation)).toEqual({ isValid: false, location: baseLocation });
|
|
89
|
+
expect(asserts.nonEmpty(null, true, baseLocation)).toEqual({ isValid: false, location: baseLocation });
|
|
90
|
+
expect(asserts.nonEmpty(undefined, true, baseLocation)).toEqual({ isValid: false, location: baseLocation });
|
|
66
91
|
});
|
|
67
92
|
it('value should be empty', () => {
|
|
68
|
-
expect(asserts.nonEmpty('', false)).
|
|
69
|
-
expect(asserts.nonEmpty(null, false)).
|
|
70
|
-
expect(asserts.nonEmpty(undefined, false)).
|
|
71
|
-
expect(asserts.nonEmpty('test', false)).
|
|
93
|
+
expect(asserts.nonEmpty('', false, baseLocation)).toEqual({ isValid: true, location: baseLocation });
|
|
94
|
+
expect(asserts.nonEmpty(null, false, baseLocation)).toEqual({ isValid: true, location: baseLocation });
|
|
95
|
+
expect(asserts.nonEmpty(undefined, false, baseLocation)).toEqual({ isValid: true, location: baseLocation });
|
|
96
|
+
expect(asserts.nonEmpty('test', false, baseLocation)).toEqual({ isValid: false, location: baseLocation });
|
|
72
97
|
});
|
|
73
98
|
});
|
|
74
99
|
|
|
75
100
|
describe('minLength', () => {
|
|
76
101
|
it('value should have less or equal than 5 symbols length', () => {
|
|
77
|
-
expect(asserts.minLength('test', 5)).
|
|
78
|
-
expect(asserts.minLength([1, 2, 3, 4], 5)).
|
|
79
|
-
expect(asserts.minLength([1, 2, 3, 4, 5], 5)).
|
|
80
|
-
expect(asserts.minLength([1, 2, 3, 4, 5, 6], 5)).
|
|
81
|
-
expect(asserts.minLength('example', 5)).
|
|
82
|
-
expect(asserts.minLength([], 5)).
|
|
83
|
-
expect(asserts.minLength('', 5)).
|
|
102
|
+
expect(asserts.minLength('test', 5, baseLocation)).toEqual({ isValid: false, location: baseLocation });
|
|
103
|
+
expect(asserts.minLength([1, 2, 3, 4], 5, baseLocation)).toEqual({ isValid: false, location: baseLocation });
|
|
104
|
+
expect(asserts.minLength([1, 2, 3, 4, 5], 5, baseLocation)).toEqual({ isValid: true, location: baseLocation });
|
|
105
|
+
expect(asserts.minLength([1, 2, 3, 4, 5, 6], 5, baseLocation)).toEqual({ isValid: true, location: baseLocation });
|
|
106
|
+
expect(asserts.minLength('example', 5, baseLocation)).toEqual({ isValid: true, location: baseLocation });
|
|
107
|
+
expect(asserts.minLength([], 5, baseLocation)).toEqual({ isValid: false, location: baseLocation });
|
|
108
|
+
expect(asserts.minLength('', 5, baseLocation)).toEqual({ isValid: false, location: baseLocation });
|
|
84
109
|
});
|
|
85
110
|
});
|
|
86
111
|
|
|
87
112
|
describe('maxLength', () => {
|
|
88
113
|
it('value should have more or equal than 5 symbols length', () => {
|
|
89
|
-
expect(asserts.maxLength('test', 5)).
|
|
90
|
-
expect(asserts.maxLength([1, 2, 3, 4], 5)).
|
|
91
|
-
expect(asserts.maxLength([1, 2, 3, 4, 5], 5)).
|
|
92
|
-
expect(asserts.maxLength([1, 2, 3, 4, 5, 6], 5)).
|
|
93
|
-
expect(asserts.maxLength('example', 5)).
|
|
94
|
-
expect(asserts.maxLength([], 5)).
|
|
95
|
-
expect(asserts.maxLength('', 5)).
|
|
114
|
+
expect(asserts.maxLength('test', 5, baseLocation)).toEqual({ isValid: true, location: baseLocation });
|
|
115
|
+
expect(asserts.maxLength([1, 2, 3, 4], 5, baseLocation)).toEqual({ isValid: true, location: baseLocation });
|
|
116
|
+
expect(asserts.maxLength([1, 2, 3, 4, 5], 5, baseLocation)).toEqual({ isValid: true, location: baseLocation });
|
|
117
|
+
expect(asserts.maxLength([1, 2, 3, 4, 5, 6], 5, baseLocation)).toEqual({ isValid: false, location: baseLocation });
|
|
118
|
+
expect(asserts.maxLength('example', 5, baseLocation)).toEqual({ isValid: false, location: baseLocation });
|
|
119
|
+
expect(asserts.maxLength([], 5, baseLocation)).toEqual({ isValid: true, location: baseLocation });
|
|
120
|
+
expect(asserts.maxLength('', 5, baseLocation)).toEqual({ isValid: true, location: baseLocation });
|
|
96
121
|
});
|
|
97
122
|
});
|
|
98
123
|
|
|
99
124
|
describe('casing', () => {
|
|
100
125
|
it('value should be camelCase', () => {
|
|
101
|
-
expect(asserts.casing(['testExample', 'fooBar'], 'camelCase')).
|
|
102
|
-
expect(asserts.casing(['testExample', 'FooBar'], 'camelCase')).
|
|
103
|
-
expect(asserts.casing('testExample', 'camelCase')).
|
|
104
|
-
expect(asserts.casing('TestExample', 'camelCase')).
|
|
105
|
-
expect(asserts.casing('test-example', 'camelCase')).
|
|
106
|
-
expect(asserts.casing('test_example', 'camelCase')).
|
|
126
|
+
expect(asserts.casing(['testExample', 'fooBar'], 'camelCase', baseLocation)).toEqual({ isValid: true });
|
|
127
|
+
expect(asserts.casing(['testExample', 'FooBar'], 'camelCase', baseLocation)).toEqual({ isValid: false, location: baseLocation.child('FooBar').key() });
|
|
128
|
+
expect(asserts.casing('testExample', 'camelCase', baseLocation)).toEqual({ isValid: true });
|
|
129
|
+
expect(asserts.casing('TestExample', 'camelCase', baseLocation)).toEqual({ isValid: false, location: baseLocation });
|
|
130
|
+
expect(asserts.casing('test-example', 'camelCase', baseLocation)).toEqual({ isValid: false, location: baseLocation });
|
|
131
|
+
expect(asserts.casing('test_example', 'camelCase', baseLocation)).toEqual({ isValid: false, location: baseLocation });
|
|
107
132
|
});
|
|
108
133
|
it('value should be PascalCase', () => {
|
|
109
|
-
expect(asserts.casing('TestExample', 'PascalCase')).
|
|
110
|
-
expect(asserts.casing(['TestExample', 'FooBar'], 'PascalCase')).
|
|
111
|
-
expect(asserts.casing(['TestExample', 'fooBar'], 'PascalCase')).
|
|
112
|
-
expect(asserts.casing('testExample', 'PascalCase')).
|
|
113
|
-
expect(asserts.casing('test-example', 'PascalCase')).
|
|
114
|
-
expect(asserts.casing('test_example', 'PascalCase')).
|
|
134
|
+
expect(asserts.casing('TestExample', 'PascalCase', baseLocation)).toEqual({ isValid: true });
|
|
135
|
+
expect(asserts.casing(['TestExample', 'FooBar'], 'PascalCase', baseLocation)).toEqual({ isValid: true });
|
|
136
|
+
expect(asserts.casing(['TestExample', 'fooBar'], 'PascalCase', baseLocation)).toEqual({ isValid: false, location: baseLocation.child('fooBar').key() });
|
|
137
|
+
expect(asserts.casing('testExample', 'PascalCase', baseLocation)).toEqual({ isValid: false, location: baseLocation });
|
|
138
|
+
expect(asserts.casing('test-example', 'PascalCase', baseLocation)).toEqual({ isValid: false, location: baseLocation });
|
|
139
|
+
expect(asserts.casing('test_example', 'PascalCase', baseLocation)).toEqual({ isValid: false, location: baseLocation });
|
|
115
140
|
});
|
|
116
141
|
it('value should be kebab-case', () => {
|
|
117
|
-
expect(asserts.casing('test-example', 'kebab-case')).
|
|
118
|
-
expect(asserts.casing(['test-example', 'foo-bar'], 'kebab-case')).
|
|
119
|
-
expect(asserts.casing(['test-example', 'foo_bar'], 'kebab-case')).
|
|
120
|
-
expect(asserts.casing('testExample', 'kebab-case')).
|
|
121
|
-
expect(asserts.casing('TestExample', 'kebab-case')).
|
|
122
|
-
expect(asserts.casing('test_example', 'kebab-case')).
|
|
142
|
+
expect(asserts.casing('test-example', 'kebab-case', baseLocation)).toEqual({ isValid: true });
|
|
143
|
+
expect(asserts.casing(['test-example', 'foo-bar'], 'kebab-case', baseLocation)).toEqual({ isValid: true });
|
|
144
|
+
expect(asserts.casing(['test-example', 'foo_bar'], 'kebab-case', baseLocation)).toEqual({ isValid: false, location: baseLocation.child('foo_bar').key() });
|
|
145
|
+
expect(asserts.casing('testExample', 'kebab-case', baseLocation)).toEqual({ isValid: false, location: baseLocation });
|
|
146
|
+
expect(asserts.casing('TestExample', 'kebab-case', baseLocation)).toEqual({ isValid: false, location: baseLocation });
|
|
147
|
+
expect(asserts.casing('test_example', 'kebab-case', baseLocation)).toEqual({ isValid: false, location: baseLocation });
|
|
123
148
|
});
|
|
124
149
|
it('value should be snake_case', () => {
|
|
125
|
-
expect(asserts.casing('test_example', 'snake_case')).
|
|
126
|
-
expect(asserts.casing(['test_example', 'foo_bar'], 'snake_case')).
|
|
127
|
-
expect(asserts.casing(['test_example', 'foo-bar'], 'snake_case')).
|
|
128
|
-
expect(asserts.casing('testExample', 'snake_case')).
|
|
129
|
-
expect(asserts.casing('TestExample', 'snake_case')).
|
|
130
|
-
expect(asserts.casing('test-example', 'snake_case')).
|
|
150
|
+
expect(asserts.casing('test_example', 'snake_case', baseLocation)).toEqual({ isValid: true });
|
|
151
|
+
expect(asserts.casing(['test_example', 'foo_bar'], 'snake_case', baseLocation)).toEqual({ isValid: true });
|
|
152
|
+
expect(asserts.casing(['test_example', 'foo-bar'], 'snake_case', baseLocation)).toEqual({ isValid: false, location: baseLocation.child('foo-bar').key() });
|
|
153
|
+
expect(asserts.casing('testExample', 'snake_case', baseLocation)).toEqual({ isValid: false, location: baseLocation });
|
|
154
|
+
expect(asserts.casing('TestExample', 'snake_case', baseLocation)).toEqual({ isValid: false, location: baseLocation });
|
|
155
|
+
expect(asserts.casing('test-example', 'snake_case', baseLocation)).toEqual({ isValid: false, location: baseLocation });
|
|
131
156
|
});
|
|
132
157
|
it('value should be MACRO_CASE', () => {
|
|
133
|
-
expect(asserts.casing('TEST_EXAMPLE', 'MACRO_CASE')).
|
|
134
|
-
expect(asserts.casing(['TEST_EXAMPLE', 'FOO_BAR'], 'MACRO_CASE')).
|
|
135
|
-
expect(asserts.casing(['TEST_EXAMPLE', 'FOO-BAR'], 'MACRO_CASE')).
|
|
136
|
-
expect(asserts.casing('TEST_EXAMPLE_', 'MACRO_CASE')).
|
|
137
|
-
expect(asserts.casing('_TEST_EXAMPLE', 'MACRO_CASE')).
|
|
138
|
-
expect(asserts.casing('TEST__EXAMPLE', 'MACRO_CASE')).
|
|
139
|
-
expect(asserts.casing('TEST-EXAMPLE', 'MACRO_CASE')).
|
|
140
|
-
expect(asserts.casing('testExample', 'MACRO_CASE')).
|
|
141
|
-
expect(asserts.casing('TestExample', 'MACRO_CASE')).
|
|
142
|
-
expect(asserts.casing('test-example', 'MACRO_CASE')).
|
|
158
|
+
expect(asserts.casing('TEST_EXAMPLE', 'MACRO_CASE', baseLocation)).toEqual({ isValid: true });
|
|
159
|
+
expect(asserts.casing(['TEST_EXAMPLE', 'FOO_BAR'], 'MACRO_CASE', baseLocation)).toEqual({ isValid: true });
|
|
160
|
+
expect(asserts.casing(['TEST_EXAMPLE', 'FOO-BAR'], 'MACRO_CASE', baseLocation)).toEqual({ isValid: false, location: baseLocation.child('FOO-BAR').key() });
|
|
161
|
+
expect(asserts.casing('TEST_EXAMPLE_', 'MACRO_CASE', baseLocation)).toEqual({ isValid: false, location: baseLocation });
|
|
162
|
+
expect(asserts.casing('_TEST_EXAMPLE', 'MACRO_CASE', baseLocation)).toEqual({ isValid: false, location: baseLocation });
|
|
163
|
+
expect(asserts.casing('TEST__EXAMPLE', 'MACRO_CASE', baseLocation)).toEqual({ isValid: false, location: baseLocation });
|
|
164
|
+
expect(asserts.casing('TEST-EXAMPLE', 'MACRO_CASE', baseLocation)).toEqual({ isValid: false, location: baseLocation });
|
|
165
|
+
expect(asserts.casing('testExample', 'MACRO_CASE', baseLocation)).toEqual({ isValid: false, location: baseLocation });
|
|
166
|
+
expect(asserts.casing('TestExample', 'MACRO_CASE', baseLocation)).toEqual({ isValid: false, location: baseLocation });
|
|
167
|
+
expect(asserts.casing('test-example', 'MACRO_CASE', baseLocation)).toEqual({ isValid: false, location: baseLocation });
|
|
143
168
|
});
|
|
144
169
|
it('value should be COBOL-CASE', () => {
|
|
145
|
-
expect(asserts.casing('TEST-EXAMPLE', 'COBOL-CASE')).
|
|
146
|
-
expect(asserts.casing(['TEST-EXAMPLE', 'FOO-BAR'], 'COBOL-CASE')).
|
|
147
|
-
expect(asserts.casing(['TEST-EXAMPLE', 'FOO_BAR'], 'COBOL-CASE')).
|
|
148
|
-
expect(asserts.casing('TEST-EXAMPLE-', 'COBOL-CASE')).
|
|
149
|
-
expect(asserts.casing('0TEST-EXAMPLE', 'COBOL-CASE')).
|
|
150
|
-
expect(asserts.casing('-TEST-EXAMPLE', 'COBOL-CASE')).
|
|
151
|
-
expect(asserts.casing('TEST--EXAMPLE', 'COBOL-CASE')).
|
|
152
|
-
expect(asserts.casing('TEST_EXAMPLE', 'COBOL-CASE')).
|
|
153
|
-
expect(asserts.casing('testExample', 'COBOL-CASE')).
|
|
154
|
-
expect(asserts.casing('TestExample', 'COBOL-CASE')).
|
|
155
|
-
expect(asserts.casing('test-example', 'COBOL-CASE')).
|
|
170
|
+
expect(asserts.casing('TEST-EXAMPLE', 'COBOL-CASE', baseLocation)).toEqual({ isValid: true });
|
|
171
|
+
expect(asserts.casing(['TEST-EXAMPLE', 'FOO-BAR'], 'COBOL-CASE', baseLocation)).toEqual({ isValid: true });
|
|
172
|
+
expect(asserts.casing(['TEST-EXAMPLE', 'FOO_BAR'], 'COBOL-CASE', baseLocation)).toEqual({ isValid: false, location: baseLocation.child('FOO_BAR').key() });
|
|
173
|
+
expect(asserts.casing('TEST-EXAMPLE-', 'COBOL-CASE', baseLocation)).toEqual({ isValid: false, location: baseLocation });
|
|
174
|
+
expect(asserts.casing('0TEST-EXAMPLE', 'COBOL-CASE', baseLocation)).toEqual({ isValid: false, location: baseLocation });
|
|
175
|
+
expect(asserts.casing('-TEST-EXAMPLE', 'COBOL-CASE', baseLocation)).toEqual({ isValid: false, location: baseLocation });
|
|
176
|
+
expect(asserts.casing('TEST--EXAMPLE', 'COBOL-CASE', baseLocation)).toEqual({ isValid: false, location: baseLocation });
|
|
177
|
+
expect(asserts.casing('TEST_EXAMPLE', 'COBOL-CASE', baseLocation)).toEqual({ isValid: false, location: baseLocation });
|
|
178
|
+
expect(asserts.casing('testExample', 'COBOL-CASE', baseLocation)).toEqual({ isValid: false, location: baseLocation });
|
|
179
|
+
expect(asserts.casing('TestExample', 'COBOL-CASE', baseLocation)).toEqual({ isValid: false, location: baseLocation });
|
|
180
|
+
expect(asserts.casing('test-example', 'COBOL-CASE', baseLocation)).toEqual({ isValid: false, location: baseLocation });
|
|
156
181
|
});
|
|
157
182
|
it('value should be flatcase', () => {
|
|
158
|
-
expect(asserts.casing('testexample', 'flatcase')).
|
|
159
|
-
expect(asserts.casing(['testexample', 'foobar'], 'flatcase')).
|
|
160
|
-
expect(asserts.casing(['testexample', 'foo_bar'], 'flatcase')).
|
|
161
|
-
expect(asserts.casing('testexample_', 'flatcase')).
|
|
162
|
-
expect(asserts.casing('0testexample', 'flatcase')).
|
|
163
|
-
expect(asserts.casing('testExample', 'flatcase')).
|
|
164
|
-
expect(asserts.casing('TestExample', 'flatcase')).
|
|
165
|
-
expect(asserts.casing('test-example', 'flatcase')).
|
|
183
|
+
expect(asserts.casing('testexample', 'flatcase', baseLocation)).toEqual({ isValid: true });
|
|
184
|
+
expect(asserts.casing(['testexample', 'foobar'], 'flatcase', baseLocation)).toEqual({ isValid: true });
|
|
185
|
+
expect(asserts.casing(['testexample', 'foo_bar'], 'flatcase', baseLocation)).toEqual({ isValid: false, location: baseLocation.child('foo_bar').key() });
|
|
186
|
+
expect(asserts.casing('testexample_', 'flatcase', baseLocation)).toEqual({ isValid: false, location: baseLocation });
|
|
187
|
+
expect(asserts.casing('0testexample', 'flatcase', baseLocation)).toEqual({ isValid: false, location: baseLocation });
|
|
188
|
+
expect(asserts.casing('testExample', 'flatcase', baseLocation)).toEqual({ isValid: false, location: baseLocation });
|
|
189
|
+
expect(asserts.casing('TestExample', 'flatcase', baseLocation)).toEqual({ isValid: false, location: baseLocation });
|
|
190
|
+
expect(asserts.casing('test-example', 'flatcase', baseLocation)).toEqual({ isValid: false, location: baseLocation });
|
|
166
191
|
});
|
|
167
192
|
});
|
|
168
193
|
|
|
169
194
|
describe.skip('sortOrder', () => {
|
|
170
195
|
it('value should be ordered in ASC direction', () => {
|
|
171
|
-
expect(asserts.sortOrder(['example', 'foo', 'test'], 'asc')).
|
|
172
|
-
expect(asserts.sortOrder(['example', 'foo', 'test'], { direction: 'asc' })).
|
|
173
|
-
expect(asserts.sortOrder(['example'], 'asc')).
|
|
174
|
-
expect(asserts.sortOrder(['example', 'test', 'foo'], 'asc')).
|
|
175
|
-
expect(asserts.sortOrder(['example', 'foo', 'test'], 'desc')).
|
|
176
|
-
expect(
|
|
177
|
-
|
|
178
|
-
direction: 'asc',
|
|
179
|
-
property: 'name',
|
|
180
|
-
}),
|
|
181
|
-
).toBeTruthy();
|
|
182
|
-
expect(
|
|
183
|
-
asserts.sortOrder([{ name: 'bar' }, { name: 'baz' }, { name: 'foo' }], {
|
|
184
|
-
direction: 'desc',
|
|
185
|
-
property: 'name',
|
|
186
|
-
}),
|
|
187
|
-
).toBeFalsy();
|
|
196
|
+
expect(asserts.sortOrder(['example', 'foo', 'test'], 'asc', baseLocation)).toEqual({ isValid: true, location: baseLocation });
|
|
197
|
+
expect(asserts.sortOrder(['example', 'foo', 'test'], { direction: 'asc' }, baseLocation)).toEqual({ isValid: true, location: baseLocation });
|
|
198
|
+
expect(asserts.sortOrder(['example'], 'asc', baseLocation)).toEqual({ isValid: true, location: baseLocation });
|
|
199
|
+
expect(asserts.sortOrder(['example', 'test', 'foo'], 'asc', baseLocation)).toEqual({ isValid: false, location: baseLocation });
|
|
200
|
+
expect(asserts.sortOrder(['example', 'foo', 'test'], 'desc', baseLocation)).toEqual({ isValid: false, location: baseLocation });
|
|
201
|
+
expect(asserts.sortOrder([{ name: 'bar' }, { name: 'baz' }, { name: 'foo' }], { direction: 'asc', property: 'name' }, baseLocation)).toEqual({ isValid: true, location: baseLocation });
|
|
202
|
+
expect(asserts.sortOrder([{ name: 'bar' }, { name: 'baz' }, { name: 'foo' }], { direction: 'desc', property: 'name' }, baseLocation)).toEqual({ isValid: false, location: baseLocation });
|
|
188
203
|
});
|
|
189
204
|
it('value should be ordered in DESC direction', () => {
|
|
190
|
-
expect(asserts.sortOrder(['test', 'foo', 'example'], 'desc')).
|
|
191
|
-
expect(asserts.sortOrder(['test', 'foo', 'example'], { direction: 'desc' })).
|
|
192
|
-
expect(asserts.sortOrder(['example'], 'desc')).
|
|
193
|
-
expect(asserts.sortOrder(['example', 'test', 'foo'], 'desc')).
|
|
194
|
-
expect(asserts.sortOrder(['test', 'foo', 'example'], 'asc')).
|
|
195
|
-
expect(
|
|
196
|
-
|
|
197
|
-
direction: 'desc',
|
|
198
|
-
property: 'name',
|
|
199
|
-
}),
|
|
200
|
-
).toBeTruthy();
|
|
201
|
-
expect(
|
|
202
|
-
asserts.sortOrder([{ name: 'foo' }, { name: 'baz' }, { name: 'bar' }], {
|
|
203
|
-
direction: 'asc',
|
|
204
|
-
property: 'name',
|
|
205
|
-
}),
|
|
206
|
-
).toBeFalsy();
|
|
205
|
+
expect(asserts.sortOrder(['test', 'foo', 'example'], 'desc', baseLocation)).toEqual({ isValid: true, location: baseLocation });
|
|
206
|
+
expect(asserts.sortOrder(['test', 'foo', 'example'], { direction: 'desc' }, baseLocation)).toEqual({ isValid: true, location: baseLocation });
|
|
207
|
+
expect(asserts.sortOrder(['example'], 'desc', baseLocation)).toEqual({ isValid: true, location: baseLocation });
|
|
208
|
+
expect(asserts.sortOrder(['example', 'test', 'foo'], 'desc', baseLocation)).toEqual({ isValid: false, location: baseLocation });
|
|
209
|
+
expect(asserts.sortOrder(['test', 'foo', 'example'], 'asc', baseLocation)).toEqual({ isValid: false, location: baseLocation });
|
|
210
|
+
expect(asserts.sortOrder([{ name: 'foo' }, { name: 'baz' }, { name: 'bar' }], { direction: 'desc', property: 'name' }, baseLocation)).toEqual({ isValid: true, location: baseLocation });
|
|
211
|
+
expect(asserts.sortOrder([{ name: 'foo' }, { name: 'baz' }, { name: 'bar' }], { direction: 'asc', property: 'name' }, baseLocation)).toEqual({ isValid: false, location: baseLocation });
|
|
207
212
|
});
|
|
208
213
|
});
|
|
209
214
|
|
|
210
215
|
describe('mutuallyExclusive', () => {
|
|
211
216
|
it('node should not have more than one property from predefined list', () => {
|
|
212
|
-
expect(asserts.mutuallyExclusive(Object.keys(fakeNode), ['foo', 'test'])).
|
|
213
|
-
expect(asserts.mutuallyExclusive(Object.keys(fakeNode), [])).
|
|
214
|
-
expect(asserts.mutuallyExclusive(Object.keys(fakeNode), ['foo', 'bar'])).
|
|
215
|
-
expect(
|
|
216
|
-
asserts.mutuallyExclusive(Object.keys(fakeNode), ['foo', 'bar', 'test']),
|
|
217
|
-
).toBeFalsy();
|
|
217
|
+
expect(asserts.mutuallyExclusive(Object.keys(fakeNode), ['foo', 'test'], baseLocation)).toEqual({ isValid: true, location: baseLocation.key() });
|
|
218
|
+
expect(asserts.mutuallyExclusive(Object.keys(fakeNode), [], baseLocation)).toEqual({ isValid: true, location: baseLocation.key() });
|
|
219
|
+
expect(asserts.mutuallyExclusive(Object.keys(fakeNode), ['foo', 'bar'], baseLocation)).toEqual({ isValid: false, location: baseLocation.key() });
|
|
220
|
+
expect(asserts.mutuallyExclusive(Object.keys(fakeNode), ['foo', 'bar', 'test'], baseLocation)).toEqual({ isValid: false, location: baseLocation.key() });
|
|
218
221
|
});
|
|
219
222
|
});
|
|
220
223
|
|
|
221
224
|
describe('mutuallyRequired', () => {
|
|
222
225
|
it('node should have all the properties from predefined list', () => {
|
|
223
|
-
expect(asserts.mutuallyRequired(Object.keys(fakeNode), ['foo', 'bar'])).
|
|
224
|
-
expect(asserts.mutuallyRequired(Object.keys(fakeNode), ['foo', 'bar', 'baz'])).
|
|
225
|
-
expect(asserts.mutuallyRequired(Object.keys(fakeNode), [])).
|
|
226
|
-
expect(asserts.mutuallyRequired(Object.keys(fakeNode), ['foo', 'test'])).
|
|
227
|
-
expect(asserts.mutuallyRequired(Object.keys(fakeNode), ['foo', 'bar', 'test'])).
|
|
226
|
+
expect(asserts.mutuallyRequired(Object.keys(fakeNode), ['foo', 'bar'], baseLocation)).toEqual({ isValid: true, location: baseLocation.key() });
|
|
227
|
+
expect(asserts.mutuallyRequired(Object.keys(fakeNode), ['foo', 'bar', 'baz'], baseLocation)).toEqual({ isValid: true, location: baseLocation.key() });
|
|
228
|
+
expect(asserts.mutuallyRequired(Object.keys(fakeNode), [], baseLocation)).toEqual({ isValid: true, location: baseLocation.key() });
|
|
229
|
+
expect(asserts.mutuallyRequired(Object.keys(fakeNode), ['foo', 'test'], baseLocation)).toEqual({ isValid: false, location: baseLocation.key() });
|
|
230
|
+
expect(asserts.mutuallyRequired(Object.keys(fakeNode), ['foo', 'bar', 'test'], baseLocation)).toEqual({ isValid: false, location: baseLocation.key() });
|
|
228
231
|
});
|
|
229
232
|
});
|
|
230
233
|
|
|
231
234
|
describe('requireAny', () => {
|
|
232
235
|
it('node must have at least one property from predefined list', () => {
|
|
233
|
-
expect(asserts.requireAny(Object.keys(fakeNode), ['foo', 'test'])).
|
|
234
|
-
expect(asserts.requireAny(Object.keys(fakeNode), ['test', 'bar'])).
|
|
235
|
-
expect(asserts.requireAny(Object.keys(fakeNode), [])).
|
|
236
|
-
expect(asserts.requireAny(Object.keys(fakeNode), ['test', 'test1'])).
|
|
237
|
-
expect(asserts.requireAny(Object.keys(fakeNode), ['foo', 'bar'])).
|
|
238
|
-
expect(asserts.requireAny(Object.keys(fakeNode), ['foo', 'bar', 'test'])).
|
|
236
|
+
expect(asserts.requireAny(Object.keys(fakeNode), ['foo', 'test'], baseLocation)).toEqual({ isValid: true, location: baseLocation.key() });
|
|
237
|
+
expect(asserts.requireAny(Object.keys(fakeNode), ['test', 'bar'], baseLocation)).toEqual({ isValid: true, location: baseLocation.key() });
|
|
238
|
+
expect(asserts.requireAny(Object.keys(fakeNode), [], baseLocation)).toEqual({ isValid: false, location: baseLocation.key() });
|
|
239
|
+
expect(asserts.requireAny(Object.keys(fakeNode), ['test', 'test1'], baseLocation)).toEqual({ isValid: false, location: baseLocation.key() });
|
|
240
|
+
expect(asserts.requireAny(Object.keys(fakeNode), ['foo', 'bar'], baseLocation)).toEqual({ isValid: true, location: baseLocation.key() });
|
|
241
|
+
expect(asserts.requireAny(Object.keys(fakeNode), ['foo', 'bar', 'test'], baseLocation)).toEqual({ isValid: true, location: baseLocation.key() });
|
|
239
242
|
});
|
|
240
243
|
});
|
|
241
244
|
});
|