Skip to content

Commit b438f4d

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

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

test/validate_test.js

+46
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,52 @@ 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("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+
expect(errors.errors).to.eql([]);
129+
expect(errors.errorSchema).to.eql({});
130+
});
131+
it("should return a validation error about formData", () => {
132+
const errors = validateFormData(
133+
{ datasetId: "some kind of text" },
134+
schema,
135+
null,
136+
null,
137+
metaSchema
138+
);
139+
expect(errors.validationErrors).to.equal(null);
140+
expect(errors.errors).to.have.lengthOf(1);
141+
expect(errors.errors[0].stack).to.equal(
142+
'.datasetId should match pattern "\\d+"'
143+
);
144+
});
145+
});
146+
101147
describe("Custom validate function", () => {
102148
let errors, errorSchema;
103149

0 commit comments

Comments
 (0)