-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-real-data-flow.js
More file actions
executable file
Β·237 lines (192 loc) Β· 7.71 KB
/
test-real-data-flow.js
File metadata and controls
executable file
Β·237 lines (192 loc) Β· 7.71 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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
#!/usr/bin/env node
/**
* Test script to verify the real data flow in the candidate matching system
* This script tests:
* 1. Check real users and skills in database
* 2. Test candidate matching with real data
* 3. Verify the match API endpoint
*/
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 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('β Failed to check real users:', result.error);
return false;
}
const { summary, users, usersWithSkills, topSkills } = result.data;
console.log('π Database Summary:');
console.log(` β’ Total Users: ${summary.totalUsers}`);
console.log(` β’ Users with Skills: ${summary.usersWithSkills}`);
console.log(` β’ Total User Skills: ${summary.totalUserSkills}`);
console.log(` β’ Unique Skills: ${summary.uniqueSkills}`);
if (summary.totalUsers === 0) {
console.log('β οΈ No users found in database');
return false;
}
if (summary.usersWithSkills === 0) {
console.log('β οΈ No users with skills found');
console.log('π‘ Users need to take AI interviews to generate skill data');
return false;
}
console.log('\\nπ₯ Sample Users:');
users.slice(0, 3).forEach(user => {
console.log(` β’ ${user.name} (${user.email}) - Created: ${new Date(user.createdAt).toLocaleDateString()}`);
});
console.log('\\nπ― Top Skills:');
topSkills.slice(0, 5).forEach(skill => {
console.log(` β’ ${skill.skillName}: ${skill.userCount} users (avg proficiency: ${skill.avgProficiency}%)`);
});
console.log('\\nβ
Real users check completed successfully');
return true;
}
async function testCandidateMatching() {
console.log('\\nπ― Testing Candidate Matching...');
console.log('=' .repeat(50));
// Test with a sample job description
const jobDescription = `
We are looking for a Senior Software Engineer with experience in:
- JavaScript and TypeScript
- React and Node.js
- Database design and SQL
- API development and integration
- Agile development methodologies
`;
const result = await makeRequest('/api/match', {
method: 'POST',
body: JSON.stringify({
jobDescription,
limit: 10,
minMatchScore: 20
})
});
if (!result.success) {
console.log('β Candidate matching failed:', result.data?.error || result.error);
return false;
}
const { job, candidates, summary } = result.data.data;
console.log('π Job Analysis:');
console.log(` β’ Title: ${job.title}`);
console.log(` β’ Required Skills: ${job.requiredSkills?.length || 0}`);
console.log(` β’ Preferred Skills: ${job.preferredSkills?.length || 0}`);
console.log('\\nπ Matching Results:');
console.log(` β’ Total Candidates in DB: ${summary.totalCandidates}`);
console.log(` β’ Matched Candidates: ${summary.matchedCandidates}`);
console.log(` β’ Average Match Score: ${summary.averageMatchScore}%`);
console.log(` β’ Top Match Score: ${summary.topMatchScore}%`);
if (candidates.length === 0) {
console.log('β οΈ No matching candidates found');
console.log('π‘ This could mean:');
console.log(' - No users have skills matching the job requirements');
console.log(' - Users need to take AI interviews to build skill profiles');
console.log(' - Match score threshold is too high');
return false;
}
console.log('\\nπ Top Matching Candidates:');
candidates.slice(0, 3).forEach((candidate, index) => {
console.log(` ${index + 1}. ${candidate.candidate.name} (${candidate.match.score}% match)`);
console.log(` β’ Email: ${candidate.candidate.email}`);
console.log(` β’ Skills: ${candidate.candidate.skills.length}`);
console.log(` β’ Matching Skills: ${candidate.match.matchingSkills.length}`);
console.log(` β’ Skill Gaps: ${candidate.match.skillGaps.length}`);
console.log(` β’ Overall Fit: ${candidate.match.overallFit}`);
console.log('');
});
console.log('β
Candidate matching completed successfully');
return true;
}
async function testJobBasedMatching() {
console.log('\\nπ Testing Job-Based Matching...');
console.log('=' .repeat(50));
// First, get available jobs
const jobsResult = await makeRequest('/api/debug/jobs');
if (!jobsResult.success || !jobsResult.data.data.jobs.length) {
console.log('β οΈ No jobs found for testing job-based matching');
return false;
}
const firstJob = jobsResult.data.data.jobs[0];
console.log(`π― Testing with job: \"${firstJob.title}\"`);
const result = await makeRequest('/api/match', {
method: 'POST',
body: JSON.stringify({
jobId: firstJob.id,
limit: 5,
minMatchScore: 10
})
});
if (!result.success) {
console.log('β Job-based matching failed:', result.data?.error || result.error);
return false;
}
const { candidates, summary } = result.data.data;
console.log('π Job-Based Matching Results:');
console.log(` β’ Matched Candidates: ${summary.matchedCandidates}`);
console.log(` β’ Average Match Score: ${summary.averageMatchScore}%`);
if (candidates.length > 0) {
console.log('\\nπ Top Candidate:');
const top = candidates[0];
console.log(` β’ ${top.candidate.name} (${top.match.score}% match)`);
console.log(` β’ Skills: ${top.candidate.skills.map(s => s.name).join(', ')}`);
}
console.log('β
Job-based matching completed successfully');
return true;
}
async function runAllTests() {
console.log('π Starting Real Data Flow Tests');
console.log('=' .repeat(60));
const tests = [
{ name: 'Real Users Check', fn: testRealUsersCheck },
{ name: 'Candidate Matching', fn: testCandidateMatching },
{ name: 'Job-Based Matching', fn: testJobBasedMatching },
];
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π Test Results Summary');
console.log('=' .repeat(60));
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('π All tests passed! The system is using real data correctly.');
} else {
console.log('β οΈ Some tests failed. Check the details above.');
}
console.log('\\nπ‘ Next Steps:');
console.log(' 1. Ensure users take AI interviews to generate skill data');
console.log(' 2. Create job postings with skill requirements');
console.log(' 3. Test the recruiter dashboard matching functionality');
console.log(' 4. Verify that new interview data updates candidate profiles');
}
// Run the tests
runAllTests().catch(console.error);