Skip to content

Commit 639043d

Browse files
author
Mateusz Puczynski
committed
add more test cases
1 parent b52218c commit 639043d

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

test/validate_test.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,50 @@ describe("Validation", () => {
9898
});
9999
});
100100

101+
describe("validating using custom meta schema", () => {
102+
const schema = {
103+
$ref: "#/definitions/Dataset",
104+
$schema: "http://json-schema.org/draft-04/schema#",
105+
definitions: {
106+
Dataset: {
107+
properties: {
108+
datasetId: {
109+
pattern: "\\d+",
110+
type: "string",
111+
},
112+
},
113+
required: ["datasetId"],
114+
type: "object",
115+
},
116+
},
117+
};
118+
const metaSchema = require("ajv/lib/refs/json-schema-draft-04.json");
119+
120+
it.only("should return a validation error about meta schema", () => {
121+
const errors = validateFormData(
122+
{ datasetId: "some kind of text" },
123+
schema
124+
);
125+
expect(errors.validationErrors.message).to.equal(
126+
'no schema with key or ref "http://json-schema.org/draft-04/schema#"'
127+
);
128+
});
129+
it.only("should return a validation error about formData", () => {
130+
const errors = validateFormData(
131+
{ datasetId: "some kind of text" },
132+
schema,
133+
null,
134+
null,
135+
metaSchema
136+
);
137+
expect(errors.validationErrors).to.equal(null);
138+
expect(errors.errors).to.have.lengthOf(1);
139+
expect(errors.errors[0].stack).to.equal(
140+
'.datasetId should match pattern "\\d+"'
141+
);
142+
});
143+
});
144+
101145
describe("Custom validate function", () => {
102146
let errors, errorSchema;
103147

0 commit comments

Comments
 (0)