From 0eb8e2683c429797044b190134e9a2a908cead5d Mon Sep 17 00:00:00 2001 From: gelbeinhalb Date: Sat, 7 Feb 2026 17:31:23 +0100 Subject: [PATCH] add replace players in a match test --- .../relationships/player_match_test.dart | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/test/db_tests/relationships/player_match_test.dart b/test/db_tests/relationships/player_match_test.dart index ddc36d2..397f1b7 100644 --- a/test/db_tests/relationships/player_match_test.dart +++ b/test/db_tests/relationships/player_match_test.dart @@ -884,5 +884,36 @@ void main() { expect(playersInTeam.length, 1); expect(playersInTeam[0].id, testPlayer2.id); }); + + // Verifies that replaceMatchPlayers removes all existing players and replaces with new list. + test('replaceMatchPlayers replaces all match players correctly', () async { + // Create initial match with 3 players + await database.matchDao.addMatch(match: testMatchOnlyPlayers); + + // Verify initial players + var matchPlayers = await database.matchDao.getMatchById( + matchId: testMatchOnlyPlayers.id, + ); + expect(matchPlayers.players.length, 3); + + // Replace with new list containing 2 different players + final newPlayersList = [testPlayer1, testPlayer2]; + await database.matchDao.replaceMatchPlayers( + matchId: testMatchOnlyPlayers.id, + newPlayers: newPlayersList, + ); + + // Get updated match and verify players + matchPlayers = await database.matchDao.getMatchById( + matchId: testMatchOnlyPlayers.id, + ); + + expect(matchPlayers.players.length, 2); + expect(matchPlayers.players.any((p) => p.id == testPlayer1.id), true); + expect(matchPlayers.players.any((p) => p.id == testPlayer2.id), true); + expect(matchPlayers.players.any((p) => p.id == testPlayer4.id), false); + expect(matchPlayers.players.any((p) => p.id == testPlayer5.id), false); + expect(matchPlayers.players.any((p) => p.id == testPlayer6.id), false); + }); }); }