92 lines
2.5 KiB
JavaScript
92 lines
2.5 KiB
JavaScript
const argon2 = require('argon2');
|
|
const { PrismaClient } = require('@prisma/client');
|
|
|
|
async function createTestUser() {
|
|
const prisma = new PrismaClient({
|
|
datasourceUrl: 'postgres://app:app@localhost:5432/skymoney'
|
|
});
|
|
|
|
try {
|
|
// Delete existing test user if exists
|
|
await prisma.user.deleteMany({
|
|
where: { email: 'test@skymoney.com' }
|
|
});
|
|
console.log('✓ Cleaned up old test user');
|
|
|
|
// Create user
|
|
const hash = await argon2.hash('password123');
|
|
const user = await prisma.user.create({
|
|
data: {
|
|
email: 'test@skymoney.com',
|
|
passwordHash: hash,
|
|
displayName: 'Test User',
|
|
timezone: 'America/New_York'
|
|
}
|
|
});
|
|
console.log('✓ Created user:', user.id);
|
|
|
|
// Create income
|
|
await prisma.incomeEvent.create({
|
|
data: {
|
|
userId: user.id,
|
|
amountCents: 300000n, // $3000
|
|
postedAt: new Date(),
|
|
isScheduledIncome: true
|
|
}
|
|
});
|
|
console.log('✓ Created income: $3000');
|
|
|
|
// Create categories (must total 100%)
|
|
await prisma.variableCategory.create({
|
|
data: {
|
|
userId: user.id,
|
|
name: 'Groceries',
|
|
percent: 50,
|
|
balanceCents: 150000n // $1500
|
|
}
|
|
});
|
|
await prisma.variableCategory.create({
|
|
data: {
|
|
userId: user.id,
|
|
name: 'Other',
|
|
percent: 50,
|
|
balanceCents: 0n
|
|
}
|
|
});
|
|
console.log('✓ Created categories (100% total)');
|
|
|
|
// Create rent bill due today - PARTIALLY FUNDED & OVERDUE
|
|
const today = new Date();
|
|
today.setHours(0, 0, 0, 0);
|
|
|
|
await prisma.fixedPlan.create({
|
|
data: {
|
|
userId: user.id,
|
|
name: 'Rent',
|
|
totalCents: 150000n, // $1500 total
|
|
fundedCents: 100000n, // $1000 funded (partial)
|
|
currentFundedCents: 100000n, // $1000 available
|
|
dueOn: today,
|
|
cycleStart: today,
|
|
frequency: 'monthly',
|
|
needsFundingThisPeriod: true,
|
|
isOverdue: true, // Marked overdue
|
|
overdueAmount: 50000n, // $500 outstanding
|
|
overdueSince: new Date()
|
|
}
|
|
});
|
|
console.log('✓ Created Rent plan: $1500 total, $1000 funded, $500 overdue');
|
|
console.log('\n✅ Test user ready!');
|
|
console.log(' Email: test@skymoney.com');
|
|
console.log(' Password: password123');
|
|
console.log(' Rent: $1500 due today (partially funded, overdue)');
|
|
|
|
} catch (error) {
|
|
console.error('❌ Error:', error.message);
|
|
} finally {
|
|
await prisma.$disconnect();
|
|
}
|
|
}
|
|
|
|
createTestUser();
|