-
Notifications
You must be signed in to change notification settings - Fork 42
/
encoding.js
75 lines (66 loc) · 2.38 KB
/
encoding.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
var accepts = require('..')
var assert = require('assert')
describe('accepts.encodings()', function(){
describe('with no arguments', function(){
describe('when Accept-Encoding is populated', function(){
it('should return accepted types', function(){
var req = createRequest('gzip, compress;q=0.2')
var accept = accepts(req)
assert.deepEqual(accept.encodings(), ['gzip', 'compress', 'identity'])
assert.equal(accept.encodings('gzip', 'compress'), 'gzip')
})
})
describe('when Accept-Encoding is not in request', function(){
it('should return identity', function(){
var req = createRequest()
var accept = accepts(req)
assert.deepEqual(accept.encodings(), ['identity'])
assert.equal(accept.encodings('gzip', 'deflate', 'identity'), 'identity')
})
describe('when identity is not included', function(){
it('should return false', function(){
var req = createRequest()
var accept = accepts(req)
assert.strictEqual(accept.encodings('gzip', 'deflate'), false)
})
})
})
describe('when Accept-Encoding is empty', function(){
it('should return identity', function(){
var req = createRequest('')
var accept = accepts(req)
assert.deepEqual(accept.encodings(), ['identity'])
assert.equal(accept.encodings('gzip', 'deflate', 'identity'), 'identity')
})
describe('when identity is not included', function(){
it('should return false', function(){
var req = createRequest('')
var accept = accepts(req)
assert.strictEqual(accept.encodings('gzip', 'deflate'), false)
})
})
})
})
describe('with multiple arguments', function(){
it('should return the best fit', function(){
var req = createRequest('gzip, compress;q=0.2')
var accept = accepts(req)
assert.equal(accept.encodings('compress', 'gzip'), 'gzip')
assert.equal(accept.encodings('gzip', 'compress'), 'gzip')
})
})
describe('with an array', function(){
it('should return the best fit', function(){
var req = createRequest('gzip, compress;q=0.2')
var accept = accepts(req)
assert.equal(accept.encodings(['compress', 'gzip']), 'gzip')
})
})
})
function createRequest(encoding) {
return {
headers: {
'accept-encoding': encoding
}
}
}