From e15f5d163db0b40c3bf1c5198e71d147e6f99035 Mon Sep 17 00:00:00 2001 From: Felix Kirchner Date: Fri, 21 Nov 2025 13:12:36 +0100 Subject: [PATCH] Added missing methods --- test/db_tests/group_game_test.dart | 42 ++++++++++++++++------------ test/db_tests/player_game_test.dart | 18 ++++++++++-- test/db_tests/player_group_test.dart | 14 ++++++++-- 3 files changed, 52 insertions(+), 22 deletions(-) diff --git a/test/db_tests/group_game_test.dart b/test/db_tests/group_game_test.dart index 6621d9a..e231284 100644 --- a/test/db_tests/group_game_test.dart +++ b/test/db_tests/group_game_test.dart @@ -15,8 +15,8 @@ void main() { late Player player4; late Player player5; late Group testgroup; - late Game gameWithGroup; - late Game gameWithPlayers; + late Game testgameWithGroup; + late Game testgameWithPlayers; final fixedDate = DateTime(2025, 19, 11, 00, 11, 23); final fakeClock = Clock(() => fixedDate); @@ -39,11 +39,11 @@ void main() { name: 'Test Group', members: [player1, player2, player3], ); - gameWithPlayers = Game( + testgameWithPlayers = Game( name: 'Game with Players', players: [player4, player5], ); - gameWithGroup = Game(name: 'Game with Group', group: testgroup); + testgameWithGroup = Game(name: 'Game with Group', group: testgroup); }); }); tearDown(() async { @@ -51,63 +51,69 @@ void main() { }); group('Group-Game Tests', () { test('Game has group works correctly', () async { - database.gameDao.addGame(game: gameWithPlayers); + database.gameDao.addGame(game: testgameWithPlayers); database.groupDao.addGroup(group: testgroup); var gameHasGroup = await database.groupGameDao.gameHasGroup( - gameId: gameWithPlayers.id, + gameId: testgameWithPlayers.id, ); expect(gameHasGroup, false); - database.groupGameDao.addGroupToGame(gameWithPlayers.id, testgroup.id); + database.groupGameDao.addGroupToGame( + testgameWithPlayers.id, + testgroup.id, + ); gameHasGroup = await database.groupGameDao.gameHasGroup( - gameId: gameWithPlayers.id, + gameId: testgameWithPlayers.id, ); expect(gameHasGroup, true); }); test('Adding a group to a game works correctly', () async { - database.gameDao.addGame(game: gameWithPlayers); + database.gameDao.addGame(game: testgameWithPlayers); database.groupDao.addGroup(group: testgroup); - database.groupGameDao.addGroupToGame(gameWithPlayers.id, testgroup.id); + database.groupGameDao.addGroupToGame( + testgameWithPlayers.id, + testgroup.id, + ); var groupAdded = await database.groupGameDao.isGroupInGame( - gameId: gameWithPlayers.id, + gameId: testgameWithPlayers.id, groupId: testgroup.id, ); expect(groupAdded, true); groupAdded = await database.groupGameDao.isGroupInGame( - gameId: gameWithPlayers.id, + gameId: testgameWithPlayers.id, groupId: '', ); expect(groupAdded, false); }); test('Removing group from game works correctly', () async { - await database.gameDao.addGame(game: gameWithGroup); + await database.gameDao.addGame(game: testgameWithGroup); - final groupToRemove = gameWithGroup.group!; + final groupToRemove = testgameWithGroup.group!; final removed = await database.groupGameDao.removeGroupFromGame( groupId: groupToRemove.id, - gameId: gameWithGroup.id, + gameId: testgameWithGroup.id, ); expect(removed, true); final result = await database.gameDao.getGameById( - gameId: gameWithGroup.id, + gameId: testgameWithGroup.id, ); expect(result.group, null); }); test('Retrieving group of a game works correctly', () async { - await database.gameDao.addGame(game: gameWithGroup); + await database.gameDao.addGame(game: testgameWithGroup); final group = await database.groupGameDao.getGroupOfGame( - gameId: gameWithGroup.id, + gameId: testgameWithGroup.id, ); if (group == null) { diff --git a/test/db_tests/player_game_test.dart b/test/db_tests/player_game_test.dart index d6f282e..1fd0128 100644 --- a/test/db_tests/player_game_test.dart +++ b/test/db_tests/player_game_test.dart @@ -120,7 +120,21 @@ void main() { expect(playerExists, false); }); - //TODO: test getPlayersOfGame() - test('Retrieving players of a game works correctly', () async {}); + test('Retrieving players of a game works correctly', () async { + await database.gameDao.addGame(game: testgameWithPlayers); + final players = await database.playerGameDao.getPlayersOfGame( + gameId: testgameWithPlayers.id, + ); + + if (players == null) { + fail('Players should not be null'); + } + + for (int i = 0; i < players.length; i++) { + expect(players[i].id, testgameWithPlayers.players![i].id); + expect(players[i].name, testgameWithPlayers.players![i].name); + expect(players[i].createdAt, testgameWithPlayers.players![i].createdAt); + } + }); }); } diff --git a/test/db_tests/player_group_test.dart b/test/db_tests/player_group_test.dart index 1181eda..9e367e0 100644 --- a/test/db_tests/player_group_test.dart +++ b/test/db_tests/player_group_test.dart @@ -87,7 +87,17 @@ void main() { expect(playerExists, false); }); - //TODO: test getPlayersOfGroup() - test('Retrieving players of a group works correctly', () async {}); + test('Retrieving players of a group works correctly', () async { + await database.groupDao.addGroup(group: testgroup); + final players = await database.playerGroupDao.getPlayersOfGroup( + groupId: testgroup.id, + ); + + for (int i = 0; i < players.length; i++) { + expect(players[i].id, testgroup.members[i].id); + expect(players[i].name, testgroup.members[i].name); + expect(players[i].createdAt, testgroup.members[i].createdAt); + } + }); }); }