generated from Real-Dev-Squad/website-template
-
Notifications
You must be signed in to change notification settings - Fork 265
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implements a new GET route /users?profile=true (#2201)
* adding new route for query param profile * removing some mixed changes of other commit * modified test cases and and controller logic * Implemented GET route /users?profile=true to fetch user's details * refactored: moved authentication logic from controller to middleware * test cases fo authCondition file * updated test cases and routes and middleware of users * bug fix for using only in test cases * code refactor and updated function naming
- Loading branch information
1 parent
9a5e799
commit ba269bd
Showing
7 changed files
with
174 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,10 @@ | ||
const authenticateProfile = (authenticate) => { | ||
return async (req, res, next) => { | ||
if (req.query.profile === "true") { | ||
return await authenticate(req, res, next); | ||
} | ||
return next(); | ||
}; | ||
}; | ||
|
||
module.exports = authenticateProfile; |
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
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,48 @@ | ||
const chai = require("chai"); | ||
const sinon = require("sinon"); | ||
const { expect } = chai; | ||
const authenticateProfile = require("../../../middlewares/authenticateProfile.js"); | ||
|
||
describe("authenticateProfile Middleware", function () { | ||
let req, res, next, authenticateStub, auth; | ||
|
||
beforeEach(function () { | ||
authenticateStub = sinon.spy(); | ||
auth = authenticateProfile(authenticateStub); | ||
|
||
req = { | ||
query: {}, | ||
}; | ||
res = { | ||
boom: { | ||
unauthorized: sinon.spy(), | ||
forbidden: sinon.spy(), | ||
}, | ||
}; | ||
next = sinon.spy(); | ||
}); | ||
|
||
it("should call authenticate when profile query is true", async function () { | ||
req.query.profile = "true"; | ||
await auth(req, res, next); | ||
|
||
expect(authenticateStub.withArgs(req, res, next).calledOnce).to.equal(true); | ||
expect(next.calledOnce).to.equal(false); | ||
}); | ||
|
||
it("should call next when profile query is not true", async function () { | ||
req.query.profile = "false"; | ||
|
||
await auth(req, res, next); | ||
|
||
expect(authenticateStub.calledOnce).to.equal(false); | ||
expect(next.calledOnce).to.equal(true); | ||
}); | ||
|
||
it("should call next when profile query is missing", async function () { | ||
await auth(req, res, next); | ||
|
||
expect(authenticateStub.calledOnce).to.equal(false); | ||
expect(next.calledOnce).to.equal(true); | ||
}); | ||
}); |
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