Initial commit: full-stack Bun + Elysia + React template
Elysia.js API with session-based auth (email/password + Google OAuth), role system (USER/ADMIN/SUPER_ADMIN), Prisma + PostgreSQL, React 19 with Mantine UI, TanStack Router, dark theme, and comprehensive test suite (unit, integration, E2E with Lightpanda). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
38
tests/helpers.ts
Normal file
38
tests/helpers.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import { prisma } from '../src/lib/db'
|
||||
import { createApp } from '../src/app'
|
||||
|
||||
export { prisma }
|
||||
|
||||
export function createTestApp() {
|
||||
const app = createApp()
|
||||
return app
|
||||
}
|
||||
|
||||
/** Create a test user with hashed password, returns the user record */
|
||||
export async function seedTestUser(email = 'test@example.com', password = 'test123', name = 'Test User', role: 'USER' | 'ADMIN' | 'SUPER_ADMIN' = 'USER') {
|
||||
const hashed = await Bun.password.hash(password, { algorithm: 'bcrypt' })
|
||||
return prisma.user.upsert({
|
||||
where: { email },
|
||||
update: { name, password: hashed, role },
|
||||
create: { email, name, password: hashed, role },
|
||||
})
|
||||
}
|
||||
|
||||
/** Create a session for a user, returns the token */
|
||||
export async function createTestSession(userId: string, expiresAt?: Date) {
|
||||
const token = crypto.randomUUID()
|
||||
await prisma.session.create({
|
||||
data: {
|
||||
token,
|
||||
userId,
|
||||
expiresAt: expiresAt ?? new Date(Date.now() + 24 * 60 * 60 * 1000),
|
||||
},
|
||||
})
|
||||
return token
|
||||
}
|
||||
|
||||
/** Clean up test data */
|
||||
export async function cleanupTestData() {
|
||||
await prisma.session.deleteMany()
|
||||
await prisma.user.deleteMany()
|
||||
}
|
||||
Reference in New Issue
Block a user