Repository Public
1/**2 * =============================================================================3 * SP BOUCHER | INFRASTRUCTURE & AUTOMATION4 * ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project : MacLustr SMS Gateway8 * File : dashboard/e2e/dashboard.spec.ts9 * Module : dashboard10 * Repository : https://git.spboucher.ai/maclustr-sms11 * Project Website : https://sms.spboucher.ai12 * Created : 2026-11-3013 * Last Modified : 2026-11-3014 *15 * Author : Simon-Pierre Boucher16 * Position : Professor of Finance17 * Institution : Université du Québec en Outaouais (UQO)18 * Organization : SP Boucher19 * Website : https://spboucher.ai20 * Git : https://git.spboucher.ai21 *22 * Preferred Contact: admin@spboucher.ai23 * Technical Contact: dev@spboucher.ai24 * Security/Admin : admin@spboucher.ai25 *26 * Copyright (c) 202627 * Simon-Pierre Boucher28 * All rights reserved where applicable. This file is governed by the29 * applicable project license, copyright notices and relevant law.30 * Existing third-party rights and notices remain unaffected.31 *32 * License : None specified (no license file in this repository)33 *34 * Do not embed credentials, private keys, access tokens,35 * certificates or confidential personal information.36 *37 * =============================================================================38 * END OF SP BOUCHER SOURCE HEADER39 * =============================================================================40 */4142// Parcours complet du tableau de bord dans un vrai navigateur (Chromium), contre le vrai serveur et une vraie base.43// Clé d'accès : authentificateur virtuel du navigateur (CDP). Téléphone : appareil simulé du banc d'essai (aucun SMS réel).44import { expect, test, type Page } from "@playwright/test"45import crypto from "node:crypto"46import { readFileSync } from "node:fs"47import { call, cli, FakeDevice, resetDatabase, sql, startServer, stopServer, until } from "../../backend/tests/harness.ts"4849const SHOTS = "docs/captures/dashboard"50const dev = new FakeDevice()51let page: Page52const shot = (name: string) => page.screenshot({ path: `${SHOTS}/${name}.png`, fullPage: true })53const nav = (label: string) => page.locator(".nav a", { hasText: new RegExp(`^${label}`) }).click()5455test.describe.configure({ mode: "serial" })56test.beforeAll(async ({ browser }) => {57 await resetDatabase(); await startServer()58 const ctx = await browser.newContext()59 page = await ctx.newPage()60 const cdp = await ctx.newCDPSession(page)61 await cdp.send("WebAuthn.enable")62 await cdp.send("WebAuthn.addVirtualAuthenticator", { options: { protocol: "ctap2", transport: "internal", hasResidentKey: true, hasUserVerification: true, isUserVerified: true, automaticPresenceSimulation: true } })63})64test.afterAll(async () => { await dev.close(); await stopServer(); await sql.end() })6566test("accès refusé sans session, enrôlement par lien à usage unique", async () => {67 await page.goto("/")68 await expect(page.getByRole("button", { name: "Se connecter avec une clé d'accès" })).toBeVisible()69 await shot("00-connexion")70 const link = /(\/enroll#\S+)/.exec(cli("enroll", "--handle", "simon", "--name", "Simon-Pierre Boucher"))![1]71 await page.goto(link)72 await page.getByRole("button", { name: "Créer ma clé d'accès" }).click()73 await expect(page.getByRole("heading", { name: "Overview" })).toBeVisible()74 await expect(page.locator(".tile", { hasText: "Appareils connectés" }).locator(".v")).toHaveText("0")75})7677test("association d'un appareil par code temporaire", async () => {78 await nav("Devices")79 await page.getByRole("button", { name: "Associer un appareil" }).click()80 await page.getByPlaceholder("Pixel passerelle").fill("Pixel passerelle")81 await page.getByRole("button", { name: "Générer le code" }).click()82 const code = (await page.locator(".code").innerText()).trim()83 expect(code).toMatch(/^[A-Z2-9]{4}-[A-Z2-9]{4}-[A-Z2-9]{4}$/)84 await expect(page.locator(".qr svg")).toBeVisible()85 await shot("03-association")86 expect((await dev.pair(code, "Pixel passerelle")).status).toBe(201)87 await dev.connect()88 await page.getByRole("button", { name: "Terminé" }).click()89 await expect(page.locator("tr", { hasText: "android-01" })).toContainText("disponible")90 await shot("04-devices")91 await page.locator("tr", { hasText: "android-01" }).click()92 await expect(page.getByText("Historique des incidents")).toBeVisible()93 await page.getByRole("button", { name: "Lancer un diagnostic" }).click()94 await expect(page.getByText("send_sms_permission")).toBeVisible()95 await shot("05-device-detail")96 await page.getByRole("button", { name: "Fermer" }).click()97})9899test("SIM : autorisation d'envoi, destinataire autorisé", async () => {100 await nav("SIM Cards")101 const row = page.locator("tr", { hasText: "sim-1" })102 await expect(row).toContainText("+14185550124"); await expect(row).toContainText("non autorisé")103 await row.getByRole("button", { name: "Autoriser" }).click()104 await expect(row.locator(".badge.ok")).toHaveText("autorisé")105 await shot("06-sims")106 await nav("Settings")107 const allow = page.locator("div:has(> h2)", { hasText: "Destinataires autorisés" }).first()108 await allow.getByPlaceholder("+14185550123").fill("418 555-0123")109 await allow.getByPlaceholder("Libellé").fill("Téléphone d'essai")110 await allow.getByRole("button", { name: "Ajouter" }).click()111 await expect(allow.getByText("+14185550123")).toBeVisible()112})113114let apiKey = ""115test("application et clé API : la clé n'est affichée qu'une fois", async () => {116 await nav("API Keys")117 await page.getByRole("button", { name: "Nouvelle application" }).click()118 await page.getByPlaceholder("lou-ka, agent-os…").fill("lou-ka")119 await page.getByRole("button", { name: "Enregistrer" }).click()120 await page.getByRole("button", { name: "Nouvelle clé" }).click()121 await page.getByPlaceholder("production").fill("production")122 await page.getByRole("button", { name: "Créer la clé" }).click()123 apiKey = (await page.locator(".modal pre").innerText()).trim()124 expect(apiKey).toMatch(/^mlsk_/)125 await page.getByRole("button", { name: "J'ai noté la valeur" }).click()126 await expect(page.locator("body")).not.toContainText(apiKey)127 await shot("09-api-keys")128})129130test("console SMS : confirmation, envoi, suivi jusqu'à « livré »", async () => {131 await nav("Messages")132 await page.getByRole("button", { name: "Envoyer un SMS" }).click()133 await page.getByPlaceholder("+14185550123").fill("+14185550123")134 await page.locator("textarea").fill("Bonjour depuis MacLustr ! Ceci est un message de démonstration assez long pour tenir sur deux segments SMS, afin de montrer le compteur de caractères et l'estimation du découpage.")135 await expect(page.getByText("2 segment(s) SMS estimé(s)")).toBeVisible()136 await shot("07-console")137 await page.getByRole("button", { name: "Continuer" }).click()138 await expect(page.getByText("véritable SMS")).toBeVisible()139 await page.getByRole("button", { name: "Envoyer le SMS" }).click()140 await expect(page.locator("tbody tr").first().locator(".badge")).toHaveText("livré")141 expect(dev.modem.length).toBe(1)142 // un envoi par l'API apparaît en temps réel, sans recharger la page143 const r = await call("POST", "/v1/messages", { key: apiKey, body: { to: "+14185550123", text: "Votre rendez-vous est confirmé pour demain 10 h." }, headers: { "idempotency-key": "ui-1" } })144 expect(r.status).toBe(201)145 await expect(page.locator("tbody tr")).toHaveCount(2)146 dev.mode = "fail"147 await call("POST", "/v1/messages", { key: apiKey, body: { to: "+14185550123", text: "Essai hors couverture" } })148 await expect(page.locator("tbody tr").first().locator(".badge")).toHaveText("échec")149 dev.mode = "ok"150 dev.receive("+14185550123", "Merci, bien reçu !")151 await expect(page.locator("tbody tr").first()).toContainText("Merci, bien reçu !")152 await shot("01-messages")153 await page.locator("tbody tr", { hasText: "rendez-vous" }).click()154 await expect(page.getByText("Journal des transitions")).toBeVisible()155 await expect(page.locator(".timeline")).toContainText("submitted → delivered")156 await shot("02-message-detail")157 await page.getByRole("button", { name: "Fermer" }).click()158})159160test("conversations, file, statistiques, journal, documentation", async () => {161 await nav("Conversations")162 await page.locator("tr", { hasText: "+14185550123" }).click()163 await expect(page.locator(".bubble", { hasText: "Merci, bien reçu !" })).toBeVisible()164 await shot("08-conversation")165 await page.getByRole("button", { name: "Fermer" }).click()166 await dev.close()167 await call("POST", "/v1/messages", { key: apiKey, body: { to: "+14185550123", text: "En attente de l'appareil" } })168 await nav("Queue")169 await expect(page.locator("tbody tr")).toHaveCount(1)170 await expect(page.locator("tbody tr")).toContainText("en file")171 await shot("10-queue")172 await dev.connect()173 await expect(page.getByText("La file est vide.")).toBeVisible()174 await nav("Analytics")175 await expect(page.locator(".tile", { hasText: "SMS demandés" }).locator(".v")).toHaveText("4")176 await shot("11-analytics")177 await nav("Audit Logs")178 await expect(page.locator("tbody")).toContainText("device.paired"); await expect(page.locator("tbody")).toContainText("api_key.created")179 await expect(page.locator("tbody")).not.toContainText("rendez-vous")180 await shot("12-audit")181 await nav("Documentation")182 await expect(page.locator("tbody")).toContainText("/v1/messages/{id}/cancel")183 await shot("13-documentation")184 await nav("Webhooks")185 await expect(page.getByText("Aucun webhook configuré.")).toBeVisible()186 await shot("14-webhooks")187})188189test("arrêt d'urgence : bannière, API refusée, reprise", async () => {190 await nav("Settings")191 await page.getByRole("button", { name: "Déclencher l'arrêt d'urgence" }).click()192 await page.getByRole("button", { name: "Tout arrêter" }).click()193 await expect(page.locator(".banner")).toContainText("Arrêt d'urgence actif")194 await shot("15-arret-urgence")195 expect((await call("POST", "/v1/messages", { key: apiKey, body: { to: "+14185550123", text: "x" } })).body.error.code).toBe("kill_switch_active")196 await page.getByRole("button", { name: "Lever l'arrêt d'urgence" }).click()197 await page.getByRole("button", { name: "Reprendre les envois" }).click()198 await expect(page.locator(".banner")).toHaveCount(0)199 expect((await call("POST", "/v1/messages", { key: apiKey, body: { to: "+14185550123", text: "reprise" } })).status).toBe(201)200})201202test("page /apps : APK signé, empreinte, lien temporaire pour le téléphone", async () => {203 const rel = JSON.parse(readFileSync("releases/android-release.json", "utf8"))204 await page.goto("/apps")205 await expect(page.getByText(`MacLustr SMS ${rel.version}`)).toBeVisible()206 await expect(page.locator("body")).toContainText(rel.sha256)207 await shot("16-apps")208 const cookies = (await page.context().cookies()).map(c => `${c.name}=${c.value}`).join("; ")209 const apk = await fetch("http://localhost:8762/api/admin/android/download", { headers: { cookie: cookies } })210 expect(apk.status).toBe(200)211 expect(crypto.createHash("sha256").update(Buffer.from(await apk.arrayBuffer())).digest("hex")).toBe(rel.sha256)212 expect((await fetch("http://localhost:8762/api/admin/android/download")).status).toBe(401)213 await page.getByRole("button", { name: "Lien temporaire pour le téléphone" }).click()214 const url = (await page.locator(".modal pre").innerText()).trim()215 const dl = await fetch(url)216 expect(dl.status).toBe(200); expect(dl.headers.get("content-type")).toBe("application/vnd.android.package-archive")217 expect(Number(dl.headers.get("content-length"))).toBe(rel.size)218 await dl.body?.cancel()219 await page.getByRole("button", { name: "Fermer" }).click()220 await page.goto("/android") // alias221 await expect(page.getByText(`MacLustr SMS ${rel.version}`)).toBeVisible()222})223224test("vue d'ensemble (sombre et clair), déconnexion puis connexion par clé d'accès", async () => {225 await page.goto("/")226 await expect(page.locator(".tile", { hasText: "Appareils connectés" }).locator(".v")).toHaveText("1")227 await until(async () => (await sql`select count(*)::int as n from message_queue`)[0].n === 0, "file vide")228 await expect(page.locator(".tile", { hasText: "Messages en attente" }).locator(".v")).toHaveText("0")229 await shot("17-overview-sombre")230 await page.emulateMedia({ colorScheme: "light" }); await shot("18-overview-clair"); await page.emulateMedia({ colorScheme: "dark" })231 await page.getByText("Se déconnecter").click()232 await expect(page.getByRole("button", { name: "Se connecter avec une clé d'accès" })).toBeVisible()233 await page.goto("/settings")234 await expect(page.getByRole("button", { name: "Se connecter avec une clé d'accès" })).toBeVisible()235 await page.getByRole("button", { name: "Se connecter avec une clé d'accès" }).click()236 await expect(page.getByRole("heading", { name: "Settings" })).toBeVisible()237})238