Add wechat reminder LLM toggle
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import {
|
||||
createWechatScheduleLlmConfigService,
|
||||
wechatScheduleLlmConfigInternals,
|
||||
} from './wechat-schedule-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('wechat schedule llm config service falls back to env defaults', async () => {
|
||||
const service = createWechatScheduleLlmConfigService(createPool(), {
|
||||
env: { H5_WECHAT_SCHEDULE_LLM_ENABLED: '1' },
|
||||
});
|
||||
const result = await service.getConfig();
|
||||
assert.equal(result.scheduleLlmEnabled, true);
|
||||
assert.equal(result.updatedAt, null);
|
||||
});
|
||||
|
||||
test('wechat schedule llm config service persists admin toggle', async () => {
|
||||
const service = createWechatScheduleLlmConfigService(createPool(), {
|
||||
env: { H5_WECHAT_SCHEDULE_LLM_ENABLED: '0' },
|
||||
});
|
||||
const updated = await service.updateConfig({ scheduleLlmEnabled: true }, { updatedBy: 'admin-1' });
|
||||
assert.equal(updated.scheduleLlmEnabled, true);
|
||||
assert.equal(updated.updatedBy, 'admin-1');
|
||||
assert.equal(await service.isScheduleLlmEnabled(), true);
|
||||
});
|
||||
|
||||
test('wechat schedule llm config internals normalize booleans consistently', () => {
|
||||
assert.equal(wechatScheduleLlmConfigInternals.normalizeBoolean('1', false), true);
|
||||
assert.equal(wechatScheduleLlmConfigInternals.normalizeBoolean('off', true), false);
|
||||
assert.equal(
|
||||
wechatScheduleLlmConfigInternals.defaultsFromEnv({
|
||||
H5_WECHAT_SCHEDULE_LLM_ENABLED: 'true',
|
||||
}).scheduleLlmEnabled,
|
||||
true,
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user