|
| 1 | +const chai = require("chai"); |
| 2 | +const sinon = require("sinon"); |
| 3 | +const { assert } = chai; |
| 4 | +const skipAuthorizeRolesUnderFF = require("../../../middlewares/skipAuthorizeRolesWrapper"); |
| 5 | + |
| 6 | +describe("skipAuthorizeRolesUnderFF Middleware", function () { |
| 7 | + let req, res, next, authorizeMiddleware; |
| 8 | + |
| 9 | + beforeEach(function () { |
| 10 | + req = { query: {} }; |
| 11 | + res = {}; |
| 12 | + next = sinon.spy(); |
| 13 | + authorizeMiddleware = sinon.spy(); |
| 14 | + }); |
| 15 | + |
| 16 | + it("should call next() when dev is true", function () { |
| 17 | + req.query.dev = "true"; |
| 18 | + |
| 19 | + const middleware = skipAuthorizeRolesUnderFF(authorizeMiddleware); |
| 20 | + middleware(req, res, next); |
| 21 | + |
| 22 | + assert.isTrue(next.calledOnce, "next() should be called once"); |
| 23 | + assert.isFalse(authorizeMiddleware.called, "authorizeMiddleware should not be called"); |
| 24 | + }); |
| 25 | + |
| 26 | + it("should call authorizeMiddleware when dev is false", function () { |
| 27 | + req.query.dev = "false"; |
| 28 | + |
| 29 | + const middleware = skipAuthorizeRolesUnderFF(authorizeMiddleware); |
| 30 | + middleware(req, res, next); |
| 31 | + |
| 32 | + assert.isTrue(authorizeMiddleware.calledOnce, "authorizeMiddleware should be called once"); |
| 33 | + assert.isFalse(next.called, "next() should not be called"); |
| 34 | + }); |
| 35 | + |
| 36 | + it("should call authorizeMiddleware when dev is not provided", function () { |
| 37 | + const middleware = skipAuthorizeRolesUnderFF(authorizeMiddleware); |
| 38 | + middleware(req, res, next); |
| 39 | + |
| 40 | + assert.isTrue(authorizeMiddleware.calledOnce, "authorizeMiddleware should be called once"); |
| 41 | + assert.isFalse(next.called, "next() should not be called"); |
| 42 | + }); |
| 43 | +}); |
0 commit comments