22 test files moved from core, plus the two that were split out of files core keeps. 351 tests pass. One change runs through every moved test, and it is the boundary rather than a chore: 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 a better seam anyway, since it is exactly the surface the contract promises and nothing wider. The ctx _setup installs is deliberately unfrozen. Core freezes what it hands a module and entry.test.js still asserts against a frozen one; but a test that needs settings.get to return a path has to be able to say so. Two tests changed SHAPE, and that is the boundary too. fromShardEvent used to assert through publish() into pushDevices and a captured fetch -- which endpoints were hit, how many requests went out. None of that is this module's any more: publish is ctx.push.publish, and the device registry and the relay are behind it. Reaching for them from here would be reaching past ctx. What remains is what the module owns and is the part worth guarding: a game account resolves to a website user, a personal target that resolves to nobody is dropped rather than published, and a sensitive kind never reaches publish at all. Co-Authored-By: Claude <noreply@anthropic.com>
78 lines
3.2 KiB
JavaScript
78 lines
3.2 KiB
JavaScript
// 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, /<CENTER>Double XP Weekend<\/CENTER>/)
|
|
assert.match(a.body, /Starts Friday\./)
|
|
assert.match(a.url, /\/site\/news$/)
|
|
assert.equal(a.announce, false)
|
|
})
|
|
|
|
test('a fresh publish into news pushes with announce=true', async () => {
|
|
await newsGump.syncPost(newsPost(), { wasPublished: false, wasNews: false })
|
|
assert.equal(calls.post.length, 1)
|
|
assert.equal(calls.post[0].announce, true)
|
|
assert.equal(calls.del.length, 0)
|
|
})
|
|
|
|
test('an edit of already-published news refreshes silently (announce=false)', async () => {
|
|
await newsGump.syncPost(newsPost({ title: 'Edited' }), { wasPublished: true, wasNews: true })
|
|
assert.equal(calls.post.length, 1)
|
|
assert.equal(calls.post[0].announce, false)
|
|
})
|
|
|
|
test('unpublishing published news pulls the article from the gump', async () => {
|
|
await newsGump.syncPost(newsPost({ published: false }), { wasPublished: true, wasNews: true })
|
|
assert.equal(calls.post.length, 0)
|
|
assert.deepEqual(calls.del, ['42'])
|
|
})
|
|
|
|
test('a draft never-published news post does nothing', async () => {
|
|
await newsGump.syncPost(newsPost({ published: false }), { wasPublished: false, wasNews: false })
|
|
assert.equal(calls.post.length, 0)
|
|
assert.equal(calls.del.length, 0)
|
|
})
|
|
|
|
test('a non-news post (e.g. screenshot) is never pushed', async () => {
|
|
await newsGump.syncPost(newsPost({ category: 'screenshot' }), { wasPublished: false, wasNews: false })
|
|
assert.equal(calls.post.length, 0)
|
|
})
|