Files
EpicNext-Cms/src/lib/services/alert.test.ts
T
openhands 17847545dd
Deploy / release (push) Skipped
Deploy / deploy (push) Successful in 1m52s
Improvements: remove dead config, fix ESM, add URL validation, unify types, add missing logging
- Remove .prettierrc (dead config, Biome replaces Prettier)
- Rename lighthouserc.json to lighthouserc.cjs with module.exports for ESM compat
- Add logger.warn to empty catch blocks in auth, register, site-settings, prisma-cache, redis, security, rate-limit
- Unify ActionResult type: action-helper.ts uses 'ok' consistent with safe-action-shared.ts
- Add noUnusedLocals + noUnusedParameters to tsconfig + fix 25 pre-existing unused vars
- Replace barrel export src/types/index.ts with direct @/types/common imports
- Make trustHost conditional (development only) in auth.ts
- Add pre-flight URL validation to update-Nitrov3.sh to catch image.library.url misconfigurations
- Improve NITRO_IMAGE_LIBRARY_URL content validation in pre-flight & post-compute checks
2026-07-26 20:28:11 +02:00

63 lines
1.4 KiB
TypeScript

import { beforeEach, describe, expect, it, vi } from "vitest";
const createFn = vi.hoisted(() => vi.fn());
const sendMailFn = vi.hoisted(() => vi.fn().mockResolvedValue(true));
vi.mock("@/lib/prisma", () => ({
prisma: { alertLogs: { create: createFn } },
}));
vi.mock("@/lib/services/email", () => ({
sendMail: sendMailFn,
}));
vi.mock("@/env", () => ({
env: {
DISCORD_WEBHOOK_URL: "",
ALERT_EMAIL: "",
HOTEL_NAME: "TestHotel",
APP_URL: "http://localhost:3000",
NODE_ENV: "test",
},
}));
import { sendAlert } from "./alert";
beforeEach(() => {
createFn.mockReset();
sendMailFn.mockReset();
createFn.mockResolvedValue({ id: 1 });
});
describe("sendAlert", () => {
it("persists an alert log entry", async () => {
await sendAlert({
type: "test",
severity: "warning",
message: "test alert",
});
expect(createFn).toHaveBeenCalledWith({
data: expect.objectContaining({
type: "test",
severity: "warning",
message: "test alert",
isRead: false,
}),
});
});
it("returns logged=true when DB write succeeds", async () => {
const result = await sendAlert({
type: "test",
severity: "info",
message: "ok",
});
expect(result.logged).toBe(true);
});
it("does not call sendMail when ALERT_EMAIL is unset", async () => {
await sendAlert({ type: "test", severity: "error", message: "m" });
expect(sendMailFn).not.toHaveBeenCalled();
});
});