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

+6 -6
View File
@@ -1,8 +1,8 @@
import { NormalizeData, calculatePercentile } from "../../utils/dataUtils.js";
import sinon from "sinon";
describe("NormalizeData", () => {
it("should normalize response times when checks length is greater than 1", () => {
describe("NormalizeData", function() {
it("should normalize response times when checks length is greater than 1", function() {
const checks = [
{ responseTime: 20, _doc: { id: 1 } },
{ responseTime: 40, _doc: { id: 2 } },
@@ -21,7 +21,7 @@ describe("NormalizeData", () => {
});
});
it("should return checks with original response times when checks length is 1", () => {
it("should return checks with original response times when checks length is 1", function() {
const checks = [{ responseTime: 20, _doc: { id: 1 } }];
const rangeMin = 1;
const rangeMax = 100;
@@ -32,7 +32,7 @@ describe("NormalizeData", () => {
expect(result[0]).to.have.property("originalResponseTime", 20);
});
it("should handle edge cases with extreme response times", () => {
it("should handle edge cases with extreme response times", function() {
const checks = [
{ responseTime: 5, _doc: { id: 1 } },
{ responseTime: 95, _doc: { id: 2 } },
@@ -49,8 +49,8 @@ describe("NormalizeData", () => {
});
});
describe("calculatePercentile", () => {
it("should return the lower value when upper is greater than or equal to the length of the sorted array", () => {
describe("calculatePercentile", function() {
it("should return the lower value when upper is greater than or equal to the length of the sorted array", function() {
const checks = [
{ responseTime: 10 },
{ responseTime: 20 },
+3 -3
View File
@@ -3,8 +3,8 @@ import sinon from "sinon";
import sharp from "sharp";
import { GenerateAvatarImage } from "../../utils/imageProcessing.js";
describe("imageProcessing - GenerateAvatarImage", () => {
it("should resize the image to 64x64 and return a base64 string", async () => {
describe("imageProcessing - GenerateAvatarImage", function() {
it("should resize the image to 64x64 and return a base64 string", async function() {
const file = {
buffer: Buffer.from("test image buffer"),
};
@@ -30,7 +30,7 @@ describe("imageProcessing - GenerateAvatarImage", () => {
sharpStub.restore();
});
it("should throw an error if resizing fails", async () => {
it("should throw an error if resizing fails", async function() {
const file = {
buffer: Buffer.from("test image buffer"),
};
+11 -10
View File
@@ -3,20 +3,20 @@ import logger from "../../utils/logger.js";
import { Logger } from "../../utils/logger.js";
import winston from "winston";
describe("Logger", () => {
describe("Logger", function() {
let infoStub, warnStub, errorStub;
beforeEach(() => {
beforeEach(function() {
infoStub = sinon.stub(logger.logger, "info");
warnStub = sinon.stub(logger.logger, "warn");
errorStub = sinon.stub(logger.logger, "error");
});
afterEach(() => {
afterEach(function() {
sinon.restore();
});
describe("constructor", () => {
describe("constructor", function() {
let createLoggerStub;
beforeEach(function () {
@@ -46,6 +46,7 @@ describe("Logger", () => {
const logger = new Logger();
logger.logger.info(logMessage);
});
it("should convert details to JSON string if it is an object", function () {
const logDetails = { key: "value" };
const expectedDetails = JSON.stringify(logDetails, null, 2); // Removed .s
@@ -68,8 +69,8 @@ describe("Logger", () => {
});
});
describe("info", () => {
it("should log an informational message", () => {
describe("info", function() {
it("should log an informational message", function() {
const config = {
message: "Info message",
service: "TestService",
@@ -90,8 +91,8 @@ describe("Logger", () => {
});
});
describe("warn", () => {
it("should log a warning message", () => {
describe("warn", function() {
it("should log a warning message", function() {
const config = {
message: "Warning message",
service: "TestService",
@@ -112,8 +113,8 @@ describe("Logger", () => {
});
});
describe("error", () => {
it("should log an error message", () => {
describe("error", function() {
it("should log an error message", function() {
const config = {
message: "Error message",
service: "TestService",
+6 -6
View File
@@ -1,14 +1,14 @@
import { errorMessages, successMessages } from "../../utils/messages.js";
describe("Messages", () => {
describe("messages - errorMessages", () => {
it("should have a DB_FIND_MONITOR_BY_ID function", () => {
describe("Messages", function() {
describe("messages - errorMessages", function() {
it("should have a DB_FIND_MONITOR_BY_ID function", function() {
const monitorId = "12345";
expect(errorMessages.DB_FIND_MONITOR_BY_ID(monitorId)).to.equal(
`Monitor with id ${monitorId} not found`
);
});
it("should have a DB_DELETE_CHECKS function", () => {
it("should have a DB_DELETE_CHECKS function", function() {
const monitorId = "12345";
expect(errorMessages.DB_DELETE_CHECKS(monitorId)).to.equal(
`No checks found for monitor with id ${monitorId}`
@@ -16,8 +16,8 @@ describe("Messages", () => {
});
});
describe("messages - successMessages", () => {
it("should have a MONITOR_GET_BY_USER_ID function", () => {
describe("messages - successMessages", function() {
it("should have a MONITOR_GET_BY_USER_ID function", function() {
const userId = "12345";
expect(successMessages.MONITOR_GET_BY_USER_ID(userId)).to.equal(
`Got monitor for ${userId} successfully"`
+11 -11
View File
@@ -1,49 +1,49 @@
import { ParseBoolean, getTokenFromHeaders } from "../../utils/utils.js";
describe("utils - ParseBoolean", () => {
it("should return true", () => {
describe("utils - ParseBoolean", function() {
it("should return true", function() {
const result = ParseBoolean("true");
expect(result).to.be.true;
});
it("should return false", () => {
it("should return false", function() {
const result = ParseBoolean("false");
expect(result).to.be.false;
});
it("should return false", () => {
it("should return false", function() {
const result = ParseBoolean(null);
expect(result).to.be.false;
});
it("should return false", () => {
it("should return false", function() {
const result = ParseBoolean(undefined);
expect(result).to.be.false;
});
});
describe("utils - getTokenFromHeaders", () => {
it("should throw an error if authorization header is missing", () => {
describe("utils - getTokenFromHeaders", function() {
it("should throw an error if authorization header is missing", function() {
const headers = {};
expect(() => getTokenFromHeaders(headers)).to.throw("No auth headers");
});
it("should throw an error if authorization header does not start with Bearer", () => {
it("should throw an error if authorization header does not start with Bearer", function() {
const headers = { authorization: "Basic abcdef" };
expect(() => getTokenFromHeaders(headers)).to.throw("Invalid auth headers");
});
it("should return the token if authorization header is correctly formatted", () => {
it("should return the token if authorization header is correctly formatted", function() {
const headers = { authorization: "Bearer abcdef" };
expect(getTokenFromHeaders(headers)).to.equal("abcdef");
});
it("should throw an error if authorization header has more than two parts", () => {
it("should throw an error if authorization header has more than two parts", function() {
const headers = { authorization: "Bearer abc def" };
expect(() => getTokenFromHeaders(headers)).to.throw("Invalid auth headers");
});
it("should throw an error if authorization header has less than two parts", () => {
it("should throw an error if authorization header has less than two parts", function() {
const headers = { authorization: "Bearer" };
expect(() => getTokenFromHeaders(headers)).to.throw("Invalid auth headers");
});