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

Feat/server auth controller tests #922

Merged
merged 10 commits into from
Oct 10, 2024
8 changes: 8 additions & 0 deletions Server/.mocharc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
require: ["chai/register-expect.js"], // Include Chai's "expect" interface globally
spec: "tests/**/*.test.js", // Specify test files
timeout: 5000, // Set test-case timeout in milliseconds
recursive: true, // Include subdirectories
reporter: "spec", // Use the "spec" reporter
exit: true, // Force Mocha to quit after tests complete
};
4 changes: 2 additions & 2 deletions Server/controllers/authController.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ const loginUser = async (req, res, next) => {
delete userWithoutPassword.avatarImage;

// Happy path, return token
const appSettings = req.settingsService.getSettings();
const appSettings = await req.settingsService.getSettings();
const token = issueToken(userWithoutPassword, appSettings);
// reset avatar image
userWithoutPassword.avatarImage = user.avatarImage;
Expand Down Expand Up @@ -392,6 +392,7 @@ const deleteUser = async (req, res, next) => {
const result = await req.db.getMonitorsByTeamId({
params: { teamId: user.teamId },
});

if (user.role.includes("superadmin")) {
//2. Remove all jobs, delete checks and alerts
result?.monitors.length > 0 &&
Expand All @@ -413,7 +414,6 @@ const deleteUser = async (req, res, next) => {
}
// 6. Delete the user by id
await req.db.deleteUser(user._id);

return res.status(200).json({
success: true,
msg: successMessages.AUTH_DELETE_USER,
Expand Down
3 changes: 0 additions & 3 deletions Server/middleware/verifyJWT.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
const jwt = require("jsonwebtoken");
const logger = require("../utils/logger");
const SERVICE_NAME = "verifyJWT";
const TOKEN_PREFIX = "Bearer ";
const { errorMessages } = require("../utils/messages");
const { parse } = require("path");
const User = require("../db/models/User");
/**
* Verifies the JWT token
* @function
Expand Down
Loading
Loading