Track HiveGrid Cloud planning reference
This commit is contained in:
1 parent
b3d5ea6764
commit
e341c5938a
5784 files changed
+1104929
-3
No files matched your search
@@ -0,0 +1,97 @@
|
||||
import type { ActionFunctionArgs } from "react-router";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { action } from "./$id";
|
||||
import { getTranslations } from "~/locale/i18next.server";
|
||||
import { db } from "~/utils/db.server";
|
||||
import { verifyUserHasPermission } from "~/utils/helpers/.server/PermissionsService";
|
||||
|
||||
const dbMocks = vi.hoisted(() => ({
|
||||
sequenceFindFirst: vi.fn(),
|
||||
sequenceUpdate: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock("~/utils/db.server", () => ({
|
||||
db: {
|
||||
emailSequence: {
|
||||
findFirst: dbMocks.sequenceFindFirst,
|
||||
update: dbMocks.sequenceUpdate,
|
||||
},
|
||||
},
|
||||
dbRead: {
|
||||
emailSequence: {
|
||||
findFirst: vi.fn(),
|
||||
},
|
||||
},
|
||||
}));
|
||||
|
||||
vi.mock("~/utils/helpers/.server/PermissionsService", () => ({
|
||||
verifyUserHasPermission: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock("~/locale/i18next.server", () => ({
|
||||
getTranslations: vi.fn(async () => ({ t: (key: string) => `translated:${key}` })),
|
||||
}));
|
||||
|
||||
vi.mock("i18next", () => ({
|
||||
t: (key: string) => key,
|
||||
}));
|
||||
|
||||
async function callAction(values: Record<string, string>) {
|
||||
const body = new URLSearchParams(values);
|
||||
const response = (await action({
|
||||
request: new Request("https://admin.example.test/email-sequences/seq-1", {
|
||||
method: "POST",
|
||||
body,
|
||||
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
||||
}),
|
||||
params: { id: "seq-1" },
|
||||
context: {},
|
||||
unstable_pattern: "admin/email-sequences/:id",
|
||||
} as ActionFunctionArgs)) as Response;
|
||||
return response.json();
|
||||
}
|
||||
|
||||
describe("admin email sequence detail action", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
vi.mocked(verifyUserHasPermission).mockResolvedValue(undefined as never);
|
||||
vi.mocked(db.emailSequence.findFirst).mockResolvedValue({
|
||||
id: "seq-1",
|
||||
isEnabled: false,
|
||||
} as never);
|
||||
vi.mocked(db.emailSequence.update).mockResolvedValue({ id: "seq-1" } as never);
|
||||
});
|
||||
|
||||
it("localizes validation errors for visible edit-form feedback", async () => {
|
||||
const result = await callAction({
|
||||
name: "",
|
||||
triggerEvent: "lead.captured",
|
||||
stepsJson: "[]",
|
||||
});
|
||||
|
||||
expect(result).toEqual({
|
||||
ok: false,
|
||||
error: "translated:admin.emailSequences.errors.nameRequired",
|
||||
field: "name",
|
||||
});
|
||||
expect(getTranslations).toHaveBeenCalledWith(expect.any(Request));
|
||||
expect(db.emailSequence.update).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("uses the shared conditions JSON translation key on parse failure", async () => {
|
||||
const result = await callAction({
|
||||
name: "Welcome",
|
||||
triggerEvent: "lead.captured",
|
||||
stepsJson: "[]",
|
||||
conditionsJson: "{",
|
||||
});
|
||||
|
||||
expect(result).toEqual({
|
||||
ok: false,
|
||||
error: "translated:admin.emailSequences.errors.conditionsJsonInvalid",
|
||||
field: "conditionsJson",
|
||||
});
|
||||
expect(db.emailSequence.update).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user