Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions __tests__/prisma/schema.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { describe, it, expect } from 'vitest'
import { prisma } from '../../lib/prisma/client'

describe('Database Schema', () => {
it('should create a user with valid data', async () => {
const user = await prisma.user.create({
data: {
email: 'test@example.com',
password: 'hashedpassword123',
username: 'testuser',
firstName: 'Test',
lastName: 'User'
}
})

expect(user).toBeDefined()
expect(user.email).toBe('test@example.com')
expect(user.username).toBe('testuser')
})

it('should prevent duplicate email creation', async () => {
await prisma.user.create({
data: {
email: 'unique@example.com',
password: 'hashedpassword123'
}
})

await expect(prisma.user.create({
data: {
email: 'unique@example.com',
password: 'anotherpassword'
}
})).rejects.toThrow()
})

it('should create a saved job for a user', async () => {
const user = await prisma.user.create({
data: {
email: 'jobseeker@example.com',
password: 'hashedpassword123'
}
})

const savedJob = await prisma.savedJob.create({
data: {
jobId: 'job123',
title: 'Software Engineer',
company: 'Tech Corp',
userId: user.id
}
})

expect(savedJob).toBeDefined()
expect(savedJob.userId).toBe(user.id)
})
})
12 changes: 12 additions & 0 deletions lib/prisma/client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { PrismaClient } from '@prisma/client'

// Ensure a single instance of PrismaClient in development
const globalForPrisma = global as unknown as { prisma: PrismaClient }

export const prisma =
globalForPrisma.prisma ||
new PrismaClient({
log: process.env.NODE_ENV === 'development' ? ['query', 'error', 'warn'] : ['error'],
})

if (process.env.NODE_ENV !== 'production') globalForPrisma.prisma = prisma
Loading