forked from Hitarth2510/Cloudify
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-auth.js
More file actions
84 lines (71 loc) · 2.5 KB
/
test-auth.js
File metadata and controls
84 lines (71 loc) · 2.5 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
// Quick test script to verify authentication endpoints
import fetch from 'node-fetch';
const BASE_URL = 'http://localhost:3000';
async function testAuth() {
console.log('🧪 Testing CloudPilot AI Authentication...\n');
// Test 1: Login with existing mock user
console.log('1️⃣ Testing login with mock user...');
try {
const loginResponse = await fetch(`${BASE_URL}/api/auth/login`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
email: 'ravi@example.com',
password: 'password123'
})
});
const loginData = await loginResponse.json();
console.log('Login Status:', loginResponse.status);
console.log('Login Response:', JSON.stringify(loginData, null, 2));
console.log('✅ Login test completed\n');
} catch (error) {
console.error('❌ Login test failed:', error.message);
}
// Test 2: Try to signup a new user
console.log('2️⃣ Testing signup with new user...');
try {
const signupResponse = await fetch(`${BASE_URL}/api/auth/signup`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
name: 'Test User',
email: 'test@example.com',
password: 'testpassword123',
company: 'Test Company',
role: 'devops'
})
});
const signupData = await signupResponse.json();
console.log('Signup Status:', signupResponse.status);
console.log('Signup Response:', JSON.stringify(signupData, null, 2));
console.log('✅ Signup test completed\n');
} catch (error) {
console.error('❌ Signup test failed:', error.message);
}
// Test 3: Test invalid login
console.log('3️⃣ Testing invalid login...');
try {
const invalidLoginResponse = await fetch(`${BASE_URL}/api/auth/login`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
email: 'invalid@example.com',
password: 'wrongpassword'
})
});
const invalidLoginData = await invalidLoginResponse.json();
console.log('Invalid Login Status:', invalidLoginResponse.status);
console.log('Invalid Login Response:', JSON.stringify(invalidLoginData, null, 2));
console.log('✅ Invalid login test completed\n');
} catch (error) {
console.error('❌ Invalid login test failed:', error.message);
}
console.log('🎉 All authentication tests completed!');
}
testAuth().catch(console.error);