add gitignore

This commit is contained in:
Alex Holliday committed 2025-09-22 12:53:44 -07:00
1 parent e4e75632c5
commit d8ed9abebf
49 files changed
+590 -9780

No files matched your search

-61
View File
@@ -1,61 +0,0 @@
import { NormalizeData, calculatePercentile } from "../../utils/dataUtils.js";
import sinon from "sinon";
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 } },
{ responseTime: 60, _doc: { id: 3 } },
];
const rangeMin = 1;
const rangeMax = 100;
const result = NormalizeData(checks, rangeMin, rangeMax);
expect(result).to.be.an("array");
expect(result).to.have.lengthOf(3);
result.forEach((check) => {
expect(check).to.have.property("responseTime").that.is.a("number");
expect(check).to.have.property("originalResponseTime").that.is.a("number");
});
});
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;
const result = NormalizeData(checks, rangeMin, rangeMax);
expect(result).to.be.an("array");
expect(result).to.have.lengthOf(1);
expect(result[0]).to.have.property("originalResponseTime", 20);
});
it("should handle edge cases with extreme response times", function () {
const checks = [
{ responseTime: 5, _doc: { id: 1 } },
{ responseTime: 95, _doc: { id: 2 } },
];
const rangeMin = 1;
const rangeMax = 100;
const result = NormalizeData(checks, rangeMin, rangeMax);
expect(result).to.be.an("array");
expect(result).to.have.lengthOf(2);
expect(result[0]).to.have.property("responseTime").that.is.at.least(rangeMin);
expect(result[1]).to.have.property("responseTime").that.is.at.most(rangeMax);
});
});
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 }, { responseTime: 30 }, { responseTime: 40 }, { responseTime: 50 }];
const percentile = 100;
const result = calculatePercentile(checks, percentile);
const expected = 50;
expect(result).to.equal(expected);
});
});
@@ -1,53 +0,0 @@
import { expect } from "chai";
import sinon from "sinon";
import sharp from "sharp";
import { GenerateAvatarImage } from "../../utils/imageProcessing.js";
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"),
};
// Stub the sharp function
const toBufferStub = sinon.stub().resolves(Buffer.from("resized image buffer"));
const resizeStub = sinon.stub().returns({ toBuffer: toBufferStub });
const sharpStub = sinon.stub(sharp.prototype, "resize").returns({ toBuffer: toBufferStub });
const result = await GenerateAvatarImage(file);
// Verify the result
const expected = Buffer.from("resized image buffer").toString("base64");
expect(result).to.equal(expected);
// Verify that the sharp function was called with the correct arguments
expect(sharpStub.calledOnceWith({ width: 64, height: 64, fit: "cover" })).to.be.true;
expect(toBufferStub.calledOnce).to.be.true;
// Restore the stubbed functions
sharpStub.restore();
});
it("should throw an error if resizing fails", async function () {
const file = {
buffer: Buffer.from("test image buffer"),
};
// Stub the sharp function to throw an error
const toBufferStub = sinon.stub().rejects(new Error("Resizing failed"));
const resizeStub = sinon.stub().returns({ toBuffer: toBufferStub });
const sharpStub = sinon.stub(sharp.prototype, "resize").returns({ toBuffer: toBufferStub });
try {
await GenerateAvatarImage(file);
// If no error is thrown, fail the test
expect.fail("Expected error to be thrown");
} catch (error) {
// Verify that the error message is correct
expect(error.message).to.equal("Resizing failed");
}
// Restore the stubbed functions
sharpStub.restore();
});
});
-139
View File
@@ -1,139 +0,0 @@
import sinon from "sinon";
import logger from "../../utils/logger.js";
import { Logger } from "../../utils/logger.js";
import winston from "winston";
describe("Logger", function () {
let infoStub, warnStub, errorStub;
beforeEach(function () {
infoStub = sinon.stub(logger.logger, "info");
warnStub = sinon.stub(logger.logger, "warn");
errorStub = sinon.stub(logger.logger, "error");
});
afterEach(function () {
sinon.restore();
});
describe("constructor", function () {
let createLoggerStub;
beforeEach(function () {
createLoggerStub = sinon.stub(winston, "createLogger");
});
afterEach(function () {
sinon.restore();
});
it("should convert message to JSON string if it is an object", function () {
const logMessage = { key: "value" };
const expectedMessage = JSON.stringify(logMessage, null, 2);
createLoggerStub.callsFake((config) => {
const consoleTransport = config.transports[0];
const logEntry = {
level: "info",
message: logMessage,
timestamp: new Date().toISOString(),
};
const formattedMessage = consoleTransport.format.transform(logEntry);
expect(formattedMessage).to.include(expectedMessage);
return { log: sinon.spy() };
});
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
createLoggerStub.callsFake((config) => {
const consoleTransport = config.transports[0];
const logEntry = {
level: "info",
message: "", // Add empty message since it's required
details: logDetails,
timestamp: new Date().toISOString(),
};
const formattedMessage = consoleTransport.format.transform(logEntry);
expect(formattedMessage).to.include(expectedDetails);
return { info: sinon.spy() }; // Changed to return info method
});
const logger = new Logger();
logger.logger.info("", { details: logDetails }); // Updated to pass details properly
});
});
describe("info", function () {
it("should log an informational message", function () {
const config = {
message: "Info message",
service: "TestService",
method: "TestMethod",
details: { key: "value" },
};
logger.info(config);
expect(infoStub.calledOnce).to.be.true;
expect(
infoStub.calledWith(config.message, {
service: config.service,
method: config.method,
details: config.details,
})
).to.be.true;
});
});
describe("warn", function () {
it("should log a warning message", function () {
const config = {
message: "Warning message",
service: "TestService",
method: "TestMethod",
details: { key: "value" },
};
logger.warn(config);
expect(warnStub.calledOnce).to.be.true;
expect(
warnStub.calledWith(config.message, {
service: config.service,
method: config.method,
details: config.details,
})
).to.be.true;
});
});
describe("error", function () {
it("should log an error message", function () {
const config = {
message: "Error message",
service: "TestService",
method: "TestMethod",
details: { key: "value" },
stack: "Error stack trace",
};
logger.error(config);
expect(errorStub.calledOnce).to.be.true;
expect(
errorStub.calledWith(config.message, {
service: config.service,
method: config.method,
details: config.details,
stack: config.stack,
})
).to.be.true;
});
});
});
-23
View File
@@ -1,23 +0,0 @@
import { errorMessages, successMessages } from "../../utils/messages.js";
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", function () {
const monitorId = "12345";
expect(errorMessages.DB_DELETE_CHECKS(monitorId)).to.equal(`No checks found for monitor with id ${monitorId}`);
});
});
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"`);
});
// Add more tests for other success messages as needed
});
});
-50
View File
@@ -1,50 +0,0 @@
import { ParseBoolean, getTokenFromHeaders } from "../../utils/utils.js";
describe("utils - ParseBoolean", function () {
it("should return true", function () {
const result = ParseBoolean("true");
expect(result).to.be.true;
});
it("should return false", function () {
const result = ParseBoolean("false");
expect(result).to.be.false;
});
it("should return false", function () {
const result = ParseBoolean(null);
expect(result).to.be.false;
});
it("should return false", function () {
const result = ParseBoolean(undefined);
expect(result).to.be.false;
});
});
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", 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", 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", 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", function () {
const headers = { authorization: "Bearer" };
expect(() => getTokenFromHeaders(headers)).to.throw("Invalid auth headers");
});
});