e42417bd6e
Enable daily morning greeting on reply 1 (with custom time, modify, and cancel), random greeting delivery, M发现 in subscribe welcome, and optional LLM parsing when rules miss. Also fix WeChat MP draft/config error passthrough and add Tang E2E scripts. Co-authored-by: Cursor <cursoragent@cursor.com>
57 lines
1.9 KiB
JavaScript
57 lines
1.9 KiB
JavaScript
import assert from 'node:assert/strict';
|
|
import test from 'node:test';
|
|
|
|
import {
|
|
createWechatSubscribeMorningLlmConfigService,
|
|
wechatSubscribeMorningLlmConfigInternals,
|
|
} from './wechat-subscribe-morning-llm-config.mjs';
|
|
|
|
function createPool(seedRow = null) {
|
|
const state = { row: seedRow };
|
|
return {
|
|
async query(sql, params) {
|
|
if (sql.includes('CREATE TABLE')) return [[], []];
|
|
if (sql.includes('SELECT config_json')) {
|
|
return [state.row ? [state.row] : [], []];
|
|
}
|
|
if (sql.includes('INSERT INTO h5_wechat_admin_config')) {
|
|
state.row = {
|
|
config_json: params[1],
|
|
updated_by: params[2],
|
|
updated_at: params[3],
|
|
};
|
|
return [[], []];
|
|
}
|
|
throw new Error(`Unexpected query: ${sql}`);
|
|
},
|
|
};
|
|
}
|
|
|
|
test('subscribe morning llm config falls back to env defaults', async () => {
|
|
const service = createWechatSubscribeMorningLlmConfigService(createPool(), {
|
|
env: { H5_WECHAT_SUBSCRIBE_MORNING_LLM_ENABLED: '1' },
|
|
});
|
|
const result = await service.getConfig();
|
|
assert.equal(result.subscribeMorningLlmEnabled, true);
|
|
assert.equal(result.minConfidence, 0.65);
|
|
});
|
|
|
|
test('subscribe morning llm config persists admin toggle', async () => {
|
|
const service = createWechatSubscribeMorningLlmConfigService(createPool(), {
|
|
env: { H5_WECHAT_SUBSCRIBE_MORNING_LLM_ENABLED: '0' },
|
|
});
|
|
const updated = await service.updateConfig({ subscribeMorningLlmEnabled: true }, { updatedBy: 'admin-1' });
|
|
assert.equal(updated.subscribeMorningLlmEnabled, true);
|
|
assert.equal(await service.isSubscribeMorningLlmEnabled(), true);
|
|
});
|
|
|
|
test('subscribe morning llm config internals normalize booleans', () => {
|
|
assert.equal(wechatSubscribeMorningLlmConfigInternals.normalizeBoolean('1', false), true);
|
|
assert.equal(
|
|
wechatSubscribeMorningLlmConfigInternals.defaultsFromEnv({
|
|
H5_WECHAT_SUBSCRIBE_MORNING_LLM_ENABLED: 'true',
|
|
}).subscribeMorningLlmEnabled,
|
|
true,
|
|
);
|
|
});
|