// The Twitch join, option (b), in compose (release 23 F1b): a report cites a // Twitch record by its `v`, and readCitedRecord reads it from `data//` // — the record keeps the id it is cited by. Synthetic ids. // // Run with: node_modules/.bin/tsx --test publish/composeReportsTwitch.test.ts import { test } from "node:test"; import assert from "node:assert/strict"; import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs"; import { tmpdir } from "node:os"; import path from "node:path"; import { readCitedRecord } from "./composeReports"; const N = "2700000001"; const VTT = "WEBVTT\nKind: captions\nLanguage: en\n\n" + "00:00:00.000 --> 00:00:05.000 align:start position:0%\n" + "First<00:00:01.000> caption<00:00:02.000> line.\n\n" + "00:01:00.000 --> 00:01:50.000 align:start position:0%\n" + "Second<00:01:10.000> caption<00:01:20.000> line.\n"; function channel(root: string, slug: string, config: object): void { const dir = path.join(root, slug, "data", N); mkdirSync(dir, { recursive: true }); writeFileSync(path.join(root, slug, "config.json"), JSON.stringify(config)); writeFileSync( path.join(dir, "metadata.info.json"), JSON.stringify({ id: `v${N}`, title: "Example stream", upload_date: "20260105", duration: 120, webpage_url: `https://www.twitch.tv/videos/${N}`, extractor_key: "TwitchVod", }), ); writeFileSync(path.join(dir, "transcript.en.vtt"), VTT); } test("readCitedRecord reads a Twitch v citation from data//, and the record keeps its id", async () => { const root = mkdtempSync(path.join(tmpdir(), "compose-twitch-")); try { channel(root, "example-twitch", { handling: "transcribe", url: "https://www.twitch.tv/example" }); const rec = await readCitedRecord(root, "example-twitch", `v${N}`); assert.ok(rec, "the record is found"); assert.equal(rec.summary.id, `v${N}`); assert.equal(rec.summary.slug, `example-twitch/v${N}`); assert.equal(rec.summary.platform, "twitch"); assert.equal(rec.cues.length, 2); // A channel of another platform: a v-id is never mapped. channel(root, "example-yt", { handling: "youtube", platform: "youtube" }); assert.equal(await readCitedRecord(root, "example-yt", `v${N}`), null); } finally { rmSync(root, { recursive: true, force: true }); } });