feat: Implement tournament schedule tab and fix E2E tests #27

Merged
david merged 43 commits from feature/7-schedule-tab into main 2026-04-27 01:59:17 +00:00
2 changed files with 37 additions and 30 deletions
Showing only changes of commit ade3b82e3c - Show all commits
+11 -12
View File
@@ -101,12 +101,12 @@ describe('Tournament Update API', () => {
);
});
it('should default allowTies to false when not provided', async () => {
it('should NOT modify allowTies when not provided in request', async () => {
// Mock existing tournament
eventFindUniqueMock.mockImplementation(async () => ({
id: 1,
name: 'Test Tournament',
allowTies: true,
allowTies: true, // This is the current value
targetScore: 5,
eventType: 'tournament',
format: 'round_robin',
@@ -119,11 +119,11 @@ describe('Tournament Update API', () => {
updatedAt: new Date(),
} as any));
// Mock successful update
// Mock successful update (allowTies should remain unchanged)
eventUpdateMock.mockImplementation(async () => ({
id: 1,
name: 'Test Tournament',
allowTies: false,
allowTies: true, // Should remain true, not reset to false
targetScore: 5,
eventType: 'tournament',
format: 'round_robin',
@@ -141,7 +141,7 @@ describe('Tournament Update API', () => {
body: JSON.stringify({
name: 'Test Tournament',
targetScore: 5,
// allowTies not provided
// allowTies not provided - should NOT be modified
}),
});
@@ -149,13 +149,12 @@ describe('Tournament Update API', () => {
const response = await PUT(request, { params });
expect(response.status).toBe(200);
expect(prisma.event.update).toHaveBeenCalledWith(
expect.objectContaining({
data: expect.objectContaining({
allowTies: false, // Should default to false
}),
})
);
// When allowTies is not provided, it should NOT be in the update data
// (it will keep its existing value in the database)
const updateCall = eventUpdateMock.mock.calls[0][0];
expect(updateCall.data.allowTies).toBeUndefined();
expect(updateCall.data.name).toBe('Test Tournament');
expect(updateCall.data.targetScore).toBe(5);
});
it('should preserve allowTies value when updating other fields', async () => {
+21 -13
View File
@@ -151,28 +151,36 @@ export async function PUT(request: Request, { params }: RouteParams) {
ownerId,
targetScore,
allowTies,
teamDurability,
partnerRotation,
allowByes,
} = body;
// Validate required fields
// Validate name only if it's being updated
if (body.hasOwnProperty('name')) {
if (!name || typeof name !== 'string' || name.trim().length === 0) {
return NextResponse.json(
{ error: "Tournament name is required" },
{ status: 400 }
);
}
}
// Prepare update data
const updateData: Record<string, unknown> = {
name: name.trim(),
description: description || null,
eventDate: eventDate ? new Date(eventDate) : null,
eventType: eventType || "tournament",
tournamentType: tournamentType || "individual",
format: format || "round_robin",
maxParticipants: maxParticipants ? parseInt(maxParticipants) : null,
targetScore: targetScore ? parseInt(targetScore) : null,
allowTies: allowTies ?? false,
};
// Prepare update data - only include fields that are present in the request
const updateData: Record<string, unknown> = {};
if (body.hasOwnProperty('name')) updateData.name = name.trim();
if (body.hasOwnProperty('description')) updateData.description = description || null;
if (body.hasOwnProperty('eventDate')) updateData.eventDate = eventDate ? new Date(eventDate) : null;
if (body.hasOwnProperty('eventType')) updateData.eventType = eventType || "tournament";
if (body.hasOwnProperty('tournamentType')) updateData.tournamentType = tournamentType || "individual";
if (body.hasOwnProperty('format')) updateData.format = format || "round_robin";
if (body.hasOwnProperty('maxParticipants')) updateData.maxParticipants = maxParticipants ? parseInt(maxParticipants) : null;
if (body.hasOwnProperty('targetScore')) updateData.targetScore = targetScore ? parseInt(targetScore) : null;
if (body.hasOwnProperty('allowTies')) updateData.allowTies = allowTies ?? false;
if (body.hasOwnProperty('teamDurability')) updateData.teamDurability = teamDurability || "permanent";
if (body.hasOwnProperty('partnerRotation')) updateData.partnerRotation = partnerRotation || "none";
if (body.hasOwnProperty('allowByes')) updateData.allowByes = allowByes ?? true;
// Only allow status updates if they don't conflict with auto-calculation
if (status) {