2baf29b3ae
Deliver encrypted health zone, observation API, baseline maturity pipeline, page-data bindings, and H5/WeChat channel integration for health P0. Co-authored-by: Cursor <cursoragent@cursor.com>
84 lines
2.8 KiB
JavaScript
84 lines
2.8 KiB
JavaScript
import assert from 'node:assert/strict';
|
|
import fs from 'node:fs';
|
|
import os from 'node:os';
|
|
import path from 'node:path';
|
|
import test from 'node:test';
|
|
import {
|
|
bootstrapHealthWorkspace,
|
|
ensureHealthTimelinePage,
|
|
HEALTH_TIMELINE_PAGE_TITLE,
|
|
} from './health-workspace-bootstrap.mjs';
|
|
import { resetHealthPageDataBootstrapCache } from './health-page-data-bootstrap.mjs';
|
|
|
|
test('bootstrapHealthWorkspace registers share snapshot dataset', async () => {
|
|
resetHealthPageDataBootstrapCache();
|
|
const workspaceRoot = fs.mkdtempSync(path.join(os.tmpdir(), 'health-ws-'));
|
|
const userId = 'health-bootstrap-user';
|
|
const result = await bootstrapHealthWorkspace({
|
|
userId,
|
|
env: { MEMIND_HEALTH_ENABLED: '1', NODE_TEST_CONTEXT: '1' },
|
|
resolveWorkspaceRoot: async () => workspaceRoot,
|
|
});
|
|
assert.equal(result.ok, true);
|
|
assert.equal(result.firstBootstrap, true);
|
|
assert.ok(result.datasets.includes('health_share_snapshots'));
|
|
});
|
|
|
|
test('ensureHealthTimelinePage creates a health category html page once', async () => {
|
|
const created = [];
|
|
const pages = [{ id: 'page-1', title: HEALTH_TIMELINE_PAGE_TITLE, templateId: 'health-timeline-summary' }];
|
|
const createHealthSystemPage = async (_userId, input) => {
|
|
created.push(input);
|
|
return { id: 'page-1', ...input };
|
|
};
|
|
const listPages = async () => ({ items: pages, total: pages.length });
|
|
|
|
const first = await ensureHealthTimelinePage({
|
|
userId: 'user-1',
|
|
createHealthSystemPage,
|
|
listPages,
|
|
});
|
|
assert.equal(first.skipped, true);
|
|
assert.equal(first.pageId, 'page-1');
|
|
|
|
const second = await ensureHealthTimelinePage({
|
|
userId: 'user-1',
|
|
createHealthSystemPage: async () => {
|
|
throw new Error('should not create twice');
|
|
},
|
|
listPages,
|
|
});
|
|
assert.equal(second.skipped, true);
|
|
assert.equal(created.length, 0);
|
|
});
|
|
|
|
test('ensureHealthTimelinePage falls back to workspace file without page service', async () => {
|
|
const h5Root = fs.mkdtempSync(path.join(os.tmpdir(), 'health-timeline-file-'));
|
|
const userId = '11111111-1111-1111-1111-111111111111';
|
|
const result = await ensureHealthTimelinePage({
|
|
userId,
|
|
h5Root,
|
|
createHealthSystemPage: null,
|
|
listPages: null,
|
|
});
|
|
assert.equal(result.ok, true);
|
|
assert.equal(result.mode, 'workspace_file');
|
|
assert.equal(result.relativePath, 'public/health-timeline-summary.html');
|
|
});
|
|
|
|
test('ensureHealthTimelinePage creates page when listPages is unavailable', async () => {
|
|
const created = [];
|
|
const result = await ensureHealthTimelinePage({
|
|
userId: 'user-2',
|
|
createHealthSystemPage: async (_userId, input) => {
|
|
created.push(input);
|
|
return { id: 'page-new', ...input };
|
|
},
|
|
});
|
|
assert.equal(result.ok, true);
|
|
assert.equal(result.skipped, false);
|
|
assert.equal(result.pageId, 'page-new');
|
|
assert.equal(created[0].categoryCode, 'health');
|
|
assert.equal(created[0].contentFormat, 'html');
|
|
});
|