// Ported from core in Phase 3 (MODULE_SYSTEM.md §2.7.1). One change runs through // every moved test: core internals can no longer be stubbed by requiring them, // because there are none to require — `../utils/db` and `../model/settings` do // not exist here. What a test controls instead is the `ctx` core would have // handed over, installed once by `test/_setup.js`, which is the seam the // contract actually promises. const { test, beforeEach, afterEach } = require('node:test') const assert = require('node:assert/strict') // Exercise the News-gump sync decisions against a fake sidecar client by // monkeypatching the shared modules newsGump require()s (same instance) — no DB, // no network. const uoLinkClient = require('../utils/uoLinkClient') const { ctx } = require('./_setup') const settings = ctx.settings const newsGump = require('../utils/newsGump') let calls const saved = {} beforeEach(() => { calls = { post: [], del: [] } saved.postNews = uoLinkClient.postNews saved.deleteNews = uoLinkClient.deleteNews saved.get = settings.get uoLinkClient.postNews = async (article) => { calls.post.push(article); return { ok: true, status: 200 } } uoLinkClient.deleteNews = async (id) => { calls.del.push(id); return { ok: true, status: 200 } } settings.get = async () => null // no gump image configured }) afterEach(() => { uoLinkClient.postNews = saved.postNews uoLinkClient.deleteNews = saved.deleteNews settings.get = saved.get }) const newsPost = (over = {}) => ({ id: 42, category: 'news', published: true, title: 'Double XP Weekend', excerpt: 'Starts Friday.', body: null, ...over }) test('buildArticle centres the title, links the news list, and respects announce', async () => { const a = await newsGump.buildArticle(newsPost(), { announce: false }) assert.equal(a.id, '42') assert.match(a.body, /