import test from 'node:test';import assert from 'node:assert/strict';
import {renderNewsBody,validateNewsContent,newsBBCode,newsPlainText} from '../web/news-format.mjs';
import {forumNewsRevision} from '../node/forum-news.mjs';
import {createApplication} from '../node/server.mjs';import {LocalD1} from './d1-adapter.mjs';
const article='# A dispatch\n\nOur **House** uses *care* and `code`. Read [the report](https://www.dunerealms.com/news).\n\n1. First item\n2. Second item\n\n- One\n- Two\n\n';
test('one article retains formatting, link labels, ordered lists and image alt text across website, forum and plain delivery',()=>{
assert.equal(validateNewsContent(article),article);const html=renderNewsBody(article),forum=newsBBCode(article),plain=newsPlainText(article);
for(const expected of ['
A dispatch
','House','care','code','- First item
','- One
','alt="House seal"','rel="noopener noreferrer"'])assert.ok(html.includes(expected),expected);
for(const expected of ['[b]House[/b]','[i]care[/i]','[list=1]','[url=https://www.dunerealms.com/news]the report[/url]','[img]https://www.dunerealms.com/assets/seals/house-seal.webp[/img]'])assert.ok(forum.includes(expected),expected);
assert.match(plain,/Our House uses care and code\. Read the report/);assert.ok(!plain.includes('**'));assert.ok(plain.includes('House seal'));
const post=forumNewsRevision({id:'id',status:'published',published_at:1,title:'Title',body:article,category:'news',author_name:'Author'},2);assert.equal(post.format_version,3);assert.equal(post.body_bbcode,forum);assert.equal(post.author_name,'Author');
});
test('unsafe schemes, credentials, HTML and remote images fail validation; renderers cannot turn legacy input into active code',()=>{
for(const body of ['','[click](javascript:alert(1))','[click](data:text/html,hello)','[click](https://user:pass@example.com)','',''])assert.throws(()=>validateNewsContent(body),body);
const html=renderNewsBody('
\n\n[click](javascript:alert(1))\n\n');assert.ok(!html.includes('
bad');assert.ok(!bb.includes('[img]'));assert.ok(!bb.includes('