Files
memind/schedule-reminder-worker.test.mjs
T
john 229805a070 Improve WeChat MP replies and ship MindSpace/H5 production updates.
Add WeChat service account routing with sync acks, connectivity tests, and context isolation; document deploy runbooks; and bundle related MindSpace, voice, Plaza, and server gateway changes for production rollout.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-19 23:06:43 +08:00

55 lines
1.5 KiB
JavaScript

import assert from 'node:assert/strict';
import test from 'node:test';
import { startScheduleReminderWorker } from './schedule-reminder-worker.mjs';
test('schedule reminder worker sends due daily todo digest', async () => {
const calls = [];
const sent = [];
const subscription = {
id: 'sub-1',
userId: 'user-1',
hour: 7,
minute: 0,
timezone: 'Asia/Shanghai',
channel: 'wechat',
attempts: 1,
};
const worker = startScheduleReminderWorker({
intervalMs: 60_000,
scheduleService: {
async listDueDigestSubscriptions() {
calls.push('list');
return [subscription];
},
async lockDigestSubscription(id) {
calls.push(`lock:${id}`);
return subscription;
},
async buildTodoDigestText({ userId }) {
calls.push(`digest:${userId}`);
return '6月18日 待办记录\n\n1. 开会';
},
async logDelivery(input) {
calls.push(`log:${input.status}`);
},
async markDigestSent(input) {
calls.push(`sent:${input.id}`);
},
async markDigestFailed() {
calls.push('failed');
},
},
async sendWechatTextToUser(userId, text) {
sent.push({ userId, text });
},
logger: { warn() {} },
runOnStart: false,
});
await worker.runOnce();
worker.stop();
assert.deepEqual(sent, [{ userId: 'user-1', text: '6月18日 待办记录\n\n1. 开会' }]);
assert.deepEqual(calls, ['list', 'lock:sub-1', 'digest:user-1', 'log:success', 'sent:sub-1']);
});