Files
euchre_camp/e2e/account-acceptance-api.test.ts
T
david bb6be245b7
Release / release (push) Failing after 9s
Build CI Images / build-ci-base (push) Failing after 18s
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>
2026-04-27 01:59:16 +00:00

134 lines
3.8 KiB
TypeScript

/**
* Acceptance Test: Account Creation, Login, and Deletion (API-based)
*
* This test demonstrates the full workflow using API calls:
* 1. Create a test account via registration API
* 2. Log in using the authentication API
* 3. Delete the test account
*/
import { test, expect } from '@playwright/test';
import { prisma } from '@/lib/prisma';
// Generate unique test account credentials
function getTestCredentials() {
const timestamp = Date.now();
const random = Math.random().toString(36).substring(7);
return {
email: `test-api-${timestamp}-${random}@example.com`,
password: 'TestPassword1234!',
name: `Test API User ${timestamp}`
};
}
test.describe.serial('Account Lifecycle API Acceptance Test', () => {
let testEmail: string;
let testPassword: string;
let testName: string;
test.beforeAll(async () => {
const credentials = getTestCredentials();
testEmail = credentials.email;
testPassword = credentials.password;
testName = credentials.name;
});
test.afterAll(async () => {
// Clean up: delete test user if they still exist
try {
const user = await prisma.user.findUnique({
where: { email: testEmail }
});
if (user) {
await prisma.user.delete({ where: { id: user.id } });
console.log(`Cleaned up test user: ${testEmail}`);
}
} catch (error) {
console.error('Cleanup error:', error);
}
});
test('1. Create test account via API', async ({ request }) => {
console.log('Test 1 - testEmail:', testEmail);
// Register via API
const response = await request.post('http://localhost:3000/api/auth/sign-up/email', {
data: {
email: testEmail,
password: testPassword,
name: testName
},
headers: {
'Origin': 'http://localhost:3000'
}
});
console.log('API Registration Response:', response.status(), await response.text());
expect(response.ok()).toBeTruthy();
const data = await response.json();
expect(data.user.email).toBe(testEmail);
expect(data.user.name).toBe(testName);
// Verify user was created in database
const user = await prisma.user.findUnique({
where: { email: testEmail }
});
console.log('User created in DB:', user ? 'yes' : 'no');
if (user) {
console.log('User ID:', user.id);
console.log('User role:', user.role);
}
expect(user).not.toBeNull();
expect(user?.email).toBe(testEmail);
expect(user?.role).toBe('player');
});
test('2. Log in with test account via API', async ({ request }) => {
console.log('Test 2 - testEmail:', testEmail);
// Check if user exists first
const user = await prisma.user.findUnique({
where: { email: testEmail }
});
console.log('User exists for login:', user ? 'yes' : 'no');
if (user) {
console.log('User ID:', user.id);
}
// Login via API
const response = await request.post('http://localhost:3000/api/auth/sign-in/email', {
data: {
email: testEmail,
password: testPassword
},
headers: {
'Origin': 'http://localhost:3000'
}
});
console.log('Login API Response:', response.status(), await response.text());
expect(response.ok()).toBeTruthy();
const data = await response.json();
expect(data.user.email).toBe(testEmail);
expect(data.token).toBeDefined();
});
test('3. Delete test account', async () => {
// Delete via database
const user = await prisma.user.findUnique({
where: { email: testEmail }
});
if (user) {
await prisma.user.delete({ where: { id: user.id } });
console.log(`Test user deleted: ${testEmail}`);
}
// Verify user was deleted
const deletedUser = await prisma.user.findUnique({
where: { email: testEmail }
});
expect(deletedUser).toBeNull();
});
});