feat: 完善采购申请流程 - 添加审批、执行、列表筛选排序功能
This commit is contained in:
@@ -0,0 +1,139 @@
|
||||
const axios = require('axios');
|
||||
|
||||
// 测试配置
|
||||
const API_BASE = 'http://localhost:3005/api';
|
||||
|
||||
// 测试用户信息
|
||||
const user = {
|
||||
username: 'admin',
|
||||
password: 'X123c321@'
|
||||
};
|
||||
|
||||
let token = '';
|
||||
|
||||
// 测试步骤
|
||||
async function runTest() {
|
||||
console.log('=== 开始测试申请-审批-执行流程 ===\n');
|
||||
|
||||
try {
|
||||
// 1. 登录获取token
|
||||
console.log('1. 登录系统...');
|
||||
const loginResponse = await axios.post(`${API_BASE}/auth/login`, user);
|
||||
if (loginResponse.data.success) {
|
||||
console.log('✓ 登录成功');
|
||||
token = loginResponse.data.data;
|
||||
} else {
|
||||
console.log('✗ 登录失败');
|
||||
return;
|
||||
}
|
||||
|
||||
// 2. 创建一个测试预支申请
|
||||
console.log('\n2. 创建测试预支申请...');
|
||||
const advanceResponse = await axios.post(`${API_BASE}/advances`, {
|
||||
amount: 1000,
|
||||
reason: '测试预支申请',
|
||||
currency: 'CNY',
|
||||
advance_date: new Date().toISOString(),
|
||||
applicant: '测试用户',
|
||||
attachments: []
|
||||
});
|
||||
|
||||
if (advanceResponse.data.success) {
|
||||
console.log('✓ 预支申请创建成功');
|
||||
const advanceId = advanceResponse.data.data.id;
|
||||
console.log(` 预支申请ID: ${advanceId}`);
|
||||
|
||||
// 3. 审批通过预支申请
|
||||
console.log('\n3. 审批通过预支申请...');
|
||||
const approveResponse = await axios.post(`${API_BASE}/advances/${advanceId}/approve`);
|
||||
if (approveResponse.data.success) {
|
||||
console.log('✓ 预支申请审批通过');
|
||||
} else {
|
||||
console.log('✗ 预支申请审批失败');
|
||||
return;
|
||||
}
|
||||
|
||||
// 4. 检查执行管理中的待执行列表
|
||||
console.log('\n4. 检查执行管理待执行列表...');
|
||||
const pendingResponse = await axios.get(`${API_BASE}/executions/pending`);
|
||||
if (pendingResponse.data.success) {
|
||||
console.log('✓ 获取待执行列表成功');
|
||||
console.log(` 待执行数量: ${pendingResponse.data.data.length}`);
|
||||
const pendingAdvance = pendingResponse.data.data.find(item => item.id === advanceId);
|
||||
if (pendingAdvance) {
|
||||
console.log('✓ 测试预支申请在待执行列表中');
|
||||
} else {
|
||||
console.log('✗ 测试预支申请不在待执行列表中');
|
||||
}
|
||||
} else {
|
||||
console.log('✗ 获取待执行列表失败');
|
||||
return;
|
||||
}
|
||||
|
||||
// 5. 执行预支申请
|
||||
console.log('\n5. 执行预支申请...');
|
||||
const executeResponse = await axios.post(`${API_BASE}/executions`, {
|
||||
apply_id: advanceId,
|
||||
apply_type: 'advance',
|
||||
action: 'execute',
|
||||
execute_method: 'bank',
|
||||
voucher_no: 'TEST-001',
|
||||
remark: '测试执行'
|
||||
});
|
||||
|
||||
if (executeResponse.data.success) {
|
||||
console.log('✓ 预支申请执行成功');
|
||||
} else {
|
||||
console.log('✗ 预支申请执行失败');
|
||||
return;
|
||||
}
|
||||
|
||||
// 6. 检查执行管理中的已执行列表
|
||||
console.log('\n6. 检查执行管理已执行列表...');
|
||||
const executedResponse = await axios.get(`${API_BASE}/executions/executed`);
|
||||
if (executedResponse.data.success) {
|
||||
console.log('✓ 获取已执行列表成功');
|
||||
console.log(` 已执行数量: ${executedResponse.data.data.length}`);
|
||||
const executedAdvance = executedResponse.data.data.find(item => item.id === advanceId);
|
||||
if (executedAdvance) {
|
||||
console.log('✓ 测试预支申请在已执行列表中');
|
||||
} else {
|
||||
console.log('✗ 测试预支申请不在已执行列表中');
|
||||
}
|
||||
} else {
|
||||
console.log('✗ 获取已执行列表失败');
|
||||
return;
|
||||
}
|
||||
|
||||
// 7. 检查执行记录
|
||||
console.log('\n7. 检查执行记录...');
|
||||
const executionsResponse = await axios.get(`${API_BASE}/executions`);
|
||||
if (executionsResponse.data.success) {
|
||||
console.log('✓ 获取执行记录成功');
|
||||
console.log(` 执行记录数量: ${executionsResponse.data.data.length}`);
|
||||
const executionRecord = executionsResponse.data.data.find(item => item.apply_id === advanceId.toString());
|
||||
if (executionRecord) {
|
||||
console.log('✓ 测试预支申请有执行记录');
|
||||
} else {
|
||||
console.log('✗ 测试预支申请没有执行记录');
|
||||
}
|
||||
} else {
|
||||
console.log('✗ 获取执行记录失败');
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('\n=== 测试完成 ===');
|
||||
console.log('✓ 申请-审批-执行流程测试成功');
|
||||
|
||||
} else {
|
||||
console.log('✗ 预支申请创建失败');
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.error('测试过程中发生错误:', error.message);
|
||||
console.error('错误详情:', error.response ? error.response.data : error);
|
||||
}
|
||||
}
|
||||
|
||||
// 运行测试
|
||||
runTest();
|
||||
Reference in New Issue
Block a user