Skip to content

Commit

Permalink
js schema validation test and small fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jbleon95 committed Nov 19, 2024
1 parent 557159e commit 2f2f107
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
60 changes: 60 additions & 0 deletions shared-data/js/__tests__/liquidClassSchema.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/** Ensure that the liquid class schema itself functions as intended,
* and that all v1 liquid class fixtures will validate */
import Ajv from 'ajv'
import path from 'path'
import glob from 'glob'
import { describe, expect, it } from 'vitest'
import liquidClassSchemaV1 from '../../liquid-class/schemas/1.json'

Check failure on line 7 in shared-data/js/__tests__/liquidClassSchema.test.ts

View workflow job for this annotation

GitHub Actions / js checks

File '/home/runner/work/opentrons/opentrons/shared-data/liquid-class/schemas/1.json' is not listed within the file list of project '/home/runner/work/opentrons/opentrons/shared-data/tsconfig.json'. Projects must list all files or use an 'include' pattern.

Check failure on line 7 in shared-data/js/__tests__/liquidClassSchema.test.ts

View workflow job for this annotation

GitHub Actions / js checks

File '/home/runner/work/opentrons/opentrons/shared-data/liquid-class/schemas/1.json' is not listed within the file list of project '/home/runner/work/opentrons/opentrons/shared-data/tsconfig.json'. Projects must list all files or use an 'include' pattern.

const fixtureV1Glob = path.join(__dirname, '../../liquid-class/fixtures/1/*.json')
const defV1Glob = path.join(__dirname, '../../liquid-class/definitions/3/*.json')

const ajv = new Ajv({ allErrors: true, jsonPointers: true })

const validateSchemaV1 = ajv.compile(liquidClassSchemaV1)

describe('validate v1 liquid class definitions and fixtures', () => {
const fixtures = glob.sync(fixtureV1Glob)

fixtures.forEach(fixturePath => {
const fixtureDef = require(fixturePath)

it('fixture validates against schema', () => {
const valid = validateSchemaV1(fixtureDef)
const validationErrors = validateSchemaV1.errors

if (validationErrors) {
console.log(
path.parse(fixturePath).base +
' ' +
JSON.stringify(validationErrors, null, 4)
)
}

expect(validationErrors).toBe(null)
expect(valid).toBe(true)
})
})

const defs = glob.sync(defV1Glob)

defs.forEach(defPath => {
const liquidClassDef = require(defPath)

it('liquid class definition validates against v1 schema', () => {
const valid = validateSchemaV1(liquidClassDef)
const validationErrors = validateSchemaV1.errors

if (validationErrors) {
console.log(
path.parse(defPath).base +
' ' +
JSON.stringify(validationErrors, null, 4)
)
}

expect(validationErrors).toBe(null)
expect(valid).toBe(true)
})
})
})
1 change: 0 additions & 1 deletion shared-data/liquid-class/schemas/1.json
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,6 @@
"positionReference",
"offset",
"flowRateByVolume",
"mix",
"conditioningByVolume",
"disposalByVolume",
"delay"
Expand Down

0 comments on commit 2f2f107

Please sign in to comment.