-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck-users-for-testing.js
More file actions
112 lines (92 loc) · 3.19 KB
/
check-users-for-testing.js
File metadata and controls
112 lines (92 loc) · 3.19 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
const { PrismaClient } = require('@prisma/client');
const prisma = new PrismaClient();
async function checkUsers() {
try {
console.log('Checking users in database for sales rep matching tests...\n');
const users = await prisma.user.findMany({
select: {
id: true,
name: true,
email: true,
role: true
}
});
console.log('Current users in the system:');
console.log('============================');
if (users.length === 0) {
console.log('No users found in the database.');
console.log('Please create some users first through the admin panel.');
return;
}
users.forEach((user, index) => {
console.log(`${index + 1}. Name: "${user.name || 'No name'}", Email: "${user.email}", Role: ${user.role}`);
});
console.log('\nTesting sales rep matching:');
console.log('===========================');
// Test the matching logic
const testNames = [
'John Doe',
'admin@example.com',
'Admin User',
'NonExistentUser'
];
// Simulate the findSalesRepByName function
const findSalesRepByName = (salesRepName) => {
if (!salesRepName || typeof salesRepName !== 'string') {
return null;
}
const trimmedName = salesRepName.trim();
if (!trimmedName) {
return null;
}
// Try exact match first (case insensitive)
let user = users.find(u =>
u.name && u.name.toLowerCase() === trimmedName.toLowerCase()
);
// If no exact match, try partial match
if (!user) {
user = users.find(u =>
u.name && (
u.name.toLowerCase().includes(trimmedName.toLowerCase()) ||
trimmedName.toLowerCase().includes(u.name.toLowerCase())
)
);
}
// Try matching by email as well
if (!user) {
user = users.find(u =>
u.email.toLowerCase() === trimmedName.toLowerCase()
);
}
return user;
};
testNames.forEach(testName => {
const foundUser = findSalesRepByName(testName);
if (foundUser) {
console.log(`✓ "${testName}" → Found: ${foundUser.name || foundUser.email} (${foundUser.email})`);
} else {
console.log(`✗ "${testName}" → Not found (will fallback to current user)`);
}
});
console.log('\nRecommendations for test file:');
console.log('==============================');
if (users.length > 0) {
console.log('Update the test-import.js file with these actual user names/emails:');
users.forEach((user, index) => {
if (index < 3) { // Show first 3 users
console.log(`- salesRepName: "${user.name || user.email}"`);
}
});
}
console.log('\nThe import test file contains these sales rep references:');
console.log('- "John Doe" (may not exist)');
console.log('- "admin@example.com" (may exist)');
console.log('- "Admin User" (may exist)');
console.log('- "NonExistentUser" (should not exist)');
} catch (error) {
console.error('Error checking users:', error);
} finally {
await prisma.$disconnect();
}
}
checkUsers();