Repository navigation
Expand file tree
/
Copy pathtest-api.js
More file actions
115 lines (102 loc) · 4.24 KB
/
Copy pathtest-api.js
File metadata and controls
115 lines (102 loc) · 4.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
const axios = require('axios');
const API_BASE = 'http://localhost:3000/api';
async function testAPI() {
console.log('🧪 Testing Video to Audio API...\n');
try {
// Test 1: Invalid request (missing videoUrl)
console.log('1. Testing invalid request (missing videoUrl)...');
try {
await axios.post(`${API_BASE}/extract-audio`, {});
} catch (error) {
if (error.response && error.response.status === 400) {
console.log('✅ Correctly rejected invalid request');
console.log(` Response: ${error.response.data.message}\n`);
} else {
console.log('❌ Unexpected error response\n');
}
}
// Test 2: Invalid URL
console.log('2. Testing invalid URL...');
try {
await axios.post(`${API_BASE}/extract-audio`, {
videoUrl: 'not-a-valid-url'
});
} catch (error) {
if (error.response && error.response.status === 400) {
console.log('✅ Correctly rejected invalid URL');
console.log(` Response: ${error.response.data.message}\n`);
} else {
console.log('❌ Unexpected error response\n');
}
}
// Test 3: Unsupported URL
console.log('3. Testing unsupported URL...');
try {
await axios.post(`${API_BASE}/extract-audio`, {
videoUrl: 'https://example.com/not-a-video'
});
} catch (error) {
if (error.response && error.response.status === 400) {
console.log('✅ Correctly rejected unsupported URL');
console.log(` Response: ${error.response.data.message}\n`);
} else {
console.log('❌ Unexpected error response\n');
}
}
// Test 4: Valid Google Drive URL format (will fail without actual file, but should pass validation)
console.log('4. Testing valid Google Drive URL format...');
try {
const response = await axios.post(`${API_BASE}/extract-audio`, {
videoUrl: 'https://drive.google.com/file/d/1234567890abcdef/view?usp=sharing'
});
if (response.status === 202) {
console.log('✅ Successfully accepted Google Drive URL');
console.log(` Job ID: ${response.data.jobId}`);
console.log(` Status: ${response.data.status}\n`);
// Test 5: Check job status
console.log('5. Testing job status endpoint...');
const statusResponse = await axios.get(`${API_BASE}/status/${response.data.jobId}`);
console.log('✅ Status endpoint working');
console.log(` Status: ${statusResponse.data.status}`);
console.log(` Progress: ${statusResponse.data.progress}%\n`);
// Test 6: Try download (should fail since job will fail)
console.log('6. Testing download endpoint (should fail for incomplete job)...');
try {
await axios.get(`${API_BASE}/download/${response.data.jobId}`);
} catch (downloadError) {
if (downloadError.response && downloadError.response.status === 409) {
console.log('✅ Correctly rejected download for incomplete job');
console.log(` Response: ${downloadError.response.data.message}\n`);
}
}
}
} catch (error) {
console.log('❌ Error with valid URL format');
console.log(` Error: ${error.message}\n`);
}
// Test 7: Invalid job ID
console.log('7. Testing invalid job ID...');
try {
await axios.get(`${API_BASE}/status/invalid-job-id`);
} catch (error) {
if (error.response && error.response.status === 404) {
console.log('✅ Correctly handled invalid job ID');
console.log(` Response: ${error.response.data.message}\n`);
}
}
console.log('🎉 API testing completed!');
console.log('\n📝 Summary:');
console.log('- All endpoints are responding correctly');
console.log('- Input validation is working');
console.log('- Error handling is proper');
console.log('- Job management system is functional');
console.log('\n⚠️ Note: Actual video processing will require:');
console.log('- FFmpeg installed on the system');
console.log('- BLOB_READ_WRITE_TOKEN environment variable');
console.log('- Valid video URLs with accessible files');
} catch (error) {
console.error('❌ Test failed:', error.message);
}
}
// Run tests
testAPI();