198 lines
6.2 KiB
JavaScript
198 lines
6.2 KiB
JavaScript
const http = require('http');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
// 测试基础URL
|
|
const BASE_URL = 'http://localhost:3005';
|
|
|
|
// 测试数据
|
|
const testUser = {
|
|
username: 'admin',
|
|
password: 'X123c321@'
|
|
};
|
|
|
|
let authToken = '';
|
|
|
|
// 测试结果
|
|
const testResults = [];
|
|
|
|
// HTTP请求函数
|
|
function httpRequest(options, postData = null) {
|
|
return new Promise((resolve, reject) => {
|
|
const req = http.request(options, (res) => {
|
|
let data = '';
|
|
res.on('data', (chunk) => {
|
|
data += chunk;
|
|
});
|
|
res.on('end', () => {
|
|
resolve({ status: res.statusCode, data: JSON.parse(data) });
|
|
});
|
|
});
|
|
|
|
req.on('error', (e) => {
|
|
reject(e);
|
|
});
|
|
|
|
if (postData) {
|
|
req.write(JSON.stringify(postData));
|
|
}
|
|
|
|
req.end();
|
|
});
|
|
}
|
|
|
|
// 登录函数
|
|
async function login() {
|
|
console.log('\n🔐 登录测试...');
|
|
|
|
const options = {
|
|
hostname: 'localhost',
|
|
port: 3005,
|
|
path: '/api/auth/login',
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
}
|
|
};
|
|
|
|
try {
|
|
const response = await httpRequest(options, testUser);
|
|
|
|
console.log('登录响应状态:', response.status);
|
|
console.log('登录响应数据:', JSON.stringify(response.data, null, 2));
|
|
|
|
if (response.status === 200 && response.data.success) {
|
|
authToken = 'test-token'; // 后端没有返回token,使用模拟token
|
|
testResults.push({ test: '登录', status: '✅ 成功' });
|
|
console.log('✅ 登录成功');
|
|
} else {
|
|
testResults.push({ test: '登录', status: '❌ 失败', message: response.data.message || '登录失败' });
|
|
console.log('❌ 登录失败:', response.data.message);
|
|
}
|
|
} catch (error) {
|
|
testResults.push({ test: '登录', status: '❌ 失败', message: error.message });
|
|
console.log('❌ 登录失败:', error.message);
|
|
console.log('错误详情:', error);
|
|
}
|
|
}
|
|
|
|
// 测试执行记录查询
|
|
async function testExecutionRecords() {
|
|
console.log('\n📊 测试执行记录查询...');
|
|
|
|
// 1. 查询执行记录列表
|
|
console.log('1. 查询执行记录列表...');
|
|
const options = {
|
|
hostname: 'localhost',
|
|
port: 3005,
|
|
path: '/api/executions',
|
|
method: 'GET'
|
|
};
|
|
|
|
try {
|
|
console.log('正在请求:', options.path);
|
|
const response = await httpRequest(options);
|
|
console.log('响应状态:', response.status);
|
|
console.log('响应数据:', JSON.stringify(response.data, null, 2));
|
|
if (response.status === 200 && response.data.success) {
|
|
testResults.push({ test: '查询执行记录列表', status: '✅ 成功', message: `找到 ${response.data.data.length} 条记录` });
|
|
console.log('✅ 执行记录查询成功,找到', response.data.data.length, '条记录');
|
|
} else {
|
|
testResults.push({ test: '查询执行记录列表', status: '❌ 失败', message: response.data.message || '查询失败' });
|
|
console.log('❌ 执行记录查询失败:', response.data.message);
|
|
}
|
|
} catch (error) {
|
|
testResults.push({ test: '查询执行记录列表', status: '❌ 失败', message: error.message });
|
|
console.log('❌ 执行记录查询失败:', error.message);
|
|
console.log('错误详情:', error);
|
|
}
|
|
|
|
// 2. 查询待执行列表
|
|
console.log('2. 查询待执行列表...');
|
|
const pendingOptions = {
|
|
hostname: 'localhost',
|
|
port: 3005,
|
|
path: '/api/executions/pending',
|
|
method: 'GET'
|
|
};
|
|
|
|
try {
|
|
const response = await httpRequest(pendingOptions);
|
|
if (response.status === 200 && response.data.success) {
|
|
testResults.push({ test: '查询待执行列表', status: '✅ 成功', message: `找到 ${response.data.data.length} 条记录` });
|
|
console.log('✅ 待执行列表查询成功,找到', response.data.data.length, '条记录');
|
|
} else {
|
|
testResults.push({ test: '查询待执行列表', status: '❌ 失败', message: response.data.message || '查询失败' });
|
|
console.log('❌ 待执行列表查询失败:', response.data.message);
|
|
}
|
|
} catch (error) {
|
|
testResults.push({ test: '查询待执行列表', status: '❌ 失败', message: error.message });
|
|
console.log('❌ 待执行列表查询失败:', error.message);
|
|
}
|
|
|
|
// 3. 查询已执行列表
|
|
console.log('3. 查询已执行列表...');
|
|
const executedOptions = {
|
|
hostname: 'localhost',
|
|
port: 3005,
|
|
path: '/api/executions/executed',
|
|
method: 'GET'
|
|
};
|
|
|
|
try {
|
|
const response = await httpRequest(executedOptions);
|
|
if (response.status === 200 && response.data.success) {
|
|
testResults.push({ test: '查询已执行列表', status: '✅ 成功', message: `找到 ${response.data.data.length} 条记录` });
|
|
console.log('✅ 已执行列表查询成功,找到', response.data.data.length, '条记录');
|
|
} else {
|
|
testResults.push({ test: '查询已执行列表', status: '❌ 失败', message: response.data.message || '查询失败' });
|
|
console.log('❌ 已执行列表查询失败:', response.data.message);
|
|
}
|
|
} catch (error) {
|
|
testResults.push({ test: '查询已执行列表', status: '❌ 失败', message: error.message });
|
|
console.log('❌ 已执行列表查询失败:', error.message);
|
|
}
|
|
}
|
|
|
|
// 运行测试
|
|
async function runTests() {
|
|
console.log('🚀 开始执行财务流程测试\n');
|
|
|
|
// 直接测试执行记录查询,跳过登录
|
|
await testExecutionRecords();
|
|
|
|
// 输出测试结果
|
|
console.log('\n📋 测试结果汇总:');
|
|
console.log('=============================================');
|
|
|
|
let successCount = 0;
|
|
let failureCount = 0;
|
|
|
|
testResults.forEach(result => {
|
|
console.log(`${result.test}: ${result.status}`);
|
|
if (result.status.includes('✅')) {
|
|
successCount++;
|
|
} else {
|
|
failureCount++;
|
|
}
|
|
});
|
|
|
|
console.log('=============================================');
|
|
console.log(`总测试数: ${testResults.length}`);
|
|
console.log(`成功: ${successCount}`);
|
|
console.log(`失败: ${failureCount}`);
|
|
|
|
if (failureCount === 0) {
|
|
console.log('\n🎉 所有测试通过!执行记录查询功能正常。');
|
|
} else {
|
|
console.log('\n⚠️ 部分测试失败,需要检查问题。');
|
|
}
|
|
|
|
console.log('\n测试完成。');
|
|
}
|
|
|
|
// 启动测试
|
|
runTests().catch(error => {
|
|
console.error('测试过程中出现错误:', error);
|
|
});
|