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

Commit ddf4aed

Browse files
test: adds JsonSchema test case for "validateBody"
1 parent 6dee6d6 commit ddf4aed

File tree

1 file changed

+68
-2
lines changed

1 file changed

+68
-2
lines changed

lib/api/test/unit/units/validateBody.test.js

Lines changed: 68 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,74 @@ describe('validateBody', () => {
277277
});
278278
});
279279

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+
});
282348
});
283349
});
284350
});

0 commit comments

Comments
 (0)