Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3ef7ff4
commit 4a58fa7
Showing
2 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
var Test = require('../lib/test'); | ||
|
||
describe('test grant that calls end', function() { | ||
|
||
var grant = {}; | ||
grant.request = function(req) {} | ||
grant.response = function(txn, res, next) { | ||
res.end('Hello'); | ||
} | ||
|
||
describe('with an end callback', function() { | ||
var res; | ||
|
||
before(function(done) { | ||
var test = new Test(grant); | ||
test.end(function(r) { | ||
res = r; | ||
done(); | ||
}).decide(); | ||
}); | ||
|
||
it('should call end callback', function() { | ||
expect(res.statusCode).to.be.equal(200); | ||
expect(res.body).to.be.equal('Hello'); | ||
}); | ||
}); | ||
|
||
describe('without an end callback', function() { | ||
it('should throw an error', function() { | ||
expect(function() { | ||
var test = new Test(grant); | ||
test.decide(); | ||
}).to.throw(Error, 'res#end should not be called'); | ||
}); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
var Test = require('../lib/test'); | ||
|
||
describe('test grant that calls next', function() { | ||
|
||
var grant = {}; | ||
grant.request = function(req) {} | ||
grant.response = function(txn, res, next) { | ||
next() | ||
} | ||
|
||
describe('with a next callback', function() { | ||
var err; | ||
|
||
before(function(done) { | ||
var test = new Test(grant); | ||
test.next(function(e) { | ||
err = e; | ||
done(); | ||
}).decide(); | ||
}); | ||
|
||
it('should call next callback', function() { | ||
expect(err).to.be.undefined; | ||
}); | ||
}); | ||
|
||
describe('without a next callback', function() { | ||
it('should throw an error', function() { | ||
expect(function() { | ||
var test = new Test(grant); | ||
test.decide(); | ||
}).to.throw(Error, 'next should not be called'); | ||
}); | ||
}); | ||
|
||
}); | ||
|
||
describe('test grant that calls next with error', function() { | ||
|
||
var grant = {}; | ||
grant.request = function(req) {} | ||
grant.response = function(txn, res, next) { | ||
next(new Error('oops')) | ||
} | ||
|
||
describe('with a next callback', function() { | ||
var err; | ||
|
||
before(function(done) { | ||
var test = new Test(grant); | ||
test.next(function(e) { | ||
err = e; | ||
done(); | ||
}).decide(); | ||
}); | ||
|
||
it('should call next callback', function() { | ||
expect(err).to.be.an.instanceOf(Error); | ||
expect(err.message).to.equal('oops'); | ||
}); | ||
}); | ||
|
||
}); |