full-test-final.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. const http = require('http');
  2. function httpRequest(method, path, data) {
  3. return new Promise((resolve, reject) => {
  4. const options = {
  5. hostname: 'localhost',
  6. port: 3000,
  7. path: path,
  8. method: method,
  9. headers: { 'Content-Type': 'application/json' }
  10. };
  11. const req = http.request(options, (res) => {
  12. let body = '';
  13. res.on('data', chunk => body += chunk);
  14. res.on('end', () => {
  15. try { resolve({ status: res.statusCode, data: JSON.parse(body) }); }
  16. catch { resolve({ status: res.statusCode, data: body }); }
  17. });
  18. });
  19. req.on('error', reject);
  20. if (data) req.write(JSON.stringify(data));
  21. req.end();
  22. });
  23. }
  24. (async () => {
  25. console.log('=== 完整功能测试 ===\n');
  26. try {
  27. console.log('1. 测试API连接...');
  28. const apiTest = await httpRequest('GET', '/api/video/projects');
  29. console.log(' 状态:', apiTest.status === 200 ? '✅' : '❌', apiTest.status);
  30. console.log('\n2. 创建测试项目...');
  31. const create = await httpRequest('POST', '/api/video/projects', {
  32. title: '自动化测试',
  33. config: {
  34. images: [{ url: '/uploads/materials/dnoz9actogl6q0kp9togy2fym.png', duration: 5 }],
  35. audio: { url: '/uploads/materials/xlgman1g6tyt53zl5k3jhc42n.mp3', volume: 1 },
  36. video: { width: 720, height: 1280, fps: 30 },
  37. kenburns: { enabled: true, minZoom: 1, maxZoom: 1.2 }
  38. }
  39. });
  40. console.log(' 状态:', create.status === 200 ? '✅' : '❌', create.status);
  41. if (create.data.success) {
  42. console.log(' 项目ID:', create.data.data.id);
  43. console.log('\n3. 测试视频生成...');
  44. const gen = await httpRequest('POST', `/api/video/projects/${create.data.data.id}/generate`);
  45. console.log(' 状态:', gen.status === 200 ? '✅' : '❌', gen.status);
  46. console.log(' 结果:', JSON.stringify(gen.data).substring(0, 150));
  47. }
  48. console.log('\n=== 测试完成 ===');
  49. } catch (e) {
  50. console.error('测试失败:', e.message);
  51. }
  52. })();