e2e/helpers/seed.ts
Rama develop · réplica de lectura del repositorio original.
import type { Api } from "./api";
import { emailOf, personas, seedPersonas, type PersonaKey } from "./personas";
export const OUTGOING_EMAIL = "e2e-support@example.com";
/** Baseline every spec relies on; safe to run on an already seeded site. */
export async function seedSite(api: Api) {
await seedPersonas(api);
await ensureOutgoingEmailAccount(api);
await resetDefaultTicketViews(api);
await api.update("HD Settings", "HD Settings", {
setup_complete: 1,
});
}
// Without a password Frappe skips the SMTP check, so mails just stay queued.
async function ensureOutgoingEmailAccount(api: Api) {
if (await api.exists("Email Account", { email_id: OUTGOING_EMAIL })) return;
await api.insert("Email Account", {
email_account_name: "E2E Support",
email_id: OUTGOING_EMAIL,
smtp_server: "smtp.example.invalid",
no_smtp_authentication: 1,
enable_outgoing: 1,
default_outgoing: 1,
enable_incoming: 0,
});
}
// Filters typed on the ticket list auto save into the user's default view.
async function resetDefaultTicketViews(api: Api) {
const keys = ["admin", ...Object.keys(personas)] as PersonaKey[];
const views = await api.list("HD View", {
filters: { dt: "HD Ticket", is_default: 1, user: ["in", keys.map(emailOf)] },
});
for (const view of views) await api.delete("HD View", view.name);
}