Skip to content

Commit

Permalink
add more test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Mateusz Puczynski committed Jan 28, 2019
1 parent b52218c commit 639043d
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions test/validate_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,50 @@ describe("Validation", () => {
});
});

describe("validating using custom meta schema", () => {
const schema = {
$ref: "#/definitions/Dataset",
$schema: "http://json-schema.org/draft-04/schema#",
definitions: {
Dataset: {
properties: {
datasetId: {
pattern: "\\d+",
type: "string",
},
},
required: ["datasetId"],
type: "object",
},
},
};
const metaSchema = require("ajv/lib/refs/json-schema-draft-04.json");

it.only("should return a validation error about meta schema", () => {
const errors = validateFormData(
{ datasetId: "some kind of text" },
schema
);
expect(errors.validationErrors.message).to.equal(
'no schema with key or ref "http://json-schema.org/draft-04/schema#"'
);
});
it.only("should return a validation error about formData", () => {
const errors = validateFormData(
{ datasetId: "some kind of text" },
schema,
null,
null,
metaSchema
);
expect(errors.validationErrors).to.equal(null);
expect(errors.errors).to.have.lengthOf(1);
expect(errors.errors[0].stack).to.equal(
'.datasetId should match pattern "\\d+"'
);
});
});

describe("Custom validate function", () => {
let errors, errorSchema;

Expand Down

0 comments on commit 639043d

Please sign in to comment.