2013-11-13 17:01:15 +00:00
|
|
|
|
2015-10-11 22:59:51 +00:00
|
|
|
'use strict';
|
|
|
|
|
2015-10-12 04:59:30 +00:00
|
|
|
const context = require('../helpers/context');
|
2013-11-13 17:01:15 +00:00
|
|
|
|
|
|
|
describe('ctx.acceptsCharsets()', function(){
|
|
|
|
describe('with no arguments', function(){
|
|
|
|
describe('when Accept-Charset is populated', function(){
|
|
|
|
it('should return accepted types', function(){
|
2015-10-05 18:23:47 +00:00
|
|
|
const ctx = context();
|
2013-11-13 17:01:15 +00:00
|
|
|
ctx.req.headers['accept-charset'] = 'utf-8, iso-8859-1;q=0.2, utf-7;q=0.5';
|
|
|
|
ctx.acceptsCharsets().should.eql(['utf-8', 'utf-7', 'iso-8859-1']);
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('with multiple arguments', function(){
|
2013-11-26 22:49:07 +00:00
|
|
|
describe('when Accept-Charset is populated', function(){
|
|
|
|
describe('if any types match', function(){
|
|
|
|
it('should return the best fit', function(){
|
2015-10-05 18:23:47 +00:00
|
|
|
const ctx = context();
|
2013-11-26 22:49:07 +00:00
|
|
|
ctx.req.headers['accept-charset'] = 'utf-8, iso-8859-1;q=0.2, utf-7;q=0.5';
|
|
|
|
ctx.acceptsCharsets('utf-7', 'utf-8').should.equal('utf-8');
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('if no types match', function(){
|
|
|
|
it('should return false', function(){
|
2015-10-05 18:23:47 +00:00
|
|
|
const ctx = context();
|
2013-11-26 22:49:07 +00:00
|
|
|
ctx.req.headers['accept-charset'] = 'utf-8, iso-8859-1;q=0.2, utf-7;q=0.5';
|
|
|
|
ctx.acceptsCharsets('utf-16').should.be.false;
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('when Accept-Charset is not populated', function(){
|
|
|
|
it('should return the first type', function(){
|
2015-10-05 18:23:47 +00:00
|
|
|
const ctx = context();
|
2013-11-26 22:49:07 +00:00
|
|
|
ctx.acceptsCharsets('utf-7', 'utf-8').should.equal('utf-7');
|
|
|
|
})
|
2013-11-13 17:01:15 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('with an array', function(){
|
|
|
|
it('should return the best fit', function(){
|
2015-10-05 18:23:47 +00:00
|
|
|
const ctx = context();
|
2013-11-13 17:01:15 +00:00
|
|
|
ctx.req.headers['accept-charset'] = 'utf-8, iso-8859-1;q=0.2, utf-7;q=0.5';
|
|
|
|
ctx.acceptsCharsets(['utf-7', 'utf-8']).should.equal('utf-8');
|
|
|
|
})
|
|
|
|
})
|
2014-06-04 04:35:11 +00:00
|
|
|
})
|