- useWorkbenchAiApplicationPreviewFlow/useWorkbenchAiActionRouter/useWorkbenchAiCommandIntents 支持 task1 完成后自动推进 task2,确认按钮直接拉起申请预览,草稿/提交成功后继续推进下一 task - workbenchAiIntentPlannerModel/workbenchAiMessageModel/workbenchAiCommandIntentModel 适配多 task 意图规划与消息结构 - aiApplicationPreviewActions/aiApplicationPrecheckModel/aiExpenseDraftModel/aiWorkbenchConversationStore 草稿与会话存储适配 - PersonalWorkbenchAiMode 与样式适配,更新 preview-actions/expense-draft/conversation-store/fast-preview/action-router/command-intent/intent-planner 测试
161 lines
4.6 KiB
JavaScript
161 lines
4.6 KiB
JavaScript
import assert from 'node:assert/strict'
|
|
|
|
import {
|
|
AI_APPLICATION_ACTION_SAVE_DRAFT,
|
|
AI_APPLICATION_ACTION_SUBMIT,
|
|
runAiApplicationPreviewAction
|
|
} from '../src/services/aiApplicationPreviewActions.js'
|
|
|
|
async function testSubmitActionUsesFastPreviewEndpoint() {
|
|
let capturedUrl = ''
|
|
let capturedOptions = null
|
|
|
|
global.fetch = async (url, options) => {
|
|
capturedUrl = String(url)
|
|
capturedOptions = options
|
|
return {
|
|
ok: true,
|
|
async json() {
|
|
return {
|
|
status: 'succeeded',
|
|
result: {
|
|
draft_payload: {
|
|
claim_id: 'claim-fast-submit',
|
|
claim_no: 'AP-20260620-FAST',
|
|
status: 'submitted',
|
|
approval_stage: '直属领导审批'
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
await runAiApplicationPreviewAction({
|
|
actionType: AI_APPLICATION_ACTION_SUBMIT,
|
|
applicationPreview: {
|
|
fields: {
|
|
applicationType: '差旅费用申请',
|
|
time: '2026-07-01 至 2026-07-03',
|
|
location: '北京',
|
|
reason: '项目实施',
|
|
days: '3天',
|
|
transportMode: '火车',
|
|
amount: '1000元'
|
|
}
|
|
},
|
|
currentUser: { username: 'zhangsan@example.com', name: '张三' },
|
|
conversationId: 'conversation-fast-submit'
|
|
})
|
|
|
|
assert.equal(capturedUrl, '/api/v1/reimbursements/application-preview-action')
|
|
assert.equal(capturedOptions.method, 'POST')
|
|
const body = JSON.parse(capturedOptions.body)
|
|
assert.equal(body.context_json.session_type, 'application')
|
|
assert.equal(body.context_json.application_stage, 'expense_application')
|
|
assert.equal(body.context_json.application_preview.fields.transportMode, '火车')
|
|
}
|
|
|
|
async function testSaveDraftActionUsesFastPreviewEndpoint() {
|
|
let capturedUrl = ''
|
|
let capturedOptions = null
|
|
|
|
global.fetch = async (url, options) => {
|
|
capturedUrl = String(url)
|
|
capturedOptions = options
|
|
return {
|
|
ok: true,
|
|
async json() {
|
|
return {
|
|
status: 'succeeded',
|
|
result: {
|
|
draft_payload: {
|
|
claim_id: 'claim-fast-draft',
|
|
claim_no: 'AP-20260620-DRAFT',
|
|
status: 'draft',
|
|
approval_stage: '待提交'
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
await runAiApplicationPreviewAction({
|
|
actionType: AI_APPLICATION_ACTION_SAVE_DRAFT,
|
|
applicationPreview: { fields: { reason: '项目实施' } },
|
|
currentUser: { username: 'zhangsan@example.com', name: '张三' }
|
|
})
|
|
|
|
assert.equal(capturedUrl, '/api/v1/reimbursements/application-preview-action')
|
|
assert.equal(capturedOptions.method, 'POST')
|
|
const body = JSON.parse(capturedOptions.body)
|
|
assert.equal(body.context_json.application_action, 'save_draft')
|
|
assert.equal(body.context_json.application_save_mode, true)
|
|
assert.equal(body.context_json.application_stage, 'expense_application')
|
|
}
|
|
|
|
async function testEditDraftActionCarriesClaimAndEditableFields() {
|
|
let capturedOptions = null
|
|
|
|
global.fetch = async (_url, options) => {
|
|
capturedOptions = options
|
|
return {
|
|
ok: true,
|
|
async json() {
|
|
return {
|
|
status: 'succeeded',
|
|
result: {
|
|
draft_payload: {
|
|
claim_id: 'claim-edit-application',
|
|
claim_no: 'AP-20260620-EDIT',
|
|
status: 'draft',
|
|
approval_stage: '待提交'
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
await runAiApplicationPreviewAction({
|
|
actionType: AI_APPLICATION_ACTION_SAVE_DRAFT,
|
|
applicationPreview: {
|
|
applicationEditMode: true,
|
|
editableFields: ['reason', 'time', 'location', 'transportMode'],
|
|
fields: {
|
|
applicationType: '差旅费用申请',
|
|
time: '2026-07-01 至 2026-07-03',
|
|
location: '北京',
|
|
reason: '项目实施',
|
|
days: '3天',
|
|
transportMode: '火车',
|
|
amount: '1000元'
|
|
}
|
|
},
|
|
currentUser: { username: 'zhangsan@example.com', name: '张三' },
|
|
draftPayload: {
|
|
claim_id: 'claim-edit-application',
|
|
claim_no: 'AP-20260620-EDIT',
|
|
status: 'returned'
|
|
}
|
|
})
|
|
|
|
const body = JSON.parse(capturedOptions.body)
|
|
assert.equal(body.context_json.application_edit_claim_id, 'claim-edit-application')
|
|
assert.equal(body.context_json.application_edit_mode, true)
|
|
assert.deepEqual(body.context_json.application_editable_fields, ['reason', 'time', 'location', 'transportMode'])
|
|
}
|
|
|
|
async function run() {
|
|
await testSubmitActionUsesFastPreviewEndpoint()
|
|
await testSaveDraftActionUsesFastPreviewEndpoint()
|
|
await testEditDraftActionCarriesClaimAndEditableFields()
|
|
console.log('ai-application-preview-actions tests passed')
|
|
}
|
|
|
|
run().catch((error) => {
|
|
console.error(error)
|
|
process.exit(1)
|
|
})
|