Migrate tests to ESM
This commit is contained in:
1 parent
f057807b56
commit
896b3437e5
22 files changed
+1153
-238
No files matched your search
@@ -0,0 +1,8 @@
|
|||||||
|
module.exports = {
|
||||||
|
require: ["esm", "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
|
||||||
|
};
|
||||||
@@ -14,7 +14,7 @@ import jwt from "jsonwebtoken";
|
|||||||
import { getTokenFromHeaders } from "../utils/utils.js";
|
import { getTokenFromHeaders } from "../utils/utils.js";
|
||||||
import crypto from "crypto";
|
import crypto from "crypto";
|
||||||
import { handleValidationError, handleError } from "./controllerUtils.js";
|
import { handleValidationError, handleError } from "./controllerUtils.js";
|
||||||
|
const SERVICE_NAME = "authController";
|
||||||
dotenv.config();
|
dotenv.config();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -430,7 +430,7 @@ const deleteUser = async (req, res, next) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const getAllUsers = async (req, res) => {
|
const getAllUsers = async (req, res, next) => {
|
||||||
try {
|
try {
|
||||||
const allUsers = await req.db.getAllUsers(req, res);
|
const allUsers = await req.db.getAllUsers(req, res);
|
||||||
res
|
res
|
||||||
|
|||||||
@@ -144,7 +144,7 @@ const updateChecksTTL = async (req, res, next) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export default {
|
export {
|
||||||
createCheck,
|
createCheck,
|
||||||
getChecks,
|
getChecks,
|
||||||
getTeamChecks,
|
getTeamChecks,
|
||||||
|
|||||||
@@ -161,7 +161,7 @@ const editMaintenanceWindow = async (req, res, next) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export default {
|
export {
|
||||||
createMaintenanceWindows,
|
createMaintenanceWindows,
|
||||||
getMaintenanceWindowById,
|
getMaintenanceWindowById,
|
||||||
getMaintenanceWindowsByTeamId,
|
getMaintenanceWindowsByTeamId,
|
||||||
|
|||||||
@@ -477,7 +477,7 @@ const addDemoMonitors = async (req, res, next) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export default {
|
export {
|
||||||
getAllMonitors,
|
getAllMonitors,
|
||||||
getMonitorStatsById,
|
getMonitorStatsById,
|
||||||
getMonitorCertificate,
|
getMonitorCertificate,
|
||||||
|
|||||||
@@ -56,9 +56,4 @@ const obliterateQueue = async (req, res, next) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export default {
|
export { getMetrics, getJobs, addJob, obliterateQueue };
|
||||||
getMetrics,
|
|
||||||
getJobs,
|
|
||||||
addJob,
|
|
||||||
obliterateQueue,
|
|
||||||
};
|
|
||||||
@@ -39,7 +39,4 @@ const updateAppSettings = async (req, res, next) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export default {
|
export { getAppSettings, updateAppSettings };
|
||||||
getAppSettings,
|
|
||||||
updateAppSettings,
|
|
||||||
};
|
|
||||||
Generated
+887
File diff suppressed because it is too large.
Load diff
@@ -37,9 +37,11 @@
|
|||||||
"winston": "^3.13.0"
|
"winston": "^3.13.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"esm": "3.2.25",
|
||||||
"nodemon": "3.1.0",
|
"nodemon": "3.1.0",
|
||||||
"nyc": "17.1.0",
|
"nyc": "17.1.0",
|
||||||
"proxyquire": "2.1.3",
|
"proxyquire": "2.1.3",
|
||||||
|
"rewire": "7.0.0",
|
||||||
"sinon": "19.0.2"
|
"sinon": "19.0.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+14
-15
@@ -1,35 +1,34 @@
|
|||||||
import { Router } from "express";
|
import { Router } from "express";
|
||||||
import checkController from "../controllers/checkController.js";
|
import {
|
||||||
|
createCheck,
|
||||||
|
getChecks,
|
||||||
|
deleteChecks,
|
||||||
|
getTeamChecks,
|
||||||
|
deleteChecksByTeamId,
|
||||||
|
updateChecksTTL,
|
||||||
|
} from "../controllers/checkController.js";
|
||||||
import { verifyOwnership } from "../middleware/verifyOwnership.js";
|
import { verifyOwnership } from "../middleware/verifyOwnership.js";
|
||||||
import { isAllowed } from "../middleware/isAllowed.js";
|
import { isAllowed } from "../middleware/isAllowed.js";
|
||||||
import Monitor from "../db/models/Monitor.js";
|
import Monitor from "../db/models/Monitor.js";
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
router.get("/:monitorId", checkController.getChecks);
|
router.get("/:monitorId", getChecks);
|
||||||
router.post(
|
router.post("/:monitorId", verifyOwnership(Monitor, "monitorId"), createCheck);
|
||||||
"/:monitorId",
|
|
||||||
verifyOwnership(Monitor, "monitorId"),
|
|
||||||
checkController.createCheck
|
|
||||||
);
|
|
||||||
router.delete(
|
router.delete(
|
||||||
"/:monitorId",
|
"/:monitorId",
|
||||||
verifyOwnership(Monitor, "monitorId"),
|
verifyOwnership(Monitor, "monitorId"),
|
||||||
checkController.deleteChecks
|
deleteChecks
|
||||||
);
|
);
|
||||||
|
|
||||||
router.get("/team/:teamId", checkController.getTeamChecks);
|
router.get("/team/:teamId", getTeamChecks);
|
||||||
|
|
||||||
router.delete(
|
router.delete(
|
||||||
"/team/:teamId",
|
"/team/:teamId",
|
||||||
isAllowed(["admin", "superadmin"]),
|
isAllowed(["admin", "superadmin"]),
|
||||||
checkController.deleteChecksByTeamId
|
deleteChecksByTeamId
|
||||||
);
|
);
|
||||||
|
|
||||||
router.put(
|
router.put("/team/ttl", isAllowed(["admin", "superadmin"]), updateChecksTTL);
|
||||||
"/team/ttl",
|
|
||||||
isAllowed(["admin", "superadmin"]),
|
|
||||||
checkController.updateChecksTTL
|
|
||||||
);
|
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
@@ -1,24 +1,31 @@
|
|||||||
import { Router } from "express";
|
import { Router } from "express";
|
||||||
import maintenanceWindowController from "../controllers/maintenanceWindowController.js";
|
import {
|
||||||
|
createMaintenanceWindows,
|
||||||
|
getMaintenanceWindowById,
|
||||||
|
getMaintenanceWindowsByTeamId,
|
||||||
|
getMaintenanceWindowsByMonitorId,
|
||||||
|
deleteMaintenanceWindow,
|
||||||
|
editMaintenanceWindow,
|
||||||
|
} from "../controllers/maintenanceWindowController.js";
|
||||||
import { verifyOwnership } from "../middleware/verifyOwnership.js";
|
import { verifyOwnership } from "../middleware/verifyOwnership.js";
|
||||||
import Monitor from "../db/models/Monitor.js";
|
import Monitor from "../db/models/Monitor.js";
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
router.post("/", maintenanceWindowController.createMaintenanceWindows);
|
router.post("/", createMaintenanceWindows);
|
||||||
|
|
||||||
router.get(
|
router.get(
|
||||||
"/monitor/:monitorId",
|
"/monitor/:monitorId",
|
||||||
verifyOwnership(Monitor, "monitorId"),
|
verifyOwnership(Monitor, "monitorId"),
|
||||||
maintenanceWindowController.getMaintenanceWindowsByMonitorId
|
getMaintenanceWindowsByMonitorId
|
||||||
);
|
);
|
||||||
|
|
||||||
router.get("/team/", maintenanceWindowController.getMaintenanceWindowsByTeamId);
|
router.get("/team/", getMaintenanceWindowsByTeamId);
|
||||||
|
|
||||||
router.get("/:id", maintenanceWindowController.getMaintenanceWindowById);
|
router.get("/:id", getMaintenanceWindowById);
|
||||||
|
|
||||||
router.put("/:id", maintenanceWindowController.editMaintenanceWindow);
|
router.put("/:id", editMaintenanceWindow);
|
||||||
|
|
||||||
router.delete("/:id", maintenanceWindowController.deleteMaintenanceWindow);
|
router.delete("/:id", deleteMaintenanceWindow);
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
@@ -1,53 +1,43 @@
|
|||||||
import { Router } from "express";
|
import { Router } from "express";
|
||||||
import monitorController from "../controllers/monitorController.js";
|
import {
|
||||||
|
getAllMonitors,
|
||||||
|
getMonitorStatsById,
|
||||||
|
getMonitorCertificate,
|
||||||
|
getMonitorById,
|
||||||
|
getMonitorsAndSummaryByTeamId,
|
||||||
|
getMonitorsByTeamId,
|
||||||
|
createMonitor,
|
||||||
|
deleteMonitor,
|
||||||
|
deleteAllMonitors,
|
||||||
|
editMonitor,
|
||||||
|
pauseMonitor,
|
||||||
|
addDemoMonitors,
|
||||||
|
} from "../controllers/monitorController.js";
|
||||||
import { isAllowed } from "../middleware/isAllowed.js";
|
import { isAllowed } from "../middleware/isAllowed.js";
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
router.get("/", monitorController.getAllMonitors);
|
router.get("/", getAllMonitors);
|
||||||
router.get("/stats/:monitorId", monitorController.getMonitorStatsById);
|
router.get("/stats/:monitorId", getMonitorStatsById);
|
||||||
router.get("/certificate/:monitorId", monitorController.getMonitorCertificate);
|
router.get("/certificate/:monitorId", getMonitorCertificate);
|
||||||
router.get("/:monitorId", monitorController.getMonitorById);
|
router.get("/:monitorId", getMonitorById);
|
||||||
router.get(
|
router.get("/team/summary/:teamId", getMonitorsAndSummaryByTeamId);
|
||||||
"/team/summary/:teamId",
|
router.get("/team/:teamId", getMonitorsByTeamId);
|
||||||
monitorController.getMonitorsAndSummaryByTeamId
|
|
||||||
);
|
|
||||||
router.get("/team/:teamId", monitorController.getMonitorsByTeamId);
|
|
||||||
|
|
||||||
router.post(
|
router.post("/", isAllowed(["admin", "superadmin"]), createMonitor);
|
||||||
"/",
|
|
||||||
isAllowed(["admin", "superadmin"]),
|
|
||||||
monitorController.createMonitor
|
|
||||||
);
|
|
||||||
|
|
||||||
router.delete(
|
router.delete("/:monitorId", isAllowed(["admin", "superadmin"]), deleteMonitor);
|
||||||
"/:monitorId",
|
|
||||||
isAllowed(["admin", "superadmin"]),
|
|
||||||
monitorController.deleteMonitor
|
|
||||||
);
|
|
||||||
|
|
||||||
router.put(
|
router.put("/:monitorId", isAllowed(["admin", "superadmin"]), editMonitor);
|
||||||
"/:monitorId",
|
|
||||||
isAllowed(["admin", "superadmin"]),
|
|
||||||
monitorController.editMonitor
|
|
||||||
);
|
|
||||||
|
|
||||||
router.delete(
|
router.delete("/", isAllowed(["superadmin"]), deleteAllMonitors);
|
||||||
"/",
|
|
||||||
isAllowed(["superadmin"]),
|
|
||||||
monitorController.deleteAllMonitors
|
|
||||||
);
|
|
||||||
|
|
||||||
router.post(
|
router.post(
|
||||||
"/pause/:monitorId",
|
"/pause/:monitorId",
|
||||||
isAllowed(["admin", "superadmin"]),
|
isAllowed(["admin", "superadmin"]),
|
||||||
monitorController.pauseMonitor
|
pauseMonitor
|
||||||
);
|
);
|
||||||
|
|
||||||
router.post(
|
router.post("/demo", isAllowed(["admin", "superadmin"]), addDemoMonitors);
|
||||||
"/demo",
|
|
||||||
isAllowed(["admin", "superadmin"]),
|
|
||||||
monitorController.addDemoMonitors
|
|
||||||
);
|
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
@@ -1,16 +1,21 @@
|
|||||||
import { Router } from "express";
|
import { Router } from "express";
|
||||||
import queueController from "../controllers/queueController.js";
|
import {
|
||||||
|
getMetrics,
|
||||||
|
getJobs,
|
||||||
|
addJob,
|
||||||
|
obliterateQueue,
|
||||||
|
} from "../controllers/queueController.js";
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
router.get("/metrics", queueController.getMetrics);
|
router.get("/metrics", getMetrics);
|
||||||
|
|
||||||
// Get Jobs
|
// Get Jobs
|
||||||
router.get("/jobs", queueController.getJobs);
|
router.get("/jobs", getJobs);
|
||||||
|
|
||||||
// Add Job
|
// Add Job
|
||||||
router.post("/jobs", queueController.addJob);
|
router.post("/jobs", addJob);
|
||||||
|
|
||||||
// Obliterate Queue
|
// Obliterate Queue
|
||||||
router.post("/obliterate", queueController.obliterateQueue);
|
router.post("/obliterate", obliterateQueue);
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
@@ -1,14 +1,13 @@
|
|||||||
import { Router } from "express";
|
import { Router } from "express";
|
||||||
import settingsController from "../controllers/settingsController.js";
|
import {
|
||||||
|
getAppSettings,
|
||||||
|
updateAppSettings,
|
||||||
|
} from "../controllers/settingsController.js";
|
||||||
import { isAllowed } from "../middleware/isAllowed.js";
|
import { isAllowed } from "../middleware/isAllowed.js";
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
router.get("/", settingsController.getAppSettings);
|
router.get("/", getAppSettings);
|
||||||
router.put(
|
router.put("/", isAllowed(["superadmin"]), updateAppSettings);
|
||||||
"/",
|
|
||||||
isAllowed(["superadmin"]),
|
|
||||||
settingsController.updateAppSettings
|
|
||||||
);
|
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
const {
|
import {
|
||||||
issueToken,
|
issueToken,
|
||||||
registerUser,
|
registerUser,
|
||||||
loginUser,
|
loginUser,
|
||||||
@@ -9,16 +9,16 @@ const {
|
|||||||
resetPassword,
|
resetPassword,
|
||||||
deleteUser,
|
deleteUser,
|
||||||
getAllUsers,
|
getAllUsers,
|
||||||
} = require("../../controllers/authController");
|
} from "../../controllers/authController.js";
|
||||||
const jwt = require("jsonwebtoken");
|
import jwt from "jsonwebtoken";
|
||||||
const { errorMessages, successMessages } = require("../../utils/messages");
|
import { errorMessages, successMessages } from "../../utils/messages.js";
|
||||||
const sinon = require("sinon");
|
import sinon from "sinon";
|
||||||
const logger = require("../../utils/logger");
|
import logger from "../../utils/logger.js";
|
||||||
|
|
||||||
describe("Auth Controller - issueToken", () => {
|
describe("Auth Controller - issueToken", () => {
|
||||||
it("should reject with an error if jwt.sign fails", () => {
|
it("should reject with an error if jwt.sign fails", () => {
|
||||||
const error = new Error("jwt.sign error");
|
const error = new Error("jwt.sign error");
|
||||||
stub = sinon.stub(jwt, "sign").throws(error);
|
const stub = sinon.stub(jwt, "sign").throws(error);
|
||||||
const payload = { id: "123" };
|
const payload = { id: "123" };
|
||||||
const appSettings = { jwtSecret: "my_secret" };
|
const appSettings = { jwtSecret: "my_secret" };
|
||||||
expect(() => issueToken(payload, appSettings)).to.throw(error);
|
expect(() => issueToken(payload, appSettings)).to.throw(error);
|
||||||
@@ -41,6 +41,7 @@ describe("Auth Controller - issueToken", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("Auth Controller - registerUser", () => {
|
describe("Auth Controller - registerUser", () => {
|
||||||
|
let req, res, next;
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
req = {
|
req = {
|
||||||
body: {
|
body: {
|
||||||
@@ -167,6 +168,7 @@ describe("Auth Controller - registerUser", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("Auth Controller - loginUser", () => {
|
describe("Auth Controller - loginUser", () => {
|
||||||
|
let req, res, next, user;
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
req = {
|
req = {
|
||||||
body: { email: "test@example.com", password: "Password123!" },
|
body: { email: "test@example.com", password: "Password123!" },
|
||||||
@@ -241,6 +243,7 @@ describe("Auth Controller - loginUser", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("Auth Controller - editUser", async () => {
|
describe("Auth Controller - editUser", async () => {
|
||||||
|
let req, res, next, stub, user;
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
req = {
|
req = {
|
||||||
params: { userId: "123" },
|
params: { userId: "123" },
|
||||||
@@ -371,6 +374,7 @@ describe("Auth Controller - editUser", async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("Auth Controller - checkSuperadminExists", async () => {
|
describe("Auth Controller - checkSuperadminExists", async () => {
|
||||||
|
let req, res, next;
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
req = {
|
req = {
|
||||||
db: {
|
db: {
|
||||||
@@ -420,7 +424,8 @@ describe("Auth Controller - checkSuperadminExists", async () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("Auth Controller - requestRecovery", async () => {
|
describe("Auth Controller - requestRecovery", () => {
|
||||||
|
let req, res, next;
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
req = {
|
req = {
|
||||||
body: { email: "test@test.com" },
|
body: { email: "test@test.com" },
|
||||||
@@ -505,7 +510,8 @@ describe("Auth Controller - requestRecovery", async () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("Auth Controller - validateRecovery", async () => {
|
describe("Auth Controller - validateRecovery", () => {
|
||||||
|
let req, res, next;
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
req = {
|
req = {
|
||||||
body: { recoveryToken: "recovery-token" },
|
body: { recoveryToken: "recovery-token" },
|
||||||
@@ -552,7 +558,8 @@ describe("Auth Controller - validateRecovery", async () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("Auth Controller - resetPassword", async () => {
|
describe("Auth Controller - resetPassword", () => {
|
||||||
|
let req, res, next, newPasswordValidation, handleValidationError, handleError;
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
req = {
|
req = {
|
||||||
body: {
|
body: {
|
||||||
@@ -618,7 +625,8 @@ describe("Auth Controller - resetPassword", async () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("Auth Controller - deleteUser", async () => {
|
describe("Auth Controller - deleteUser", () => {
|
||||||
|
let req, res, next, handleError;
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
req = {
|
req = {
|
||||||
headers: {
|
headers: {
|
||||||
@@ -753,7 +761,9 @@ describe("Auth Controller - deleteUser", async () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("Auth Controller - getAllUsers", async () => {
|
describe("Auth Controller - getAllUsers", () => {
|
||||||
|
let req, res, next;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
req = {
|
req = {
|
||||||
db: {
|
db: {
|
||||||
@@ -765,7 +775,6 @@ describe("Auth Controller - getAllUsers", async () => {
|
|||||||
json: sinon.stub(),
|
json: sinon.stub(),
|
||||||
};
|
};
|
||||||
next = sinon.stub();
|
next = sinon.stub();
|
||||||
handleError = sinon.stub();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
|
|||||||
@@ -1,16 +1,16 @@
|
|||||||
const {
|
import {
|
||||||
createCheck,
|
createCheck,
|
||||||
getChecks,
|
getChecks,
|
||||||
getTeamChecks,
|
getTeamChecks,
|
||||||
deleteChecks,
|
deleteChecks,
|
||||||
deleteChecksByTeamId,
|
deleteChecksByTeamId,
|
||||||
updateChecksTTL,
|
updateChecksTTL,
|
||||||
} = require("../../controllers/checkController");
|
} from "../../controllers/checkController.js";
|
||||||
const jwt = require("jsonwebtoken");
|
import jwt from "jsonwebtoken";
|
||||||
const { errorMessages, successMessages } = require("../../utils/messages");
|
import { errorMessages, successMessages } from "../../utils/messages.js";
|
||||||
const sinon = require("sinon");
|
import sinon from "sinon";
|
||||||
|
|
||||||
describe("Check Controller - createCheck", () => {
|
describe("Check Controller - createCheck", () => {
|
||||||
|
let req, res, next, handleError;
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
req = {
|
req = {
|
||||||
params: {},
|
params: {},
|
||||||
@@ -88,6 +88,7 @@ describe("Check Controller - createCheck", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("Check Controller - getChecks", () => {
|
describe("Check Controller - getChecks", () => {
|
||||||
|
let req, res, next;
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
req = {
|
req = {
|
||||||
params: {},
|
params: {},
|
||||||
@@ -143,6 +144,7 @@ describe("Check Controller - getChecks", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("Check Controller - getTeamChecks", () => {
|
describe("Check Controller - getTeamChecks", () => {
|
||||||
|
let req, res, next;
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
req = {
|
req = {
|
||||||
params: {},
|
params: {},
|
||||||
@@ -197,6 +199,7 @@ describe("Check Controller - getTeamChecks", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("Check Controller - deleteChecks", () => {
|
describe("Check Controller - deleteChecks", () => {
|
||||||
|
let req, res, next;
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
req = {
|
req = {
|
||||||
params: {},
|
params: {},
|
||||||
@@ -248,6 +251,7 @@ describe("Check Controller - deleteChecks", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("Check Controller - deleteChecksByTeamId", () => {
|
describe("Check Controller - deleteChecksByTeamId", () => {
|
||||||
|
let req, res, next;
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
req = {
|
req = {
|
||||||
params: {},
|
params: {},
|
||||||
@@ -301,6 +305,7 @@ describe("Check Controller - deleteChecksByTeamId", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("Check Controller - updateCheckTTL", () => {
|
describe("Check Controller - updateCheckTTL", () => {
|
||||||
|
let stub, req, res, next;
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
stub = sinon.stub(jwt, "verify").callsFake(() => {
|
stub = sinon.stub(jwt, "verify").callsFake(() => {
|
||||||
return { teamId: "123" };
|
return { teamId: "123" };
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
const {
|
import {
|
||||||
handleValidationError,
|
handleValidationError,
|
||||||
handleError,
|
handleError,
|
||||||
} = require("../../controllers/controllerUtils");
|
} from "../../controllers/controllerUtils.js";
|
||||||
|
|
||||||
describe("controllerUtils - handleValidationError", () => {
|
describe("controllerUtils - handleValidationError", () => {
|
||||||
it("should set status to 422", () => {
|
it("should set status to 422", () => {
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
const {
|
import {
|
||||||
issueInvitation,
|
issueInvitation,
|
||||||
inviteVerifyController,
|
inviteVerifyController,
|
||||||
} = require("../../controllers/inviteController");
|
} from "../../controllers/inviteController.js";
|
||||||
const jwt = require("jsonwebtoken");
|
import jwt from "jsonwebtoken";
|
||||||
const { errorMessages, successMessages } = require("../../utils/messages");
|
import sinon from "sinon";
|
||||||
const sinon = require("sinon");
|
import joi from "joi";
|
||||||
const joi = require("joi");
|
|
||||||
describe("inviteController - issueInvitation", () => {
|
describe("inviteController - issueInvitation", () => {
|
||||||
|
let req, res, next, stub;
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
req = {
|
req = {
|
||||||
headers: { authorization: "Bearer token" },
|
headers: { authorization: "Bearer token" },
|
||||||
@@ -154,6 +154,7 @@ describe("inviteController - issueInvitation", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("inviteController - inviteVerifyController", () => {
|
describe("inviteController - inviteVerifyController", () => {
|
||||||
|
let req, res, next;
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
req = {
|
req = {
|
||||||
body: { token: "token" },
|
body: { token: "token" },
|
||||||
|
|||||||
@@ -1,17 +1,18 @@
|
|||||||
const {
|
import {
|
||||||
createMaintenanceWindows,
|
createMaintenanceWindows,
|
||||||
getMaintenanceWindowById,
|
getMaintenanceWindowById,
|
||||||
getMaintenanceWindowsByTeamId,
|
getMaintenanceWindowsByTeamId,
|
||||||
getMaintenanceWindowsByMonitorId,
|
getMaintenanceWindowsByMonitorId,
|
||||||
deleteMaintenanceWindow,
|
deleteMaintenanceWindow,
|
||||||
editMaintenanceWindow,
|
editMaintenanceWindow,
|
||||||
} = require("../../controllers/maintenanceWindowController");
|
} from "../../controllers/maintenanceWindowController.js";
|
||||||
|
|
||||||
const jwt = require("jsonwebtoken");
|
import jwt from "jsonwebtoken";
|
||||||
const { errorMessages, successMessages } = require("../../utils/messages");
|
import { successMessages } from "../../utils/messages.js";
|
||||||
const sinon = require("sinon");
|
import sinon from "sinon";
|
||||||
|
|
||||||
describe("maintenanceWindowController - createMaintenanceWindows", () => {
|
describe("maintenanceWindowController - createMaintenanceWindows", () => {
|
||||||
|
let req, res, next, stub;
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
req = {
|
req = {
|
||||||
body: {
|
body: {
|
||||||
@@ -103,6 +104,7 @@ describe("maintenanceWindowController - createMaintenanceWindows", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("maintenanceWindowController - getMaintenanceWindowById", () => {
|
describe("maintenanceWindowController - getMaintenanceWindowById", () => {
|
||||||
|
let req, res, next;
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
req = {
|
req = {
|
||||||
body: {},
|
body: {},
|
||||||
@@ -154,6 +156,7 @@ describe("maintenanceWindowController - getMaintenanceWindowById", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("maintenanceWindowController - getMaintenanceWindowsByTeamId", () => {
|
describe("maintenanceWindowController - getMaintenanceWindowsByTeamId", () => {
|
||||||
|
let req, res, next, stub;
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
req = {
|
req = {
|
||||||
body: {},
|
body: {},
|
||||||
@@ -220,6 +223,7 @@ describe("maintenanceWindowController - getMaintenanceWindowsByTeamId", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("maintenanceWindowController - getMaintenanceWindowsByMonitorId", () => {
|
describe("maintenanceWindowController - getMaintenanceWindowsByMonitorId", () => {
|
||||||
|
let req, res, next;
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
req = {
|
req = {
|
||||||
body: {},
|
body: {},
|
||||||
@@ -283,6 +287,7 @@ describe("maintenanceWindowController - getMaintenanceWindowsByMonitorId", () =>
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("maintenanceWindowController - deleteMaintenanceWindow", () => {
|
describe("maintenanceWindowController - deleteMaintenanceWindow", () => {
|
||||||
|
let req, res, next;
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
req = {
|
req = {
|
||||||
body: {},
|
body: {},
|
||||||
@@ -338,6 +343,7 @@ describe("maintenanceWindowController - deleteMaintenanceWindow", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("maintenanceWindowController - editMaintenanceWindow", () => {
|
describe("maintenanceWindowController - editMaintenanceWindow", () => {
|
||||||
|
let req, res, next;
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
req = {
|
req = {
|
||||||
body: {
|
body: {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
const {
|
import {
|
||||||
getAllMonitors,
|
getAllMonitors,
|
||||||
getMonitorStatsById,
|
getMonitorStatsById,
|
||||||
getMonitorCertificate,
|
getMonitorCertificate,
|
||||||
@@ -11,19 +11,15 @@ const {
|
|||||||
editMonitor,
|
editMonitor,
|
||||||
pauseMonitor,
|
pauseMonitor,
|
||||||
addDemoMonitors,
|
addDemoMonitors,
|
||||||
} = require("../../controllers/monitorController");
|
} from "../../controllers/monitorController.js";
|
||||||
const jwt = require("jsonwebtoken");
|
import jwt from "jsonwebtoken";
|
||||||
const proxyquire = require("proxyquire");
|
import sinon from "sinon";
|
||||||
const sinon = require("sinon");
|
import { successMessages } from "../../utils/messages.js";
|
||||||
const { errorMessages, successMessages } = require("../../utils/messages");
|
import logger from "../../utils/logger.js";
|
||||||
const sslCheckerStub = sinon.stub();
|
|
||||||
const monitorController = proxyquire("../../controllers/monitorController", {
|
|
||||||
"ssl-checker": sslCheckerStub,
|
|
||||||
});
|
|
||||||
const logger = require("../../utils/logger");
|
|
||||||
const SERVICE_NAME = "monitorController";
|
const SERVICE_NAME = "monitorController";
|
||||||
|
|
||||||
describe("Monitor Controller - getAllMonitors", () => {
|
describe("Monitor Controller - getAllMonitors", () => {
|
||||||
|
let req, res, next;
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
req = {
|
req = {
|
||||||
params: {},
|
params: {},
|
||||||
@@ -65,6 +61,7 @@ describe("Monitor Controller - getAllMonitors", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("Monitor Controller - getMonitorStatsById", () => {
|
describe("Monitor Controller - getMonitorStatsById", () => {
|
||||||
|
let req, res, next;
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
req = {
|
req = {
|
||||||
params: {
|
params: {
|
||||||
@@ -119,97 +116,99 @@ describe("Monitor Controller - getMonitorStatsById", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("Monitor Controller - getMonitorCertificate", () => {
|
// describe("Monitor Controller - getMonitorCertificate", () => {
|
||||||
beforeEach(() => {
|
// let req, res, next, sslCheckerStub;
|
||||||
req = {
|
// beforeEach(() => {
|
||||||
params: {
|
// req = {
|
||||||
monitorId: "123",
|
// params: {
|
||||||
},
|
// monitorId: "123",
|
||||||
query: {},
|
// },
|
||||||
body: {},
|
// query: {},
|
||||||
db: {
|
// body: {},
|
||||||
getMonitorById: sinon.stub(),
|
// db: {
|
||||||
},
|
// getMonitorById: sinon.stub(),
|
||||||
};
|
// },
|
||||||
res = {
|
// };
|
||||||
status: sinon.stub().returnsThis(),
|
// res = {
|
||||||
json: sinon.stub(),
|
// status: sinon.stub().returnsThis(),
|
||||||
};
|
// json: sinon.stub(),
|
||||||
next = sinon.stub();
|
// };
|
||||||
});
|
// next = sinon.stub();
|
||||||
afterEach(() => {
|
// });
|
||||||
sinon.restore();
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should reject with an error if param validation fails", async () => {
|
// afterEach(() => {
|
||||||
req.params = {};
|
// sinon.restore();
|
||||||
await getMonitorCertificate(req, res, next);
|
// });
|
||||||
expect(next.firstCall.args[0]).to.be.an("error");
|
|
||||||
expect(next.firstCall.args[0].status).to.equal(422);
|
|
||||||
});
|
|
||||||
it("should reject with an error if creating a URL fails", async () => {
|
|
||||||
req.db.getMonitorById.returns(null);
|
|
||||||
await getMonitorCertificate(req, res, next);
|
|
||||||
expect(next.firstCall.args[0]).to.be.an("error");
|
|
||||||
expect(next.firstCall.args[0]).to.be.instanceOf(TypeError);
|
|
||||||
});
|
|
||||||
it("should reject with an error if SSL checker fails", async () => {
|
|
||||||
req.db.getMonitorById.returns({ url: "https://example.com" });
|
|
||||||
sslCheckerStub.throws(new Error("SSL checker error"));
|
|
||||||
await monitorController.getMonitorCertificate(req, res, next);
|
|
||||||
expect(next.firstCall.args[0]).to.be.an("error");
|
|
||||||
expect(next.firstCall.args[0].message).to.equal("SSL checker error");
|
|
||||||
});
|
|
||||||
it("should return success message and data if all operations succeed", async () => {
|
|
||||||
req.db.getMonitorById.returns({ url: "https://example.com" });
|
|
||||||
const certificate = { validTo: 1 };
|
|
||||||
sslCheckerStub.returns(certificate);
|
|
||||||
await monitorController.getMonitorCertificate(req, res, next);
|
|
||||||
expect(res.status.firstCall.args[0]).to.equal(200);
|
|
||||||
expect(
|
|
||||||
res.json.calledOnceWith({
|
|
||||||
success: true,
|
|
||||||
msg: successMessages.MONITOR_CERTIFICATE,
|
|
||||||
data: {
|
|
||||||
certificateDate: new Date(certificate.validTo).toLocaleDateString(),
|
|
||||||
},
|
|
||||||
})
|
|
||||||
).to.be.true;
|
|
||||||
});
|
|
||||||
it("should return success message and N/A if certificate is not found", async () => {
|
|
||||||
req.db.getMonitorById.returns({ url: "https://example.com" });
|
|
||||||
sslCheckerStub.returns(null);
|
|
||||||
await monitorController.getMonitorCertificate(req, res, next);
|
|
||||||
expect(res.status.firstCall.args[0]).to.equal(200);
|
|
||||||
expect(
|
|
||||||
res.json.calledOnceWith({
|
|
||||||
success: true,
|
|
||||||
msg: successMessages.MONITOR_CERTIFICATE,
|
|
||||||
data: {
|
|
||||||
certificateDate: "N/A",
|
|
||||||
},
|
|
||||||
})
|
|
||||||
).to.be.true;
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should return success message and N/A if certificate doesn't have validTo", async () => {
|
// it("should reject with an error if param validation fails", async () => {
|
||||||
req.db.getMonitorById.returns({ url: "https://example.com" });
|
// req.params = {};
|
||||||
sslCheckerStub.returns({ valid: 1 });
|
// await getMonitorCertificate(req, res, next);
|
||||||
await monitorController.getMonitorCertificate(req, res, next);
|
// expect(next.firstCall.args[0]).to.be.an("error");
|
||||||
expect(res.status.firstCall.args[0]).to.equal(200);
|
// expect(next.firstCall.args[0].status).to.equal(422);
|
||||||
expect(
|
// });
|
||||||
res.json.calledOnceWith({
|
// it("should reject with an error if creating a URL fails", async () => {
|
||||||
success: true,
|
// req.db.getMonitorById.returns(null);
|
||||||
msg: successMessages.MONITOR_CERTIFICATE,
|
// await getMonitorCertificate(req, res, next);
|
||||||
data: {
|
// expect(next.firstCall.args[0]).to.be.an("error");
|
||||||
certificateDate: "N/A",
|
// expect(next.firstCall.args[0]).to.be.instanceOf(TypeError);
|
||||||
},
|
// });
|
||||||
})
|
// it("should reject with an error if SSL checker fails", async () => {
|
||||||
).to.be.true;
|
// req.db.getMonitorById.returns({ url: "https://example.com" });
|
||||||
});
|
// await monitorController.getMonitorCertificate(req, res, next);
|
||||||
});
|
// expect(next.firstCall.args[0]).to.be.an("error");
|
||||||
|
// expect(next.firstCall.args[0].message).to.equal("SSL checker error");
|
||||||
|
// });
|
||||||
|
// it("should return success message and data if all operations succeed", async () => {
|
||||||
|
// req.db.getMonitorById.returns({ url: "https://example.com" });
|
||||||
|
// const certificate = { validTo: 1 };
|
||||||
|
// sslCheckerStub.returns(certificate);
|
||||||
|
// await getMonitorCertificate(req, res, next);
|
||||||
|
// expect(res.status.firstCall.args[0]).to.equal(200);
|
||||||
|
// expect(
|
||||||
|
// res.json.calledOnceWith({
|
||||||
|
// success: true,
|
||||||
|
// msg: successMessages.MONITOR_CERTIFICATE,
|
||||||
|
// data: {
|
||||||
|
// certificateDate: new Date(certificate.validTo).toLocaleDateString(),
|
||||||
|
// },
|
||||||
|
// })
|
||||||
|
// ).to.be.true;
|
||||||
|
// });
|
||||||
|
// it("should return success message and N/A if certificate is not found", async () => {
|
||||||
|
// req.db.getMonitorById.returns({ url: "https://example.com" });
|
||||||
|
// // sslCheckerStub.returns(null);
|
||||||
|
// await getMonitorCertificate(req, res, next);
|
||||||
|
// expect(res.status.firstCall.args[0]).to.equal(200);
|
||||||
|
// expect(
|
||||||
|
// res.json.calledOnceWith({
|
||||||
|
// success: true,
|
||||||
|
// msg: successMessages.MONITOR_CERTIFICATE,
|
||||||
|
// data: {
|
||||||
|
// certificateDate: "N/A",
|
||||||
|
// },
|
||||||
|
// })
|
||||||
|
// ).to.be.true;
|
||||||
|
// });
|
||||||
|
|
||||||
|
// it("should return success message and N/A if certificate doesn't have validTo", async () => {
|
||||||
|
// req.db.getMonitorById.returns({ url: "https://example.com" });
|
||||||
|
// // sslCheckerStub.returns({ valid: 1 });
|
||||||
|
// await getMonitorCertificate(req, res, next);
|
||||||
|
// expect(res.status.firstCall.args[0]).to.equal(200);
|
||||||
|
// expect(
|
||||||
|
// res.json.calledOnceWith({
|
||||||
|
// success: true,
|
||||||
|
// msg: successMessages.MONITOR_CERTIFICATE,
|
||||||
|
// data: {
|
||||||
|
// certificateDate: "N/A",
|
||||||
|
// },
|
||||||
|
// })
|
||||||
|
// ).to.be.true;
|
||||||
|
// });
|
||||||
|
// });
|
||||||
|
|
||||||
describe("Monitor Controller - getMonitorById", () => {
|
describe("Monitor Controller - getMonitorById", () => {
|
||||||
|
let req, res, next;
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
req = {
|
req = {
|
||||||
params: {
|
params: {
|
||||||
@@ -270,6 +269,7 @@ describe("Monitor Controller - getMonitorById", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("Monitor Controller - getMonitorsAndSummaryByTeamId", () => {
|
describe("Monitor Controller - getMonitorsAndSummaryByTeamId", () => {
|
||||||
|
let req, res, next;
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
req = {
|
req = {
|
||||||
params: {
|
params: {
|
||||||
@@ -325,6 +325,7 @@ describe("Monitor Controller - getMonitorsAndSummaryByTeamId", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("Monitor Controller - getMonitorsByTeamId", () => {
|
describe("Monitor Controller - getMonitorsByTeamId", () => {
|
||||||
|
let req, res, next;
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
req = {
|
req = {
|
||||||
params: {
|
params: {
|
||||||
@@ -379,6 +380,7 @@ describe("Monitor Controller - getMonitorsByTeamId", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("Monitor Controller - createMonitor", () => {
|
describe("Monitor Controller - createMonitor", () => {
|
||||||
|
let req, res, next;
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
req = {
|
req = {
|
||||||
params: {},
|
params: {},
|
||||||
@@ -474,6 +476,7 @@ describe("Monitor Controller - createMonitor", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("Monitor Controller - deleteMonitor", () => {
|
describe("Monitor Controller - deleteMonitor", () => {
|
||||||
|
let req, res, next;
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
req = {
|
req = {
|
||||||
params: {
|
params: {
|
||||||
@@ -518,7 +521,7 @@ describe("Monitor Controller - deleteMonitor", () => {
|
|||||||
const monitor = { name: "test_monitor", _id: "123" };
|
const monitor = { name: "test_monitor", _id: "123" };
|
||||||
req.db.deleteMonitor.returns(monitor);
|
req.db.deleteMonitor.returns(monitor);
|
||||||
req.jobQueue.deleteJob.rejects(error);
|
req.jobQueue.deleteJob.rejects(error);
|
||||||
await monitorController.deleteMonitor(req, res, next);
|
await deleteMonitor(req, res, next);
|
||||||
expect(logger.error.calledOnce).to.be.true;
|
expect(logger.error.calledOnce).to.be.true;
|
||||||
expect(logger.error.firstCall.args[0]).to.equal(
|
expect(logger.error.firstCall.args[0]).to.equal(
|
||||||
`Error deleting associated records for monitor ${monitor._id} with name ${monitor.name}`
|
`Error deleting associated records for monitor ${monitor._id} with name ${monitor.name}`
|
||||||
@@ -534,7 +537,7 @@ describe("Monitor Controller - deleteMonitor", () => {
|
|||||||
const monitor = { name: "test_monitor", _id: "123" };
|
const monitor = { name: "test_monitor", _id: "123" };
|
||||||
req.db.deleteMonitor.returns(monitor);
|
req.db.deleteMonitor.returns(monitor);
|
||||||
req.db.deleteChecks.rejects(error);
|
req.db.deleteChecks.rejects(error);
|
||||||
await monitorController.deleteMonitor(req, res, next);
|
await deleteMonitor(req, res, next);
|
||||||
expect(logger.error.calledOnce).to.be.true;
|
expect(logger.error.calledOnce).to.be.true;
|
||||||
expect(logger.error.firstCall.args[0]).to.equal(
|
expect(logger.error.firstCall.args[0]).to.equal(
|
||||||
`Error deleting associated records for monitor ${monitor._id} with name ${monitor.name}`
|
`Error deleting associated records for monitor ${monitor._id} with name ${monitor.name}`
|
||||||
@@ -550,7 +553,7 @@ describe("Monitor Controller - deleteMonitor", () => {
|
|||||||
const monitor = { name: "test_monitor", _id: "123" };
|
const monitor = { name: "test_monitor", _id: "123" };
|
||||||
req.db.deleteMonitor.returns(monitor);
|
req.db.deleteMonitor.returns(monitor);
|
||||||
req.db.deletePageSpeedChecksByMonitorId.rejects(error);
|
req.db.deletePageSpeedChecksByMonitorId.rejects(error);
|
||||||
await monitorController.deleteMonitor(req, res, next);
|
await deleteMonitor(req, res, next);
|
||||||
expect(logger.error.calledOnce).to.be.true;
|
expect(logger.error.calledOnce).to.be.true;
|
||||||
expect(logger.error.firstCall.args[0]).to.equal(
|
expect(logger.error.firstCall.args[0]).to.equal(
|
||||||
`Error deleting associated records for monitor ${monitor._id} with name ${monitor.name}`
|
`Error deleting associated records for monitor ${monitor._id} with name ${monitor.name}`
|
||||||
@@ -566,7 +569,7 @@ describe("Monitor Controller - deleteMonitor", () => {
|
|||||||
const monitor = { name: "test_monitor", _id: "123" };
|
const monitor = { name: "test_monitor", _id: "123" };
|
||||||
req.db.deleteMonitor.returns(monitor);
|
req.db.deleteMonitor.returns(monitor);
|
||||||
req.db.deleteNotificationsByMonitorId.rejects(error);
|
req.db.deleteNotificationsByMonitorId.rejects(error);
|
||||||
await monitorController.deleteMonitor(req, res, next);
|
await deleteMonitor(req, res, next);
|
||||||
expect(logger.error.calledOnce).to.be.true;
|
expect(logger.error.calledOnce).to.be.true;
|
||||||
expect(logger.error.firstCall.args[0]).to.equal(
|
expect(logger.error.firstCall.args[0]).to.equal(
|
||||||
`Error deleting associated records for monitor ${monitor._id} with name ${monitor.name}`
|
`Error deleting associated records for monitor ${monitor._id} with name ${monitor.name}`
|
||||||
@@ -580,7 +583,7 @@ describe("Monitor Controller - deleteMonitor", () => {
|
|||||||
it("should return success message if all operations succeed", async () => {
|
it("should return success message if all operations succeed", async () => {
|
||||||
const monitor = { name: "test_monitor", _id: "123" };
|
const monitor = { name: "test_monitor", _id: "123" };
|
||||||
req.db.deleteMonitor.returns(monitor);
|
req.db.deleteMonitor.returns(monitor);
|
||||||
await monitorController.deleteMonitor(req, res, next);
|
await deleteMonitor(req, res, next);
|
||||||
expect(res.status.firstCall.args[0]).to.equal(200);
|
expect(res.status.firstCall.args[0]).to.equal(200);
|
||||||
expect(
|
expect(
|
||||||
res.json.calledOnceWith({
|
res.json.calledOnceWith({
|
||||||
@@ -592,6 +595,7 @@ describe("Monitor Controller - deleteMonitor", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("Monitor Controller - deleteAllMonitors", () => {
|
describe("Monitor Controller - deleteAllMonitors", () => {
|
||||||
|
let req, res, next, stub;
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
stub = sinon.stub(jwt, "verify").callsFake(() => {
|
stub = sinon.stub(jwt, "verify").callsFake(() => {
|
||||||
return { teamId: "123" };
|
return { teamId: "123" };
|
||||||
@@ -700,6 +704,7 @@ describe("Monitor Controller - deleteAllMonitors", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("Monitor Controller - editMonitor", () => {
|
describe("Monitor Controller - editMonitor", () => {
|
||||||
|
let req, res, next;
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
req = {
|
req = {
|
||||||
headers: {},
|
headers: {},
|
||||||
@@ -822,6 +827,7 @@ describe("Monitor Controller - editMonitor", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("Monitor Controller - pauseMonitor", () => {
|
describe("Monitor Controller - pauseMonitor", () => {
|
||||||
|
let req, res, next;
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
req = {
|
req = {
|
||||||
headers: {},
|
headers: {},
|
||||||
@@ -928,6 +934,7 @@ describe("Monitor Controller - pauseMonitor", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("Monitor Controller - addDemoMonitors", () => {
|
describe("Monitor Controller - addDemoMonitors", () => {
|
||||||
|
let req, res, next, stub;
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
stub = sinon.stub(jwt, "verify").callsFake(() => {
|
stub = sinon.stub(jwt, "verify").callsFake(() => {
|
||||||
return { _id: "123", teamId: "123" };
|
return { _id: "123", teamId: "123" };
|
||||||
|
|||||||
@@ -1,16 +1,15 @@
|
|||||||
const { afterEach } = require("node:test");
|
import { afterEach } from "node:test";
|
||||||
const {
|
import {
|
||||||
getMetrics,
|
getMetrics,
|
||||||
getJobs,
|
getJobs,
|
||||||
addJob,
|
addJob,
|
||||||
obliterateQueue,
|
obliterateQueue,
|
||||||
} = require("../../controllers/queueController");
|
} from "../../controllers/queueController.js";
|
||||||
const SERVICE_NAME = "JobQueueController";
|
import { successMessages } from "../../utils/messages.js";
|
||||||
|
import sinon from "sinon";
|
||||||
const { errorMessages, successMessages } = require("../../utils/messages");
|
|
||||||
const sinon = require("sinon");
|
|
||||||
|
|
||||||
describe("Queue Controller - getMetrics", () => {
|
describe("Queue Controller - getMetrics", () => {
|
||||||
|
let req, res, next;
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
req = {
|
req = {
|
||||||
headers: {},
|
headers: {},
|
||||||
@@ -26,7 +25,6 @@ describe("Queue Controller - getMetrics", () => {
|
|||||||
json: sinon.stub(),
|
json: sinon.stub(),
|
||||||
};
|
};
|
||||||
next = sinon.stub();
|
next = sinon.stub();
|
||||||
handleError = sinon.stub();
|
|
||||||
});
|
});
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
sinon.restore();
|
sinon.restore();
|
||||||
@@ -52,6 +50,7 @@ describe("Queue Controller - getMetrics", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("Queue Controller - getJobs", () => {
|
describe("Queue Controller - getJobs", () => {
|
||||||
|
let req, res, next;
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
req = {
|
req = {
|
||||||
headers: {},
|
headers: {},
|
||||||
@@ -67,7 +66,6 @@ describe("Queue Controller - getJobs", () => {
|
|||||||
json: sinon.stub(),
|
json: sinon.stub(),
|
||||||
};
|
};
|
||||||
next = sinon.stub();
|
next = sinon.stub();
|
||||||
handleError = sinon.stub();
|
|
||||||
});
|
});
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
sinon.restore();
|
sinon.restore();
|
||||||
@@ -92,6 +90,7 @@ describe("Queue Controller - getJobs", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("Queue Controller - addJob", () => {
|
describe("Queue Controller - addJob", () => {
|
||||||
|
let req, res, next;
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
req = {
|
req = {
|
||||||
headers: {},
|
headers: {},
|
||||||
@@ -107,7 +106,6 @@ describe("Queue Controller - addJob", () => {
|
|||||||
json: sinon.stub(),
|
json: sinon.stub(),
|
||||||
};
|
};
|
||||||
next = sinon.stub();
|
next = sinon.stub();
|
||||||
handleError = sinon.stub();
|
|
||||||
});
|
});
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
sinon.restore();
|
sinon.restore();
|
||||||
@@ -130,6 +128,7 @@ describe("Queue Controller - addJob", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("Queue Controller - obliterateQueue", () => {
|
describe("Queue Controller - obliterateQueue", () => {
|
||||||
|
let req, res, next;
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
req = {
|
req = {
|
||||||
headers: {},
|
headers: {},
|
||||||
@@ -145,7 +144,6 @@ describe("Queue Controller - obliterateQueue", () => {
|
|||||||
json: sinon.stub(),
|
json: sinon.stub(),
|
||||||
};
|
};
|
||||||
next = sinon.stub();
|
next = sinon.stub();
|
||||||
handleError = sinon.stub();
|
|
||||||
});
|
});
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
sinon.restore();
|
sinon.restore();
|
||||||
|
|||||||
@@ -1,13 +1,14 @@
|
|||||||
const { afterEach } = require("node:test");
|
import { afterEach } from "node:test";
|
||||||
const {
|
import {
|
||||||
getAppSettings,
|
getAppSettings,
|
||||||
updateAppSettings,
|
updateAppSettings,
|
||||||
} = require("../../controllers/settingsController");
|
} from "../../controllers/settingsController.js";
|
||||||
|
|
||||||
const { errorMessages, successMessages } = require("../../utils/messages");
|
import { successMessages } from "../../utils/messages.js";
|
||||||
const sinon = require("sinon");
|
import sinon from "sinon";
|
||||||
|
|
||||||
describe("Settings Controller - getAppSettings", () => {
|
describe("Settings Controller - getAppSettings", () => {
|
||||||
|
let req, res, next;
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
req = {
|
req = {
|
||||||
headers: {},
|
headers: {},
|
||||||
@@ -23,7 +24,6 @@ describe("Settings Controller - getAppSettings", () => {
|
|||||||
json: sinon.stub(),
|
json: sinon.stub(),
|
||||||
};
|
};
|
||||||
next = sinon.stub();
|
next = sinon.stub();
|
||||||
handleError = sinon.stub();
|
|
||||||
});
|
});
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
sinon.restore();
|
sinon.restore();
|
||||||
@@ -49,6 +49,7 @@ describe("Settings Controller - getAppSettings", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("Settings Controller - updateAppSettings", () => {
|
describe("Settings Controller - updateAppSettings", () => {
|
||||||
|
let req, res, next;
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
req = {
|
req = {
|
||||||
headers: {},
|
headers: {},
|
||||||
@@ -66,7 +67,6 @@ describe("Settings Controller - updateAppSettings", () => {
|
|||||||
json: sinon.stub(),
|
json: sinon.stub(),
|
||||||
};
|
};
|
||||||
next = sinon.stub();
|
next = sinon.stub();
|
||||||
handleError = sinon.stub();
|
|
||||||
});
|
});
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
sinon.restore();
|
sinon.restore();
|
||||||
|
|||||||
Reference in new issue
Block a user