diff --git a/src/__tests__/e2e/csv-upload-deduplication.test.ts b/src/__tests__/e2e/csv-upload-deduplication.test.ts index 252a0b8..30dec08 100644 --- a/src/__tests__/e2e/csv-upload-deduplication.test.ts +++ b/src/__tests__/e2e/csv-upload-deduplication.test.ts @@ -71,8 +71,12 @@ test.describe('CSV Upload Player Deduplication', () => { try { // Upload the CSV + const csvFileContent = fs.readFileSync(csvPath, 'utf-8'); + const blob = new Blob([csvFileContent], { type: 'text/csv' }); + const file = new File([blob], 'deduplication-test.csv', { type: 'text/csv' }); + const formData = new FormData(); - formData.append('csvFile', fs.createReadStream(csvPath), 'deduplication-test.csv'); + formData.append('csvFile', file); formData.append('eventId', testTournamentId.toString()); const response = await request.post('http://localhost:3000/api/matches/upload', { @@ -97,11 +101,11 @@ test.describe('CSV Upload Player Deduplication', () => { expect(dedupePlayers.length).toBe(2); // Verify the players have the correct names (original case preserved) - const playerNames = dedupePlayers.map(p => p.name).sort(); + const playerNames = dedupePlayers.map((p: { name: string }) => p.name).sort(); expect(playerNames).toEqual(['Dedupe Player', 'Dedupe Player2']); // Verify each player has games played - dedupePlayers.forEach(player => { + dedupePlayers.forEach((player: { gamesPlayed: number }) => { expect(player.gamesPlayed).toBeGreaterThan(0); }); } finally { @@ -121,8 +125,12 @@ test.describe('CSV Upload Player Deduplication', () => { fs.writeFileSync(csvPath, csvContent); try { + const csvFileContent = fs.readFileSync(csvPath, 'utf-8'); + const blob = new Blob([csvFileContent], { type: 'text/csv' }); + const file = new File([blob], 'whitespace-test.csv', { type: 'text/csv' }); + const formData = new FormData(); - formData.append('csvFile', fs.createReadStream(csvPath), 'whitespace-test.csv'); + formData.append('csvFile', file); formData.append('eventId', testTournamentId.toString()); const response = await request.post('http://localhost:3000/api/matches/upload', { @@ -141,7 +149,7 @@ test.describe('CSV Upload Player Deduplication', () => { }); // Verify no players have leading/trailing whitespace - whitespacePlayers.forEach(player => { + whitespacePlayers.forEach((player: { name: string, normalizedName: string }) => { expect(player.name).toBe(player.name.trim()); expect(player.normalizedName).toBe(player.name.trim().toLowerCase()); }); @@ -174,8 +182,12 @@ test.describe('CSV Upload Player Deduplication', () => { fs.writeFileSync(csvPath, csvContent); try { + const csvFileContent = fs.readFileSync(csvPath, 'utf-8'); + const blob = new Blob([csvFileContent], { type: 'text/csv' }); + const file = new File([blob], 'aggregate-test.csv', { type: 'text/csv' }); + const formData = new FormData(); - formData.append('csvFile', fs.createReadStream(csvPath), 'aggregate-test.csv'); + formData.append('csvFile', file); formData.append('eventId', testTournamentId.toString()); const response = await request.post('http://localhost:3000/api/matches/upload', { diff --git a/src/__tests__/unit/player-deduplication.test.ts b/src/__tests__/unit/player-deduplication.test.ts index 2764b85..ab8ca80 100644 --- a/src/__tests__/unit/player-deduplication.test.ts +++ b/src/__tests__/unit/player-deduplication.test.ts @@ -35,6 +35,8 @@ async function findOrCreatePlayer(name: string) { normalizedName, rating: 1000, currentElo: 1000, + createdAt: new Date(), + updatedAt: new Date(), }, }); } @@ -57,6 +59,9 @@ describe('Player Deduplication', () => { gamesPlayed: 5, wins: 4, losses: 1, + createdAt: new Date(), + updatedAt: new Date(), + rating: 0, }; vi.mocked(prisma.player.findFirst).mockResolvedValue(mockPlayer); @@ -79,6 +84,9 @@ describe('Player Deduplication', () => { gamesPlayed: 5, wins: 4, losses: 1, + createdAt: new Date(), + updatedAt: new Date(), + rating: 0, }; vi.mocked(prisma.player.findFirst).mockResolvedValue(mockPlayer); @@ -101,6 +109,9 @@ describe('Player Deduplication', () => { gamesPlayed: 5, wins: 4, losses: 1, + createdAt: new Date(), + updatedAt: new Date(), + rating: 0, }; vi.mocked(prisma.player.findFirst).mockResolvedValue(mockPlayer); @@ -126,6 +137,8 @@ describe('Player Deduplication', () => { gamesPlayed: 0, wins: 0, losses: 0, + createdAt: new Date(), + updatedAt: new Date(), }; vi.mocked(prisma.player.create).mockResolvedValue(newPlayer); @@ -142,6 +155,8 @@ describe('Player Deduplication', () => { normalizedName: 'newplayer', rating: 1000, currentElo: 1000, + createdAt: expect.any(Date), + updatedAt: expect.any(Date), }, }); }); @@ -158,6 +173,8 @@ describe('Player Deduplication', () => { gamesPlayed: 0, wins: 0, losses: 0, + createdAt: new Date(), + updatedAt: new Date(), }; vi.mocked(prisma.player.create).mockResolvedValue(newPlayer); @@ -171,6 +188,8 @@ describe('Player Deduplication', () => { normalizedName: 'test-player_123', rating: 1000, currentElo: 1000, + createdAt: expect.any(Date), + updatedAt: expect.any(Date), }, }); }); @@ -187,6 +206,8 @@ describe('Player Deduplication', () => { gamesPlayed: 0, wins: 0, losses: 0, + createdAt: new Date(), + updatedAt: new Date(), }; vi.mocked(prisma.player.create).mockResolvedValue(newPlayer); @@ -200,6 +221,8 @@ describe('Player Deduplication', () => { normalizedName: 'dave b', rating: 1000, currentElo: 1000, + createdAt: expect.any(Date), + updatedAt: expect.any(Date), }, }); }); @@ -214,6 +237,9 @@ describe('Player Deduplication', () => { gamesPlayed: 5, wins: 4, losses: 1, + createdAt: new Date(), + updatedAt: new Date(), + rating: 0, }; vi.mocked(prisma.player.findFirst).mockResolvedValue(mockPlayer); @@ -240,6 +266,8 @@ describe('Player Deduplication', () => { gamesPlayed: 0, wins: 0, losses: 0, + createdAt: new Date(), + updatedAt: new Date(), }; vi.mocked(prisma.player.create).mockResolvedValue(newPlayer); @@ -253,6 +281,8 @@ describe('Player Deduplication', () => { normalizedName: '', rating: 1000, currentElo: 1000, + createdAt: expect.any(Date), + updatedAt: expect.any(Date), }, }); }); @@ -285,6 +315,9 @@ describe('Player Deduplication', () => { gamesPlayed: 5, wins: 4, losses: 1, + createdAt: new Date(), + updatedAt: new Date(), + rating: 0, }; vi.mocked(prisma.player.findFirst) diff --git a/src/__tests__/unit/player-profile.test.ts b/src/__tests__/unit/player-profile.test.ts index 63dbb23..73e80ff 100644 --- a/src/__tests__/unit/player-profile.test.ts +++ b/src/__tests__/unit/player-profile.test.ts @@ -7,7 +7,7 @@ * - Partnership performance */ -import { describe, test, expect, vi } from 'vitest'; +import { describe, test, expect, vi, beforeEach } from 'vitest'; import { prisma } from '@/lib/prisma'; import type { Player, Event, Match, PartnershipStat } from '@prisma/client'; @@ -56,6 +56,9 @@ const createMockTournament = (id: number, name: string): Event => ({ ownerId: null, createdAt: new Date(), updatedAt: new Date(), + event_id: null, + targetScore: null, + allowTies: false, }); // Helper to create mock match @@ -82,6 +85,7 @@ const createMockMatch = ( createdById: null, createdAt: new Date(), updatedAt: new Date(), + isCasual: false, }); // Helper to create mock partnership stat diff --git a/src/__tests__/unit/user-management.test.ts b/src/__tests__/unit/user-management.test.ts index 2c236f0..3a52950 100644 --- a/src/__tests__/unit/user-management.test.ts +++ b/src/__tests__/unit/user-management.test.ts @@ -4,7 +4,7 @@ * Tests for user name editing and profile management */ -import { describe, test, expect, vi } from 'vitest'; +import { describe, test, expect, vi, beforeEach } from 'vitest'; import { hasRole } from '@/lib/permissions'; import { getSession } from '@/lib/auth-simple'; import { prisma } from '@/lib/prisma'; @@ -41,7 +41,7 @@ const createMockUser = (id: string, email: string, role: string, name?: string): }); // Helper to create mock player -const createMockPlayer = (id: number, userId: string, name: string): Player => ({ +const createMockPlayer = (id: number, name: string): Player => ({ id, name, normalizedName: name.toLowerCase(), @@ -52,7 +52,6 @@ const createMockPlayer = (id: number, userId: string, name: string): Player => ( losses: 0, createdAt: new Date(), updatedAt: new Date(), - userId, }); describe('User Management', () => { @@ -158,7 +157,7 @@ describe('User Management', () => { describe('Player Name Updates', () => { test('player name should be updated when user name is updated', async () => { const mockUser = createMockUser('user-1', 'user@example.com', 'club_admin'); - const mockPlayer = createMockPlayer(1, 'user-1', 'Old Name'); + const mockPlayer = createMockPlayer(1, 'Old Name'); vi.mocked(getSession).mockResolvedValue({ user: { id: 'user-1', email: 'user@example.com' },