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
|
|
|
|
2015-10-25 07:54:57 +00:00
|
|
|
describe('ctx.acceptsCharsets()', () => {
|
|
|
|
describe('with no arguments', () => {
|
|
|
|
describe('when Accept-Charset is populated', () => {
|
|
|
|
it('should return accepted types', () => {
|
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']);
|
2015-10-12 20:36:41 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2013-11-13 17:01:15 +00:00
|
|
|
|
2015-10-25 07:54:57 +00:00
|
|
|
describe('with multiple arguments', () => {
|
|
|
|
describe('when Accept-Charset is populated', () => {
|
|
|
|
describe('if any types match', () => {
|
|
|
|
it('should return the best fit', () => {
|
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');
|
2015-10-12 20:36:41 +00:00
|
|
|
});
|
|
|
|
});
|
2013-11-26 22:49:07 +00:00
|
|
|
|
2015-10-25 07:54:57 +00:00
|
|
|
describe('if no types match', () => {
|
|
|
|
it('should return false', () => {
|
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;
|
2015-10-12 20:36:41 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2013-11-26 22:49:07 +00:00
|
|
|
|
2015-10-25 07:54:57 +00:00
|
|
|
describe('when Accept-Charset is not populated', () => {
|
|
|
|
it('should return the first type', () => {
|
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');
|
2015-10-12 20:36:41 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2013-11-13 17:01:15 +00:00
|
|
|
|
2015-10-25 07:54:57 +00:00
|
|
|
describe('with an array', () => {
|
|
|
|
it('should return the best fit', () => {
|
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');
|
2015-10-12 20:36:41 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|