Files
memind/health-event-notification.test.mjs
T
john 2baf29b3ae feat(health): complete P0 health channel — baseline engine, page-data, MindSpace UI
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>
2026-09-09 18:04:57 +08:00

85 lines
2.6 KiB
JavaScript

import assert from 'node:assert/strict';
import test from 'node:test';
import {
buildHealthEventNotificationCopy,
formatHealthAlertsPreamble,
isHealthAlertsAckText,
shouldAttemptWechatNotification,
shouldCreateWebNotification,
} from './health-event-notification.mjs';
import { createHealthEventNotificationService } from './health-event-notification-service.mjs';
test('notification severity policy matches O5', () => {
assert.equal(shouldCreateWebNotification('info'), false);
assert.equal(shouldCreateWebNotification('watch'), true);
assert.equal(shouldCreateWebNotification('alert'), true);
assert.equal(shouldAttemptWechatNotification('watch'), false);
assert.equal(shouldAttemptWechatNotification('alert'), true);
});
test('buildHealthEventNotificationCopy avoids diagnosis wording', () => {
const alertCopy = buildHealthEventNotificationCopy({
severity: 'alert',
message: 'bp_systolic 近 14 天偏离',
});
assert.match(alertCopy.body, /不是医疗诊断/);
assert.match(alertCopy.body, /下次进入/);
});
test('formatHealthAlertsPreamble requires explicit acknowledgement', () => {
const text = formatHealthAlertsPreamble([
{ severity: 'alert', message: '收缩压偏高' },
]);
assert.match(text, /未读健康提醒/);
assert.match(text, /知道了/);
assert.equal(isHealthAlertsAckText('知道了'), true);
});
test('notification service creates web alert and attempts wechat', async () => {
const calls = [];
const service = createHealthEventNotificationService({
createUserNotification: async (input) => {
calls.push(['web', input.notificationType]);
return input;
},
notificationDispatcher: {
sendHealthEventNotification: async (input) => {
calls.push(['wechat', input.severity]);
return true;
},
},
});
const result = await service.notifyNewEvent(
'user-1',
{
severity: 'alert',
eventType: 'threshold_breach',
ruleId: 'bp_sys_high',
metricType: 'bp_systolic',
message: '收缩压触发阈值',
},
{ eventId: 9 },
);
assert.equal(result.webCreated, true);
assert.equal(result.wechatSent, true);
assert.deepEqual(calls, [
['web', 'health_event_alert'],
['wechat', 'alert'],
]);
});
test('notification service skips info severity', async () => {
const service = createHealthEventNotificationService({
createUserNotification: async () => {
throw new Error('should not notify');
},
});
const result = await service.notifyNewEvent('user-1', {
severity: 'info',
message: 'silent',
});
assert.equal(result.skipped, true);
});