From 0f230c4d70e20c56e41c7edc2c17f514ab290ffe Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Wed, 24 Jun 2026 10:53:13 -0700 Subject: [PATCH] update tests --- .../test/integration/backfillLastEvaluatedAt.test.ts | 11 +++++++---- server/test/unit/middleware/handleErrors.test.ts | 11 +++++++---- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/server/test/integration/backfillLastEvaluatedAt.test.ts b/server/test/integration/backfillLastEvaluatedAt.test.ts index ec0459b7d..f4c8a58c5 100644 --- a/server/test/integration/backfillLastEvaluatedAt.test.ts +++ b/server/test/integration/backfillLastEvaluatedAt.test.ts @@ -3,6 +3,9 @@ import mongoose from "mongoose"; import { MongoMemoryServer } from "mongodb-memory-server"; import { MonitorModel } from "../../src/domain/monitors/monitor.model.ts"; import { backfillMonitorLastEvaluatedAt } from "../../src/db/migration/0008_backfillMonitorLastEvaluatedAt.ts"; +import { createMockLogger } from "../helpers/createMockLogger.ts"; + +const logger = createMockLogger(); // ── Real-Mongo harness ───────────────────────────────────────────────────────── // Legacy monitors are inserted through the raw driver, NOT MonitorModel.create — the @@ -30,7 +33,7 @@ describe("0008_backfillMonitorLastEvaluatedAt", () => { await MonitorModel.collection.insertOne({ name: "legacy" }); // pre-upgrade doc, no lastEvaluatedAt const before = Date.now(); - await backfillMonitorLastEvaluatedAt(); + await backfillMonitorLastEvaluatedAt(logger); const doc = await MonitorModel.collection.findOne({ name: "legacy" }); // Must be a recent timestamp — backfilling 0 would replay the whole check history on the first evaluate. @@ -42,7 +45,7 @@ describe("0008_backfillMonitorLastEvaluatedAt", () => { it("leaves monitors that already have lastEvaluatedAt untouched (idempotent)", async () => { await MonitorModel.collection.insertOne({ name: "current", lastEvaluatedAt: 12345 }); - await backfillMonitorLastEvaluatedAt(); + await backfillMonitorLastEvaluatedAt(logger); const doc = await MonitorModel.collection.findOne({ name: "current" }); expect(doc?.lastEvaluatedAt).toBe(12345); @@ -52,13 +55,13 @@ describe("0008_backfillMonitorLastEvaluatedAt", () => { const db = mongoose.connection.db!; await db.collection("jobs").insertOne({ id: "legacy-job", template: "monitor-job" }); // old-scheduler row - await backfillMonitorLastEvaluatedAt(); + await backfillMonitorLastEvaluatedAt(logger); const exists = await db.listCollections({ name: "jobs" }).toArray(); expect(exists).toHaveLength(0); }); it("does not throw when there is no jobs collection to drop", async () => { - await expect(backfillMonitorLastEvaluatedAt()).resolves.toBeUndefined(); + await expect(backfillMonitorLastEvaluatedAt(logger)).resolves.toBeUndefined(); }); }); diff --git a/server/test/unit/middleware/handleErrors.test.ts b/server/test/unit/middleware/handleErrors.test.ts index 5994cf7d3..3ce49adbb 100644 --- a/server/test/unit/middleware/handleErrors.test.ts +++ b/server/test/unit/middleware/handleErrors.test.ts @@ -3,6 +3,9 @@ import type { NextFunction, Request, Response } from "express"; import { MulterError } from "multer"; import { handleErrors } from "../../../src/api/middleware/handleErrors.ts"; import { AppError } from "../../../src/utils/AppError.ts"; +import { createMockLogger } from "../../helpers/createMockLogger.ts"; + +const logger = createMockLogger(); const makeRes = (): Response => { const res = {} as Response; @@ -14,25 +17,25 @@ const makeRes = (): Response => { describe("handleErrors", () => { it("maps a multer file-size violation to 413 Payload Too Large", () => { const res = makeRes(); - handleErrors(new MulterError("LIMIT_FILE_SIZE", "profileImage"), {} as Request, res, (() => {}) as NextFunction); + handleErrors(logger)(new MulterError("LIMIT_FILE_SIZE", "profileImage"), {} as Request, res, (() => {}) as NextFunction); expect(res.status).toHaveBeenCalledWith(413); }); it("maps other multer errors to 400", () => { const res = makeRes(); - handleErrors(new MulterError("LIMIT_UNEXPECTED_FILE", "profileImage"), {} as Request, res, (() => {}) as NextFunction); + handleErrors(logger)(new MulterError("LIMIT_UNEXPECTED_FILE", "profileImage"), {} as Request, res, (() => {}) as NextFunction); expect(res.status).toHaveBeenCalledWith(400); }); it("preserves AppError status codes", () => { const res = makeRes(); - handleErrors(new AppError({ status: 415, message: "bad image" }), {} as Request, res, (() => {}) as NextFunction); + handleErrors(logger)(new AppError({ status: 415, message: "bad image" }), {} as Request, res, (() => {}) as NextFunction); expect(res.status).toHaveBeenCalledWith(415); }); it("falls back to 500 for unknown errors", () => { const res = makeRes(); - handleErrors(new Error("boom"), {} as Request, res, (() => {}) as NextFunction); + handleErrors(logger)(new Error("boom"), {} as Request, res, (() => {}) as NextFunction); expect(res.status).toHaveBeenCalledWith(500); }); });