// The social text (release 29 G2): out/x.txt and out/bluesky.txt composed by // code from `publish.x` / `publish.bluesky` — the first post, then each // thread post under a `— k/n —` line — and build-video's writer, which writes // each platform's file and removes one whose post is gone. // // Run with: node --test umtool/report-to-video/social.test.mjs import assert from "node:assert/strict"; import test, { after } from "node:test"; import { existsSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs"; import os from "node:os"; import path from "node:path"; import { composeSocialText, socialPosts, socialTextName, socialTexts } from "./social.mjs"; import { writeSocialText } from "./build-video.mjs"; const ROOT = mkdtempSync(path.join(os.tmpdir(), "social-text-")); after(() => rmSync(ROOT, { recursive: true, force: true })); const LINK = "https://archilyzer.example/articles/synth-basic/"; test("one post is the file; a thread is numbered under it, each post whole", () => { assert.equal(composeSocialText({ post: `The post.\n\n${LINK}` }), `The post.\n\n${LINK}\n`); assert.equal( composeSocialText({ post: `The post.\n\n${LINK}`, thread: ["Two.", " ", "Three."] }), `The post.\n\n${LINK}\n\n— 2/3 —\nTwo.\n\n— 3/3 —\nThree.\n`, ); assert.equal(composeSocialText({ post: " " }), null); assert.equal(composeSocialText(undefined), null); assert.deepEqual(socialPosts({ post: "a", thread: ["b", ""] }), ["a", "b"]); assert.equal(socialTextName("x"), "x.txt"); assert.deepEqual( socialTexts({ publish: { bluesky: { post: "b" } } }).map((t) => [t.name, t.text]), [ ["x.txt", null], ["bluesky.txt", "b\n"], ], ); }); test("build-video writes each platform's file, and removes one whose post is gone", async () => { writeFileSync(path.join(ROOT, "x.txt"), "an old post\n"); await writeSocialText({ publish: { bluesky: { post: `The post.\n\n${LINK}`, thread: ["Two."] } } }, ROOT); assert.equal(readFileSync(path.join(ROOT, "bluesky.txt"), "utf8"), `The post.\n\n${LINK}\n\n— 2/2 —\nTwo.\n`); assert.equal(existsSync(path.join(ROOT, "x.txt")), false, "the manifest has no X post now"); await writeSocialText({}, ROOT); assert.equal(existsSync(path.join(ROOT, "bluesky.txt")), false); });