import assert from 'node:assert/strict'; import test from 'node:test'; import { createWorkspacePageDeliverService } from './mindspace-workspace-page-deliver.mjs'; test('refreshOnlineWorkspacePublications refreshes online auto-synced workspace html pages', async () => { const refreshed = []; const service = createWorkspacePageDeliverService({ pool: { async query() { return [[{ page_id: 'page-1', title: '隔离验证页', current_version_id: 'ver-1', workspace_relative_path: 'public/demo.html', source_snapshot_json: JSON.stringify({ auto_synced: true, relative_path: 'public/demo.html', content_mode: 'static_html', }), }]]; }, }, publicationService: { async refreshOnlinePublicationHtml(userId, pageId) { refreshed.push({ userId, pageId }); return { id: 'pub-1', publicUrl: 'http://127.0.0.1:8081/u/john/pages/page-demo' }; }, }, }); const result = await service.refreshOnlineWorkspacePublications('user-1'); assert.equal(result.refreshed, 1); assert.deepEqual(refreshed, [{ userId: 'user-1', pageId: 'page-1' }]); }); test('ensureWorkspaceHtmlPublications publishes auto-synced workspace html pages', async () => { const published = []; const service = createWorkspacePageDeliverService({ pool: { async query() { return [[{ page_id: 'page-1', title: '隔离验证页', current_version_id: 'ver-1', workspace_relative_path: 'public/demo.html', source_snapshot_json: JSON.stringify({ auto_synced: true, relative_path: 'public/demo.html', content_mode: 'static_html', }), }]]; }, }, pageService: { async getPage() { return { id: 'page-1', title: '隔离验证页', currentVersionId: 'ver-1' }; }, }, publicationService: { async getCurrent() { return null; }, async publish(userId, pageId, input) { published.push({ userId, pageId, input }); return { id: 'pub-1', publicUrl: 'http://127.0.0.1:9181/u/john/pages/page-demo' }; }, }, }); const result = await service.ensureWorkspaceHtmlPublications('user-1'); assert.equal(result.published, 1); assert.equal(published.length, 1); assert.equal(published[0].input.accessMode, 'public'); assert.equal(published[0].input.autoAcknowledgeFindings, true); });