diff --git a/lib/api/test/unit/units/validateHeaders.test.js b/lib/api/test/unit/units/validateHeaders.test.js index 960f7d3f..804da20a 100644 --- a/lib/api/test/unit/units/validateHeaders.test.js +++ b/lib/api/test/unit/units/validateHeaders.test.js @@ -18,11 +18,11 @@ 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', @@ -30,7 +30,7 @@ describe('validateHeaders', () => { ); }); - it('has proper expected type', () => { + it('has "application/vnd.apiary.http-headers+json" expected type', () => { assert.propertyVal( res, 'expectedType', @@ -52,17 +52,18 @@ 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', @@ -70,7 +71,7 @@ describe('validateHeaders', () => { ); }); - it('has proper expected type', () => { + it('has "application/vnd.apiary.http-headers+json" expected type', () => { assert.propertyVal( res, 'expectedType', @@ -78,25 +79,37 @@ describe('validateHeaders', () => { ); }); - 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}` + ); + }); + }); + }); }); }); }); @@ -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".` - ); + ); + }); }); }); });