forked from expressjs/express
-
Notifications
You must be signed in to change notification settings - Fork 0
/
req.is.js
103 lines (86 loc) · 2.11 KB
/
req.is.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
var express = require('../')
, request = require('supertest');
function req(ct) {
var req = {
headers: {
'content-type': ct,
'transfer-encoding': 'chunked'
},
__proto__: express.request
};
return req;
}
describe('req.is()', function(){
it('should ignore charset', function(){
req('application/json')
.is('json')
.should.equal('json');
})
describe('when content-type is not present', function(){
it('should return false', function(){
req('')
.is('json')
.should.be.false;
})
})
describe('when given an extension', function(){
it('should lookup the mime type', function(){
req('application/json')
.is('json')
.should.equal('json');
req('text/html')
.is('json')
.should.be.false;
})
})
describe('when given a mime type', function(){
it('should match', function(){
req('application/json')
.is('application/json')
.should.equal('application/json');
req('image/jpeg')
.is('application/json')
.should.be.false;
})
})
describe('when given */subtype', function(){
it('should match', function(){
req('application/json')
.is('*/json')
.should.equal('application/json');
req('image/jpeg')
.is('*/json')
.should.be.false;
})
describe('with a charset', function(){
it('should match', function(){
req('text/html; charset=utf-8')
.is('*/html')
.should.equal('text/html');
req('text/plain; charset=utf-8')
.is('*/html')
.should.be.false;
})
})
})
describe('when given type/*', function(){
it('should match', function(){
req('image/png')
.is('image/*')
.should.equal('image/png');
req('text/html')
.is('image/*')
.should.be.false;
})
describe('with a charset', function(){
it('should match', function(){
req('text/html; charset=utf-8')
.is('text/*')
.should.equal('text/html');
req('something/html; charset=utf-8')
.is('text/*')
.should.be.false;
})
})
})
})