-
-
Notifications
You must be signed in to change notification settings - Fork 77
/
Copy pathvalidateStreamConfig.ts
45 lines (38 loc) · 1.25 KB
/
validateStreamConfig.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import type {
ValidateFunction,
} from 'ajv';
import Ajv from 'ajv';
import ajvKeywords from 'ajv-keywords';
import ajvSchemaDraft06 from 'ajv/lib/refs/json-schema-draft-06.json';
import {
expect,
} from 'chai';
import validators from '../src/generated/validators';
import sharedSchema from '../src/schemas/shared.json';
import configSchema from '../src/schemas/streamConfig.json';
import streamConfigSamples from './streamConfigSamples';
const validateConfig = validators['streamConfig.json'];
describe('streamConfig.json schema', () => {
let validate: ValidateFunction;
before(() => {
const ajv = new Ajv({
allErrors: true,
});
ajv.addMetaSchema(ajvSchemaDraft06);
ajvKeywords(ajv, 'typeof');
ajv.addSchema(sharedSchema);
validate = ajv.compile(configSchema);
});
it('passes validation of valid streamConfig samples', () => {
for (const sample of streamConfigSamples.valid) {
expect(validate(sample)).to.equal(true);
expect(validateConfig(sample)).to.equal(true);
}
});
it('fails validation of invalid streamConfig samples', () => {
for (const sample of streamConfigSamples.invalid) {
expect(validate(sample)).to.equal(false);
expect(validateConfig(sample)).to.equal(false);
}
});
});