// The XenForo extractor over SYNTHETIC captures (__fixtures__/xenforoCaptures.ts, // built on the forum parser's own synthetic thread page): a capture's posts // are the posts a live forum channel stores for the same page — same ids, // same `forum`, same text — and a captured wall is accounted for. // // Run with: pnpm --filter yt-dlp-transcript-common exec tsx --test lib/waybackPages/extractors/xenforo.test.ts import { test } from "node:test"; import assert from "node:assert/strict"; import { parseXenforoThreadPage } from "../../../social/xenforoParse"; import { extractXenforo, xenforoExtractor } from "./xenforo"; import { captureOf } from "./__fixtures__/capture"; import { CAPTURE_TS, LIVE_PAGE, LOGIN_WALL, REPLAY_PAGE, THREAD_URL } from "./__fixtures__/xenforoCaptures"; const PAGE_URL = `${THREAD_URL}page-2`; test("a replayed capture's posts line up with the live channel's posts of the same page", () => { const live = parseXenforoThreadPage(LIVE_PAGE, { channelSlug: "teapots", pageUrl: PAGE_URL }).posts; const drafts = extractXenforo({ html: REPLAY_PAGE, capture: captureOf(PAGE_URL, CAPTURE_TS) }); assert.deepEqual(drafts.map((d) => d.itemId), ["1001", "1002", "1003"]); assert.deepEqual(drafts.map((d) => d.itemId), live.map((p) => p.id)); drafts.forEach((d, i) => { const p = live[i]; assert.equal(d.kind, "forum-post"); assert.equal(d.url, p.url); assert.equal(d.author, p.author); assert.equal(d.publishedAt, p.createdAt); assert.equal(d.text, p.text); assert.deepEqual(d.links, p.links); assert.deepEqual(d.media, p.media); assert.deepEqual(d.forum, p.forum); assert.deepEqual(d.replyTo, p.replyTo); assert.deepEqual(d.quoted, p.quoted); assert.equal(d.isReply, p.isReply); assert.equal(d.title, "The Teapot Collectors Thread"); }); assert.equal(drafts[0].publishedAt, "2023-11-14T22:13:20.000Z"); assert.equal(drafts[0].text, "The blue one is a reproduction.\nLook at the glaze."); assert.deepEqual(drafts[0].forum, { host: "forum.example", threadId: "4242", page: 2, threadTitle: "The Teapot Collectors Thread", threadUrl: THREAD_URL, position: 21, authorId: "7", }); // A quote is a reply ref to the quoted post, on the forum's platform. assert.deepEqual(drafts[1].quoted, { platform: "xenforo", id: "1001", url: "https://forum.example/posts/1001/", author: "Marigold" }); // No URL in a draft points back into the Wayback Machine. const urls = drafts.flatMap((d) => [d.url ?? "", ...d.links, ...(d.media ?? []).map((m) => m.url)]); assert.ok(urls.every((u) => !u.includes("web.archive.org")), urls.join(" ")); }); test("a captured login wall: one whole-page noContent draft saying so", () => { const drafts = extractXenforo({ html: LOGIN_WALL, capture: captureOf(PAGE_URL, CAPTURE_TS) }); assert.deepEqual(drafts, [ { kind: "generic", text: "This capture holds no forum posts. The forum asked for a login.", links: [], noContent: true, title: "Log in | Example Forum", }, ]); }); test("matches: XenForo's markup on any host, nothing else", () => { const m = (html: string) => xenforoExtractor.matches(new URL("https://forum.example/threads/x.1/"), html); assert.equal(m(LIVE_PAGE), true); assert.equal(m(REPLAY_PAGE), true); assert.equal(m(LOGIN_WALL), true); assert.equal(m("