-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcreate-simple-test-user.js
More file actions
61 lines (50 loc) · 1.85 KB
/
create-simple-test-user.js
File metadata and controls
61 lines (50 loc) · 1.85 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
const mongoose = require('mongoose');
const bcrypt = require('bcrypt');
const User = require('./src/models/user');
// Create a simple test user with known credentials for frontend testing
async function createSimpleTestUser() {
try {
// Connect to MongoDB
await mongoose.connect(process.env.MONGODB_URI || 'mongodb://localhost:27017/quickshift');
console.log('MongoDB connected');
// Check if a simple test user exists
let testUser = await User.findOne({ email: 'testuser@example.com' });
if (testUser) {
console.log('Test user already exists, updating...');
} else {
console.log('Creating new test user...');
testUser = new User({
firstName: 'Test',
lastName: 'User',
email: 'testuser@example.com',
role: 'job_seeker',
university: 'Test University',
faculty: 'Computer Science',
yearOfStudy: 2,
phone: '+1234567890',
isActive: true,
isVerified: true,
studentIdVerified: true
});
}
// Set a simple password
testUser.password = await bcrypt.hash('test123', 10);
await testUser.save();
console.log('✅ Test user created/updated:');
console.log(' Email: testuser@example.com');
console.log(' Password: test123');
console.log(' Role: job_seeker');
console.log(' Active: true');
console.log(' Verified: true');
// Test login with this user
console.log('\n🧪 Testing login with new credentials...');
const loginTest = await User.findOne({ email: 'testuser@example.com' });
const isMatch = await bcrypt.compare('test123', loginTest.password);
console.log(`Password test: ${isMatch ? '✅ Correct' : '❌ Failed'}`);
process.exit(0);
} catch (error) {
console.error('Error:', error);
process.exit(1);
}
}
createSimpleTestUser();