Skip to content

Commit

Permalink
[test] added tests for web-outgoing.js
Browse files Browse the repository at this point in the history
  • Loading branch information
yawnt committed Sep 17, 2013
1 parent 2c10f25 commit 16a4d9d
Showing 1 changed file with 90 additions and 0 deletions.
90 changes: 90 additions & 0 deletions test/lib-caronte-passes-web-outgoing-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
var caronte = require('../lib/caronte/passes/web-outgoing'),
expect = require('expect.js');

describe('lib/caronte/passes/web-outgoing.js', function () {
describe('#setConnection', function () {
it('set the right connection with 1.0 - `close`', function() {
var proxyRes = { headers: {} };
caronte.setConnection({
httpVersion: '1.0',
headers: {
connection: null
}
}, {}, proxyRes);

expect(proxyRes.headers.connection).to.eql('close');
});

it('set the right connection with 1.0 - req.connection', function() {
var proxyRes = { headers: {} };
caronte.setConnection({
httpVersion: '1.0',
headers: {
connection: 'hey'
}
}, {}, proxyRes);

expect(proxyRes.headers.connection).to.eql('hey');
});

it('set the right connection - req.connection', function() {
var proxyRes = { headers: {} };
caronte.setConnection({
httpVersion: null,
headers: {
connection: 'hola'
}
}, {}, proxyRes);

expect(proxyRes.headers.connection).to.eql('hola');
});

it('set the right connection - `keep-alive`', function() {
var proxyRes = { headers: {} };
caronte.setConnection({
httpVersion: null,
headers: {
connection: null
}
}, {}, proxyRes);

expect(proxyRes.headers.connection).to.eql('keep-alive');
});

});

describe('#writeStatusCode', function () {
it('should write status code', function() {
var res = {
writeHead: function(n) {
expect(n).to.eql(200);
}
}

caronte.writeStatusCode({}, res, { statusCode: 200 });
});
});

describe('#writeHeaders', function() {
var proxyRes = {
headers: {
hey: 'hello',
how: 'are you?'
}
};

var res = {
setHeader: function(k, v) {
this.headers[k] = v;
},
headers: {}
};

caronte.writeHeaders({}, res, proxyRes);

expect(res.headers.hey).to.eql('hello');
expect(res.headers.how).to.eql('are you?');
});

});

0 comments on commit 16a4d9d

Please sign in to comment.