generated from Real-Dev-Squad/website-template
-
Notifications
You must be signed in to change notification settings - Fork 263
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow user to edit Extension Requests before approval (#2215)
* added edit ability for ER * fixing function name and export type * fix feature flag value check * error message and status code updated * middleware tests added * pending status check added * added comment regarding middleware for FF removal
- Loading branch information
Showing
5 changed files
with
120 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const skipAuthorizeRolesUnderFF = (authorizeMiddleware) => { | ||
return (req, res, next) => { | ||
const { dev } = req.query; | ||
const isDev = dev === "true"; | ||
if (isDev) { | ||
next(); | ||
} else { | ||
authorizeMiddleware(req, res, next); | ||
} | ||
}; | ||
}; | ||
|
||
module.exports = skipAuthorizeRolesUnderFF; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
}); | ||
}); |