-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeployment-test.js
More file actions
145 lines (124 loc) Β· 4.12 KB
/
Copy pathdeployment-test.js
File metadata and controls
145 lines (124 loc) Β· 4.12 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
// Quick deployment test script
// Run this in your browser console on the deployed site
console.log('π Starting deployment debug...');
// Test 1: Check if the API endpoint exists
async function testEndpoint() {
console.log('π Testing API endpoint accessibility...');
try {
// Get current URL info
const currentUrl = window.location.href;
const baseUrl = window.location.origin;
console.log('Current page:', currentUrl);
console.log('Base URL:', baseUrl);
// Test GET request first (health check)
console.log('π Testing GET request...');
const getResponse = await fetch(`${baseUrl}/api/interview-questions`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
});
console.log('GET Response:', {
status: getResponse.status,
statusText: getResponse.statusText,
ok: getResponse.ok,
url: getResponse.url
});
if (getResponse.ok) {
const getData = await getResponse.json();
console.log('β
GET Success:', getData);
} else {
console.log('β GET Failed - Response text:', await getResponse.text());
}
// Test POST request
console.log('π Testing POST request...');
const postResponse = await fetch(`${baseUrl}/api/interview-questions`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
role: 'Software Engineer',
questionType: 'technical',
company: '',
mode: 'interview'
})
});
console.log('POST Response:', {
status: postResponse.status,
statusText: postResponse.statusText,
ok: postResponse.ok,
url: postResponse.url,
headers: Object.fromEntries(postResponse.headers.entries())
});
if (postResponse.ok) {
const postData = await postResponse.json();
console.log('β
POST Success:', {
questionCount: postData.questions?.length || 0,
hasQuestions: !!postData.questions,
mode: postData.mode,
role: postData.role
});
} else {
const errorText = await postResponse.text();
console.log('β POST Failed - Response text:', errorText);
// Try to parse as JSON
try {
const errorJson = JSON.parse(errorText);
console.log('β POST Error JSON:', errorJson);
} catch (e) {
console.log('β Could not parse error as JSON');
}
}
} catch (error) {
console.error('π₯ Test failed with error:', error);
console.error('Error details:', {
name: error.name,
message: error.message,
stack: error.stack
});
}
}
// Test 2: Check network connectivity
async function testNetworkConnectivity() {
console.log('π Testing network connectivity...');
try {
// Test basic connectivity
const response = await fetch(window.location.origin, {
method: 'HEAD',
mode: 'no-cors'
});
console.log('β
Basic connectivity OK');
} catch (error) {
console.error('β Network connectivity issue:', error);
}
}
// Test 3: Check if API routes are built correctly
async function testApiRouteStructure() {
console.log('π Testing API route structure...');
const testUrls = [
'/api/interview-questions',
'/api/interview-questions/',
'/_next/static/chunks/pages/api/interview-questions.js'
];
for (const url of testUrls) {
try {
const response = await fetch(window.location.origin + url, {
method: 'HEAD'
});
console.log(`${url}: ${response.status} ${response.statusText}`);
} catch (error) {
console.log(`${url}: Error - ${error.message}`);
}
}
}
// Run all tests
async function runAllTests() {
console.log('π Starting comprehensive deployment test...');
await testNetworkConnectivity();
await testApiRouteStructure();
await testEndpoint();
console.log('β
All tests completed! Check the logs above for issues.');
}
// Auto-run the tests
runAllTests();