Files
HiveGrid-Wireframes/hivegrid-cloud/apps/web/app/utils/db/entities/rowTasks.db.server.test.ts
T

47 lines
1.2 KiB
TypeScript

import { beforeEach, describe, expect, it, vi } from "vitest";
type RowTaskDbMocks = {
findMany: ReturnType<typeof vi.fn>;
};
function getMocks(): RowTaskDbMocks {
const store = globalThis as typeof globalThis & { __rowTaskDbMocks__?: RowTaskDbMocks };
store.__rowTaskDbMocks__ ??= {
findMany: vi.fn(),
};
return store.__rowTaskDbMocks__;
}
vi.mock("~/utils/db.server", () => ({
db: {
rowTask: {
findMany: getMocks().findMany,
},
},
}));
import { getAllRowTasks } from "./rowTasks.db.server";
const mocks = getMocks();
describe("row task db helpers", () => {
beforeEach(() => {
vi.clearAllMocks();
mocks.findMany.mockResolvedValue([]);
});
it("filters task lists through row tenant scope when provided", async () => {
await getAllRowTasks({ tenantId: "tenant_1", assignedOrCreatedUserId: "user_1", completed: false });
expect(mocks.findMany).toHaveBeenCalledWith(
expect.objectContaining({
where: expect.objectContaining({
completed: false,
row: { tenantId: "tenant_1" },
OR: [{ createdByUserId: "user_1" }, { assignedToUserId: "user_1" }],
}),
})
);
});
});