Added missing methods
All checks were successful
Pull Request Pipeline / test (pull_request) Successful in 2m6s
Pull Request Pipeline / lint (pull_request) Successful in 2m7s

This commit is contained in:
2025-11-21 13:12:36 +01:00
parent 32f3f68da9
commit e15f5d163d
3 changed files with 52 additions and 22 deletions

View File

@@ -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) {

View File

@@ -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);
}
});
});
}

View File

@@ -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);
}
});
});
}