feat: Implement tournament schedule tab and fix E2E tests (#27)
## Summary This PR implements the tournament schedule tab functionality and fixes all remaining E2E test failures. ### Changes Included 1. **Tournament Schedule Feature** - Added tournament schedule page at `/admin/tournaments/[id]/schedule` - Implemented "Generate Schedule" button functionality - Added schedule generation logic for round-robin tournaments 2. **E2E Test Fixes** - Fixed database connection issues in production builds - Improved test reliability with better error handling and debugging - Updated test infrastructure to use environment variables instead of hardcoded values 3. **CI/CD Updates** - Added E2E test job to PR workflow - Configured tests to run against development database - Moved database password to Gitea secrets 4. **Code Quality** - Removed hardcoded passwords from codebase - Improved Prisma client configuration - Enhanced authentication and navigation components ### Test Results All 16 E2E test scenarios are now passing: - Authentication tests: ✅ - Registration tests: ✅ - Tournament schedule tests: ✅ - Player schedule tests: ✅ - Admin navigation tests: ✅ ### Database Configuration - Tests run against `euchre_camp_dev` database - Production builds use environment variables for database configuration - Database password stored in Gitea secrets as `DB_PASSWORD` ### CI Pipeline The PR workflow now includes: 1. Unit tests 2. E2E tests (using production build) 3. Version bump analysis E2E tests must pass before PR can be merged. Reviewed-on: #27 Co-authored-by: David Gwilliam <dhgwilliam@gmail.com> Co-committed-by: David Gwilliam <dhgwilliam@gmail.com>
This commit was merged in pull request #27.
This commit is contained in:
+92
-29
@@ -29,6 +29,46 @@ if (DB_URL.includes('_dev') || DB_URL.includes('_dev_')) {
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// Single source of truth for test object patterns
|
||||
const TEST_PATTERNS = {
|
||||
players: [
|
||||
'%Test%',
|
||||
'%Setup%',
|
||||
'%Home Test%',
|
||||
'%Home Match Player%',
|
||||
'%Admin User%',
|
||||
'%NinePart%',
|
||||
'%Nine Part%',
|
||||
'%Test Player%',
|
||||
'%TestUser%',
|
||||
'%Cucumber%',
|
||||
'%Config Admin%',
|
||||
],
|
||||
events: [
|
||||
'%Test%',
|
||||
'%Setup%',
|
||||
'%Recent%',
|
||||
'%Test Tournament%',
|
||||
'%Cucumber%',
|
||||
],
|
||||
users: [
|
||||
'%test%',
|
||||
'%setup%',
|
||||
'%cucumber%',
|
||||
'%TestUser%',
|
||||
]
|
||||
};
|
||||
|
||||
// Helper to build SQL LIKE clause from patterns
|
||||
function buildLikeClause(patterns) {
|
||||
return patterns.map(p => `name LIKE '${p}'`).join(' OR ');
|
||||
}
|
||||
|
||||
// Helper to build email LIKE clause
|
||||
function buildEmailLikeClause(patterns) {
|
||||
return patterns.map(p => `email LIKE '${p}'`).join(' OR ');
|
||||
}
|
||||
|
||||
// Helper to run SQL and log results
|
||||
function runSQL(sql, description) {
|
||||
console.log(`\n🔍 ${description}...`);
|
||||
@@ -42,13 +82,23 @@ function runSQL(sql, description) {
|
||||
}
|
||||
}
|
||||
|
||||
// Helper to run multi-line SQL
|
||||
function runMultiLineSQL(sqlLines, description) {
|
||||
// Helper to run SQL via file (avoids quote escaping issues)
|
||||
function runSQLViaFile(sql, description) {
|
||||
console.log(`\n🔍 ${description}...`);
|
||||
const fs = require('fs');
|
||||
const os = require('os');
|
||||
const path = require('path');
|
||||
|
||||
try {
|
||||
const sql = sqlLines.join('\n');
|
||||
const result = execSync(`psql "${DB_URL}" -c "${sql}"`, { encoding: 'utf8' });
|
||||
// Create temp file with SQL
|
||||
const tmpFile = path.join(os.tmpdir(), `cleanup_${Date.now()}.sql`);
|
||||
fs.writeFileSync(tmpFile, sql);
|
||||
|
||||
const result = execSync(`psql "${DB_URL}" -f "${tmpFile}"`, { encoding: 'utf8' });
|
||||
console.log(result);
|
||||
|
||||
// Clean up temp file
|
||||
fs.unlinkSync(tmpFile);
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error(`❌ Error: ${error.message}`);
|
||||
@@ -56,9 +106,12 @@ function runMultiLineSQL(sqlLines, description) {
|
||||
}
|
||||
}
|
||||
|
||||
// Helper to count records matching pattern
|
||||
function countRecords(table, column, pattern) {
|
||||
const sql = `SELECT COUNT(*) FROM ${table} WHERE ${column} LIKE '${pattern}';`;
|
||||
// Helper to count records matching any of the patterns
|
||||
function countRecordsByPatterns(table, patterns) {
|
||||
const whereClause = table === 'users'
|
||||
? buildEmailLikeClause(patterns)
|
||||
: buildLikeClause(patterns);
|
||||
const sql = `SELECT COUNT(*) FROM ${table} WHERE ${whereClause};`;
|
||||
try {
|
||||
const result = execSync(`psql "${DB_URL}" -c "${sql}" -t`, { encoding: 'utf8' }).trim();
|
||||
return parseInt(result);
|
||||
@@ -89,57 +142,67 @@ async function main() {
|
||||
|
||||
console.log('\n📋 Checking test records...\n');
|
||||
|
||||
// Count test players
|
||||
const testPlayerCount = countRecords('players', 'name', '%Test%') +
|
||||
countRecords('players', 'name', '%Setup%') +
|
||||
countRecords('players', 'name', '%Home Test%') +
|
||||
countRecords('players', 'name', '%Home Match Player%') +
|
||||
countRecords('players', 'name', '%Admin User%');
|
||||
// Count test records using centralized patterns
|
||||
const testPlayerCount = countRecordsByPatterns('players', TEST_PATTERNS.players);
|
||||
console.log(`Test players found: ${testPlayerCount}`);
|
||||
|
||||
// Count test tournaments
|
||||
const testEventCount = countRecords('events', 'name', '%Test%') +
|
||||
countRecords('events', 'name', '%Setup%') +
|
||||
countRecords('events', 'name', '%Recent%');
|
||||
const testEventCount = countRecordsByPatterns('events', TEST_PATTERNS.events);
|
||||
console.log(`Test tournaments found: ${testEventCount}`);
|
||||
|
||||
// Count test users
|
||||
const testUserCount = countRecords('users', 'email', '%test%') +
|
||||
countRecords('users', 'email', '%setup%');
|
||||
const testUserCount = countRecordsByPatterns('users', TEST_PATTERNS.users);
|
||||
console.log(`Test users found: ${testUserCount}`);
|
||||
|
||||
console.log('\n🔄 Starting cleanup...\n');
|
||||
|
||||
// Step 1: Delete test tournaments (with matches due to cascade delete)
|
||||
console.log('1. Deleting test tournaments (matches will be deleted via cascade)...');
|
||||
runSQL(
|
||||
"DELETE FROM events WHERE (name LIKE '%Test%' OR name LIKE '%Setup%' OR name LIKE '%Recent%');",
|
||||
const eventWhere = buildLikeClause(TEST_PATTERNS.events);
|
||||
runSQLViaFile(
|
||||
`DELETE FROM events WHERE (${eventWhere});`,
|
||||
'Deleted test tournaments'
|
||||
);
|
||||
|
||||
// Step 2: Delete test players (all of them, since we deleted their matches)
|
||||
console.log('\n2. Deleting test players...');
|
||||
runSQL(
|
||||
"DELETE FROM players WHERE (name LIKE '%Test%' OR name LIKE '%Setup%' OR name LIKE '%Home Test%' OR name LIKE '%Home Match Player%' OR name LIKE '%Admin User%');",
|
||||
const playerWhere = buildLikeClause(TEST_PATTERNS.players);
|
||||
runSQLViaFile(
|
||||
`DELETE FROM players WHERE (${playerWhere});`,
|
||||
'Deleted test players'
|
||||
);
|
||||
|
||||
// Step 3: Delete test users (they shouldn't have player associations)
|
||||
console.log('\n3. Deleting test users...');
|
||||
runSQL(
|
||||
"DELETE FROM users WHERE (email LIKE '%test%' OR email LIKE '%setup%') AND \"playerId\" IS NULL;",
|
||||
const userWhere = buildEmailLikeClause(TEST_PATTERNS.users);
|
||||
runSQLViaFile(
|
||||
`DELETE FROM users WHERE (${userWhere}) AND "playerId" IS NULL;`,
|
||||
'Deleted test users'
|
||||
);
|
||||
|
||||
// Summary
|
||||
console.log('\n✅ Cleanup complete!');
|
||||
console.log('\n📊 Remaining test records:');
|
||||
runSQL("SELECT COUNT(*) FROM players WHERE name LIKE '%Test%' OR name LIKE '%Setup%' OR name LIKE '%Home Test%';", 'Remaining test players');
|
||||
runSQL("SELECT COUNT(*) FROM events WHERE name LIKE '%Test%' OR name LIKE '%Setup%';", 'Remaining test tournaments');
|
||||
runSQL("SELECT COUNT(*) FROM users WHERE email LIKE '%test%' OR email LIKE '%setup%';", 'Remaining test users');
|
||||
|
||||
const remainingPlayerWhere = buildLikeClause(TEST_PATTERNS.players);
|
||||
runSQLViaFile(
|
||||
`SELECT COUNT(*) FROM players WHERE ${remainingPlayerWhere};`,
|
||||
'Remaining test players'
|
||||
);
|
||||
|
||||
const remainingEventWhere = buildLikeClause(TEST_PATTERNS.events);
|
||||
runSQLViaFile(
|
||||
`SELECT COUNT(*) FROM events WHERE ${remainingEventWhere};`,
|
||||
'Remaining test tournaments'
|
||||
);
|
||||
|
||||
const remainingUserWhere = buildEmailLikeClause(TEST_PATTERNS.users);
|
||||
runSQLViaFile(
|
||||
`SELECT COUNT(*) FROM users WHERE ${remainingUserWhere};`,
|
||||
'Remaining test users'
|
||||
);
|
||||
|
||||
console.log('\n💡 Note: All test records deleted. Matches are automatically deleted');
|
||||
console.log(' via cascade delete when their parent tournament is deleted.');
|
||||
console.log('\n📝 To add new test patterns, edit TEST_PATTERNS in this script.');
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user