SPB Git

Repository Public

automation.spec.ts 6.2 KB 108 lines typescript

1// Console d'administration — automatisation : règles d'une boîte (constructeur des Réglages réutilisé), réexpédition2// limitée aux domaines hébergés, réponse automatique, messages programmés (liste, annulation). Aucun message ne part.3import { api, axeBoth, expect, noOverflow, openAdmin, st, test, toastText } from "./fixtures"45const automation = async () => (await api("GET", `/api/v1/addresses/${encodeURIComponent(st.addrA)}/automation`)).body67test("automatisation : créer une règle pour une boîte ; réexpédition externe refusée et expliquée", async ({ page, watch }) => {8  const before = await automation()9  const name = `Essai règles ${st.run} ${Date.now()}`10  try {11    await openAdmin(page, "rules")12    await page.getByTestId("automation-mailbox").selectOption(st.addrA)13    const auto = page.getByTestId("automation")14    await expect(auto).toHaveAttribute("data-mailbox", st.addrA)15    await expect(auto.getByRole("heading", { level: 3, name: "Règles de tri" })).toBeVisible()1617    await auto.getByRole("button", { name: "Ajouter une règle" }).click()18    const dlg = page.getByRole("dialog", { name: "Nouvelle règle" })19    await dlg.getByLabel("Nom de la règle").fill(name)20    await dlg.getByLabel("Valeur").fill("factures@exemple.test")21    await dlg.getByLabel("Marquer comme lu").check()22    await dlg.getByLabel("Laisser dans la boîte de réception").check()23    await dlg.getByRole("button", { name: "Ajouter la règle" }).click()24    await expect(dlg).toBeHidden()25    await expect(auto.locator(".set-item", { hasText: name })).toContainText("De contient « factures@exemple.test » → marquer comme lu")26    await expect(auto.getByText("Modifications non enregistrées")).toBeVisible()2728    await auto.getByTestId("rules-save").click()29    await expect(toastText(page, `Règles de ${st.addrA} enregistrées et activées`)).toBeVisible({ timeout: 30_000 })30    const after = await automation()31    expect(after.managed).toBe(true)32    expect(after.active).toBe(true)33    const rule = (after.rules as { name: string }[]).find((r) => r.name === name)34    expect(rule).toMatchObject({ enabled: true, match: "all", conditions: [{ field: "from", op: "contains", value: "factures@exemple.test" }], actions: [{ type: "markRead" }] })35    await expect(auto.getByText("Script actif sur le serveur")).toBeVisible()3637    await axeBoth(page, "admin-automatisation-regles")38    await noOverflow(page)3940    // réexpédition : un domaine non hébergé est refusé par l'API (400 forward_not_local) — rien n'est enregistré41    watch.allow.push(/status of 400/)42    await auto.getByLabel("Réexpédier le courrier de cette boîte").check()43    await auto.getByLabel("Adresse de destination").fill("quelquun@example.org")44    await auto.getByRole("button", { name: "Enregistrer", exact: true }).click()45    await expect(auto.getByRole("alert").filter({ hasText: "forward_not_local" })).toContainText("domaine hébergé par ce serveur")46    expect((await automation()).forward).toBeNull()47  } finally {48    // la boîte du lanceur sert à d'autres essais : ses règles reviennent à l'état de départ49    await api("PUT", `/api/v1/addresses/${encodeURIComponent(st.addrA)}/automation`, { rules: before.rules ?? [], forward: null })50  }51})5253test("automatisation : activer puis désactiver la réponse automatique d'une boîte", async ({ page }) => {54  const before = await automation()55  try {56    await openAdmin(page, "autoreply")57    await page.getByTestId("automation-mailbox").selectOption(st.addrA)58    const card = page.getByTestId("autoreply")59    const state = card.locator("[data-vacation-state]")60    await expect(state).toHaveAttribute("data-vacation-state", "off")6162    await card.getByLabel("Activer la réponse automatique").check()63    await card.getByLabel("Objet", { exact: true }).fill("Absence")64    await card.getByLabel("Message", { exact: true }).fill(`Je suis absent (${st.run}).`)65    await card.getByRole("button", { name: "Enregistrer", exact: true }).click()66    await expect(toastText(page, "Réponse automatique activée")).toBeVisible({ timeout: 30_000 })67    await expect(state).toHaveAttribute("data-vacation-state", "on")68    expect((await automation()).vacation).toMatchObject({ enabled: true, subject: "Absence", text: `Je suis absent (${st.run}).` })6970    await axeBoth(page, "admin-automatisation-reponse")71    await noOverflow(page)7273    await card.getByLabel("Activer la réponse automatique").uncheck()74    await card.getByRole("button", { name: "Enregistrer", exact: true }).click()75    await expect(toastText(page, "Réponse automatique désactivée")).toBeVisible({ timeout: 30_000 })76    await expect(state).toHaveAttribute("data-vacation-state", "off")77    expect((await automation()).vacation.enabled).toBe(false)78  } finally {79    await api("PUT", `/api/v1/addresses/${encodeURIComponent(st.addrA)}/automation`, { vacation: { ...before.vacation, enabled: false } })80  }81})8283test("automatisation : messages programmés — un envoi prévu est listé, puis annulé", async ({ page }) => {84  const subject = `programmé ${st.run} ${Date.now()}`85  const sendAt = new Date(Date.now() + 86_400_000).toISOString()86  const seeded = await api("POST", "/api/v1/messages/send", { from: st.addrA, to: [{ email: st.addrB }], subject, text: "Ce message ne partira pas.", send_at: sendAt })87  expect(seeded.ok, JSON.stringify(seeded.body)).toBe(true)88  expect(seeded.body.status).toBe("scheduled")89  const id = seeded.body.id as string9091  await openAdmin(page, "scheduled")92  const r = page.locator(`[data-testid="scheduled-row"][data-outbound-id="${id}"]`)93  await expect(r).toBeVisible()94  await expect(r).toContainText(st.addrA)95  await expect(r).toContainText(st.addrB)96  await expect(r).toContainText("Session web")97  await axeBoth(page, "admin-automatisation-programmes")98  await noOverflow(page)99100  await r.getByRole("button", { name: /^Annuler l'envoi programmé/ }).click()101  const dlg = page.getByRole("alertdialog", { name: "Annuler cet envoi ?" })102  await expect(dlg).toContainText(st.addrB)103  await dlg.getByTestId("scheduled-cancel-confirm").click()104  await expect(toastText(page, "Envoi programmé annulé")).toBeVisible()105  await expect(r).toHaveCount(0)106  expect((await api("GET", `/api/v1/messages/outbound/${id}`)).body.status).toBe("cancelled")107})108
Files main
Menu

Theme