@@ -98,6 +98,52 @@ describe("Validation", () => {
98
98
} ) ;
99
99
} ) ;
100
100
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
+
101
147
describe ( "Custom validate function" , ( ) => {
102
148
let errors , errorSchema ;
103
149
0 commit comments