42 lines
1.4 KiB
TypeScript
42 lines
1.4 KiB
TypeScript
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
|
|
const mocks = vi.hoisted(() => ({
|
|
withTenantRLS: vi.fn(),
|
|
findFirst: vi.fn(),
|
|
create: vi.fn(),
|
|
}));
|
|
|
|
vi.mock("~/utils/db/.server/tenantRls.server", () => ({ withTenantRLS: mocks.withTenantRLS }));
|
|
|
|
import { seedShkCustomFieldTemplate, seedShkCustomFieldTemplateWithTx, SHK_CUSTOM_FIELD_TEMPLATE } from "./customFieldService.server";
|
|
|
|
const tx = {
|
|
customFieldDefinition: {
|
|
findFirst: mocks.findFirst,
|
|
create: mocks.create,
|
|
},
|
|
};
|
|
|
|
beforeEach(() => {
|
|
vi.clearAllMocks();
|
|
mocks.withTenantRLS.mockImplementation(async (_tenantId, callback) => callback(tx));
|
|
});
|
|
|
|
describe("SHK custom-field template transaction boundary", () => {
|
|
it("keeps the intentionally empty template as a no-op in an existing transaction", async () => {
|
|
const result = await seedShkCustomFieldTemplateWithTx(tx as never, { tenantId: "tenant-atomic-bootstrap" });
|
|
|
|
expect(SHK_CUSTOM_FIELD_TEMPLATE).toEqual([]);
|
|
expect(result).toEqual({ created: 0 });
|
|
expect(mocks.withTenantRLS).not.toHaveBeenCalled();
|
|
expect(mocks.findFirst).not.toHaveBeenCalled();
|
|
expect(mocks.create).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("avoids an RLS transaction while the versioned template is empty", async () => {
|
|
await expect(seedShkCustomFieldTemplate({ tenantId: "tenant-wrapper" })).resolves.toEqual({ created: 0 });
|
|
|
|
expect(mocks.withTenantRLS).not.toHaveBeenCalled();
|
|
});
|
|
});
|