adding tests
This commit is contained in:
parent
ebec834752
commit
85674731ad
@ -25,3 +25,7 @@ tasks:
|
|||||||
-c ajv-keywords \
|
-c ajv-keywords \
|
||||||
-s schemas-yaml/character.yml \
|
-s schemas-yaml/character.yml \
|
||||||
-d {{.CLI_ARGS}}
|
-d {{.CLI_ARGS}}
|
||||||
|
test:
|
||||||
|
deps: [ schemas ]
|
||||||
|
cmds:
|
||||||
|
- vitest run
|
||||||
|
@ -15,9 +15,11 @@
|
|||||||
"author": "Yanick Champoux <yanick@babyl.ca> (http://techblog.babyl.ca/)",
|
"author": "Yanick Champoux <yanick@babyl.ca> (http://techblog.babyl.ca/)",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"prettier": "^2.6.2"
|
"prettier": "^2.6.2",
|
||||||
|
"vitest": "^0.10.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"ajv": "^8.11.0",
|
||||||
"ajv-cli": "^5.0.0",
|
"ajv-cli": "^5.0.0",
|
||||||
"ajv-keywords": "^5.1.0"
|
"ajv-keywords": "^5.1.0"
|
||||||
}
|
}
|
||||||
|
50
schemas-json/character.json
Normal file
50
schemas-json/character.json
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
{
|
||||||
|
"$defs" : {
|
||||||
|
"statistic" : {
|
||||||
|
"maximum" : 20,
|
||||||
|
"minimum" : 1,
|
||||||
|
"type" : "number"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"$id" : "https://hyperboria.babyl.ca/character.json",
|
||||||
|
"additionalProperties" : false,
|
||||||
|
"properties" : {
|
||||||
|
"name" : {
|
||||||
|
"type" : "string"
|
||||||
|
},
|
||||||
|
"player" : {
|
||||||
|
"type" : "string"
|
||||||
|
},
|
||||||
|
"statistics" : {
|
||||||
|
"allRequired" : true,
|
||||||
|
"properties" : {
|
||||||
|
"charisma" : {
|
||||||
|
"$ref" : "#/$defs/statistic"
|
||||||
|
},
|
||||||
|
"constitution" : {
|
||||||
|
"$ref" : "#/$defs/statistic"
|
||||||
|
},
|
||||||
|
"dexterity" : {
|
||||||
|
"$ref" : "#/$defs/statistic"
|
||||||
|
},
|
||||||
|
"intelligence" : {
|
||||||
|
"$ref" : "#/$defs/statistic"
|
||||||
|
},
|
||||||
|
"strength" : {
|
||||||
|
"$ref" : "#/$defs/statistic"
|
||||||
|
},
|
||||||
|
"wisdom" : {
|
||||||
|
"$ref" : "#/$defs/statistic"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"type" : "object"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required" : [
|
||||||
|
"name",
|
||||||
|
"player",
|
||||||
|
"statistics"
|
||||||
|
],
|
||||||
|
"title" : "Hyperboria character sheet",
|
||||||
|
"type" : "object"
|
||||||
|
}
|
20
src/statistics.test.js
Normal file
20
src/statistics.test.js
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
import { test, expect } from "vitest";
|
||||||
|
|
||||||
|
import Ajv from "ajv";
|
||||||
|
|
||||||
|
import characterSchema from "../schemas-json/character.json";
|
||||||
|
|
||||||
|
const ajv = new Ajv();
|
||||||
|
const validate = ajv.compile(characterSchema.$defs.statistic);
|
||||||
|
|
||||||
|
test("good statistic", () => {
|
||||||
|
expect(validate(12)).toBeTruthy();
|
||||||
|
expect(validate.errors).toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
test("bad statistic", () => {
|
||||||
|
expect(validate(21)).toBeFalsy();
|
||||||
|
expect(validate.errors[0]).toMatchObject({
|
||||||
|
message: "must be <= 20",
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user