Update hivegrid-cloud reference to latest main

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
davidandClaude Fable 5 committed 2026-07-08 16:15:37 +02:00
1 parent e98d38e716
commit 7b21524c86
3781 files changed
+373484 -225607

No files matched your search

@@ -0,0 +1,144 @@
import { beforeEach, describe, expect, it, vi } from "vitest";
type FormRow = {
id: string;
key: string;
name: string;
isEnabled: boolean;
_count: { submissions: number };
};
type FormCreateArgs = {
data: {
tenantId: string;
name: string;
definition: { fields: Array<{ key: string; type: string }> };
allowedOrigins: string[];
config: { honeypotEnabled: boolean };
};
};
const dbMock = {
form: {
create: vi.fn<(args: FormCreateArgs) => Promise<{ id: string; key: string }>>(),
findMany: vi.fn<() => Promise<FormRow[]>>(),
findUnique: vi.fn<() => Promise<{ id: string; name: string } | null>>(),
delete: vi.fn<() => Promise<{ id: string }>>(),
},
};
vi.mock("@hivegrid/db/client.server", () => ({
getDbClient: () => dbMock,
}));
vi.mock("consola", () => ({
default: {
info: vi.fn(),
log: vi.fn(),
error: vi.fn(),
success: vi.fn(),
},
}));
import consola from "consola";
import { formsCreateCommand } from "./create.js";
import { formsDeleteCommand } from "./delete.js";
import { formsListCommand } from "./list.js";
const consoleMock = vi.mocked(consola);
describe("forms create command", () => {
beforeEach(() => {
vi.clearAllMocks();
process.exitCode = undefined;
dbMock.form.create.mockResolvedValue({ id: "form_1", key: "pub_key_1" });
});
it("seeds the default text/email/textarea/honeypot definition with no origins", async () => {
await formsCreateCommand.run?.({ args: { tenant: "tenant_1", name: "Contact" } } as never);
expect(dbMock.form.create).toHaveBeenCalledTimes(1);
const payload = dbMock.form.create.mock.calls[0]![0];
expect(payload.data.tenantId).toBe("tenant_1");
expect(payload.data.name).toBe("Contact");
expect(payload.data.allowedOrigins).toEqual([]);
expect(payload.data.config).toEqual({ honeypotEnabled: true });
const fieldTypes = payload.data.definition.fields.map((f) => f.type);
expect(fieldTypes).toEqual(["text", "email", "textarea", "honeypot"]);
expect(consoleMock.success).toHaveBeenCalledWith("Form created: id=form_1 key=pub_key_1");
expect(consoleMock.log).toHaveBeenCalledWith(expect.stringContaining('data-form-key="pub_key_1"'));
});
it("records the allowed embedding origin when --origin is supplied", async () => {
await formsCreateCommand.run?.({
args: { tenant: "tenant_1", name: "Newsletter", origin: "https://acme.example" },
} as never);
const payload = dbMock.form.create.mock.calls[0]![0];
expect(payload.data.allowedOrigins).toEqual(["https://acme.example"]);
});
});
describe("forms list command", () => {
beforeEach(() => {
vi.clearAllMocks();
dbMock.form.findMany.mockResolvedValue([]);
});
it("prints ON/OFF state, submission counts, and a closing summary", async () => {
dbMock.form.findMany.mockResolvedValueOnce([
{ id: "form_1", key: "pub_a", name: "Contact", isEnabled: true, _count: { submissions: 12 } },
{ id: "form_2", key: "pub_b", name: "Survey", isEnabled: false, _count: { submissions: 0 } },
]);
await formsListCommand.run?.({ args: { tenant: "tenant_1" } } as never);
expect(dbMock.form.findMany).toHaveBeenCalledWith({
where: { tenantId: "tenant_1" },
orderBy: { createdAt: "desc" },
select: {
id: true,
key: true,
name: true,
isEnabled: true,
_count: { select: { submissions: true } },
},
});
expect(consoleMock.log).toHaveBeenCalledWith(expect.stringMatching(/^ON .*form_1.*subs=12 Contact/u));
expect(consoleMock.log).toHaveBeenCalledWith(expect.stringMatching(/^OFF.*form_2.*subs=0 Survey/u));
expect(consoleMock.success).toHaveBeenCalledWith("2 forms listed.");
});
it("reports an empty tenant without a summary line", async () => {
await formsListCommand.run?.({ args: { tenant: "tenant_empty" } } as never);
expect(consoleMock.info).toHaveBeenCalledWith("No forms for tenant tenant_empty.");
expect(consoleMock.success).not.toHaveBeenCalled();
});
});
describe("forms delete command", () => {
beforeEach(() => {
vi.clearAllMocks();
process.exitCode = undefined;
dbMock.form.findUnique.mockResolvedValue(null);
dbMock.form.delete.mockResolvedValue({ id: "form_1" });
});
it("hard-deletes an existing form and confirms with its name", async () => {
dbMock.form.findUnique.mockResolvedValueOnce({ id: "form_1", name: "Contact" });
await formsDeleteCommand.run?.({ args: { id: "form_1" } } as never);
expect(dbMock.form.delete).toHaveBeenCalledWith({ where: { id: "form_1" } });
expect(consoleMock.success).toHaveBeenCalledWith("Form deleted: form_1 (Contact).");
expect(process.exitCode).toBeUndefined();
});
it("sets a non-zero exit code and skips the delete when the form is missing", async () => {
await formsDeleteCommand.run?.({ args: { id: "ghost" } } as never);
expect(consoleMock.error).toHaveBeenCalledWith("Form ghost not found.");
expect(process.exitCode).toBe(1);
expect(dbMock.form.delete).not.toHaveBeenCalled();
});
});
@@ -5,7 +5,7 @@
*/
import { defineCommand } from "citty";
import consola from "consola";
import { FormDefinitionSchema, HONEYPOT_FIELD_KEY } from "@toolctrl/form-widget";
import { FormDefinitionSchema, HONEYPOT_FIELD_KEY } from "@hivegrid/form-widget";
export const formsCreateCommand = defineCommand({
meta: { name: "create", description: "Seed a minimal form for a tenant." },
@@ -29,7 +29,7 @@ export const formsCreateCommand = defineCommand({
{ key: HONEYPOT_FIELD_KEY, type: "honeypot", label: "Leave empty" },
],
});
const { getDbClient } = await import("@toolctrl/db/client.server");
const { getDbClient } = await import("@hivegrid/db/client.server");
const prisma = getDbClient();
const created = await prisma.form.create({
data: {
@@ -11,7 +11,7 @@ export const formsDeleteCommand = defineCommand({
id: { type: "string", required: true, description: "Form ID." },
},
async run({ args }) {
const { getDbClient } = await import("@toolctrl/db/client.server");
const { getDbClient } = await import("@hivegrid/db/client.server");
const prisma = getDbClient();
const id = String(args.id);
const existing = await prisma.form.findUnique({ where: { id }, select: { id: true, name: true } });
@@ -10,7 +10,7 @@ export const formsListCommand = defineCommand({
tenant: { type: "string", required: true, description: "Tenant ID." },
},
async run({ args }) {
const { getDbClient } = await import("@toolctrl/db/client.server");
const { getDbClient } = await import("@hivegrid/db/client.server");
const prisma = getDbClient();
const tenantId = String(args.tenant);
const forms = await prisma.form.findMany({