From f42f615534d10073daeb27d7822c2160705bd74a Mon Sep 17 00:00:00 2001 From: artem-zakharchenko Date: Fri, 17 May 2019 16:17:17 +0200 Subject: [PATCH] test: adds JsonSchema test case for "validateBody" --- lib/api/test/unit/units/validateBody.test.js | 70 +++++++++++++++++++- 1 file changed, 68 insertions(+), 2 deletions(-) diff --git a/lib/api/test/unit/units/validateBody.test.js b/lib/api/test/unit/units/validateBody.test.js index 6f6346b9..2449439c 100644 --- a/lib/api/test/unit/units/validateBody.test.js +++ b/lib/api/test/unit/units/validateBody.test.js @@ -277,8 +277,74 @@ describe('validateBody', () => { }); }); - describe.skip('application/schema+json', () => { - // ... + describe('application/schema+json', () => { + describe('with matching bodies', () => { + const res = validateBody( + { body: '{ "foo": "bar" }' }, + { + bodySchema: { + required: ['foo'] + } + } + ); + + it('has "JsonSchema" validator', () => { + assert.propertyVal(res, 'validator', 'JsonSchema'); + }); + + it('has "application/json" real type', () => { + assert.propertyVal(res, 'realType', 'application/json'); + }); + + it('has "application/schema+json" expected type', () => { + assert.propertyVal(res, 'expectedType', 'application/schema+json'); + }); + + it('has no errors', () => { + assert.lengthOf(res.results, 0); + }); + }); + + describe('with non-matching bodies', () => { + const res = validateBody( + { body: '{ "oneTwoThree": "bar" }' }, + { + bodySchema: { + required: ['doe'] + } + } + ); + + it('has "JsonSchema" validator', () => { + assert.propertyVal(res, 'validator', 'JsonSchema'); + }); + + it('has "application/json" real type', () => { + assert.propertyVal(res, 'realType', 'application/json'); + }); + + it('has "application/schema+json" expected type', () => { + assert.propertyVal(res, 'expectedType', 'application/schema+json'); + }); + + describe('produces an error', () => { + it('exactly one error', () => { + assert.lengthOf(res.results, 1); + }); + + it('has "error" severity', () => { + assert.propertyVal(res.results[0], 'severity', 'error'); + }); + + it('has explanatory message', () => { + assert.propertyVal( + res.results[0], + 'message', + `At '/doe' Missing required property: doe` + ); + }); + }); + }); }); }); });