Files
euchre_camp/e2e/tournament-edit-allowTies.test.ts
T
david 005cf7293d
Pull Request / unit-tests (pull_request) Successful in 2m31s
Pull Request / analyze-bump-type (pull_request) Successful in 12s
Pull Request / build-and-deploy-ci (pull_request) Failing after 42m4s
fix: reduce timeout values and fix test auth issues
- Reduce URL wait timeouts from 10000ms to 5000ms across tests
- Fix tournament-edit-allowTies: add login before navigating to edit page
- Fix epic4-tournament-creation: fill name field before clicking Next
- Fix cucumber config: remove broken cucumber-pretty formatter
2026-05-18 20:05:15 -07:00

187 lines
5.9 KiB
TypeScript

/**
* E2E Test: Tournament Edit with allowTies
*
* User Story: As a tournament admin, I want to edit tournament settings including allowTies
*
* Acceptance Criteria:
* - Can edit tournament settings
* - allowTies checkbox can be toggled
* - allowTies value is saved correctly
*/
import { test, expect } from '@playwright/test';
import { prisma } from '@/lib/prisma';
const BASE_URL = process.env.CI ? 'https://euchre-ci.notsosm.art' : 'http://localhost:3000';
function getTestCredentials() {
const timestamp = Date.now();
return {
email: `allowties-admin-${timestamp}@example.com`,
password: 'AdminPassword123!',
name: `AllowTies Admin ${timestamp}`,
};
}
test.describe('Tournament Edit - allowTies functionality', () => {
let tournamentId: number;
let testEmail: string;
let testPassword: string;
test.beforeAll(async () => {
// Create admin user via API
const credentials = getTestCredentials();
testEmail = credentials.email;
testPassword = credentials.password;
const response = await fetch(`${BASE_URL}/api/auth/sign-up/email`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Origin: BASE_URL,
},
body: JSON.stringify({
email: testEmail,
password: testPassword,
name: credentials.name,
}),
});
console.log('allowTies test user creation response:', response.status);
// Update user to club_admin role
const user = await prisma.user.findUnique({
where: { email: testEmail },
});
if (user) {
await prisma.user.update({
where: { id: user.id },
data: { role: 'club_admin' },
});
}
// Create a test tournament for editing
const tournament = await prisma.event.create({
data: {
name: 'Test Tournament for AllowTies Edit',
eventType: 'tournament',
format: 'round_robin',
status: 'planned',
allowTies: false,
targetScore: 5,
ownerId: user?.id,
createdAt: new Date(),
updatedAt: new Date(),
},
});
tournamentId = tournament.id;
});
test.afterAll(async () => {
// Clean up test tournament
if (tournamentId) {
await prisma.event.delete({
where: { id: tournamentId },
}).catch(() => {});
}
// Clean up user
const user = await prisma.user.findUnique({ where: { email: testEmail } });
if (user) {
await prisma.user.delete({ where: { id: user.id } });
}
});
test('should display allowTies checkbox on edit form @chromium-admin', async ({ page }) => {
// Login first
await page.goto('/auth/login');
await page.fill('input[name="email"]', testEmail);
await page.fill('input[name="password"]', testPassword);
await page.click('button[type="submit"]');
await page.waitForURL(/\/(admin|players)/, { timeout: 5000 });
// Navigate to tournament edit page
await page.goto(`/admin/tournaments/${tournamentId}/edit`);
// Wait for form to load - edit page shows "Edit Tournament" heading
await expect(page.locator('text=Edit Tournament')).toBeVisible({ timeout: 5000 });
// Check that allowTies checkbox exists
const allowTiesCheckbox = page.locator('input[name="allowTies"]');
await expect(allowTiesCheckbox).toBeVisible();
await expect(allowTiesCheckbox).not.toBeChecked();
});
test('should save allowTies when toggled to true @chromium-admin', async ({ page }) => {
// Login first
await page.goto('/auth/login');
await page.fill('input[name="email"]', testEmail);
await page.fill('input[name="password"]', testPassword);
await page.click('button[type="submit"]');
await page.waitForURL(/\/(admin|players)/, { timeout: 5000 });
// Navigate to tournament edit page
await page.goto(`/admin/tournaments/${tournamentId}/edit`);
// Wait for form to load
await expect(page.locator('text=Edit Tournament')).toBeVisible({ timeout: 5000 });
// Toggle allowTies checkbox
const allowTiesCheckbox = page.locator('input[name="allowTies"]');
await allowTiesCheckbox.check();
await expect(allowTiesCheckbox).toBeChecked();
// Submit form
await page.click('button[type="submit"]');
// Wait for success message
await expect(page.locator('text=Tournament updated successfully')).toBeVisible({ timeout: 5000 });
// Verify allowTies was saved by checking the database
const updatedTournament = await prisma.event.findUnique({
where: { id: tournamentId },
});
expect(updatedTournament?.allowTies).toBe(true);
});
test('should save allowTies when toggled to false @chromium-admin', async ({ page }) => {
// First, set allowTies to true
await prisma.event.update({
where: { id: tournamentId },
data: { allowTies: true },
});
// Login first
await page.goto('/auth/login');
await page.fill('input[name="email"]', testEmail);
await page.fill('input[name="password"]', testPassword);
await page.click('button[type="submit"]');
await page.waitForURL(/\/(admin|players)/, { timeout: 5000 });
// Navigate to tournament edit page
await page.goto(`/admin/tournaments/${tournamentId}/edit`);
// Wait for form to load
await expect(page.locator('text=Edit Tournament')).toBeVisible({ timeout: 5000 });
// Verify checkbox is checked
const allowTiesCheckbox = page.locator('input[name="allowTies"]');
await expect(allowTiesCheckbox).toBeChecked();
// Uncheck allowTies checkbox
await allowTiesCheckbox.uncheck();
await expect(allowTiesCheckbox).not.toBeChecked();
// Submit form
await page.click('button[type="submit"]');
// Wait for success message
await expect(page.locator('text=Tournament updated successfully')).toBeVisible({ timeout: 5000 });
// Verify allowTies was saved by checking the database
const updatedTournament = await prisma.event.findUnique({
where: { id: tournamentId },
});
expect(updatedTournament?.allowTies).toBe(false);
});
});