fix(test): Use 'npm run lint-fix' to fix 'mocha/no-mocha-arrows' like lint warnings

- ref: https://mochajs.org/#arrow-functions
This commit is contained in:
Mert Şişmanoğlu committed 2024-12-29 14:25:59 +03:00
1 parent 319e6d6017
commit fcda60fe5b
31 files changed
+1268 -907

No files matched your search

+49 -33
View File
@@ -11,7 +11,7 @@ import {
editMaintenanceWindowById,
} from "../../db/mongo/modules/maintenanceWindowModule.js";
describe("MaintenanceWindow Module", () => {
describe("MaintenanceWindow Module", function() {
const mockMaintenanceWindow = {
monitorId: "123",
active: true,
@@ -29,7 +29,7 @@ describe("MaintenanceWindow Module", () => {
maintenanceWindowDeleteManyStub,
maintenanceWindowFindByIdAndUpdateStub;
beforeEach(() => {
beforeEach(function() {
maintenanceWindowSaveStub = sinon.stub(MaintenanceWindow.prototype, "save");
maintenanceWindowFindByIdStub = sinon.stub(MaintenanceWindow, "findById");
maintenanceWindowCountDocumentsStub = sinon.stub(MaintenanceWindow, "countDocuments");
@@ -51,18 +51,18 @@ describe("MaintenanceWindow Module", () => {
);
});
afterEach(() => {
afterEach(function() {
sinon.restore();
});
describe("createMaintenanceWindow", () => {
it("should save a new maintenance window", async () => {
describe("createMaintenanceWindow", function() {
it("should save a new maintenance window", async function() {
maintenanceWindowSaveStub.resolves(mockMaintenanceWindow);
const result = await createMaintenanceWindow(mockMaintenanceWindow);
expect(result).to.deep.equal(mockMaintenanceWindow);
});
it("should handle an error", async () => {
it("should handle an error", async function() {
const err = new Error("test error");
maintenanceWindowSaveStub.rejects(err);
try {
@@ -72,13 +72,15 @@ describe("MaintenanceWindow Module", () => {
}
});
});
describe("getMaintenanceWindowById", () => {
it("should return a maintenance window", async () => {
describe("getMaintenanceWindowById", function() {
it("should return a maintenance window", async function() {
maintenanceWindowFindByIdStub.resolves(mockMaintenanceWindow);
const result = await getMaintenanceWindowById(mockMaintenanceWindow.id);
expect(result).to.deep.equal(mockMaintenanceWindow);
});
it("should handle an error", async () => {
it("should handle an error", async function() {
const err = new Error("test error");
maintenanceWindowFindByIdStub.rejects(err);
try {
@@ -89,9 +91,10 @@ describe("MaintenanceWindow Module", () => {
});
});
describe("getMaintenanceWindowsByTeamId", () => {
describe("getMaintenanceWindowsByTeamId", function() {
let query;
beforeEach(() => {
beforeEach(function() {
query = {
active: true,
page: 1,
@@ -101,11 +104,11 @@ describe("MaintenanceWindow Module", () => {
};
});
afterEach(() => {
afterEach(function() {
sinon.restore();
});
it("should return a list of maintenance windows and count", async () => {
it("should return a list of maintenance windows and count", async function() {
maintenanceWindowCountDocumentsStub.resolves(1);
const result = await getMaintenanceWindowsByTeamId(
mockMaintenanceWindow.teamId,
@@ -116,7 +119,8 @@ describe("MaintenanceWindow Module", () => {
maintenanceWindowCount: 1,
});
});
it("should return a list of maintenance windows and count with empty query", async () => {
it("should return a list of maintenance windows and count with empty query", async function() {
query = undefined;
maintenanceWindowCountDocumentsStub.resolves(1);
const result = await getMaintenanceWindowsByTeamId(
@@ -128,7 +132,8 @@ describe("MaintenanceWindow Module", () => {
maintenanceWindowCount: 1,
});
});
it("should return a list of maintenance windows and count with no pagination provided", async () => {
it("should return a list of maintenance windows and count with no pagination provided", async function() {
query.page = undefined;
query.rowsPerPage = undefined;
maintenanceWindowCountDocumentsStub.resolves(1);
@@ -141,7 +146,8 @@ describe("MaintenanceWindow Module", () => {
maintenanceWindowCount: 1,
});
});
it("should return a list of maintenance windows and count with field and desc order", async () => {
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(
@@ -153,7 +159,8 @@ describe("MaintenanceWindow Module", () => {
maintenanceWindowCount: 1,
});
});
it("should return a list of maintenance windows and count no field", async () => {
it("should return a list of maintenance windows and count no field", async function() {
query.field = undefined;
maintenanceWindowCountDocumentsStub.resolves(1);
const result = await getMaintenanceWindowsByTeamId(
@@ -165,7 +172,8 @@ describe("MaintenanceWindow Module", () => {
maintenanceWindowCount: 1,
});
});
it("should handle an error", async () => {
it("should handle an error", async function() {
const err = new Error("test error");
maintenanceWindowCountDocumentsStub.rejects(err);
try {
@@ -175,15 +183,17 @@ describe("MaintenanceWindow Module", () => {
}
});
});
describe("getMaintenanceWindowsByMonitorId", () => {
it("should return a list of maintenance windows", async () => {
describe("getMaintenanceWindowsByMonitorId", function() {
it("should return a list of maintenance windows", async function() {
maintenanceWindowFindStub.resolves(mockMaintenanceWindows);
const result = await getMaintenanceWindowsByMonitorId(
mockMaintenanceWindow.monitorId
);
expect(result).to.deep.equal(mockMaintenanceWindows);
});
it("should handle an error", async () => {
it("should handle an error", async function() {
const err = new Error("test error");
maintenanceWindowFindStub.rejects(err);
try {
@@ -193,13 +203,15 @@ describe("MaintenanceWindow Module", () => {
}
});
});
describe("deleteMaintenanceWindowById", () => {
it("should delete a maintenance window", async () => {
describe("deleteMaintenanceWindowById", function() {
it("should delete a maintenance window", async function() {
maintenanceWindowFindByIdAndDeleteStub.resolves(mockMaintenanceWindow);
const result = await deleteMaintenanceWindowById(mockMaintenanceWindow.id);
expect(result).to.deep.equal(mockMaintenanceWindow);
});
it("should handle an error", async () => {
it("should handle an error", async function() {
const err = new Error("test error");
maintenanceWindowFindByIdAndDeleteStub.rejects(err);
try {
@@ -210,15 +222,16 @@ describe("MaintenanceWindow Module", () => {
});
});
describe("deleteMaintenanceWindowByMonitorId", () => {
it("should return the number of documents deleted", async () => {
describe("deleteMaintenanceWindowByMonitorId", function() {
it("should return the number of documents deleted", async function() {
maintenanceWindowDeleteManyStub.resolves({ deletedCount: 1 });
const result = await deleteMaintenanceWindowByMonitorId(
mockMaintenanceWindow.monitorId
);
expect(result).to.deep.equal({ deletedCount: 1 });
});
it("should handle an error", async () => {
it("should handle an error", async function() {
const err = new Error("test error");
maintenanceWindowDeleteManyStub.rejects(err);
try {
@@ -229,13 +242,14 @@ describe("MaintenanceWindow Module", () => {
});
});
describe("deleteMaintenanceWindowByUserId", () => {
it("should return the number of documents deleted", async () => {
describe("deleteMaintenanceWindowByUserId", function() {
it("should return the number of documents deleted", async function() {
maintenanceWindowDeleteManyStub.resolves({ deletedCount: 1 });
const result = await deleteMaintenanceWindowByUserId(mockMaintenanceWindow.userId);
expect(result).to.deep.equal({ deletedCount: 1 });
});
it("should handle an error", async () => {
it("should handle an error", async function() {
const err = new Error("test error");
maintenanceWindowDeleteManyStub.rejects(err);
try {
@@ -245,8 +259,9 @@ describe("MaintenanceWindow Module", () => {
}
});
});
describe("editMaintenanceWindowById", () => {
it("should return the updated maintenance window", async () => {
describe("editMaintenanceWindowById", function() {
it("should return the updated maintenance window", async function() {
maintenanceWindowFindByIdAndUpdateStub.resolves(mockMaintenanceWindow);
const result = await editMaintenanceWindowById(
mockMaintenanceWindow.id,
@@ -254,7 +269,8 @@ describe("MaintenanceWindow Module", () => {
);
expect(result).to.deep.equal(mockMaintenanceWindow);
});
it("should handle an error", async () => {
it("should handle an error", async function() {
const err = new Error("test error");
maintenanceWindowFindByIdAndUpdateStub.rejects(err);
try {