-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathverify-fixes.js
More file actions
executable file
Β·211 lines (171 loc) Β· 6.79 KB
/
verify-fixes.js
File metadata and controls
executable file
Β·211 lines (171 loc) Β· 6.79 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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
#!/usr/bin/env node
/**
* Verification script to test the fixes for demo users and jobs.map error
*/
const BASE_URL = 'http://localhost:3000';
async function makeRequest(endpoint, options = {}) {
try {
const response = await fetch(`${BASE_URL}${endpoint}`, {
headers: {
'Content-Type': 'application/json',
...options.headers,
},
...options,
});
const data = await response.json();
return { success: response.ok, data, status: response.status };
} catch (error) {
return { success: false, error: error.message };
}
}
async function testJobsAPI() {
console.log('π§ Testing Jobs API (jobs.map error fix)...');
console.log('=' .repeat(50));
const result = await makeRequest('/api/recruiter/jobs?limit=5');
if (!result.success) {
console.log('β Jobs API failed:', result.error);
return false;
}
console.log('β
Jobs API working');
console.log('π Response structure:');
console.log(` β’ Success: ${result.data.success}`);
console.log(` β’ Data type: ${Array.isArray(result.data.data) ? 'Array' : typeof result.data.data}`);
console.log(` β’ Jobs count: ${result.data.data?.length || 0}`);
console.log(` β’ Has pagination: ${!!result.data.pagination}`);
return true;
}
async function testRealUsersCheck() {
console.log('\\nπ₯ Testing Real Users Check...');
console.log('=' .repeat(50));
const result = await makeRequest('/api/debug/check-real-users');
if (!result.success) {
console.log('β Real users check failed:', result.error);
return false;
}
const { summary } = result.data;
console.log('β
Real users check working');
console.log('π Database state:');
console.log(` β’ Total Users: ${summary.totalUsers}`);
console.log(` β’ Users with Skills: ${summary.usersWithSkills}`);
console.log(` β’ Total Skills: ${summary.totalUserSkills}`);
console.log(` β’ Unique Skills: ${summary.uniqueSkills}`);
if (summary.totalUsers > 0) {
console.log('\\nβ οΈ Found users in database:');
if (summary.usersWithSkills > 0) {
console.log(' β’ These could be test candidates or real users');
console.log(' β’ Use "Clear Test Data" button to remove test candidates');
} else {
console.log(' β’ Users exist but have no skills (likely real users without interviews)');
}
} else {
console.log('\\nβ
Database is clean - no users found');
console.log(' β’ This is correct if no AI interviews have been taken');
}
return true;
}
async function testClearTestData() {
console.log('\\nποΈ Testing Clear Test Data API...');
console.log('=' .repeat(50));
// First check if there are test users
const checkResult = await makeRequest('/api/debug/check-real-users');
if (!checkResult.success) {
console.log('β Cannot check users before clearing');
return false;
}
const beforeCount = checkResult.data.summary.totalUsers;
console.log(`π Users before clearing: ${beforeCount}`);
if (beforeCount === 0) {
console.log('β
No users to clear - database is already clean');
return true;
}
// Test the clear endpoint (but don't actually clear unless there are obvious test users)
const testEmails = ['alice.johnson@example.com', 'bob.smith@example.com'];
const hasTestUsers = checkResult.data.users?.some(user =>
testEmails.includes(user.email.toLowerCase())
);
if (hasTestUsers) {
console.log('β οΈ Found test users (Alice, Bob, etc.)');
console.log(' β’ Clear Test Data API is available');
console.log(' β’ Use the dashboard button to remove them');
} else {
console.log('β
No obvious test users found');
console.log(' β’ Users might be real - don\\'t auto-clear');
}
console.log('β
Clear Test Data API is ready');
return true;
}
async function testCandidateMatching() {
console.log('\\nπ― Testing Candidate Matching with Real Data...');
console.log('=' .repeat(50));
// Test with a sample job description
const result = await makeRequest('/api/match', {
method: 'POST',
body: JSON.stringify({
jobDescription: 'Looking for a JavaScript developer with React experience',
limit: 5,
minMatchScore: 10
})
});
if (!result.success) {
console.log('β Candidate matching failed:', result.data?.error || result.error);
return false;
}
const { candidates, summary } = result.data.data;
console.log('β
Candidate matching working');
console.log('π Matching results:');
console.log(` β’ Total Candidates: ${summary.totalCandidates}`);
console.log(` β’ Matched Candidates: ${summary.matchedCandidates}`);
console.log(` β’ Average Match Score: ${summary.averageMatchScore}%`);
if (candidates.length > 0) {
console.log('\\nπ Sample candidates found:');
candidates.slice(0, 3).forEach((candidate, index) => {
console.log(` ${index + 1}. ${candidate.candidate.name} (${candidate.match.score}% match)`);
});
} else {
console.log('\\nβ
No candidates found - this is correct if database is empty');
}
return true;
}
async function runVerification() {
console.log('π Verifying Fixes for Demo Users and Jobs.map Error');
console.log('=' .repeat(70));
const tests = [
{ name: 'Jobs API (jobs.map fix)', fn: testJobsAPI },
{ name: 'Real Users Check', fn: testRealUsersCheck },
{ name: 'Clear Test Data API', fn: testClearTestData },
{ name: 'Candidate Matching', fn: testCandidateMatching },
];
const results = [];
for (const test of tests) {
try {
const success = await test.fn();
results.push({ name: test.name, success });
} catch (error) {
console.log(`β ${test.name} failed with error:`, error.message);
results.push({ name: test.name, success: false, error: error.message });
}
}
console.log('\\nπ Verification Results');
console.log('=' .repeat(70));
results.forEach(result => {
const status = result.success ? 'β
' : 'β';
console.log(`${status} ${result.name}`);
if (result.error) {
console.log(` Error: ${result.error}`);
}
});
const passedTests = results.filter(r => r.success).length;
const totalTests = results.length;
console.log(`\\nπ― Overall: ${passedTests}/${totalTests} tests passed`);
if (passedTests === totalTests) {
console.log('\\nπ All fixes verified successfully!');
console.log('\\nπ Next Steps:');
console.log(' 1. Go to recruiter dashboard');
console.log(' 2. Click "Clear Test Data" to remove demo users');
console.log(' 3. Click "Check Real Users" to verify clean state');
console.log(' 4. System is ready for real users from AI interviews');
} else {
console.log('\\nβ οΈ Some tests failed. Check the details above.');
}
}
runVerification().catch(console.error);