-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcreate-test-user.js
More file actions
43 lines (35 loc) · 1.07 KB
/
create-test-user.js
File metadata and controls
43 lines (35 loc) · 1.07 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
const { PrismaClient } = require('@prisma/client');
const bcrypt = require('bcryptjs');
const prisma = new PrismaClient();
async function createTestUser() {
try {
console.log('Checking for existing test user...');
// Check if test user already exists
const existingUser = await prisma.user.findUnique({
where: { email: 'test@example.com' }
});
if (existingUser) {
console.log('Test user already exists:', existingUser.email);
return existingUser;
}
// Create test user
console.log('Creating test user...');
const hashedPassword = await bcrypt.hash('password123', 10);
const newUser = await prisma.user.create({
data: {
username: 'testuser',
email: 'test@example.com',
password: hashedPassword,
xp: 100,
coins: 500
}
});
console.log('Test user created successfully:', newUser.email);
return newUser;
} catch (error) {
console.error('Error creating test user:', error);
} finally {
await prisma.$disconnect();
}
}
createTestUser();