Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev to Main sync #2239

Merged
merged 2 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 9 additions & 13 deletions controllers/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,20 +116,16 @@ const getUsers = async (req, res) => {
const profile = req.query.profile === "true";

if (profile) {
if (dev) {
if (!req.userData.id) {
return res.boom.badRequest("User ID not provided.");
}
if (!req.userData.id) {
return res.boom.badRequest("User ID not provided.");
}

try {
const result = await dataAccess.retrieveUsers({ id: req.userData.id });
return res.send(result.user);
} catch (error) {
logger.error(`Error while fetching user: ${error}`);
return res.boom.serverUnavailable(INTERNAL_SERVER_ERROR);
}
} else {
return res.boom.badRequest("Route not found");
try {
const result = await dataAccess.retrieveUsers({ id: req.userData.id });
return res.send(result.user);
} catch (error) {
logger.error(`Error while fetching user: ${error}`);
return res.boom.serverUnavailable(INTERNAL_SERVER_ERROR);
}
}

Expand Down
22 changes: 3 additions & 19 deletions test/integration/users.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -904,10 +904,10 @@ describe("Users", function () {
});
});

it("Should return the logged-in user's details when profile and dev is true", function (done) {
it("Should return the logged-in user's details when profile is true", function (done) {
chai
.request(app)
.get("/users?profile=true&dev=true")
.get("/users?profile=true")
.set("cookie", `${cookieName}=${jwt}`)
.end((err, res) => {
if (err) {
Expand All @@ -923,26 +923,10 @@ describe("Users", function () {
});
});

it("Should throw an error when there is no feature flag given", function (done) {
chai
.request(app)
.get("/users?profile=true")
.set("cookie", `${cookieName}=${jwt}`)
.end((err, res) => {
if (err) {
return done(err);
}
expect(res).to.have.status(400);
expect(res.body).to.be.an("object");
expect(res.body.message).to.equal("Route not found");
return done();
});
});

it("Should return 401 if not logged in", function (done) {
chai
.request(app)
.get("/users?profile=true&dev=true")
.get("/users?profile=true")
.set("cookie", `${cookieName}=invalid_token`)
.end((err, res) => {
if (err) {
Expand Down
8 changes: 4 additions & 4 deletions utils/task-requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ const transformTaskRequests = async (taskRequestsList: TaskRequestType[]) => {
taskRequestsList.forEach((data) => {
data.users = data.users.map((userData) => {
const user = usersMap.get(userData.userId);
const username = user?.username || 'Undefined';
const firstName = user?.first_name || 'Undefined';
const lastName = user?.last_name || 'Undefined';
const picture = user?.picture || null;
const username = user?.username
const firstName = user?.first_name
const lastName = user?.last_name
const picture = user?.picture;

return { ...userData, username, first_name: firstName, last_name: lastName, picture };
});
Expand Down
Loading