import { test } from "node:test"; import assert from "node:assert/strict"; import { CITED_CHANNELS_FIELD, citedChannelsFromForm } from "./citedChannelsFromForm"; // Run with: pnpm -C editor exec tsx --test "app/**/*.test.ts" function form(value?: string): FormData { const fd = new FormData(); if (value !== undefined) fd.set(CITED_CHANNELS_FIELD, value); return fd; } test("the ticked slugs, trimmed, blanks and repeats dropped, in the order sent", () => { assert.deepEqual(citedChannelsFromForm(form('["critic", " other ", "critic", "", 3]'), []), [ { slug: "critic" }, { slug: "other" }, ]); // A `{slug}` entry reads the same as a bare slug. assert.deepEqual(citedChannelsFromForm(form('[{"slug":"critic"}]'), []), [{ slug: "critic" }]); }); test("a channel the pool holds is never cited-only: the pool wins", () => { assert.deepEqual( citedChannelsFromForm(form('["pool", "critic"]'), [{ slug: "pool" }]), [{ slug: "critic" }], ); }); test("no field is no cited scope; a malformed payload is refused, never read as none", () => { assert.deepEqual(citedChannelsFromForm(form(), []), []); assert.deepEqual(citedChannelsFromForm(form("[]"), []), []); assert.equal(citedChannelsFromForm(form("{"), []), null); assert.equal(citedChannelsFromForm(form('{"slug":"x"}'), []), null); assert.equal(citedChannelsFromForm(form('"critic"'), []), null); });