1import type { Api } from "./api";
2import { emailOf, personas, seedPersonas, type PersonaKey } from "./personas";
3
4export const OUTGOING_EMAIL = "e2e-support@example.com";
5
6/** Baseline every spec relies on; safe to run on an already seeded site. */
7export async function seedSite(api: Api) {
8 await seedPersonas(api);
9 await ensureOutgoingEmailAccount(api);
10 await resetDefaultTicketViews(api);
11 await api.update("OD Settings", "OD Settings", {
12 persona_captured: 1,
13 setup_complete: 1,
14 });
15}
16
17// Without a password Frappe skips the SMTP check, so mails just stay queued.
18async function ensureOutgoingEmailAccount(api: Api) {
19 if (await api.exists("Email Account", { email_id: OUTGOING_EMAIL })) return;
20 await api.insert("Email Account", {
21 email_account_name: "E2E Support",
22 email_id: OUTGOING_EMAIL,
23 smtp_server: "smtp.example.invalid",
24 no_smtp_authentication: 1,
25 enable_outgoing: 1,
26 default_outgoing: 1,
27 enable_incoming: 0,
28 });
29}
30
31// Filters typed on the ticket list auto save into the user's default view.
32async function resetDefaultTicketViews(api: Api) {
33 const keys = ["admin", ...Object.keys(personas)] as PersonaKey[];
34 const views = await api.list("OD View", {
35 filters: { dt: "OD Ticket", is_default: 1, user: ["in", keys.map(emailOf)] },
36 });
37 for (const view of views) await api.delete("OD View", view.name);
38}
39