refactor(db): finish Drizzle migration for remaining actions and services
Co-authored-by: Cursor <[email protected]>
This commit is contained in:
1 parent
22234fe102
commit
65b2fbee6a
19 files changed
+422
-342
No files matched your search
@@ -1,14 +1,16 @@
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
const createFn = vi.hoisted(() => vi.fn());
|
||||
const sendMailFn = vi.hoisted(() => vi.fn().mockResolvedValue(true));
|
||||
const insertValues = vi.hoisted(() => vi.fn());
|
||||
|
||||
vi.mock("@/lib/prisma", () => ({
|
||||
prisma: { alertLogs: { create: createFn } },
|
||||
vi.mock("@/lib/db", () => ({
|
||||
db: {
|
||||
insert: vi.fn(() => ({ values: insertValues })),
|
||||
},
|
||||
AlertLogs: {},
|
||||
}));
|
||||
|
||||
vi.mock("@/lib/services/email", () => ({
|
||||
sendMail: sendMailFn,
|
||||
sendMail: vi.fn().mockResolvedValue(true),
|
||||
}));
|
||||
|
||||
vi.mock("@/env", () => ({
|
||||
@@ -21,12 +23,14 @@ vi.mock("@/env", () => ({
|
||||
},
|
||||
}));
|
||||
|
||||
import { sendMail } from "@/lib/services/email";
|
||||
import { sendAlert } from "./alert";
|
||||
|
||||
beforeEach(() => {
|
||||
createFn.mockReset();
|
||||
sendMailFn.mockReset();
|
||||
createFn.mockResolvedValue({ id: 1 });
|
||||
insertValues.mockReset();
|
||||
vi.mocked(sendMail).mockReset();
|
||||
vi.mocked(sendMail).mockResolvedValue(true);
|
||||
insertValues.mockResolvedValue([{ insertId: 1 }]);
|
||||
});
|
||||
|
||||
describe("sendAlert", () => {
|
||||
@@ -36,14 +40,14 @@ describe("sendAlert", () => {
|
||||
severity: "warning",
|
||||
message: "test alert",
|
||||
});
|
||||
expect(createFn).toHaveBeenCalledWith({
|
||||
data: expect.objectContaining({
|
||||
expect(insertValues).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
type: "test",
|
||||
severity: "warning",
|
||||
message: "test alert",
|
||||
isRead: false,
|
||||
}),
|
||||
});
|
||||
);
|
||||
});
|
||||
|
||||
it("returns logged=true when DB write succeeds", async () => {
|
||||
@@ -57,6 +61,6 @@ describe("sendAlert", () => {
|
||||
|
||||
it("does not call sendMail when ALERT_EMAIL is unset", async () => {
|
||||
await sendAlert({ type: "test", severity: "error", message: "m" });
|
||||
expect(sendMailFn).not.toHaveBeenCalled();
|
||||
expect(sendMail).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user