37 lines
1.2 KiB
TypeScript
37 lines
1.2 KiB
TypeScript
import { describe, expect, it, vi } from "vitest";
|
|
|
|
import { findLegacyWidgetById, type LegacyWidgetReaderClient } from "./widgets.server.js";
|
|
|
|
describe("findLegacyWidgetById", () => {
|
|
it("fetches the legacy widget record by id and tenant", async () => {
|
|
const widget = {
|
|
id: "widget_123",
|
|
createdAt: new Date("2026-01-01T00:00:00.000Z"),
|
|
updatedAt: new Date("2026-01-02T00:00:00.000Z"),
|
|
tenantId: "tenant_123",
|
|
name: "Support",
|
|
appearance: "{}",
|
|
metadata: "{}",
|
|
};
|
|
const findFirst = vi.fn().mockResolvedValue(widget);
|
|
const client: LegacyWidgetReaderClient = {
|
|
widget: { findFirst },
|
|
};
|
|
|
|
await expect(findLegacyWidgetById({ widgetId: "widget_123", tenantId: "tenant_123" }, client)).resolves.toBe(widget);
|
|
expect(findFirst).toHaveBeenCalledWith({
|
|
where: { id: "widget_123", tenantId: "tenant_123" },
|
|
});
|
|
});
|
|
|
|
it("returns null when the widget does not exist", async () => {
|
|
const client: LegacyWidgetReaderClient = {
|
|
widget: {
|
|
findFirst: vi.fn().mockResolvedValue(null),
|
|
},
|
|
};
|
|
|
|
await expect(findLegacyWidgetById({ widgetId: "missing", tenantId: "tenant_123" }, client)).resolves.toBeNull();
|
|
});
|
|
});
|