162 lines
4.8 KiB
JavaScript
162 lines
4.8 KiB
JavaScript
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);
|
|
});
|
|
|
|
test('syncAndDeliver scopes sync, bind, publish, and refresh to the current session paths', async () => {
|
|
const calls = {
|
|
sync: null,
|
|
bind: null,
|
|
published: [],
|
|
refreshed: [],
|
|
};
|
|
const rows = [
|
|
{
|
|
page_id: 'page-current',
|
|
title: '当前页',
|
|
current_version_id: 'ver-current',
|
|
workspace_relative_path: 'public/current.html',
|
|
source_snapshot_json: JSON.stringify({
|
|
auto_synced: true,
|
|
relative_path: 'public/current.html',
|
|
content_mode: 'static_html',
|
|
}),
|
|
},
|
|
{
|
|
page_id: 'page-stale',
|
|
title: '历史页',
|
|
current_version_id: 'ver-stale',
|
|
workspace_relative_path: 'public/stale.html',
|
|
source_snapshot_json: JSON.stringify({
|
|
auto_synced: true,
|
|
relative_path: 'public/stale.html',
|
|
content_mode: 'static_html',
|
|
}),
|
|
},
|
|
];
|
|
const service = createWorkspacePageDeliverService({
|
|
h5Root: '/tmp',
|
|
pool: {
|
|
async query() {
|
|
return [rows];
|
|
},
|
|
},
|
|
pageSyncService: {
|
|
async syncUserGeneratedPages(_userId, options) {
|
|
calls.sync = options.onlyRelativePaths;
|
|
return { created: 0, updated: 1, skipped: 0 };
|
|
},
|
|
},
|
|
pageDataEnsure: {
|
|
async ensurePageDataHtmlPagesBound(options) {
|
|
calls.bind = options.onlyRelativePaths;
|
|
return { bound: [], skipped: [], errors: [] };
|
|
},
|
|
},
|
|
pageService: {
|
|
async getPage(_userId, pageId) {
|
|
return {
|
|
id: pageId,
|
|
title: pageId,
|
|
currentVersionId: `ver-${pageId}`,
|
|
};
|
|
},
|
|
},
|
|
publicationService: {
|
|
async getCurrent() {
|
|
return null;
|
|
},
|
|
async publish(_userId, pageId) {
|
|
calls.published.push(pageId);
|
|
return { id: `pub-${pageId}` };
|
|
},
|
|
async refreshOnlinePublicationHtml(_userId, pageId) {
|
|
calls.refreshed.push(pageId);
|
|
return { id: `pub-${pageId}` };
|
|
},
|
|
},
|
|
});
|
|
|
|
const currentPaths = ['public/current.html'];
|
|
const result = await service.syncAndDeliver('user-1', {
|
|
pageDataRelativePaths: currentPaths,
|
|
});
|
|
|
|
assert.deepEqual(calls.sync, currentPaths);
|
|
assert.deepEqual(calls.bind, currentPaths);
|
|
assert.deepEqual(calls.published, ['page-current']);
|
|
assert.deepEqual(calls.refreshed, ['page-current']);
|
|
assert.deepEqual(result.pageDataRelativePaths, currentPaths);
|
|
});
|