From 5975ce464575bd0fddfdd3d41796958cd6bfc20b Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Thu, 29 May 2014 13:20:43 -0400 Subject: [PATCH] tests: add header missing tests --- test/charset.js | 13 ++++++++++--- test/encoding.js | 19 +++++++++++++++++-- test/language.js | 13 ++++++++++--- test/type.js | 13 ++++++++++--- 4 files changed, 47 insertions(+), 11 deletions(-) diff --git a/test/charset.js b/test/charset.js index 57126d3..70588dc 100644 --- a/test/charset.js +++ b/test/charset.js @@ -1,7 +1,7 @@ function accepts(charset) { return require('../')({ headers: { - 'accept-charset': charset || '' + 'accept-charset': charset } }) } @@ -15,9 +15,16 @@ describe('accepts.charsets()', function(){ }) }) - describe('when Accept-Charset is not populated', function(){ - it('should return an empty array', function(){ + describe('when Accept-Charset is not in request', function(){ + it('should return *', function(){ var accept = accepts(); + accept.charsets().should.eql(['*']); + }) + }) + + describe('when Accept-Charset is empty', function(){ + it('should return an empty array', function(){ + var accept = accepts(''); accept.charsets().should.eql([]); }) }) diff --git a/test/encoding.js b/test/encoding.js index 79543ef..e3a4c18 100644 --- a/test/encoding.js +++ b/test/encoding.js @@ -2,7 +2,7 @@ function accepts(encoding) { return require('../')({ headers: { - 'accept-encoding': encoding || '' + 'accept-encoding': encoding } }) } @@ -17,7 +17,7 @@ describe('accepts.encodings()', function(){ }) }) - describe('when Accept-Encoding is not populated', function(){ + describe('when Accept-Encoding is not in request', function(){ it('should return identity', function(){ var accept = accepts(); accept.encodings().should.eql(['identity']); @@ -31,6 +31,21 @@ describe('accepts.encodings()', function(){ }) }) }) + + describe('when Accept-Encoding is empty', function(){ + it('should return identity', function(){ + var accept = accepts(''); + accept.encodings().should.eql(['identity']); + accept.encodings('gzip', 'deflate', 'identity').should.equal('identity'); + }) + + describe('when identity is not included', function(){ + it('should return false', function(){ + var accept = accepts(''); + accept.encodings('gzip', 'deflate').should.equal(false); + }) + }) + }) }) describe('with multiple arguments', function(){ diff --git a/test/language.js b/test/language.js index c878232..3d3d327 100644 --- a/test/language.js +++ b/test/language.js @@ -2,7 +2,7 @@ function accepts(language) { return require('../')({ headers: { - 'accept-language': language || '' + 'accept-language': language } }) } @@ -16,9 +16,16 @@ describe('accepts.languages()', function(){ }) }) - describe('when Accept-Language is not populated', function(){ - it('should return an empty array', function(){ + describe('when Accept-Language is not in request', function(){ + it('should return *', function(){ var accept = accepts(); + accept.languages().should.eql(['*']); + }) + }) + + describe('when Accept-Language is empty', function(){ + it('should return an empty array', function(){ + var accept = accepts(''); accept.languages().should.eql([]); }) }) diff --git a/test/type.js b/test/type.js index 3cf4b15..1c336e9 100644 --- a/test/type.js +++ b/test/type.js @@ -2,7 +2,7 @@ function accepts(type) { return require('../')({ headers: { - 'accept': type || '' + 'accept': type } }) } @@ -16,9 +16,16 @@ describe('accepts.types()', function(){ }) }) - describe('when Accept is not populated', function(){ - it('should return []', function(){ + describe('when Accept not in request', function(){ + it('should return */*', function(){ var accept = accepts(); + accept.types().should.eql(['*/*']); + }) + }) + + describe('when Accept is empty', function(){ + it('should return []', function(){ + var accept = accepts(''); accept.types().should.eql([]); }) })