Skip to content

Commit

Permalink
Refactored acceptence/auth.
Browse files Browse the repository at this point in the history
  • Loading branch information
slaskis authored and tj committed Feb 18, 2012
1 parent 277e35f commit 03e5919
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions test/acceptance/auth.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,37 @@
var app = require('../../examples/auth/app')
, request = require('../support/http');

function redirects(to,fn){
return function(res){
res.statusCode.should.equal(302)
res.headers.should.have.property('location').match(to);
fn()
}
}

describe('auth', function(){
var cookie;
describe('GET /',function(){
it('should redirect to /login', function(done){
request(app)
.get('/')
.end(function(res){
res.statusCode.should.equal(302);
res.headers.should.have.property('location').match(/\/login$/);
done();
})
.end(redirects(/\/login$/,done))
})
})
describe('GET /restricted (w/o cookie)',function(){
it('should redirect to /login', function(done){
request(app)
.get('/restricted')
.end(function(res){
res.statusCode.should.equal(302);
res.headers.should.have.property('location').match(/\/login$/);
done();
})
.end(redirects(/\/login$/,done))
})
})
describe('POST /login', function(){
it('should fail without proper credentials', function(done){
request(app)
.post('/login')
.set('content-type','application/x-www-form-urlencoded')
.write('&username=not-tj&password=foobar')
.end(function(res){
res.statusCode.should.equal(302);
res.headers.should.have.property('location').match(/\/login$/);
done();
})
.end(redirects(/\/login$/,done))
})
it('should authenticate', function(done){
request(app)
Expand Down

0 comments on commit 03e5919

Please sign in to comment.