Skip to content

Commit 16a4d9d

Browse files
committed
[test] added tests for web-outgoing.js
1 parent 2c10f25 commit 16a4d9d

File tree

1 file changed

+90
-0
lines changed

1 file changed

+90
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
var caronte = require('../lib/caronte/passes/web-outgoing'),
2+
expect = require('expect.js');
3+
4+
describe('lib/caronte/passes/web-outgoing.js', function () {
5+
describe('#setConnection', function () {
6+
it('set the right connection with 1.0 - `close`', function() {
7+
var proxyRes = { headers: {} };
8+
caronte.setConnection({
9+
httpVersion: '1.0',
10+
headers: {
11+
connection: null
12+
}
13+
}, {}, proxyRes);
14+
15+
expect(proxyRes.headers.connection).to.eql('close');
16+
});
17+
18+
it('set the right connection with 1.0 - req.connection', function() {
19+
var proxyRes = { headers: {} };
20+
caronte.setConnection({
21+
httpVersion: '1.0',
22+
headers: {
23+
connection: 'hey'
24+
}
25+
}, {}, proxyRes);
26+
27+
expect(proxyRes.headers.connection).to.eql('hey');
28+
});
29+
30+
it('set the right connection - req.connection', function() {
31+
var proxyRes = { headers: {} };
32+
caronte.setConnection({
33+
httpVersion: null,
34+
headers: {
35+
connection: 'hola'
36+
}
37+
}, {}, proxyRes);
38+
39+
expect(proxyRes.headers.connection).to.eql('hola');
40+
});
41+
42+
it('set the right connection - `keep-alive`', function() {
43+
var proxyRes = { headers: {} };
44+
caronte.setConnection({
45+
httpVersion: null,
46+
headers: {
47+
connection: null
48+
}
49+
}, {}, proxyRes);
50+
51+
expect(proxyRes.headers.connection).to.eql('keep-alive');
52+
});
53+
54+
});
55+
56+
describe('#writeStatusCode', function () {
57+
it('should write status code', function() {
58+
var res = {
59+
writeHead: function(n) {
60+
expect(n).to.eql(200);
61+
}
62+
}
63+
64+
caronte.writeStatusCode({}, res, { statusCode: 200 });
65+
});
66+
});
67+
68+
describe('#writeHeaders', function() {
69+
var proxyRes = {
70+
headers: {
71+
hey: 'hello',
72+
how: 'are you?'
73+
}
74+
};
75+
76+
var res = {
77+
setHeader: function(k, v) {
78+
this.headers[k] = v;
79+
},
80+
headers: {}
81+
};
82+
83+
caronte.writeHeaders({}, res, proxyRes);
84+
85+
expect(res.headers.hey).to.eql('hello');
86+
expect(res.headers.how).to.eql('are you?');
87+
});
88+
89+
});
90+

0 commit comments

Comments
 (0)