test-final.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. // 最终测试
  2. async function testFinal() {
  3. console.log('=== 最终测试修复后的支付成功触发API ===\n');
  4. const apiUrl = 'http://localhost:8080/api/v1/payments/payment/trigger-success';
  5. // 获取新的token
  6. const loginResponse = await fetch('http://localhost:8080/api/v1/auth/login', {
  7. method: 'POST',
  8. headers: {
  9. 'Content-Type': 'application/json'
  10. },
  11. body: JSON.stringify({
  12. username: 'admin',
  13. password: 'admin123'
  14. })
  15. });
  16. if (!loginResponse.ok) {
  17. console.error('登录失败');
  18. return;
  19. }
  20. const loginData = await loginResponse.json();
  21. const token = loginData.token;
  22. console.log(`API地址: ${apiUrl}`);
  23. console.log(`测试订单ID: 25`);
  24. console.log(`Token: ${token.substring(0, 50)}...\n`);
  25. try {
  26. const response = await fetch(apiUrl, {
  27. method: 'POST',
  28. headers: {
  29. 'Content-Type': 'application/json',
  30. 'Authorization': `Bearer ${token}`
  31. },
  32. body: JSON.stringify({
  33. orderId: 25
  34. })
  35. });
  36. console.log(`状态码: ${response.status}`);
  37. console.log(`状态文本: ${response.statusText}`);
  38. if (response.ok) {
  39. const result = await response.json();
  40. console.log('\n✅ API调用成功!');
  41. console.log('响应内容:', JSON.stringify(result, null, 2));
  42. // 等待一会儿让后台处理
  43. console.log('\n等待5秒让后台处理打印任务...');
  44. await new Promise(resolve => setTimeout(resolve, 5000));
  45. // 检查数据库
  46. console.log('\n检查数据库中的打印任务...');
  47. const { exec } = require('child_process');
  48. const util = require('util');
  49. const execPromise = util.promisify(exec);
  50. try {
  51. const { stdout } = await execPromise(
  52. 'psql -h 127.0.0.1 -U postgres -d postgres -c "SELECT id, tenant_id, task_id, order_id, print_status, scheduled_at, created_at FROM feie_print_task_mt WHERE order_id = 25 ORDER BY created_at DESC"'
  53. );
  54. console.log('查询结果:');
  55. console.log(stdout);
  56. if (stdout.includes('(0 rows)')) {
  57. console.log('\n❌ 数据库中仍然没有找到订单ID 25的打印任务');
  58. // 检查服务器日志
  59. console.log('\n检查最新的打印任务...');
  60. const { stdout: latestTasks } = await execPromise(
  61. 'psql -h 127.0.0.1 -U postgres -d postgres -c "SELECT id, tenant_id, task_id, order_id, print_status, scheduled_at, created_at FROM feie_print_task_mt ORDER BY created_at DESC LIMIT 5"'
  62. );
  63. console.log('最新的5个打印任务:');
  64. console.log(latestTasks);
  65. } else {
  66. console.log('\n🎉 成功!打印任务已创建!');
  67. // 检查任务详情
  68. console.log('\n检查任务详情...');
  69. const { stdout: taskDetails } = await execPromise(
  70. 'psql -h 127.0.0.1 -U postgres -d postgres -c "SELECT task_id, printer_sn, print_type, print_status, retry_count, max_retries, scheduled_at, error_message FROM feie_print_task_mt WHERE order_id = 25 ORDER BY created_at DESC LIMIT 1"'
  71. );
  72. console.log('任务详情:');
  73. console.log(taskDetails);
  74. }
  75. } catch (dbError) {
  76. console.error('查询数据库失败:', dbError.message);
  77. }
  78. } else {
  79. const errorText = await response.text();
  80. console.log('\n❌ API调用失败');
  81. console.log('错误响应:', errorText);
  82. }
  83. } catch (error) {
  84. console.error('请求失败:', error.message);
  85. console.error('错误堆栈:', error.stack);
  86. }
  87. }
  88. // 运行测试
  89. testFinal().catch(error => {
  90. console.error('测试脚本执行失败:', error);
  91. process.exit(1);
  92. });