Refresh HiveGrid Cloud reference snapshot
This commit is contained in:
1 parent
5e99e14772
commit
7f88026f79
5955 files changed
+1177325
-188362
No files matched your search
+1
-1
@@ -9,7 +9,7 @@
|
||||
* the home for periodic snapshots).
|
||||
*/
|
||||
import { Link, type LoaderFunctionArgs, useLoaderData } from "react-router";
|
||||
import { t as i18nT } from "i18next";
|
||||
import { requestScopedT as i18nT } from "~/locale/request-scoped-t";
|
||||
import { adminPath } from "~/utils/app/CanonicalUrlUtils";
|
||||
import { dbRead } from "~/utils/db.server";
|
||||
import { verifyUserHasPermission } from "~/utils/helpers/.server/PermissionsService";
|
||||
|
||||
+43
-2
@@ -37,9 +37,9 @@ vi.mock("i18next", () => ({
|
||||
t: (key: string) => key,
|
||||
}));
|
||||
|
||||
async function callAction(values: Record<string, string>) {
|
||||
async function callActionResponse(values: Record<string, string>) {
|
||||
const body = new URLSearchParams(values);
|
||||
const response = (await action({
|
||||
return (await action({
|
||||
request: new Request("https://admin.example.test/email-sequences/seq-1", {
|
||||
method: "POST",
|
||||
body,
|
||||
@@ -49,6 +49,10 @@ async function callAction(values: Record<string, string>) {
|
||||
context: {},
|
||||
unstable_pattern: "admin/email-sequences/:id",
|
||||
} as ActionFunctionArgs)) as Response;
|
||||
}
|
||||
|
||||
async function callAction(values: Record<string, string>) {
|
||||
const response = await callActionResponse(values);
|
||||
return response.json();
|
||||
}
|
||||
|
||||
@@ -94,4 +98,41 @@ describe("admin email sequence detail action", () => {
|
||||
});
|
||||
expect(db.emailSequence.update).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("does not expose the email-sequence engine error in validation feedback", async () => {
|
||||
const result = await callAction({
|
||||
name: "Welcome",
|
||||
triggerEvent: "lead.captured",
|
||||
stepsJson: "{}",
|
||||
});
|
||||
|
||||
expect(result).toEqual({
|
||||
ok: false,
|
||||
error: "translated:admin.emailSequences.errors.stepsJsonValidationFailed",
|
||||
field: "stepsJson",
|
||||
});
|
||||
expect(db.emailSequence.update).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("redirects with an action-specific toast after enabling a sequence", async () => {
|
||||
const response = await callActionResponse({ intent: "toggle" });
|
||||
|
||||
expect(response.status).toBe(302);
|
||||
expect(response.headers.get("Location")).toContain(
|
||||
`toast=${encodeURIComponent("admin.emailSequences.toast.enabled")}`
|
||||
);
|
||||
});
|
||||
|
||||
it("redirects with the saved toast after updating a sequence", async () => {
|
||||
const response = await callActionResponse({
|
||||
name: "Welcome",
|
||||
triggerEvent: "lead.captured",
|
||||
stepsJson: "[]",
|
||||
});
|
||||
|
||||
expect(response.status).toBe(302);
|
||||
expect(response.headers.get("Location")).toContain(
|
||||
`toast=${encodeURIComponent("admin.emailSequences.toast.saved")}`
|
||||
);
|
||||
});
|
||||
});
|
||||
+12
-5
@@ -12,7 +12,7 @@
|
||||
* engine package before save so bad JSON cannot corrupt a run.
|
||||
*/
|
||||
import { Form, Link, type ActionFunctionArgs, type LoaderFunctionArgs, redirect, useActionData, useLoaderData } from "react-router";
|
||||
import { t as i18nT } from "i18next";
|
||||
import { requestScopedT as i18nT } from "~/locale/request-scoped-t";
|
||||
import { adminPath } from "~/utils/app/CanonicalUrlUtils";
|
||||
import { db, dbRead } from "~/utils/db.server";
|
||||
import { verifyUserHasPermission } from "~/utils/helpers/.server/PermissionsService";
|
||||
@@ -63,7 +63,12 @@ export const action = async ({ params, request }: ActionFunctionArgs) => {
|
||||
|
||||
if (intent === "toggle") {
|
||||
await db.emailSequence.update({ where: { id }, data: { isEnabled: !existing.isEnabled } });
|
||||
return redirect(`${adminPath("email-sequences", { mode: "host-aware" })}/${id}`);
|
||||
const messageKey = existing.isEnabled
|
||||
? "admin.emailSequences.toast.disabled"
|
||||
: "admin.emailSequences.toast.enabled";
|
||||
return redirect(
|
||||
`${adminPath("email-sequences", { mode: "host-aware" })}/${id}?toast=${encodeURIComponent(messageKey)}`
|
||||
);
|
||||
}
|
||||
|
||||
const name = String(formData.get("name") ?? "").trim();
|
||||
@@ -84,10 +89,10 @@ export const action = async ({ params, request }: ActionFunctionArgs) => {
|
||||
const { parseSequenceSteps } = await import("@hivegrid/email-sequences");
|
||||
try {
|
||||
parseSequenceSteps(stepsJson);
|
||||
} catch (error) {
|
||||
} catch {
|
||||
return Response.json({
|
||||
ok: false,
|
||||
error: error instanceof Error ? error.message : t("admin.emailSequences.errors.stepsJsonValidationFailed"),
|
||||
error: t("admin.emailSequences.errors.stepsJsonValidationFailed"),
|
||||
field: "stepsJson",
|
||||
} satisfies ActionResponse);
|
||||
}
|
||||
@@ -113,7 +118,9 @@ export const action = async ({ params, request }: ActionFunctionArgs) => {
|
||||
conditionsJson: conditionsJson as never,
|
||||
},
|
||||
});
|
||||
return redirect(`${adminPath("email-sequences", { mode: "host-aware" })}/${id}`);
|
||||
return redirect(
|
||||
`${adminPath("email-sequences", { mode: "host-aware" })}/${id}?toast=${encodeURIComponent("admin.emailSequences.toast.saved")}`
|
||||
);
|
||||
};
|
||||
|
||||
export default function EmailSequenceDetail() {
|
||||
|
||||
+13
@@ -25,12 +25,20 @@ function readTranslations(locale: "en" | "de") {
|
||||
form: Record<string, string>;
|
||||
placeholders: Record<string, string>;
|
||||
stats: Record<string, string>;
|
||||
toast: Record<string, string>;
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
describe("admin email sequence route i18n", () => {
|
||||
it("uses the localized title key without an English meta fallback", () => {
|
||||
const source = readRoute("../email-sequences.tsx");
|
||||
|
||||
expect(source).toContain('t("admin.emailSequences.title")');
|
||||
expect(source).not.toContain('|| "Email Sequences"');
|
||||
});
|
||||
|
||||
it("uses namespaced email sequence keys for create and edit form chrome", () => {
|
||||
const source = `${readRoute("new.tsx")}\n${readRoute("$id.tsx")}`;
|
||||
|
||||
@@ -51,6 +59,10 @@ describe("admin email sequence route i18n", () => {
|
||||
"admin.emailSequences.form.triggerEvent",
|
||||
"admin.emailSequences.form.triggerHint",
|
||||
"admin.emailSequences.placeholders.triggerEvent",
|
||||
"admin.emailSequences.toast.created",
|
||||
"admin.emailSequences.toast.disabled",
|
||||
"admin.emailSequences.toast.enabled",
|
||||
"admin.emailSequences.toast.saved",
|
||||
]) {
|
||||
expect(source).toContain(key);
|
||||
}
|
||||
@@ -81,6 +93,7 @@ describe("admin email sequence route i18n", () => {
|
||||
expect(Object.keys(de.form).sort()).toEqual(Object.keys(en.form).sort());
|
||||
expect(Object.keys(de.placeholders).sort()).toEqual(Object.keys(en.placeholders).sort());
|
||||
expect(Object.keys(de.stats).sort()).toEqual(Object.keys(en.stats).sort());
|
||||
expect(Object.keys(de.toast).sort()).toEqual(Object.keys(en.toast).sort());
|
||||
});
|
||||
|
||||
it("keeps trigger event terminology coherent across email sequence locales", () => {
|
||||
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
import type { LoaderFunctionArgs } from "react-router";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { loader } from "./new";
|
||||
import { getTranslations } from "~/locale/i18next.server";
|
||||
import { verifyUserHasPermission } from "~/utils/helpers/.server/PermissionsService";
|
||||
|
||||
vi.mock("~/utils/db.server", () => ({ db: { emailSequence: { create: vi.fn() } } }));
|
||||
|
||||
vi.mock("~/utils/helpers/.server/PermissionsService", () => ({
|
||||
verifyUserHasPermission: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock("~/locale/i18next.server", () => ({
|
||||
getTranslations: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock("i18next", () => ({
|
||||
t: (key: string) => key,
|
||||
}));
|
||||
|
||||
describe("admin email sequence create loader", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
vi.mocked(verifyUserHasPermission).mockResolvedValue(undefined as never);
|
||||
});
|
||||
|
||||
it("builds the starter subject with the request-local translator", async () => {
|
||||
vi.mocked(getTranslations).mockResolvedValue({
|
||||
t: ((key: string, values?: { productName?: string }) => `${key}:${values?.productName ?? ""}`) as never,
|
||||
} as never);
|
||||
|
||||
const response = (await loader({
|
||||
request: new Request("https://admin.example.test/email-sequences/new"),
|
||||
params: {},
|
||||
context: {},
|
||||
unstable_pattern: "admin/email-sequences/new",
|
||||
} as LoaderFunctionArgs)) as Response;
|
||||
const data = (await response.json()) as { defaultSteps: string };
|
||||
const steps = JSON.parse(data.defaultSteps) as Array<{ subject: string }>;
|
||||
|
||||
expect(steps[0]?.subject).toBe(`admin.emailSequences.defaults.welcomeSubject:${process.env.APP_NAME ?? "HiveGrid"}`);
|
||||
expect(getTranslations).toHaveBeenCalledWith(expect.any(Request));
|
||||
});
|
||||
});
|
||||
+25
-21
@@ -6,8 +6,8 @@
|
||||
* before inserting so the row is always renderable by the trigger
|
||||
* handler.
|
||||
*/
|
||||
import { Form, Link, redirect, useActionData, type ActionFunctionArgs, type LoaderFunctionArgs } from "react-router";
|
||||
import { t as i18nT } from "i18next";
|
||||
import { Form, Link, redirect, useActionData, useLoaderData, type ActionFunctionArgs, type LoaderFunctionArgs } from "react-router";
|
||||
import { requestScopedT as i18nT } from "~/locale/request-scoped-t";
|
||||
import { adminPath } from "~/utils/app/CanonicalUrlUtils";
|
||||
import { db } from "~/utils/db.server";
|
||||
import { verifyUserHasPermission } from "~/utils/helpers/.server/PermissionsService";
|
||||
@@ -15,23 +15,24 @@ import { getTranslations } from "~/locale/i18next.server";
|
||||
|
||||
type ActionResponse = { ok: true } | { ok: false; error: string };
|
||||
|
||||
const DEFAULT_STEPS = JSON.stringify(
|
||||
[
|
||||
{
|
||||
stepIndex: 0,
|
||||
delayHours: 0,
|
||||
template: "welcome",
|
||||
subject: i18nT("admin.emailSequences.defaults.welcomeSubject"),
|
||||
variables: { productName: "HiveGrid" },
|
||||
},
|
||||
],
|
||||
null,
|
||||
2
|
||||
);
|
||||
|
||||
export const loader = async ({ request }: LoaderFunctionArgs) => {
|
||||
await verifyUserHasPermission(request, "admin.marketing.leads.view");
|
||||
return Response.json({});
|
||||
const { t } = await getTranslations(request);
|
||||
const productName = process.env.APP_NAME ?? "HiveGrid";
|
||||
const defaultSteps = JSON.stringify(
|
||||
[
|
||||
{
|
||||
stepIndex: 0,
|
||||
delayHours: 0,
|
||||
template: "welcome",
|
||||
subject: t("admin.emailSequences.defaults.welcomeSubject", { productName }),
|
||||
variables: { productName },
|
||||
},
|
||||
],
|
||||
null,
|
||||
2
|
||||
);
|
||||
return Response.json({ defaultSteps });
|
||||
};
|
||||
|
||||
export const action = async ({ request }: ActionFunctionArgs) => {
|
||||
@@ -54,10 +55,10 @@ export const action = async ({ request }: ActionFunctionArgs) => {
|
||||
const { parseSequenceSteps } = await import("@hivegrid/email-sequences");
|
||||
try {
|
||||
parseSequenceSteps(stepsJson);
|
||||
} catch (error) {
|
||||
} catch {
|
||||
return Response.json({
|
||||
ok: false,
|
||||
error: error instanceof Error ? error.message : t("admin.emailSequences.errors.stepsJsonValidationFailed"),
|
||||
error: t("admin.emailSequences.errors.stepsJsonValidationFailed"),
|
||||
} satisfies ActionResponse);
|
||||
}
|
||||
let conditionsJson: unknown = null;
|
||||
@@ -78,10 +79,13 @@ export const action = async ({ request }: ActionFunctionArgs) => {
|
||||
isEnabled: false,
|
||||
},
|
||||
});
|
||||
return redirect(`${adminPath("email-sequences", { mode: "host-aware" })}/${created.id}`);
|
||||
return redirect(
|
||||
`${adminPath("email-sequences", { mode: "host-aware" })}/${created.id}?toast=${encodeURIComponent("admin.emailSequences.toast.created")}`
|
||||
);
|
||||
};
|
||||
|
||||
export default function EmailSequenceNew() {
|
||||
const { defaultSteps } = useLoaderData<typeof loader>();
|
||||
const action = useActionData<ActionResponse>();
|
||||
return (
|
||||
<div className="mx-auto mb-12 max-w-5xl space-y-5 px-4 py-4 sm:px-6 lg:px-8">
|
||||
@@ -126,7 +130,7 @@ export default function EmailSequenceNew() {
|
||||
<textarea
|
||||
id="stepsJson"
|
||||
name="stepsJson"
|
||||
defaultValue={DEFAULT_STEPS}
|
||||
defaultValue={defaultSteps}
|
||||
rows={14}
|
||||
spellCheck={false}
|
||||
className="border-border w-full rounded-md border px-3 py-1.5 font-mono text-xs"
|
||||
|
||||
Reference in new issue
Block a user