koa-lite/test/request/acceptsEncodings.js

44 lines
1.4 KiB
JavaScript
Raw Normal View History

'use strict';
2017-05-11 03:30:32 +00:00
const assert = require('assert');
const context = require('../helpers/context');
describe('ctx.acceptsEncodings()', () => {
describe('with no arguments', () => {
describe('when Accept-Encoding is populated', () => {
it('should return accepted types', () => {
const ctx = context();
ctx.req.headers['accept-encoding'] = 'gzip, compress;q=0.2';
2017-05-11 03:30:32 +00:00
assert.deepEqual(ctx.acceptsEncodings(), ['gzip', 'compress', 'identity']);
assert.equal(ctx.acceptsEncodings('gzip', 'compress'), 'gzip');
2015-10-12 20:36:41 +00:00
});
});
describe('when Accept-Encoding is not populated', () => {
it('should return identity', () => {
const ctx = context();
2017-05-11 03:30:32 +00:00
assert.deepEqual(ctx.acceptsEncodings(), ['identity']);
assert.equal(ctx.acceptsEncodings('gzip', 'deflate', 'identity'), 'identity');
2015-10-12 20:36:41 +00:00
});
});
});
describe('with multiple arguments', () => {
it('should return the best fit', () => {
const ctx = context();
ctx.req.headers['accept-encoding'] = 'gzip, compress;q=0.2';
2017-05-11 03:30:32 +00:00
assert.equal(ctx.acceptsEncodings('compress', 'gzip'), 'gzip');
assert.equal(ctx.acceptsEncodings('gzip', 'compress'), 'gzip');
2015-10-12 20:36:41 +00:00
});
});
describe('with an array', () => {
it('should return the best fit', () => {
const ctx = context();
ctx.req.headers['accept-encoding'] = 'gzip, compress;q=0.2';
2017-05-11 03:30:32 +00:00
assert.equal(ctx.acceptsEncodings(['compress', 'gzip']), 'gzip');
2015-10-12 20:36:41 +00:00
});
});
});