-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-import-api.js
More file actions
81 lines (68 loc) · 2.3 KB
/
test-import-api.js
File metadata and controls
81 lines (68 loc) · 2.3 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
const fs = require('fs');
const FormData = require('form-data');
const fetch = require('node-fetch');
async function testImportAPI() {
try {
console.log('Testing import API...\n');
// First, let's check if the test file exists
const testFile = 'test-import-clients.xlsx';
if (!fs.existsSync(testFile)) {
console.error('Test file not found. Please run "node test-import.js" first.');
return;
}
// Read the test file
const fileBuffer = fs.readFileSync(testFile);
// Create form data
const formData = new FormData();
formData.append('file', fileBuffer, {
filename: testFile,
contentType: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
});
// For testing, we'll need a valid auth token
// This would normally come from logging in through the frontend
console.log('Note: This test requires a valid auth token.');
console.log('To properly test:');
console.log('1. Start the development server: npm run dev');
console.log('2. Login through the web interface');
console.log('3. Use the browser dev tools to get the auth-token cookie');
console.log('4. Use the import UI to test the functionality');
console.log('\\nOr run this test with a valid token...');
// The actual API call would look like this:
/*
const response = await fetch('http://localhost:3000/api/clients/import', {
method: 'POST',
body: formData,
headers: {
'Cookie': 'auth-token=YOUR_TOKEN_HERE'
}
});
const result = await response.json();
console.log('Import result:', JSON.stringify(result, null, 2));
*/
} catch (error) {
console.error('Test error:', error);
}
}
// Helper function to check if server is running
async function checkServer() {
try {
const response = await fetch('http://localhost:3000/api/health', {
method: 'GET'
});
return response.ok;
} catch (error) {
return false;
}
}
async function main() {
console.log('Import API Test Script');
console.log('====================\\n');
const serverRunning = await checkServer();
if (!serverRunning) {
console.log('Development server is not running.');
console.log('Please start it with: npm run dev');
return;
}
await testImportAPI();
}
main();