Files
com.gregkilmer.www/services/admin/test/posts.test.ts
Claude a9fb5b3e85 Admin: write blog posts and manage images
A Posts page lists every post with Write a post: title, topic, kind,
date, summary, a cover picked from the vault or uploaded, the pages it is
about, the Markdown body with a rendered preview, and Save draft or
Publish. An Images page uploads several images into an _attachments
folder, shows which notes use each one, copies its embed line, and
deletes unused ones. The content service gains the attachment list,
upload and delete endpoints behind the editor and admin tokens.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012aSbo2D1qP8cMFQCykf7kx
2026-10-12 03:40:59 +00:00

45 lines
1.4 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { draftFromForm, postFields } from "../src/posts.ts";
const form = (pairs: [string, string][]) => new URLSearchParams(pairs);
describe("post form", () => {
const d = draftFromForm(
form([
["title", " Pouring galaxy dice "],
["date", "2026-10-12"],
["topic", "Making"],
["postType", "article"],
["summary", "How the set came together."],
["cover", "[[galaxy.jpg]]"],
["links", "Resin"],
["links", "[[Galaxy dice]]"],
["links", ""],
["role", "Ignored for articles"],
["body", "Line one\r\nLine two"],
]),
);
it("reads the form into a draft", () => {
expect(d).toMatchObject({ title: "Pouring galaxy dice", cover: "galaxy.jpg", links: ["Resin", "Galaxy dice"], body: "Line one\nLine two" });
});
it("writes note fields, with links and the cover as wikilinks", () => {
expect(postFields(d, true, false)).toEqual({
title: "Pouring galaxy dice",
date: "2026-10-12",
topic: "Making",
postType: "article",
summary: "How the set came together.",
publish: true,
cover: "[[galaxy.jpg]]",
links: ["[[Resin]]", "[[Galaxy dice]]"],
});
});
it("clears emptied fields on an update", () => {
const f = postFields({ ...d, cover: "", links: [] }, false, true);
expect(f).toMatchObject({ cover: null, links: null, pinned: null, role: null, publish: false });
});
});