Skip to content

Commit 2f2f107

Browse files
committed
js schema validation test and small fix
1 parent 557159e commit 2f2f107

File tree

2 files changed

+60
-1
lines changed

2 files changed

+60
-1
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/** Ensure that the liquid class schema itself functions as intended,
2+
* and that all v1 liquid class fixtures will validate */
3+
import Ajv from 'ajv'
4+
import path from 'path'
5+
import glob from 'glob'
6+
import { describe, expect, it } from 'vitest'
7+
import liquidClassSchemaV1 from '../../liquid-class/schemas/1.json'
8+
9+
const fixtureV1Glob = path.join(__dirname, '../../liquid-class/fixtures/1/*.json')
10+
const defV1Glob = path.join(__dirname, '../../liquid-class/definitions/3/*.json')
11+
12+
const ajv = new Ajv({ allErrors: true, jsonPointers: true })
13+
14+
const validateSchemaV1 = ajv.compile(liquidClassSchemaV1)
15+
16+
describe('validate v1 liquid class definitions and fixtures', () => {
17+
const fixtures = glob.sync(fixtureV1Glob)
18+
19+
fixtures.forEach(fixturePath => {
20+
const fixtureDef = require(fixturePath)
21+
22+
it('fixture validates against schema', () => {
23+
const valid = validateSchemaV1(fixtureDef)
24+
const validationErrors = validateSchemaV1.errors
25+
26+
if (validationErrors) {
27+
console.log(
28+
path.parse(fixturePath).base +
29+
' ' +
30+
JSON.stringify(validationErrors, null, 4)
31+
)
32+
}
33+
34+
expect(validationErrors).toBe(null)
35+
expect(valid).toBe(true)
36+
})
37+
})
38+
39+
const defs = glob.sync(defV1Glob)
40+
41+
defs.forEach(defPath => {
42+
const liquidClassDef = require(defPath)
43+
44+
it('liquid class definition validates against v1 schema', () => {
45+
const valid = validateSchemaV1(liquidClassDef)
46+
const validationErrors = validateSchemaV1.errors
47+
48+
if (validationErrors) {
49+
console.log(
50+
path.parse(defPath).base +
51+
' ' +
52+
JSON.stringify(validationErrors, null, 4)
53+
)
54+
}
55+
56+
expect(validationErrors).toBe(null)
57+
expect(valid).toBe(true)
58+
})
59+
})
60+
})

shared-data/liquid-class/schemas/1.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,6 @@
396396
"positionReference",
397397
"offset",
398398
"flowRateByVolume",
399-
"mix",
400399
"conditioningByVolume",
401400
"disposalByVolume",
402401
"delay"

0 commit comments

Comments
 (0)