备份:修复前完整项目快照 2026-04-19
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
const http = require('http');
|
||||
|
||||
// 测试基础URL
|
||||
const BASE_URL = 'http://localhost:3005';
|
||||
|
||||
// HTTP请求函数
|
||||
function request(method, url, data = null) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const options = {
|
||||
method,
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
};
|
||||
|
||||
const req = http.request(url, options, (res) => {
|
||||
let data = '';
|
||||
res.on('data', (chunk) => {
|
||||
data += chunk;
|
||||
});
|
||||
res.on('end', () => {
|
||||
try {
|
||||
resolve(JSON.parse(data));
|
||||
} catch (e) {
|
||||
resolve({ success: false, error: 'Invalid JSON response', raw: data });
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
req.on('error', (error) => {
|
||||
reject(error);
|
||||
});
|
||||
|
||||
if (data) {
|
||||
req.write(JSON.stringify(data));
|
||||
}
|
||||
|
||||
req.end();
|
||||
});
|
||||
}
|
||||
|
||||
// 测试函数
|
||||
async function testAPI() {
|
||||
console.log('=== 测试API端点 ===');
|
||||
|
||||
try {
|
||||
// 测试登录
|
||||
console.log('1. 测试登录API...');
|
||||
const loginResponse = await request('POST', `${BASE_URL}/api/auth/login`, {
|
||||
username: 'admin',
|
||||
password: 'X123c321@'
|
||||
});
|
||||
console.log('登录响应:', loginResponse);
|
||||
|
||||
// 测试预支申请列表
|
||||
console.log('\n2. 测试预支申请列表API...');
|
||||
const advancesResponse = await request('GET', `${BASE_URL}/api/advances`);
|
||||
console.log('预支申请列表响应:', advancesResponse);
|
||||
|
||||
// 测试创建预支申请
|
||||
console.log('\n3. 测试创建预支申请API...');
|
||||
const createAdvanceResponse = await request('POST', `${BASE_URL}/api/advances`, {
|
||||
advance_date: '2026-03-24',
|
||||
amount: 5000,
|
||||
currency: 'CNY',
|
||||
reason: '测试预支',
|
||||
project_id: 1,
|
||||
applicant: '测试用户',
|
||||
attachments: []
|
||||
});
|
||||
console.log('创建预支申请响应:', createAdvanceResponse);
|
||||
|
||||
if (createAdvanceResponse.success && createAdvanceResponse.data && createAdvanceResponse.data.id) {
|
||||
const advanceId = createAdvanceResponse.data.id;
|
||||
|
||||
// 测试提交预支申请
|
||||
console.log('\n4. 测试提交预支申请API...');
|
||||
const submitResponse = await request('POST', `${BASE_URL}/api/advances/${advanceId}/submit`);
|
||||
console.log('提交预支申请响应:', submitResponse);
|
||||
}
|
||||
|
||||
// 测试执行记录API
|
||||
console.log('\n5. 测试执行记录API...');
|
||||
const executionsResponse = await request('GET', `${BASE_URL}/api/executions`);
|
||||
console.log('执行记录响应:', executionsResponse);
|
||||
|
||||
} catch (error) {
|
||||
console.error('测试过程中发生错误:', error);
|
||||
}
|
||||
}
|
||||
|
||||
// 运行测试
|
||||
testAPI();
|
||||
Reference in New Issue
Block a user