mirror of
https://github.com/jimeh/heartb.it.git
synced 2026-02-19 12:56:47 +00:00
switch to using and running *.coffee files instead of *.js as this is an app, not a package
This commit is contained in:
@@ -1,50 +0,0 @@
|
||||
(function() {
|
||||
var host_redirect;
|
||||
|
||||
require('should');
|
||||
|
||||
host_redirect = require('../middleware/host_redirect');
|
||||
|
||||
describe('host_redirect', function() {
|
||||
var redirect_map, redirector;
|
||||
redirect_map = {
|
||||
'www.foo.com': 'http://foo.com/',
|
||||
'img.foo.com': 'http://images.foo.com/'
|
||||
};
|
||||
redirector = host_redirect(redirect_map);
|
||||
describe('when request does not match any entry in map', function() {
|
||||
return it('next() is called to pass on the request', function(done) {
|
||||
var next, req, res;
|
||||
req = {
|
||||
header: function() {
|
||||
return 'www.bar.com';
|
||||
}
|
||||
};
|
||||
res = {};
|
||||
next = function() {
|
||||
return done();
|
||||
};
|
||||
return redirector(req, res, next);
|
||||
});
|
||||
});
|
||||
return describe('when request matches an entry in map', function() {
|
||||
return it('req.redirect() is called with the new URL', function(done) {
|
||||
var next, req, res;
|
||||
req = {
|
||||
header: function() {
|
||||
return 'img.foo.com';
|
||||
}
|
||||
};
|
||||
res = {
|
||||
redirect: function(url) {
|
||||
url.should.equal(redirect_map[req.header()]);
|
||||
return done();
|
||||
}
|
||||
};
|
||||
next = function() {};
|
||||
return redirector(req, res, next);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
}).call(this);
|
||||
28
test/middleware/host_redirect.test.coffee
Normal file
28
test/middleware/host_redirect.test.coffee
Normal file
@@ -0,0 +1,28 @@
|
||||
require 'should'
|
||||
|
||||
host_redirect = require '../../middleware/host_redirect'
|
||||
|
||||
describe 'host_redirect', ->
|
||||
|
||||
redirect_map =
|
||||
'www.foo.com': 'http://foo.com/',
|
||||
'img.foo.com': 'http://images.foo.com/'
|
||||
|
||||
redirector = host_redirect(redirect_map)
|
||||
|
||||
describe 'when request does not match any entry in map', ->
|
||||
it 'next() is called to pass on the request', (done) ->
|
||||
req = header: -> 'www.bar.com'
|
||||
res = {}
|
||||
next = -> done()
|
||||
redirector(req, res, next)
|
||||
|
||||
describe 'when request matches an entry in map', ->
|
||||
it 'req.redirect() is called with the new URL', (done) ->
|
||||
req = header: -> 'img.foo.com'
|
||||
res =
|
||||
redirect: (url) ->
|
||||
url.should.equal(redirect_map[req.header()])
|
||||
done()
|
||||
next = ->
|
||||
redirector(req, res, next)
|
||||
Reference in New Issue
Block a user