format
This commit is contained in:
1 parent
846564a17e
commit
bfa6832beb
83 files changed
+338
-1249
No files matched your search
@@ -216,11 +216,7 @@ describe("checkModule", function () {
|
||||
const result = await getChecksCount(req);
|
||||
|
||||
expect(result).to.equal(4);
|
||||
expect(checkCountDocumentStub.firstCall.args[0]).to.have.all.keys(
|
||||
"monitorId",
|
||||
"createdAt",
|
||||
"status"
|
||||
);
|
||||
expect(checkCountDocumentStub.firstCall.args[0]).to.have.all.keys("monitorId", "createdAt", "status");
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -52,10 +52,7 @@ const mockMonitor = {
|
||||
};
|
||||
|
||||
describe("HardwareCheckModule", function () {
|
||||
let hardwareCheckSaveStub,
|
||||
hardwareCheckCountDocumentsStub,
|
||||
monitorFindByIdStub,
|
||||
loggerStub;
|
||||
let hardwareCheckSaveStub, hardwareCheckCountDocumentsStub, monitorFindByIdStub, loggerStub;
|
||||
|
||||
beforeEach(function () {
|
||||
loggerStub = sinon.stub(logger, "error");
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
import sinon from "sinon";
|
||||
import InviteToken from "../../db/models/InviteToken.js";
|
||||
import {
|
||||
requestInviteToken,
|
||||
getInviteToken,
|
||||
getInviteTokenAndDelete,
|
||||
} from "../../db/mongo/modules/inviteModule.js";
|
||||
import { requestInviteToken, getInviteToken, getInviteTokenAndDelete } from "../../db/mongo/modules/inviteModule.js";
|
||||
import { errorMessages } from "../../utils/messages.js";
|
||||
|
||||
describe("Invite Module", function () {
|
||||
@@ -15,10 +11,7 @@ describe("Invite Module", function () {
|
||||
token: "123",
|
||||
};
|
||||
const mockInviteToken = { _id: 123, time: 123 };
|
||||
let inviteTokenDeleteManyStub,
|
||||
inviteTokenSaveStub,
|
||||
inviteTokenFindOneStub,
|
||||
inviteTokenFindOneAndDeleteStub;
|
||||
let inviteTokenDeleteManyStub, inviteTokenSaveStub, inviteTokenFindOneStub, inviteTokenFindOneAndDeleteStub;
|
||||
|
||||
beforeEach(function () {
|
||||
inviteTokenDeleteManyStub = sinon.stub(InviteToken, "deleteMany");
|
||||
|
||||
@@ -40,15 +40,9 @@ describe("MaintenanceWindow Module", function () {
|
||||
}),
|
||||
}),
|
||||
});
|
||||
maintenanceWindowFindByIdAndDeleteStub = sinon.stub(
|
||||
MaintenanceWindow,
|
||||
"findByIdAndDelete"
|
||||
);
|
||||
maintenanceWindowFindByIdAndDeleteStub = sinon.stub(MaintenanceWindow, "findByIdAndDelete");
|
||||
maintenanceWindowDeleteManyStub = sinon.stub(MaintenanceWindow, "deleteMany");
|
||||
maintenanceWindowFindByIdAndUpdateStub = sinon.stub(
|
||||
MaintenanceWindow,
|
||||
"findByIdAndUpdate"
|
||||
);
|
||||
maintenanceWindowFindByIdAndUpdateStub = sinon.stub(MaintenanceWindow, "findByIdAndUpdate");
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
@@ -110,10 +104,7 @@ describe("MaintenanceWindow Module", function () {
|
||||
|
||||
it("should return a list of maintenance windows and count", async function () {
|
||||
maintenanceWindowCountDocumentsStub.resolves(1);
|
||||
const result = await getMaintenanceWindowsByTeamId(
|
||||
mockMaintenanceWindow.teamId,
|
||||
query
|
||||
);
|
||||
const result = await getMaintenanceWindowsByTeamId(mockMaintenanceWindow.teamId, query);
|
||||
expect(result).to.deep.equal({
|
||||
maintenanceWindows: mockMaintenanceWindows,
|
||||
maintenanceWindowCount: 1,
|
||||
@@ -123,10 +114,7 @@ describe("MaintenanceWindow Module", function () {
|
||||
it("should return a list of maintenance windows and count with empty query", async function () {
|
||||
query = undefined;
|
||||
maintenanceWindowCountDocumentsStub.resolves(1);
|
||||
const result = await getMaintenanceWindowsByTeamId(
|
||||
mockMaintenanceWindow.teamId,
|
||||
query
|
||||
);
|
||||
const result = await getMaintenanceWindowsByTeamId(mockMaintenanceWindow.teamId, query);
|
||||
expect(result).to.deep.equal({
|
||||
maintenanceWindows: mockMaintenanceWindows,
|
||||
maintenanceWindowCount: 1,
|
||||
@@ -137,10 +125,7 @@ describe("MaintenanceWindow Module", function () {
|
||||
query.page = undefined;
|
||||
query.rowsPerPage = undefined;
|
||||
maintenanceWindowCountDocumentsStub.resolves(1);
|
||||
const result = await getMaintenanceWindowsByTeamId(
|
||||
mockMaintenanceWindow.teamId,
|
||||
query
|
||||
);
|
||||
const result = await getMaintenanceWindowsByTeamId(mockMaintenanceWindow.teamId, query);
|
||||
expect(result).to.deep.equal({
|
||||
maintenanceWindows: mockMaintenanceWindows,
|
||||
maintenanceWindowCount: 1,
|
||||
@@ -150,10 +135,7 @@ describe("MaintenanceWindow Module", function () {
|
||||
it("should return a list of maintenance windows and count with field and desc order", async function () {
|
||||
query.order = "desc";
|
||||
maintenanceWindowCountDocumentsStub.resolves(1);
|
||||
const result = await getMaintenanceWindowsByTeamId(
|
||||
mockMaintenanceWindow.teamId,
|
||||
query
|
||||
);
|
||||
const result = await getMaintenanceWindowsByTeamId(mockMaintenanceWindow.teamId, query);
|
||||
expect(result).to.deep.equal({
|
||||
maintenanceWindows: mockMaintenanceWindows,
|
||||
maintenanceWindowCount: 1,
|
||||
@@ -163,10 +145,7 @@ describe("MaintenanceWindow Module", function () {
|
||||
it("should return a list of maintenance windows and count no field", async function () {
|
||||
query.field = undefined;
|
||||
maintenanceWindowCountDocumentsStub.resolves(1);
|
||||
const result = await getMaintenanceWindowsByTeamId(
|
||||
mockMaintenanceWindow.teamId,
|
||||
query
|
||||
);
|
||||
const result = await getMaintenanceWindowsByTeamId(mockMaintenanceWindow.teamId, query);
|
||||
expect(result).to.deep.equal({
|
||||
maintenanceWindows: mockMaintenanceWindows,
|
||||
maintenanceWindowCount: 1,
|
||||
@@ -187,9 +166,7 @@ describe("MaintenanceWindow Module", function () {
|
||||
describe("getMaintenanceWindowsByMonitorId", function () {
|
||||
it("should return a list of maintenance windows", async function () {
|
||||
maintenanceWindowFindStub.resolves(mockMaintenanceWindows);
|
||||
const result = await getMaintenanceWindowsByMonitorId(
|
||||
mockMaintenanceWindow.monitorId
|
||||
);
|
||||
const result = await getMaintenanceWindowsByMonitorId(mockMaintenanceWindow.monitorId);
|
||||
expect(result).to.deep.equal(mockMaintenanceWindows);
|
||||
});
|
||||
|
||||
@@ -225,9 +202,7 @@ describe("MaintenanceWindow Module", function () {
|
||||
describe("deleteMaintenanceWindowByMonitorId", function () {
|
||||
it("should return the number of documents deleted", async function () {
|
||||
maintenanceWindowDeleteManyStub.resolves({ deletedCount: 1 });
|
||||
const result = await deleteMaintenanceWindowByMonitorId(
|
||||
mockMaintenanceWindow.monitorId
|
||||
);
|
||||
const result = await deleteMaintenanceWindowByMonitorId(mockMaintenanceWindow.monitorId);
|
||||
expect(result).to.deep.equal({ deletedCount: 1 });
|
||||
});
|
||||
|
||||
@@ -263,10 +238,7 @@ describe("MaintenanceWindow Module", function () {
|
||||
describe("editMaintenanceWindowById", function () {
|
||||
it("should return the updated maintenance window", async function () {
|
||||
maintenanceWindowFindByIdAndUpdateStub.resolves(mockMaintenanceWindow);
|
||||
const result = await editMaintenanceWindowById(
|
||||
mockMaintenanceWindow.id,
|
||||
mockMaintenanceWindow
|
||||
);
|
||||
const result = await editMaintenanceWindowById(mockMaintenanceWindow.id, mockMaintenanceWindow);
|
||||
expect(result).to.deep.equal(mockMaintenanceWindow);
|
||||
});
|
||||
|
||||
|
||||
@@ -120,12 +120,7 @@ describe("monitorModule", function () {
|
||||
},
|
||||
];
|
||||
|
||||
const mockChecks = [
|
||||
{ status: true },
|
||||
{ status: true },
|
||||
{ status: false },
|
||||
{ status: true },
|
||||
];
|
||||
const mockChecks = [{ status: true }, { status: true }, { status: false }, { status: true }];
|
||||
|
||||
monitorFindStub.resolves(mockMonitors);
|
||||
checkFindStub.resolves(mockChecks);
|
||||
@@ -166,12 +161,7 @@ describe("monitorModule", function () {
|
||||
},
|
||||
];
|
||||
|
||||
const mockChecks = [
|
||||
{ status: true },
|
||||
{ status: true },
|
||||
{ status: false },
|
||||
{ status: true },
|
||||
];
|
||||
const mockChecks = [{ status: true }, { status: true }, { status: false }, { status: true }];
|
||||
|
||||
monitorFindStub.resolves(mockMonitors);
|
||||
pageSpeedCheckFindStub.resolves(mockChecks);
|
||||
@@ -212,12 +202,7 @@ describe("monitorModule", function () {
|
||||
},
|
||||
];
|
||||
|
||||
const mockChecks = [
|
||||
{ status: true },
|
||||
{ status: true },
|
||||
{ status: false },
|
||||
{ status: true },
|
||||
];
|
||||
const mockChecks = [{ status: true }, { status: true }, { status: false }, { status: true }];
|
||||
|
||||
monitorFindStub.resolves(mockMonitors);
|
||||
hardwareCheckFindStub.resolves(mockChecks);
|
||||
@@ -400,10 +385,7 @@ describe("monitorModule", function () {
|
||||
});
|
||||
|
||||
it("should handle missing responseTime in checks", function () {
|
||||
const checks = [
|
||||
{ createdAt: "2024-01-01T11:30:00Z" },
|
||||
{ responseTime: 200, createdAt: "2024-01-01T11:00:00Z" },
|
||||
];
|
||||
const checks = [{ createdAt: "2024-01-01T11:30:00Z" }, { responseTime: 200, createdAt: "2024-01-01T11:00:00Z" }];
|
||||
|
||||
expect(getLatestResponseTime(checks)).to.equal(0);
|
||||
});
|
||||
@@ -441,10 +423,7 @@ describe("monitorModule", function () {
|
||||
});
|
||||
|
||||
it("should return 0 when no checks have responseTime", function () {
|
||||
const checks = [
|
||||
{ createdAt: "2024-01-01T11:30:00Z" },
|
||||
{ createdAt: "2024-01-01T11:00:00Z" },
|
||||
];
|
||||
const checks = [{ createdAt: "2024-01-01T11:30:00Z" }, { createdAt: "2024-01-01T11:00:00Z" }];
|
||||
|
||||
expect(getAverageResponseTime(checks)).to.equal(0);
|
||||
});
|
||||
@@ -470,12 +449,7 @@ describe("monitorModule", function () {
|
||||
});
|
||||
|
||||
it("should calculate correct percentage for mixed status checks", function () {
|
||||
const checks = [
|
||||
{ status: true },
|
||||
{ status: false },
|
||||
{ status: true },
|
||||
{ status: true },
|
||||
];
|
||||
const checks = [{ status: true }, { status: false }, { status: true }, { status: true }];
|
||||
// 3 up out of 4 total = 75%
|
||||
expect(getUptimePercentage(checks)).to.equal(75);
|
||||
});
|
||||
@@ -507,23 +481,12 @@ describe("monitorModule", function () {
|
||||
});
|
||||
|
||||
it("should count correct number of incidents for mixed status checks", function () {
|
||||
const checks = [
|
||||
{ status: true },
|
||||
{ status: false },
|
||||
{ status: true },
|
||||
{ status: false },
|
||||
{ status: true },
|
||||
];
|
||||
const checks = [{ status: true }, { status: false }, { status: true }, { status: false }, { status: true }];
|
||||
expect(getIncidents(checks)).to.equal(2);
|
||||
});
|
||||
|
||||
it("should handle undefined status values", function () {
|
||||
const checks = [
|
||||
{ status: true },
|
||||
{ status: undefined },
|
||||
{ status: false },
|
||||
{ status: false },
|
||||
];
|
||||
const checks = [{ status: true }, { status: undefined }, { status: false }, { status: false }];
|
||||
// Only counts explicit false values
|
||||
expect(getIncidents(checks)).to.equal(2);
|
||||
});
|
||||
@@ -628,12 +591,8 @@ describe("monitorModule", function () {
|
||||
);
|
||||
|
||||
// Assert
|
||||
expect(result.checksAll[0].createdAt).to.be.greaterThan(
|
||||
result.checksAll[1].createdAt
|
||||
);
|
||||
expect(result.checksForDateRange[0].createdAt).to.be.greaterThan(
|
||||
result.checksForDateRange[1].createdAt
|
||||
);
|
||||
expect(result.checksAll[0].createdAt).to.be.greaterThan(result.checksAll[1].createdAt);
|
||||
expect(result.checksForDateRange[0].createdAt).to.be.greaterThan(result.checksForDateRange[1].createdAt);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -753,10 +712,7 @@ describe("monitorModule", function () {
|
||||
});
|
||||
|
||||
it("should handle checks in same time group", function () {
|
||||
const checksInSameHour = [
|
||||
{ createdAt: "2024-01-15T10:15:00Z" },
|
||||
{ createdAt: "2024-01-15T10:45:00Z" },
|
||||
];
|
||||
const checksInSameHour = [{ createdAt: "2024-01-15T10:15:00Z" }, { createdAt: "2024-01-15T10:45:00Z" }];
|
||||
|
||||
const result = groupChecksByTime(checksInSameHour, "day");
|
||||
|
||||
@@ -816,11 +772,7 @@ describe("monitorModule", function () {
|
||||
it("should handle missing responseTime values", function () {
|
||||
const mockGroup = {
|
||||
time: "2024-01-15",
|
||||
checks: [
|
||||
{ status: true },
|
||||
{ status: false, responseTime: 200 },
|
||||
{ status: true, responseTime: undefined },
|
||||
],
|
||||
checks: [{ status: true }, { status: false, responseTime: 200 }, { status: true, responseTime: undefined }],
|
||||
};
|
||||
|
||||
const result = calculateGroupStats(mockGroup, uptimePercentageStub);
|
||||
@@ -1413,10 +1365,7 @@ describe("monitorModule", function () {
|
||||
|
||||
expect(Monitor.find.firstCall.args[0]).to.deep.equal({
|
||||
teamId: "team123",
|
||||
$or: [
|
||||
{ name: { $regex: "search", $options: "i" } },
|
||||
{ url: { $regex: "search", $options: "i" } },
|
||||
],
|
||||
$or: [{ name: { $regex: "search", $options: "i" } }, { url: { $regex: "search", $options: "i" } }],
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1816,14 +1765,9 @@ describe("monitorModule", function () {
|
||||
|
||||
// Assert
|
||||
expect(result).to.deep.equal(mockUpdatedMonitor);
|
||||
sinon.assert.calledWith(
|
||||
monitorFindByIdAndUpdateStub,
|
||||
candidateId,
|
||||
expectedUpdateData,
|
||||
{
|
||||
new: true,
|
||||
}
|
||||
);
|
||||
sinon.assert.calledWith(monitorFindByIdAndUpdateStub, candidateId, expectedUpdateData, {
|
||||
new: true,
|
||||
});
|
||||
});
|
||||
|
||||
it("should return null when monitor not found", async function () {
|
||||
@@ -1840,12 +1784,7 @@ describe("monitorModule", function () {
|
||||
|
||||
// Assert
|
||||
expect(result).to.be.null;
|
||||
sinon.assert.calledWith(
|
||||
monitorFindByIdAndUpdateStub,
|
||||
candidateId,
|
||||
{ name: "Updated Monitor", notifications: undefined },
|
||||
{ new: true }
|
||||
);
|
||||
sinon.assert.calledWith(monitorFindByIdAndUpdateStub, candidateId, { name: "Updated Monitor", notifications: undefined }, { new: true });
|
||||
});
|
||||
|
||||
it("should remove notifications from update data", async function () {
|
||||
@@ -1870,14 +1809,9 @@ describe("monitorModule", function () {
|
||||
await editMonitor(candidateId, candidateMonitor);
|
||||
|
||||
// Assert
|
||||
sinon.assert.calledWith(
|
||||
monitorFindByIdAndUpdateStub,
|
||||
candidateId,
|
||||
expectedUpdateData,
|
||||
{
|
||||
new: true,
|
||||
}
|
||||
);
|
||||
sinon.assert.calledWith(monitorFindByIdAndUpdateStub, candidateId, expectedUpdateData, {
|
||||
new: true,
|
||||
});
|
||||
});
|
||||
|
||||
it("should handle database errors", async function () {
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
import sinon from "sinon";
|
||||
import Notification from "../../db/models/Notification.js";
|
||||
import {
|
||||
createNotification,
|
||||
getNotificationsByMonitorId,
|
||||
deleteNotificationsByMonitorId,
|
||||
} from "../../db/mongo/modules/notificationModule.js";
|
||||
import { createNotification, getNotificationsByMonitorId, deleteNotificationsByMonitorId } from "../../db/mongo/modules/notificationModule.js";
|
||||
|
||||
describe("notificationModule", function () {
|
||||
const mockNotification = {
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
import sinon from "sinon";
|
||||
import PageSpeedCheck from "../../db/models/PageSpeedCheck.js";
|
||||
import {
|
||||
createPageSpeedCheck,
|
||||
deletePageSpeedChecksByMonitorId,
|
||||
} from "../../db/mongo/modules/pageSpeedCheckModule.js";
|
||||
import { createPageSpeedCheck, deletePageSpeedChecksByMonitorId } from "../../db/mongo/modules/pageSpeedCheckModule.js";
|
||||
|
||||
const mockPageSpeedCheck = {
|
||||
monitorId: "monitorId",
|
||||
|
||||
@@ -1,11 +1,7 @@
|
||||
import sinon from "sinon";
|
||||
import RecoveryToken from "../../db/models/RecoveryToken.js";
|
||||
import User from "../../db/models/User.js";
|
||||
import {
|
||||
requestRecoveryToken,
|
||||
validateRecoveryToken,
|
||||
resetPassword,
|
||||
} from "../../db/mongo/modules/recoveryModule.js";
|
||||
import { requestRecoveryToken, validateRecoveryToken, resetPassword } from "../../db/mongo/modules/recoveryModule.js";
|
||||
import { errorMessages } from "../../utils/messages.js";
|
||||
|
||||
const mockRecoveryToken = {
|
||||
@@ -44,12 +40,7 @@ const createQueryChain = (finalResult, comparePasswordResult = false) => ({
|
||||
});
|
||||
|
||||
describe("recoveryModule", function () {
|
||||
let deleteManyStub,
|
||||
saveStub,
|
||||
findOneStub,
|
||||
userCompareStub,
|
||||
userSaveStub,
|
||||
userFindOneStub;
|
||||
let deleteManyStub, saveStub, findOneStub, userCompareStub, userSaveStub, userFindOneStub;
|
||||
let req, res;
|
||||
|
||||
beforeEach(function () {
|
||||
@@ -153,9 +144,7 @@ describe("recoveryModule", function () {
|
||||
it("should throw an error if the passwords match", async function () {
|
||||
findOneStub.resolves(mockRecoveryToken);
|
||||
saveStub.resolves();
|
||||
userFindOneStub = sinon
|
||||
.stub(User, "findOne")
|
||||
.returns(createQueryChain(mockUser, true));
|
||||
userFindOneStub = sinon.stub(User, "findOne").returns(createQueryChain(mockUser, true));
|
||||
try {
|
||||
await resetPassword(req, res);
|
||||
} catch (error) {
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
import sinon from "sinon";
|
||||
import {
|
||||
getAppSettings,
|
||||
updateAppSettings,
|
||||
} from "../../db/mongo/modules/settingsModule.js";
|
||||
import { getAppSettings, updateAppSettings } from "../../db/mongo/modules/settingsModule.js";
|
||||
import AppSettings from "../../db/models/AppSettings.js";
|
||||
|
||||
const mockAppSettings = {
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
import sinon from "sinon";
|
||||
import {
|
||||
createStatusPage,
|
||||
getStatusPageByUrl,
|
||||
} from "../../db/mongo/modules/statusPageModule.js";
|
||||
import { createStatusPage, getStatusPageByUrl } from "../../db/mongo/modules/statusPageModule.js";
|
||||
import StatusPage from "../../db/models/StatusPage.js";
|
||||
import { errorMessages } from "../../utils/messages.js";
|
||||
|
||||
|
||||
@@ -157,12 +157,7 @@ describe("userModule", function () {
|
||||
select: sinon.stub().resolves(mockUser),
|
||||
}),
|
||||
});
|
||||
const result = await updateUser(
|
||||
req,
|
||||
res,
|
||||
parseBooleanStub,
|
||||
generateAvatarImageStub
|
||||
);
|
||||
const result = await updateUser(req, res, parseBooleanStub, generateAvatarImageStub);
|
||||
expect(result).to.deep.equal(mockUser);
|
||||
});
|
||||
|
||||
@@ -173,12 +168,7 @@ describe("userModule", function () {
|
||||
select: sinon.stub().resolves(mockUser),
|
||||
}),
|
||||
});
|
||||
const result = await updateUser(
|
||||
req,
|
||||
res,
|
||||
parseBooleanStub,
|
||||
generateAvatarImageStub
|
||||
);
|
||||
const result = await updateUser(req, res, parseBooleanStub, generateAvatarImageStub);
|
||||
expect(result).to.deep.equal(mockUser);
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user