Skip to content

Commit

Permalink
Added some test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Mathias Kretschek committed Jul 15, 2014
1 parent e2f75e6 commit ccfef68
Showing 1 changed file with 41 additions and 9 deletions.
50 changes: 41 additions & 9 deletions test/parameters.js
Expand Up @@ -46,13 +46,14 @@
before(function () {
req = {
query : {
foo : 'foobar'
},
body : {
foo : 'foobar',
bar : 'barbaz'
},
custom : {
body : {
baz : 'bazfoo'
},
arbitrary : {
woo : 'hoo'
}
};

Expand All @@ -72,9 +73,8 @@

it('calls the next middleware if all parameters are set', function () {
var middleware = parameters({
query : ['foo'],
body : ['bar'],
custom : ['baz']
query : ['foo', 'bar'],
body : ['baz']
});

middleware(req, res, next);
Expand All @@ -83,6 +83,27 @@
});


it('works with single params passed as strings', function () {
var middleware = parameters({
query : 'foo',
body : 'baz'
});

middleware(req, res, next);
expect(next).to.have.been.calledOnce;
});


it('works with multiple params passed as an array', function () {
var middleware = parameters({
query : ['foo', 'bar']
});

middleware(req, res, next);
expect(next).to.have.been.calledOnce;
});


it('does not call the next middleware if a param is missing',
function () {
var middleware = parameters({
Expand All @@ -106,6 +127,17 @@
});


it('responds with a status 400 if the property is not set in the request',
function () {
var middleware = parameters({
inexistent : 'param'
});

middleware(req, res, next);
expect(res.send).to.have.been.calledWith(400);
});


it('uses the configured message', function () {
var params = {
query : ['missing']
Expand Down Expand Up @@ -147,8 +179,8 @@

it('checks arbitrary properties in the request', function () {
var params = {
// Usually, there's no 'custom' property in the request object
custom : ['baz']
// Usually, there's no 'arbitrary' property in the request object
arbitrary : ['woo']
};

var middleware = parameters(params);
Expand Down

0 comments on commit ccfef68

Please sign in to comment.