@@ -277,8 +277,74 @@ describe('validateBody', () => {
277
277
} ) ;
278
278
} ) ;
279
279
280
- describe . skip ( 'application/schema+json' , ( ) => {
281
- // ...
280
+ describe ( 'application/schema+json' , ( ) => {
281
+ describe ( 'with matching bodies' , ( ) => {
282
+ const res = validateBody (
283
+ { body : '{ "foo": "bar" }' } ,
284
+ {
285
+ bodySchema : {
286
+ required : [ 'foo' ]
287
+ }
288
+ }
289
+ ) ;
290
+
291
+ it ( 'has "JsonSchema" validator' , ( ) => {
292
+ assert . propertyVal ( res , 'validator' , 'JsonSchema' ) ;
293
+ } ) ;
294
+
295
+ it ( 'has "application/json" real type' , ( ) => {
296
+ assert . propertyVal ( res , 'realType' , 'application/json' ) ;
297
+ } ) ;
298
+
299
+ it ( 'has "application/schema+json" expected type' , ( ) => {
300
+ assert . propertyVal ( res , 'expectedType' , 'application/schema+json' ) ;
301
+ } ) ;
302
+
303
+ it ( 'has no errors' , ( ) => {
304
+ assert . lengthOf ( res . results , 0 ) ;
305
+ } ) ;
306
+ } ) ;
307
+
308
+ describe ( 'with non-matching bodies' , ( ) => {
309
+ const res = validateBody (
310
+ { body : '{ "oneTwoThree": "bar" }' } ,
311
+ {
312
+ bodySchema : {
313
+ required : [ 'doe' ]
314
+ }
315
+ }
316
+ ) ;
317
+
318
+ it ( 'has "JsonSchema" validator' , ( ) => {
319
+ assert . propertyVal ( res , 'validator' , 'JsonSchema' ) ;
320
+ } ) ;
321
+
322
+ it ( 'has "application/json" real type' , ( ) => {
323
+ assert . propertyVal ( res , 'realType' , 'application/json' ) ;
324
+ } ) ;
325
+
326
+ it ( 'has "application/schema+json" expected type' , ( ) => {
327
+ assert . propertyVal ( res , 'expectedType' , 'application/schema+json' ) ;
328
+ } ) ;
329
+
330
+ describe ( 'produces an error' , ( ) => {
331
+ it ( 'exactly one error' , ( ) => {
332
+ assert . lengthOf ( res . results , 1 ) ;
333
+ } ) ;
334
+
335
+ it ( 'has "error" severity' , ( ) => {
336
+ assert . propertyVal ( res . results [ 0 ] , 'severity' , 'error' ) ;
337
+ } ) ;
338
+
339
+ it ( 'has explanatory message' , ( ) => {
340
+ assert . propertyVal (
341
+ res . results [ 0 ] ,
342
+ 'message' ,
343
+ `At '/doe' Missing required property: doe`
344
+ ) ;
345
+ } ) ;
346
+ } ) ;
347
+ } ) ;
282
348
} ) ;
283
349
} ) ;
284
350
} ) ;
0 commit comments