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
+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 }) => {