Skip to content

Commit

Permalink
middleware tests added
Browse files Browse the repository at this point in the history
  • Loading branch information
ahsrah7 committed Oct 20, 2024
1 parent 881158f commit 46bf763
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions test/unit/middlewares/skipAuthorizeRolesWrapper.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
const chai = require("chai");
const sinon = require("sinon");
const { assert } = chai;
const skipAuthorizeRolesUnderFF = require("../../../middlewares/skipAuthorizeRolesWrapper");

describe("skipAuthorizeRolesUnderFF Middleware", function () {
let req, res, next, authorizeMiddleware;

beforeEach(function () {
req = { query: {} };
res = {};
next = sinon.spy();
authorizeMiddleware = sinon.spy();
});

it("should call next() when dev is true", function () {
req.query.dev = "true";

const middleware = skipAuthorizeRolesUnderFF(authorizeMiddleware);
middleware(req, res, next);

assert.isTrue(next.calledOnce, "next() should be called once");
assert.isFalse(authorizeMiddleware.called, "authorizeMiddleware should not be called");
});

it("should call authorizeMiddleware when dev is false", function () {
req.query.dev = "false";

const middleware = skipAuthorizeRolesUnderFF(authorizeMiddleware);
middleware(req, res, next);

assert.isTrue(authorizeMiddleware.calledOnce, "authorizeMiddleware should be called once");
assert.isFalse(next.called, "next() should not be called");
});

it("should call authorizeMiddleware when dev is not provided", function () {
const middleware = skipAuthorizeRolesUnderFF(authorizeMiddleware);
middleware(req, res, next);

assert.isTrue(authorizeMiddleware.calledOnce, "authorizeMiddleware should be called once");
assert.isFalse(next.called, "next() should not be called");
});
});

0 comments on commit 46bf763

Please sign in to comment.