Skip to content

Commit

Permalink
ref: improve logs
Browse files Browse the repository at this point in the history
  • Loading branch information
kristian4res committed Nov 4, 2024
1 parent f6d4648 commit fd20b67
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions server/routes/blaiseApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ export default function blaiseApi(config: CustomConfig, auth: Auth, blaiseApiCli
const successMessage = `${currentUser.name || "Unknown user"} has successfully updated user role and permissions to ${role} for ${user}`;
auditLogger.info(req.log, successMessage);
return res.status(200).json({
message: successMessage
message: "Successfully updated user role and permissions to " + role + " for " + user
});
} catch (error) {
const errorMessage = `Error whilst trying to update user role and permissions to ${role} for ${req.params.user}, with error message: ${error}`;
auditLogger.info(req.log, `${currentUser.name || "Unknown user"} has failed to update user role and permissions to ${role} for ${user}`);
auditLogger.error(req.log, errorMessage);
return res.status(500).json({
message: errorMessage
message: "Failed to update user role and permissions to " + role + " for " + user
});
}
});
Expand Down
4 changes: 2 additions & 2 deletions server/tests/routes/blaiseApi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ describe("PATCH /api/users/:user/rolesAndPermissions endpoint", () => {
const log = logInfo.mock.calls[0][0];
expect(log).toEqual("AUDIT_LOG: testUser has successfully updated user role and permissions to IPS Manager for testUser");
expect(response.statusCode).toEqual(200);
expect(response.body.message).toContain(`${mockUser.name} has successfully updated user role and permissions to ${role} for ${user}`);
expect(response.body.message).toContain(`Successfully updated user role and permissions to ${role} for ${user}`);
blaiseApiMock.verify(api => api.changeUserRole(It.isValue(user), It.isValue(role)), Times.once());
blaiseApiMock.verify(api => api.changeUserServerParks(It.isValue(user), It.isValue(serverParks), It.isValue(defaultServerPark)), Times.once());
});
Expand Down Expand Up @@ -380,6 +380,6 @@ describe("PATCH /api/users/:user/rolesAndPermissions endpoint", () => {
expect(infoLog).toEqual(`AUDIT_LOG: ${mockUser.name} has failed to update user role and permissions to ${role} for ${user}`);
expect(errorLog).toEqual(`AUDIT_LOG: Error whilst trying to update user role and permissions to admin for ${mockUser.name}, with error message: Error: ${errorMessage}`);
expect(response.statusCode).toEqual(500);
expect(response.body.message).toContain(errorMessage);
expect(response.body.message).toContain("Failed to update user role and permissions to admin for testUser");
});
});

0 comments on commit fd20b67

Please sign in to comment.