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

Commit

Permalink
test: asserts each missing header in "validateHeaders" test
Browse files Browse the repository at this point in the history
  • Loading branch information
artem-zakharchenko committed May 17, 2019
1 parent e8a6406 commit 0cfab27
Showing 1 changed file with 51 additions and 30 deletions.
81 changes: 51 additions & 30 deletions lib/api/test/unit/units/validateHeaders.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@ describe('validateHeaders', () => {
}
);

it('has proper validator', () => {
it('has "HeadersJsonExample" validator', () => {
assert.propertyVal(res, 'validator', 'HeadersJsonExample');
});

it('has proper real type', () => {
it('has "application/vnd.apiary.http-headers+json" real type', () => {
assert.propertyVal(
res,
'realType',
'application/vnd.apiary.http-headers+json'
);
});

it('has proper expected type', () => {
it('has "application/vnd.apiary.http-headers+json" expected type', () => {
assert.propertyVal(
res,
'expectedType',
Expand All @@ -52,51 +52,64 @@ describe('validateHeaders', () => {
},
{
headers: {
'accept-language': 'en-US,us',
'content-type': 'application/json',
connection: 'keep-alive'
}
}
);

it('has proper validator', () => {
it('has "HeadersJsonExample" validator', () => {
assert.propertyVal(res, 'validator', 'HeadersJsonExample');
});

it('has proper real type', () => {
it('has "application/vnd.apiary.http-headers+json" real type', () => {
assert.propertyVal(
res,
'realType',
'application/vnd.apiary.http-headers+json'
);
});

it('has proper expected type', () => {
it('has "application/vnd.apiary.http-headers+json" expected type', () => {
assert.propertyVal(
res,
'expectedType',
'application/vnd.apiary.http-headers+json'
);
});

describe('has error', () => {
it('for each missing header', () => {
assert.lengthOf(res.results, 1);
});
describe('produces errors', () => {
const missingHeaders = ['accept-language', 'content-type'];

it('contains pointer to missing header(s)', () => {
assert.propertyVal(res.results[0], 'pointer', '/content-type');
it('for two missing headers', () => {
assert.lengthOf(res.results, missingHeaders.length);
});

it('contains error message', () => {
assert.propertyVal(
res.results[0],
'message',
`At '/content-type' Missing required property: content-type`
);
});

it('contains proper severity', () => {
assert.propertyVal(res.results[0], 'severity', 'error');
describe('for each missing header', () => {
missingHeaders.forEach((headerName, index) => {
describe(headerName, () => {
it('has "error" severity', () => {
assert.propertyVal(res.results[index], 'severity', 'error');
});

it('has pointer to header name', () => {
assert.propertyVal(
res.results[index],
'pointer',
`/${headerName}`
);
});

it('has explanatory message', () => {
assert.propertyVal(
res.results[index],
'message',
`At '/${headerName}' Missing required property: ${headerName}`
);
});
});
});
});
});
});
Expand All @@ -123,17 +136,25 @@ describe('validateHeaders', () => {
assert.propertyVal(res, 'expectedType', null);
});

it('has invalid format error', () => {
assert.lengthOf(res.results, 1);
assert.propertyVal(res.results[0], 'severity', 'error');
assert.propertyVal(
res.results[0],
'message',
`No validator found for real data media type
describe('produces an error', () => {
it('has one error', () => {
assert.lengthOf(res.results, 1);
});

it('has "error" severity', () => {
assert.propertyVal(res.results[0], 'severity', 'error');
});

it('has exlpanatory message', () => {
assert.propertyVal(
res.results[0],
'message',
`No validator found for real data media type
"null"
and expected data media type
"null".`
);
);
});
});
});
});

0 comments on commit 0cfab27

Please sign in to comment.