Files
X-Financial/web/tests/expense-application-ontology.test.mjs
caoxiaozhu d0e946cf47 feat: 完善文档中心与报销申请交互及侧边栏重构
后端优化编排器报销查询和本体检测精度,增强报销单草稿保
存和附件回填逻辑,前端重构侧边栏组件支持折叠和图标导
航,完善文档中心状态筛选和详情提示,报销创建和审批详情
页优化会话管理和费用明细交互,新增助手应用服务和预设动
作工具函数,补充单元测试覆盖。
2026-05-25 13:35:39 +08:00

70 lines
2.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import assert from 'node:assert/strict'
import test from 'node:test'
import {
buildApplicationFieldsFromOntology,
expandApplicationTimeWithDays,
resolveApplicationReason,
resolveApplicationTimeRange,
resolvePromptField
} from '../src/utils/expenseApplicationOntology.js'
const structuredApplicationPrompt = [
'发生时间2026-05-25',
'地点:上海',
'事由:支撑国网服务器部署',
'天数3天'
].join('\n')
test('expense application fields use labeled reason and filter resolved missing slots', () => {
const fields = buildApplicationFieldsFromOntology(
{
scenario: 'expense',
intent: 'draft',
entities: [],
time_range: {},
missing_slots: ['time_range', 'location', 'reason', 'amount']
},
structuredApplicationPrompt,
{ name: '申请员工', departmentName: '交付部' }
)
assert.equal(fields.timeRange, '2026-05-25 至 2026-05-28')
assert.equal(fields.location, '上海')
assert.equal(fields.reason, '支撑国网服务器部署')
assert.deepEqual(
fields.missingSlots.map((item) => item.key),
['amount']
)
})
test('expense application prompt field parser supports multiline labels', () => {
assert.equal(resolvePromptField(structuredApplicationPrompt, ['事由']), '支撑国网服务器部署')
assert.equal(resolveApplicationReason(structuredApplicationPrompt), '支撑国网服务器部署')
})
test('expense application expands a single selected date with natural days', () => {
const prompt = [
'发生时间2026-05-25',
'去上海出差3天支撑国网服务器部署'
].join('\n')
assert.equal(expandApplicationTimeWithDays('2026-05-25', 3), '2026-05-25 至 2026-05-28')
assert.equal(resolveApplicationTimeRange({ time_range: {} }, prompt), '2026-05-25 至 2026-05-28')
})
test('expense application keeps explicit time range before applying days', () => {
assert.equal(
resolveApplicationTimeRange(
{
time_range: {
start_date: '2026-05-25',
end_date: '2026-05-27'
}
},
'去上海出差3天支撑国网服务器部署'
),
'2026-05-25 至 2026-05-27'
)
})