Skip to content

Commit 36a9199

Browse files
committed
Add helpers: shouldBeForbidden and shouldBeRejected
From strongloop-archive/loopback-testing#56
1 parent 5b99f2d commit 36a9199

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

lib/helpers.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,33 @@ _it.shouldNotBeFound = function() {
380380
});
381381
}
382382

383+
_it.shouldBeForbidden = function() {
384+
it('should be forbidden', function() {
385+
assert(this.res);
386+
if (this.res.statusCode !== 403) {
387+
console.log(this.res.body);
388+
}
389+
assert.equal(this.res.statusCode, 403);
390+
});
391+
}
392+
393+
_it.shouldBeRejected = function(statusCode) {
394+
it('should be rejected' + (statusCode ? ' with status code ' + statusCode : ''), function() {
395+
assert(this.res);
396+
if (statusCode) {
397+
if (this.res.statusCode !== statusCode) {
398+
console.log(this.res.body);
399+
}
400+
expect(this.res.statusCode).to.equal(statusCode);
401+
} else {
402+
if (this.res.statusCode < 400 || this.res.statusCode > 499) {
403+
console.log(this.res.body);
404+
}
405+
expect(this.res.statusCode).to.be.within(400, 499);
406+
}
407+
});
408+
}
409+
383410
_it.shouldBeAllowedWhenCalledAnonymously =
384411
function(verb, url, data) {
385412
_describe.whenCalledAnonymously(verb, url, data, function() {

test/test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ describe('helpers', function () {
1717
['shouldBeAllowed',
1818
'shouldBeDenied',
1919
'shouldNotBeFound',
20+
'shouldBeForbidden',
21+
'shouldBeRejected',
2022
'shouldBeAllowedWhenCalledAnonymously',
2123
'shouldBeDeniedWhenCalledAnonymously',
2224
'shouldBeAllowedWhenCalledUnauthenticated',

0 commit comments

Comments
 (0)