From 36a919944105005581aeab6fb94a895d66723222 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Mahieu?= Date: Thu, 14 Jan 2016 12:23:25 +0100 Subject: [PATCH] Add helpers: `shouldBeForbidden` and `shouldBeRejected` From https://github.com/strongloop/loopback-testing/pull/56 --- lib/helpers.js | 27 +++++++++++++++++++++++++++ test/test.js | 2 ++ 2 files changed, 29 insertions(+) diff --git a/lib/helpers.js b/lib/helpers.js index fe7e677..353fc5d 100644 --- a/lib/helpers.js +++ b/lib/helpers.js @@ -380,6 +380,33 @@ _it.shouldNotBeFound = function() { }); } +_it.shouldBeForbidden = function() { + it('should be forbidden', function() { + assert(this.res); + if (this.res.statusCode !== 403) { + console.log(this.res.body); + } + assert.equal(this.res.statusCode, 403); + }); +} + +_it.shouldBeRejected = function(statusCode) { + it('should be rejected' + (statusCode ? ' with status code ' + statusCode : ''), function() { + assert(this.res); + if (statusCode) { + if (this.res.statusCode !== statusCode) { + console.log(this.res.body); + } + expect(this.res.statusCode).to.equal(statusCode); + } else { + if (this.res.statusCode < 400 || this.res.statusCode > 499) { + console.log(this.res.body); + } + expect(this.res.statusCode).to.be.within(400, 499); + } + }); +} + _it.shouldBeAllowedWhenCalledAnonymously = function(verb, url, data) { _describe.whenCalledAnonymously(verb, url, data, function() { diff --git a/test/test.js b/test/test.js index 182407f..7401658 100644 --- a/test/test.js +++ b/test/test.js @@ -17,6 +17,8 @@ describe('helpers', function () { ['shouldBeAllowed', 'shouldBeDenied', 'shouldNotBeFound', + 'shouldBeForbidden', + 'shouldBeRejected', 'shouldBeAllowedWhenCalledAnonymously', 'shouldBeDeniedWhenCalledAnonymously', 'shouldBeAllowedWhenCalledUnauthenticated',