feat: SDLC database separation for CI/testing (#35)
## Summary - Fix `isProductionDatabase()` to allow CI database (`euchre_camp_ci`) - Add database schema reset before CI test runs - Create `global.teardown.ts` for cleanup (CI: full reset, dev/prod: selective cleanup) - Add `acceptance-tests` job to PR workflow with CI database - Create `sync-prod-to-dev.js` script for one-way prod→dev sync - Add `just` recipes: `sync-dev`, `test-prod`, `reset-ci-db` - Store credentials in `.credentials` (gitignored) with unique CI user ## Testing Verified against CI database: - Schema reset works - Migrations apply correctly - Test users created successfully - 219 tests pass (slow but working) ## Next Steps - Set `CI_DATABASE_URL` as Gitea repository variable Reviewed-on: #35 Co-authored-by: David Gwilliam <dhgwilliam@gmail.com> Co-committed-by: David Gwilliam <dhgwilliam@gmail.com>
This commit was merged in pull request #35.
This commit is contained in:
@@ -0,0 +1,110 @@
|
||||
import { test, expect } from '@playwright/test'
|
||||
import { prisma } from '@/lib/prisma'
|
||||
|
||||
test.describe('Home Page', () => {
|
||||
const createdIds = {
|
||||
players: [] as number[],
|
||||
events: [] as number[],
|
||||
matches: [] as number[],
|
||||
users: [] as string[],
|
||||
}
|
||||
|
||||
test.afterEach(async () => {
|
||||
await prisma.match.deleteMany({ where: { id: { in: createdIds.matches } } })
|
||||
await prisma.event.deleteMany({ where: { id: { in: createdIds.events } } })
|
||||
await prisma.player.deleteMany({ id: { in: createdIds.players } })
|
||||
await prisma.user.deleteMany({ where: { id: { in: createdIds.users } } })
|
||||
createdIds.players = []
|
||||
createdIds.events = []
|
||||
createdIds.matches = []
|
||||
createdIds.users = []
|
||||
})
|
||||
|
||||
test('displays top 10 players section', async ({ page }) => {
|
||||
const timestamp = Date.now()
|
||||
|
||||
for (let i = 0; i < 3; i++) {
|
||||
const player = await prisma.player.create({
|
||||
data: {
|
||||
name: `Home Test Player ${timestamp} ${i + 1}`,
|
||||
normalizedName: `home_test_player_${timestamp}_${i + 1}`.toLowerCase(),
|
||||
currentElo: 2000 - i * 10,
|
||||
gamesPlayed: 10,
|
||||
wins: 7,
|
||||
},
|
||||
})
|
||||
createdIds.players.push(player.id)
|
||||
}
|
||||
|
||||
await page.goto('/')
|
||||
|
||||
await expect(page.locator('text=Top 10 Players')).toBeVisible()
|
||||
await expect(
|
||||
page.locator(`a:has-text("Home Test Player ${timestamp} 1")`)
|
||||
).toBeVisible()
|
||||
})
|
||||
|
||||
test('displays club president section', async ({ page }) => {
|
||||
const timestamp = Date.now()
|
||||
const user = await prisma.user.create({
|
||||
data: {
|
||||
email: `president-${timestamp}@example.com`,
|
||||
name: `Club President ${timestamp}`,
|
||||
role: 'club_admin',
|
||||
},
|
||||
})
|
||||
createdIds.users.push(user.id)
|
||||
|
||||
await page.goto('/')
|
||||
|
||||
await expect(page.locator('text=Club President')).toBeVisible()
|
||||
})
|
||||
|
||||
test('displays most recent tournament section', async ({ page }) => {
|
||||
const timestamp = Date.now()
|
||||
|
||||
const tournament = await prisma.event.create({
|
||||
data: {
|
||||
name: `Recent Tournament ${timestamp}`,
|
||||
eventType: 'tournament',
|
||||
eventDate: new Date(Date.now() + 86400000),
|
||||
status: 'completed',
|
||||
},
|
||||
})
|
||||
createdIds.events.push(tournament.id)
|
||||
|
||||
const p1 = await prisma.player.create({
|
||||
data: { name: `HP1 ${timestamp}`, normalizedName: `hp1_${timestamp}`.toLowerCase(), currentElo: 1500 },
|
||||
})
|
||||
const p2 = await prisma.player.create({
|
||||
data: { name: `HP2 ${timestamp}`, normalizedName: `hp2_${timestamp}`.toLowerCase(), currentElo: 1480 },
|
||||
})
|
||||
const p3 = await prisma.player.create({
|
||||
data: { name: `HP3 ${timestamp}`, normalizedName: `hp3_${timestamp}`.toLowerCase(), currentElo: 1450 },
|
||||
})
|
||||
const p4 = await prisma.player.create({
|
||||
data: { name: `HP4 ${timestamp}`, normalizedName: `hp4_${timestamp}`.toLowerCase(), currentElo: 1420 },
|
||||
})
|
||||
createdIds.players.push(p1.id, p2.id, p3.id, p4.id)
|
||||
|
||||
const match = await prisma.match.create({
|
||||
data: {
|
||||
eventId: tournament.id,
|
||||
player1P1Id: p1.id,
|
||||
player1P2Id: p2.id,
|
||||
player2P1Id: p3.id,
|
||||
player2P2Id: p4.id,
|
||||
team1Score: 10,
|
||||
team2Score: 5,
|
||||
status: 'completed',
|
||||
playedAt: new Date(),
|
||||
},
|
||||
})
|
||||
createdIds.matches.push(match.id)
|
||||
|
||||
await page.goto('/')
|
||||
|
||||
await expect(page.locator('text=Most Recent Tournament')).toBeVisible()
|
||||
await expect(page.locator(`text=Recent Tournament ${timestamp}`)).toBeVisible()
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user