Track HiveGrid Cloud planning reference

This commit is contained in:
david committed 2026-06-26 20:48:01 +02:00
1 parent b3d5ea6764
commit e341c5938a
5784 files changed
+1104929 -3

No files matched your search

@@ -0,0 +1,79 @@
import { beforeEach, describe, expect, it, vi } from "vitest";
const publishOutboxEventMock = vi.fn();
vi.mock("@toolctrl/db/outbox", () => ({
publishOutboxEvent: publishOutboxEventMock,
}));
vi.mock("~/modules/notifications/services/.server/NotificationService", () => ({
default: {
sendToRoles: vi.fn(),
},
}));
vi.mock("~/utils/logger.server", () => ({
createScopedLogger: () => ({
error: vi.fn(),
info: vi.fn(),
warn: vi.fn(),
}),
}));
vi.mock("~/utils/db.server", () => ({
db: {
$transaction: vi.fn(),
},
}));
describe("EventsService", () => {
beforeEach(() => {
vi.clearAllMocks();
});
it("publishes workflow trigger outbox events after the application event row is created", async () => {
const eventCreateMock = vi.fn().mockResolvedValue({ id: "event_1" });
const tx = {
event: {
create: eventCreateMock,
},
outboxEvent: {
create: vi.fn(),
findUnique: vi.fn(),
},
};
const EventsService = (await import("./EventsService")).default;
await EventsService.createInTransaction(tx as never, {
event: "row.created",
tenantId: "tenant_1",
userId: "user_1",
data: { id: "row_1", entity: { slug: "contacts", title: "Contacts" } },
});
expect(eventCreateMock).toHaveBeenCalledWith(
expect.objectContaining({
data: expect.objectContaining({
name: "row.created",
tenantId: "tenant_1",
userId: "user_1",
data: JSON.stringify({ id: "row_1", entity: { slug: "contacts", title: "Contacts" } }),
}),
})
);
expect(publishOutboxEventMock).toHaveBeenCalledWith(
tx,
expect.objectContaining({
tenantId: "tenant_1",
type: "workflow.trigger.event",
dispatchKey: "workflow-trigger:event_1",
payload: {
event: "row.created",
data: { id: "row_1", entity: { slug: "contacts", title: "Contacts" } },
userId: "user_1",
},
})
);
expect(eventCreateMock.mock.invocationCallOrder[0]).toBeLessThan(publishOutboxEventMock.mock.invocationCallOrder[0]);
});
});