feat: set up development database and test cleanup utilities

This commit is contained in:
2026-03-31 16:52:56 -07:00
parent 48a96ce65f
commit 26c5158724
6 changed files with 389 additions and 23 deletions
+19 -10
View File
@@ -5,10 +5,24 @@
import { chromium, type FullConfig } from '@playwright/test';
import { prisma } from '@/lib/prisma';
import { cleanupAllTestData } from '@/__tests__/test-utils';
const authFile = 'playwright/.auth/user.json';
const adminAuthFile = 'playwright/.auth/admin.json';
// Check if we're using the dev database
function isDevDatabase(): boolean {
const dbUrl = process.env.DATABASE_URL || '';
return dbUrl.includes('euchre_camp_dev');
}
// Warn if not using dev database
if (!isDevDatabase()) {
console.warn('⚠️ WARNING: Not using dev database!');
console.warn(' Current DATABASE_URL:', process.env.DATABASE_URL);
console.warn(' Expected to contain: euchre_camp_dev');
}
export default async function globalSetup(config: FullConfig) {
const baseURL = config.projects[0]?.use?.baseURL || 'http://localhost:3000';
@@ -144,18 +158,13 @@ export default async function globalSetup(config: FullConfig) {
// Return teardown function
return async () => {
// Clean up test users
console.log('\n=== Global Teardown ===');
// Clean up all test data
try {
await prisma.user.deleteMany({
where: {
email: {
startsWith: 'setup-'
}
}
});
console.log('Cleaned up test users');
await cleanupAllTestData();
} catch (error) {
console.error('Error cleaning up test users:', error);
console.error('Error cleaning up test data:', error);
} finally {
await prisma.$disconnect();
}
+17 -13
View File
@@ -1,22 +1,27 @@
import { test, expect } from '@playwright/test'
import { prisma } from '@/lib/prisma'
import { createTestPlayer, cleanupTestRecords, getCreatedRecordCounts } from '@/__tests__/test-utils'
test.describe('Home Page', () => {
test.beforeEach(async () => {
// Clean up any existing test records before each test
await cleanupTestRecords();
});
test.afterEach(async () => {
// Clean up test records after each test
await cleanupTestRecords();
});
test('should display top 10 players', async ({ page }) => {
// Create some test players with unique names and very high Elo to ensure they're in top 10
const timestamp = Date.now()
const players = []
for (let i = 0; i < 3; i++) {
const playerName = `Home Test Player ${timestamp} ${i + 1}`
const player = await prisma.player.create({
data: {
name: playerName,
normalizedName: playerName.toLowerCase(),
currentElo: 2000 - i * 10, // Very high Elo to ensure they're in top 10
gamesPlayed: 10 + i,
wins: 5 + Math.floor(i / 2),
losses: 5 + Math.ceil(i / 2),
},
const player = await createTestPlayer({
name: playerName,
currentElo: 2000 - i * 10,
})
players.push(player)
}
@@ -33,10 +38,9 @@ test.describe('Home Page', () => {
page.locator(`a:has-text("Home Test Player ${timestamp} 1")`)
).toBeVisible()
// Clean up
for (const player of players) {
await prisma.player.delete({ where: { id: player.id } })
}
// Verify cleanup will work
const counts = getCreatedRecordCounts();
expect(counts.players).toBe(3);
})
test('should display club president', async ({ page }) => {