Skip to content
This repository has been archived by the owner on Nov 8, 2024. It is now read-only.

Commit

Permalink
test: adds JsonSchema test case for "validateBody"
Browse files Browse the repository at this point in the history
  • Loading branch information
artem-zakharchenko committed May 17, 2019
1 parent 6dee6d6 commit ddf4aed
Showing 1 changed file with 68 additions and 2 deletions.
70 changes: 68 additions & 2 deletions lib/api/test/unit/units/validateBody.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`
);
});
});
});
});
});
});
Expand Down

1 comment on commit ddf4aed

@honzajavorek
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Please sign in to comment.