SPB Git

Repository Public

engine.spec.ts 8.7 KB 97 lines typescript

1import { expect, test, type Page } from "@playwright/test";23const PASSWORD = process.env.SPTV_PASSWORD ?? "";4test.skip(!PASSWORD, "SPTV_PASSWORD requis");5async function login(page: Page) {6  await page.goto("/connexion"); await page.fill('input[name="username"]', process.env.SPTV_USERNAME ?? "sp"); await page.fill('input[name="password"]', PASSWORD);7  await page.click('button[type="submit"]'); await page.waitForURL((u) => u.pathname === "/");8}9const get = <T,>(page: Page, path: string) => page.evaluate(async (p) => (await fetch(p)).json(), `/api${path}`) as Promise<T>;10const send = (page: Page, method: string, path: string, body?: unknown) => page.evaluate(async ([m, p, b]) => { const r = await fetch(p as string, { method: m as string, headers: b ? { "content-type": "application/json" } : undefined, body: b ? JSON.stringify(b) : undefined }); return { status: r.status, body: await r.json().catch(() => ({})) }; }, [method, `/api${path}`, body] as const);11interface T { id: number; title: string; kind: string; rights: string; source: string }12interface Inst { uid: string; type: string; family: string; name: string; builtin: boolean; metrics: { label: string; value: number }[] }1314test("moteur de sources : routes fermées sans session", async ({ request }) => {15  for (const p of ["/api/admin/engine", "/api/provider/stream/1", "/api/provider/media/1"]) expect((await request.get(p)).status(), p).toBe(401);16  expect((await request.post("/api/admin/engine", { data: { type: "stream", fields: {} } })).status()).toBeGreaterThanOrEqual(401);17});1819test("moteur de sources : connecteurs, métriques réelles, ajout et retrait sans code", async ({ page }) => {20  await login(page);21  const e = await get<{ types: { type: string; builtin?: boolean }[]; instances: Inst[]; totals: Record<string, number> }>(page, "/admin/engine");22  expect(e.types.map((t) => t.type)).toEqual(expect.arrayContaining(["m3u-url", "m3u-file", "stream", "xtream", "xmltv", "jellyfin", "wikidata", "onf", "arte", "nasa"]));23  expect(new Set(e.instances.map((i) => i.family))).toEqual(new Set(["live", "guide", "vod", ...(e.instances.some((i) => i.family === "library") ? ["library"] : [])]));24  expect(e.totals.playableChannels).toBeGreaterThan(1000); expect(e.totals.playableChannels).toBeLessThanOrEqual(e.totals.channels);25  const main = e.instances.find((i) => i.name.startsWith("IPTV-org — playlist principale"))!;26  expect(main.metrics.find((m) => m.label === "chaînes uniques à cette source")!.value).toBeGreaterThan(1000);27  // Refusals: internal addresses, missing consent, unknown type, wrong credentials reported without echoing them.28  expect((await send(page, "POST", "/admin/engine", { type: "stream", fields: { name: "x", url: "http://192.168.2.1/a.m3u8" }, consent: true })).status).toBe(400);29  expect((await send(page, "POST", "/admin/engine", { type: "stream", fields: { name: "x", url: "https://example.org/a.m3u8" } })).status).toBe(400);30  expect((await send(page, "POST", "/admin/engine", { type: "inconnu", fields: { name: "x" }, consent: true })).status).toBe(400);31  const bad = await send(page, "POST", "/admin/engine/test", { type: "jellyfin", fields: { name: "x", server: "http://127.0.0.1:9", username: "u", password: "motdepasse-secret" } });32  expect((bad.body as { ok: boolean }).ok).toBe(false); expect(JSON.stringify(bad.body)).not.toContain("motdepasse-secret");33  // Test, add, see, remove a single-stream source through the same API the screen uses.34  const url = "https://cdn3.wowza.com/5/bkFzbG5oWS9QSisz/diffusion/canal17/playlist.m3u8?sptv-e2e=1";35  const probe = await send(page, "POST", "/admin/engine/test", { type: "stream", fields: { name: "Test E2E", url } });36  expect(probe.status).toBe(200); expect(typeof (probe.body as { message: string }).message).toBe("string");37  const added = await send(page, "POST", "/admin/engine", { type: "stream", fields: { name: "Test E2E flux", url, country: "CA" }, consent: true });38  expect(added.status).toBe(200); const uid = (added.body as { uid: string }).uid;39  try {40    const after = await get<{ instances: Inst[] }>(page, "/admin/engine");41    expect(after.instances.find((i) => i.uid === uid)).toMatchObject({ type: "stream", family: "live", builtin: false });42    expect((await send(page, "PATCH", `/admin/engine/${uid}`, { priority: 7 })).status).toBe(200);43    await page.goto("/admin"); await page.getByRole("tab", { name: "Sources" }).click();44    await expect(page.getByText("Test E2E flux")).toBeVisible(); await expect(page.getByRole("heading", { name: "Ajouter une source" })).toBeVisible();45    await expect(page.getByRole("button", { name: /Fournisseur IPTV/ })).toBeVisible(); await expect(page.getByRole("button", { name: /Bibliothèque Jellyfin/ })).toBeVisible();46  } finally { expect((await send(page, "DELETE", `/admin/engine/${uid}`)).status).toBe(200); }47  expect((await send(page, "DELETE", `/admin/engine/${main.uid}`)).status).toBe(400); // built-in sources are switched off, not deleted48});4950test("ARTE : programme lu dans le lecteur officiel, droits datés", async ({ page }, info) => {51  await login(page);52  const a = await get<{ total: number; items: T[] }>(page, "/titles?source=ARTE&kind=movie&limit=5");53  test.skip(!a.total, "catalogue ARTE pas encore importé");54  expect(a.items.every((t) => t.rights === "official")).toBe(true);55  const d = await get<{ title: { rightsBasis: string; sourceUrl: string } }>(page, `/titles/${a.items[0].id}`);56  expect(d.title.rightsBasis).toMatch(/ARTE/); expect(d.title.sourceUrl).toMatch(/^https:\/\/www\.arte\.tv\//);57  await page.goto(`/titre/${a.items[0].id}`); await page.getByRole("button", { name: /^Regarder/ }).first().click();58  await expect(page.locator("[data-vod] iframe")).toHaveAttribute("src", /^https:\/\/www\.arte\.tv\/embeds\/fr\/[\w-]+$/);59  await expect(page.getByRole("link", { name: /Voir sur arte\.tv/ })).toBeVisible();60  if (!info.project.name.startsWith("chromium")) {61    await page.waitForTimeout(7000);62    const f = page.frames().find((x) => x.url().includes("arte.tv/embeds")); expect(f, "le lecteur ARTE doit être chargé").toBeTruthy();63    const ok = await f!.evaluate(async () => { const v = document.querySelector("video"); await v?.play?.().catch(() => {}); await new Promise((r) => setTimeout(r, 8000)); const w = document.querySelector("video"); return !!w && w.currentTime > 2; }).catch(() => false);64    console.log(`[${info.project.name}] ARTE « ${a.items[0].title} » : ${ok ? "lu" : "lecteur chargé, lecture non confirmée par le test"}`);65  }66  await page.keyboard.press("Escape");67  const s = await get<{ items: T[] }>(page, "/titles?source=ARTE&kind=series&limit=1");68  if (s.items[0]) { const sd = await get<{ seasons: { episodes: unknown[] }[] }>(page, `/titles/${s.items[0].id}`); expect(sd.seasons[0].episodes.length).toBeGreaterThan(1); }69});7071test("NASA : vidéo lue directement", async ({ page }, info) => {72  await login(page);73  const n = await get<{ total: number; items: T[] }>(page, "/titles?source=NASA&limit=3");74  test.skip(!n.total, "catalogue NASA pas encore importé");75  expect(n.items[0].rights).toBe("pd");76  await page.goto(`/titre/${n.items[0].id}`);77  await expect(page.getByRole("link", { name: /Page de la source/ })).toHaveAttribute("href", /^https:\/\/images\.nasa\.gov\/details\//);78  if (info.project.name.startsWith("chromium")) return;79  await page.getByRole("button", { name: /^(Regarder|Reprendre)/ }).first().click();80  const ok = await page.waitForFunction(() => { const v = document.querySelector<HTMLVideoElement>("[data-vod] video"); return !!v && !v.paused && v.readyState >= 3 && v.currentTime > 2; }, null, { timeout: 60_000 }).then(() => true, () => false);81  expect(ok, "la vidéo NASA doit être lue").toBe(true);82  expect(await page.evaluate(() => document.querySelector<HTMLVideoElement>("[data-vod] video")!.currentSrc)).toMatch(/^https:\/\/images-assets\.nasa\.gov\//);83  await page.keyboard.press("Escape");84});8586test("Sports, Paramètres et services officiels", async ({ page }) => {87  await login(page);88  await page.goto("/sports"); await expect(page.getByRole("heading", { name: "Sports", level: 1 })).toBeVisible();89  await expect(page.getByText(/chaînes? sportives? disponibles? au dernier test/)).toBeVisible();90  await page.goto("/parametres"); await expect(page.getByRole("heading", { name: "Paramètres", level: 1 })).toBeVisible();91  await expect(page.getByText("Reprendre la dernière chaîne à l'ouverture")).toBeVisible();92  await page.goto("/chaines?country=CA&language=fra");93  await expect(page.getByRole("heading", { name: "Services officiels à ouvrir sur leur site" })).toBeVisible({ timeout: 20_000 });94  await expect(page.getByRole("link", { name: /Télé-Québec/ })).toHaveAttribute("href", "https://video.telequebec.tv/");95  expect(await page.evaluate(() => document.documentElement.scrollWidth - document.documentElement.clientWidth)).toBeLessThanOrEqual(1);96});97
Files main
Menu

Theme