Neue Datenbank Struktur #156

Open
gelbeinhalb wants to merge 88 commits from feature/88-neue-datenbank-struktur into development
8 changed files with 121 additions and 19 deletions
Showing only changes of commit e09ccf9356 - Show all commits

View File

@@ -50,12 +50,14 @@ void main() {
});
group('Game Tests', () {
// ==================== getAllGames ====================
// Verifies that getAllGames returns an empty list when the database has no games.
test('getAllGames returns empty list when no games exist', () async {
final allGames = await database.gameDao.getAllGames();
expect(allGames, isEmpty);
});
// Verifies that a single game can be added and retrieved with all fields intact.
test('Adding and fetching a single game works correctly', () async {
await database.gameDao.addGame(game: testGame1);
@@ -70,6 +72,7 @@ void main() {
expect(allGames.first.createdAt, testGame1.createdAt);
});
// Verifies that multiple games can be added and retrieved correctly.
test('Adding and fetching multiple games works correctly', () async {
await database.gameDao.addGame(game: testGame1);
await database.gameDao.addGame(game: testGame2);
@@ -82,7 +85,7 @@ void main() {
expect(names, containsAll(['Chess', 'Poker', 'Monopoly']));
});
// ==================== getGameById ====================
// Verifies that getGameById returns the correct game with all properties.
test('getGameById returns correct game', () async {
await database.gameDao.addGame(game: testGame1);
await database.gameDao.addGame(game: testGame2);
@@ -96,6 +99,7 @@ void main() {
expect(game.icon, testGame2.icon);
});
// Verifies that getGameById throws a StateError when the game doesn't exist.
test('getGameById throws exception for non-existent game', () async {
expect(
() => database.gameDao.getGameById(gameId: 'non-existent-id'),
@@ -103,7 +107,7 @@ void main() {
);
});
// ==================== addGame ====================
// Verifies that addGame returns true when a game is successfully added.
test('addGame returns true when game is added successfully', () async {
final result = await database.gameDao.addGame(game: testGame1);
expect(result, true);
@@ -112,6 +116,7 @@ void main() {
expect(allGames.length, 1);
});
// Verifies that addGame returns false when trying to add a duplicate game.
test('addGame returns false when game already exists', () async {
final firstAdd = await database.gameDao.addGame(game: testGame1);
expect(firstAdd, true);
@@ -123,6 +128,7 @@ void main() {
expect(allGames.length, 1);
});
// Verifies that a game with null optional fields can be added and retrieved.
test('addGame handles game with null optional fields', () async {
final gameWithNulls = Game(name: 'Simple Game');
final result = await database.gameDao.addGame(game: gameWithNulls);
@@ -137,7 +143,7 @@ void main() {
expect(fetchedGame.icon, isNull);
});
// ==================== addGamesAsList ====================
// Verifies that multiple games can be added at once using addGamesAsList.
test('addGamesAsList adds multiple games correctly', () async {
final result = await database.gameDao.addGamesAsList(
games: [testGame1, testGame2, testGame3],
@@ -148,6 +154,7 @@ void main() {
expect(allGames.length, 3);
gelbeinhalb marked this conversation as resolved Outdated

Hier bitte ergänzen das alle Parameter (id, name, ...) auch den ursprünglichen parametern entsprechen

Hier bitte ergänzen das alle Parameter (id, name, ...) auch den ursprünglichen parametern entsprechen
});
// Verifies that addGamesAsList returns false when given an empty list.
test('addGamesAsList returns false for empty list', () async {
final result = await database.gameDao.addGamesAsList(games: []);
expect(result, false);
@@ -156,6 +163,7 @@ void main() {
expect(allGames.length, 0);
});
// Verifies that addGamesAsList ignores duplicate games when adding.
test('addGamesAsList ignores duplicate games', () async {
await database.gameDao.addGame(game: testGame1);
@@ -168,7 +176,7 @@ void main() {
expect(allGames.length, 2);
});
// ==================== deleteGame ====================
// Verifies that deleteGame returns true and removes the game from database.
test('deleteGame returns true when game is deleted', () async {
await database.gameDao.addGame(game: testGame1);
@@ -179,6 +187,7 @@ void main() {
expect(allGames, isEmpty);
});
// Verifies that deleteGame returns false for a non-existent game ID.
test('deleteGame returns false for non-existent game', () async {
final result = await database.gameDao.deleteGame(
gameId: 'non-existent-id',
@@ -186,6 +195,7 @@ void main() {
expect(result, false);
});
// Verifies that deleteGame only removes the specified game, leaving others intact.
test('deleteGame only deletes the specified game', () async {
await database.gameDao.addGamesAsList(
games: [testGame1, testGame2, testGame3],
@@ -200,7 +210,7 @@ void main() {
expect(allGames.any((g) => g.id == testGame3.id), true);
});
// ==================== gameExists ====================
// Verifies that gameExists returns true when the game exists in database.
test('gameExists returns true for existing game', () async {
await database.gameDao.addGame(game: testGame1);
@@ -208,6 +218,7 @@ void main() {
expect(exists, true);
});
// Verifies that gameExists returns false for a non-existent game ID.
test('gameExists returns false for non-existent game', () async {
final exists = await database.gameDao.gameExists(
gameId: 'non-existent-id',
@@ -215,6 +226,7 @@ void main() {
expect(exists, false);
});
// Verifies that gameExists returns false after a game has been deleted.
test('gameExists returns false after game is deleted', () async {
await database.gameDao.addGame(game: testGame1);
await database.gameDao.deleteGame(gameId: testGame1.id);
@@ -223,7 +235,7 @@ void main() {
expect(exists, false);
});
// ==================== updateGameName ====================
// Verifies that updateGameName correctly updates only the name field.
test('updateGameName updates the name correctly', () async {
await database.gameDao.addGame(game: testGame1);
@@ -239,6 +251,7 @@ void main() {
expect(updatedGame.ruleset, testGame1.ruleset);
});
// Verifies that updateGameName does nothing when game doesn't exist.
test('updateGameName does nothing for non-existent game', () async {
await database.gameDao.updateGameName(
gameId: 'non-existent-id',
@@ -249,7 +262,7 @@ void main() {
expect(allGames, isEmpty);
});
// ==================== updateGameRuleset ====================
// Verifies that updateGameRuleset correctly updates only the ruleset field.
test('updateGameRuleset updates the ruleset correctly', () async {
await database.gameDao.addGame(game: testGame1);
@@ -265,6 +278,7 @@ void main() {
expect(updatedGame.name, testGame1.name);
});
// Verifies that updateGameRuleset does nothing when game doesn't exist.
test('updateGameRuleset does nothing for non-existent game', () async {
await database.gameDao.updateGameRuleset(
gameId: 'non-existent-id',
@@ -275,7 +289,7 @@ void main() {
expect(allGames, isEmpty);
});
// ==================== updateGameDescription ====================
// Verifies that updateGameDescription correctly updates the description.
test('updateGameDescription updates the description correctly', () async {
await database.gameDao.addGame(game: testGame1);
@@ -290,6 +304,7 @@ void main() {
expect(updatedGame.description, 'An updated description');
});
// Verifies that updateGameDescription can set the description to null.
test('updateGameDescription can set description to null', () async {
await database.gameDao.addGame(game: testGame1);
@@ -304,6 +319,7 @@ void main() {
expect(updatedGame.description, isNull);
});
// Verifies that updateGameDescription does nothing when game doesn't exist.
test('updateGameDescription does nothing for non-existent game', () async {
await database.gameDao.updateGameDescription(
gameId: 'non-existent-id',
@@ -314,7 +330,7 @@ void main() {
expect(allGames, isEmpty);
});
// ==================== updateGameColor ====================
// Verifies that updateGameColor correctly updates the color value.
test('updateGameColor updates the color correctly', () async {
await database.gameDao.addGame(game: testGame1);
@@ -329,6 +345,7 @@ void main() {
expect(updatedGame.color, 0xFF00FF00);
});
// Verifies that updateGameColor can set the color to null.
test('updateGameColor can set color to null', () async {
await database.gameDao.addGame(game: testGame1);
@@ -343,6 +360,7 @@ void main() {
expect(updatedGame.color, isNull);
});
// Verifies that updateGameColor does nothing when game doesn't exist.
test('updateGameColor does nothing for non-existent game', () async {
await database.gameDao.updateGameColor(
gameId: 'non-existent-id',
@@ -353,7 +371,7 @@ void main() {
expect(allGames, isEmpty);
});
// ==================== updateGameIcon ====================
// Verifies that updateGameIcon correctly updates the icon value.
test('updateGameIcon updates the icon correctly', () async {
await database.gameDao.addGame(game: testGame1);
@@ -368,6 +386,7 @@ void main() {
expect(updatedGame.icon, 'new_chess_icon');
});
// Verifies that updateGameIcon can set the icon to null.
test('updateGameIcon can set icon to null', () async {
await database.gameDao.addGame(game: testGame1);
@@ -382,6 +401,7 @@ void main() {
expect(updatedGame.icon, isNull);
});
// Verifies that updateGameIcon does nothing when game doesn't exist.
test('updateGameIcon does nothing for non-existent game', () async {
await database.gameDao.updateGameIcon(
gameId: 'non-existent-id',
@@ -392,12 +412,13 @@ void main() {
expect(allGames, isEmpty);
});
// ==================== getGameCount ====================
// Verifies that getGameCount returns 0 when no games exist.
test('getGameCount returns 0 when no games exist', () async {
final count = await database.gameDao.getGameCount();
expect(count, 0);
});
// Verifies that getGameCount returns the correct count after adding games.
test('getGameCount returns correct count after adding games', () async {
await database.gameDao.addGamesAsList(
games: [testGame1, testGame2, testGame3],
@@ -407,6 +428,7 @@ void main() {
expect(count, 3);
});
// Verifies that getGameCount updates correctly after deleting a game.
test('getGameCount updates correctly after deletion', () async {
await database.gameDao.addGamesAsList(
games: [testGame1, testGame2],
@@ -421,7 +443,7 @@ void main() {
expect(countAfter, 1);
});
// ==================== deleteAllGames ====================
// Verifies that deleteAllGames removes all games from the database.
test('deleteAllGames removes all games', () async {
await database.gameDao.addGamesAsList(
games: [testGame1, testGame2, testGame3],
@@ -437,12 +459,13 @@ void main() {
expect(countAfter, 0);
});
// Verifies that deleteAllGames returns false when no games exist.
test('deleteAllGames returns false when no games exist', () async {
final result = await database.gameDao.deleteAllGames();
expect(result, false);
});
// ==================== Edge Cases ====================
// Verifies that games with special characters (quotes, emojis) are stored correctly.
test('Game with special characters in name is stored correctly', () async {
final specialGame = Game(
name: 'Game\'s & "Special" <Name>',
@@ -457,6 +480,7 @@ void main() {
expect(fetchedGame.description, 'Description with émojis 🎮🎲');
});
// Verifies that games with empty string fields are stored and retrieved correctly.
test('Game with empty string fields is stored correctly', () async {
final emptyGame = Game(
name: '',
@@ -475,6 +499,7 @@ void main() {
expect(fetchedGame.icon, '');
});
// Verifies that games with very long strings (10000 chars) are handled correctly.
test('Game with very long strings is stored correctly', () async {
final longString = 'A' * 10000;
final longGame = Game(
@@ -492,6 +517,7 @@ void main() {
expect(fetchedGame.ruleset?.length, 10000);
});
// Verifies that multiple sequential updates to the same game work correctly.
test('Multiple updates to the same game work correctly', () async {
await database.gameDao.addGame(game: testGame1);

View File

@@ -58,6 +58,8 @@ void main() {
await database.close();
});
group('Group Tests', () {
// Verifies that a single group can be added and retrieved with all fields and members intact.
test('Adding and fetching a single group works correctly', () async {
await database.groupDao.addGroup(group: testGroup1);
@@ -80,6 +82,7 @@ void main() {
}
});
// Verifies that multiple groups can be added and retrieved with correct members.
test('Adding and fetching multiple groups works correctly', () async {
await database.groupDao.addGroupsAsList(
groups: [testGroup1, testGroup2, testGroup3, testGroup4],
@@ -106,6 +109,7 @@ void main() {
}
});
// Verifies that adding the same group twice does not create duplicates.
test('Adding the same group twice does not create duplicates', () async {
await database.groupDao.addGroup(group: testGroup1);
await database.groupDao.addGroup(group: testGroup1);
@@ -114,6 +118,7 @@ void main() {
expect(allGroups.length, 1);
});
// Verifies that groupExists returns correct boolean based on group presence.
test('Group existence check works correctly', () async {
var groupExists = await database.groupDao.groupExists(
groupId: testGroup1.id,
@@ -126,6 +131,7 @@ void main() {
expect(groupExists, true);
});
// Verifies that deleteGroup removes the group and returns true.
test('Deleting a group works correctly', () async {
await database.groupDao.addGroup(group: testGroup1);
@@ -140,6 +146,7 @@ void main() {
expect(groupExists, false);
});
// Verifies that updateGroupName correctly updates only the name field.
test('Updating a group name works correcly', () async {
await database.groupDao.addGroup(group: testGroup1);
@@ -156,6 +163,7 @@ void main() {
expect(result.name, newGroupName);
});
// Verifies that getGroupCount returns correct count through add/delete operations.
test('Getting the group count works correctly', () async {
final initialCount = await database.groupDao.getGroupCount();
expect(initialCount, 0);
@@ -174,11 +182,13 @@ void main() {
expect(finalCount, 0);
});
// Verifies that getAllGroups returns an empty list when no groups exist.
test('getAllGroups returns empty list when no groups exist', () async {
final allGroups = await database.groupDao.getAllGroups();
expect(allGroups, isEmpty);
});
// Verifies that getGroupById throws StateError for non-existent group ID.
test('getGroupById throws exception for non-existent group', () async {
expect(
() => database.groupDao.getGroupById(groupId: 'non-existent-id'),
@@ -186,6 +196,7 @@ void main() {
);
});
// Verifies that addGroup returns false when trying to add a duplicate group.
test('addGroup returns false when group already exists', () async {
final firstAdd = await database.groupDao.addGroup(group: testGroup1);
expect(firstAdd, true);
@@ -197,6 +208,7 @@ void main() {
expect(allGroups.length, 1);
});
// Verifies that addGroupsAsList handles an empty list without errors.
test('addGroupsAsList handles empty list correctly', () async {
await database.groupDao.addGroupsAsList(groups: []);
@@ -204,6 +216,7 @@ void main() {
expect(allGroups.length, 0);
});
// Verifies that deleteGroup returns false for a non-existent group ID.
test('deleteGroup returns false for non-existent group', () async {
final deleted = await database.groupDao.deleteGroup(
groupId: 'non-existent-id',
@@ -211,6 +224,7 @@ void main() {
expect(deleted, false);
});
// Verifies that updateGroupName returns false for a non-existent group ID.
test('updateGroupName returns false for non-existent group', () async {
final updated = await database.groupDao.updateGroupName(
groupId: 'non-existent-id',
@@ -219,6 +233,7 @@ void main() {
expect(updated, false);
});
// Verifies that updateGroupDescription correctly updates the description field.
test('Updating a group description works correctly', () async {
await database.groupDao.addGroup(group: testGroup1);
@@ -236,6 +251,7 @@ void main() {
expect(result.description, newDescription);
});
// Verifies that updateGroupDescription can set the description to null.
test('updateGroupDescription can set description to null', () async {
final groupWithDescription = Group(
name: 'Group with description',
@@ -256,6 +272,7 @@ void main() {
expect(result.description, isNull);
});
// Verifies that updateGroupDescription returns false for a non-existent group.
test('updateGroupDescription returns false for non-existent group',
() async {
final updated = await database.groupDao.updateGroupDescription(
@@ -265,6 +282,7 @@ void main() {
expect(updated, false);
});
// Verifies that deleteAllGroups removes all groups from the database.
test('deleteAllGroups removes all groups', () async {
await database.groupDao.addGroupsAsList(
groups: [testGroup1, testGroup2],
@@ -280,11 +298,13 @@ void main() {
expect(countAfter, 0);
});
// Verifies that deleteAllGroups returns false when no groups exist.
test('deleteAllGroups returns false when no groups exist', () async {
final deleted = await database.groupDao.deleteAllGroups();
expect(deleted, false);
});
// Verifies that groups with special characters (quotes, emojis) are stored correctly.
test('Group with special characters in name is stored correctly', () async {
final specialGroup = Group(
name: 'Group\'s & "Special" <Name>',
@@ -300,6 +320,7 @@ void main() {
expect(fetchedGroup.description, 'Description with émojis 🎮🎲');
});
// Verifies that a group with an empty members list can be stored and retrieved.
test('Group with empty members list is stored correctly', () async {
final emptyGroup = Group(
name: 'Empty Group',
@@ -314,6 +335,7 @@ void main() {
expect(fetchedGroup.members, isEmpty);
});
// Verifies that multiple sequential updates to the same group work correctly.
test('Multiple updates to the same group work correctly', () async {
await database.groupDao.addGroup(group: testGroup1);
@@ -334,6 +356,7 @@ void main() {
expect(updatedGroup.members.length, testGroup1.members.length);
});
// Verifies that addGroupsAsList with duplicate groups only adds unique ones.
test('addGroupsAsList with duplicate groups only adds once', () async {
await database.groupDao.addGroupsAsList(
groups: [testGroup1, testGroup1, testGroup1],

View File

@@ -92,6 +92,8 @@ void main() {
});
group('Match Tests', () {
// Verifies that a single match can be added and retrieved with all fields, group, and players intact.
test('Adding and fetching single match works correctly', () async {
await database.matchDao.addMatch(match: testMatch1);
@@ -137,6 +139,7 @@ void main() {
}
});
// Verifies that multiple matches can be added and retrieved with correct groups and players.
test('Adding and fetching multiple matches works correctly', () async {
await database.matchDao.addMatchAsList(
matches: [
@@ -212,6 +215,7 @@ void main() {
}
});
// Verifies that adding the same match twice does not create duplicates.
test('Adding the same match twice does not create duplicates', () async {
await database.matchDao.addMatch(match: testMatch1);
await database.matchDao.addMatch(match: testMatch1);
@@ -220,6 +224,7 @@ void main() {
expect(matchCount, 1);
});
// Verifies that matchExists returns correct boolean based on match presence.
test('Match existence check works correctly', () async {
var matchExists = await database.matchDao.matchExists(
matchId: testMatch1.id,
@@ -232,6 +237,7 @@ void main() {
expect(matchExists, true);
});
// Verifies that deleteMatch removes the match and returns true.
test('Deleting a match works correctly', () async {
await database.matchDao.addMatch(match: testMatch1);
@@ -246,6 +252,7 @@ void main() {
expect(matchExists, false);
});
// Verifies that getMatchCount returns correct count through add/delete operations.
test('Getting the match count works correctly', () async {
var matchCount = await database.matchDao.getMatchCount();
expect(matchCount, 0);
@@ -271,6 +278,7 @@ void main() {
expect(matchCount, 0);
});
// Verifies that hasWinner correctly identifies matches with and without winners.
test('Checking if match has winner works correctly', () async {
await database.matchDao.addMatch(match: testMatch1);
await database.matchDao.addMatch(match: testMatchOnlyGroup);
@@ -284,6 +292,7 @@ void main() {
expect(hasWinner, false);
});
// Verifies that getWinner returns the correct winner player for a match.
test('Fetching the winner of a match works correctly', () async {
await database.matchDao.addMatch(match: testMatch1);
@@ -297,6 +306,7 @@ void main() {
}
});
// Verifies that setWinner correctly updates the winner of a match.
test('Updating the winner of a match works correctly', () async {
await database.matchDao.addMatch(match: testMatch1);
@@ -329,6 +339,7 @@ void main() {
}
});
// Verifies that removeWinner clears the winner and hasWinner returns false.
test('Removing a winner works correctly', () async {
await database.matchDao.addMatch(match: testMatch2);
@@ -347,6 +358,7 @@ void main() {
expect(removedWinner, null);
});
// Verifies that updateMatchName correctly updates only the name field.
test('Renaming a match works correctly', () async {
await database.matchDao.addMatch(match: testMatch1);

View File

@@ -41,9 +41,8 @@ void main() {
});
group('Player-Group Tests', () {
/// No need to test if group has players since the members attribute is
/// not nullable
// Verifies that a player can be added to an existing group and isPlayerInGroup returns true.
test('Adding a player to a group works correctly', () async {
await database.groupDao.addGroup(group: testGroup);
await database.playerDao.addPlayer(player: testPlayer4);
@@ -67,6 +66,7 @@ void main() {
expect(playerAdded, false);
});
// Verifies that a player can be removed from a group and the group's member count decreases.
test('Removing player from group works correctly', () async {
await database.groupDao.addGroup(group: testGroup);
@@ -87,6 +87,7 @@ void main() {
expect(playerExists, false);
});
// Verifies that getPlayersOfGroup returns all members of a group with correct data.
test('Retrieving players of a group works correctly', () async {
await database.groupDao.addGroup(group: testGroup);
final players = await database.playerGroupDao.getPlayersOfGroup(

View File

@@ -73,6 +73,8 @@ void main() {
});
group('Player-Match Tests', () {
// Verifies that matchHasPlayers returns false initially and true after adding a player.
test('Match has player works correctly', () async {
await database.matchDao.addMatch(match: testMatchOnlyGroup);
await database.playerDao.addPlayer(player: testPlayer1);
@@ -95,6 +97,7 @@ void main() {
expect(matchHasPlayers, true);
});
// Verifies that a player can be added to a match and isPlayerInMatch returns true.
test('Adding a player to a match works correctly', () async {
await database.matchDao.addMatch(match: testMatchOnlyGroup);
await database.playerDao.addPlayer(player: testPlayer5);
@@ -118,6 +121,7 @@ void main() {
expect(playerAdded, false);
});
// Verifies that a player can be removed from a match and the player count decreases.
test('Removing player from match works correctly', () async {
await database.matchDao.addMatch(match: testMatchOnlyPlayers);
@@ -140,6 +144,7 @@ void main() {
expect(playerExists, false);
});
// Verifies that getPlayersOfMatch returns all players of a match with correct data.
test('Retrieving players of a match works correctly', () async {
await database.matchDao.addMatch(match: testMatchOnlyPlayers);
final players = await database.playerMatchDao.getPlayersOfMatch(
@@ -160,6 +165,7 @@ void main() {
}
});
// Verifies that updatePlayersFromMatch replaces all existing players with new ones.
test('Updating the match players works correctly', () async {
await database.matchDao.addMatch(match: testMatchOnlyPlayers);
@@ -203,6 +209,7 @@ void main() {
}
});
// Verifies that the same player can be added to multiple different matches.
test(
'Adding the same player to separate matches works correctly',
() async {

View File

@@ -35,6 +35,8 @@ void main() {
});
group('Player Tests', () {
// Verifies that players can be added and retrieved with all fields intact.
test('Adding and fetching single player works correctly', () async {
await database.playerDao.addPlayer(player: testPlayer1);
await database.playerDao.addPlayer(player: testPlayer2);
@@ -55,6 +57,7 @@ void main() {
expect(fetchedPlayer2.createdAt, testPlayer2.createdAt);
});
// Verifies that multiple players can be added at once and retrieved correctly.
test('Adding and fetching multiple players works correctly', () async {
await database.playerDao.addPlayersAsList(
players: [testPlayer1, testPlayer2, testPlayer3, testPlayer4],
@@ -80,6 +83,7 @@ void main() {
}
});
// Verifies that adding the same player twice does not create duplicates.
test('Adding the same player twice does not create duplicates', () async {
await database.playerDao.addPlayer(player: testPlayer1);
await database.playerDao.addPlayer(player: testPlayer1);
@@ -88,6 +92,7 @@ void main() {
expect(allPlayers.length, 1);
});
// Verifies that playerExists returns correct boolean based on player presence.
test('Player existence check works correctly', () async {
var playerExists = await database.playerDao.playerExists(
playerId: testPlayer1.id,
@@ -102,6 +107,7 @@ void main() {
expect(playerExists, true);
});
// Verifies that deletePlayer removes the player and returns true.
test('Deleting a player works correctly', () async {
await database.playerDao.addPlayer(player: testPlayer1);
final playerDeleted = await database.playerDao.deletePlayer(
@@ -115,6 +121,7 @@ void main() {
expect(playerExists, false);
});
// Verifies that updatePlayerName correctly updates only the name field.
test('Updating a player name works correctly', () async {
await database.playerDao.addPlayer(player: testPlayer1);
@@ -131,6 +138,7 @@ void main() {
expect(result.name, newPlayerName);
});
// Verifies that getPlayerCount returns correct count through add/delete operations.
test('Getting the player count works correctly', () async {
var playerCount = await database.playerDao.getPlayerCount();
expect(playerCount, 0);

View File

@@ -57,6 +57,8 @@ void main() {
});
group('Score Tests', () {
// Verifies that a score can be added and retrieved with all fields intact.
test('Adding and fetching a score works correctly', () async {
await database.scoreDao.addScore(
playerId: testPlayer1.id,
@@ -80,6 +82,7 @@ void main() {
expect(score.change, 10);
});
// Verifies that getScoresForMatch returns all scores for a given match.
test('Getting scores for a match works correctly', () async {
await database.scoreDao.addScore(
playerId: testPlayer1.id,
@@ -110,6 +113,7 @@ void main() {
expect(scores.length, 3);
});
// Verifies that getPlayerScoresInMatch returns all scores for a player in a match, ordered by round.
test('Getting player scores in a match works correctly', () async {
await database.scoreDao.addScore(
playerId: testPlayer1.id,
@@ -147,6 +151,7 @@ void main() {
expect(playerScores[2].score, 30);
});
// Verifies that getScoreForRound returns null for a non-existent round number.
test('Getting score for a non-existent round returns null', () async {
final score = await database.scoreDao.getScoreForRound(
playerId: testPlayer1.id,
@@ -157,6 +162,7 @@ void main() {
expect(score, isNull);
});
// Verifies that updateScore correctly updates the score and change values.
test('Updating a score works correctly', () async {
await database.scoreDao.addScore(
playerId: testPlayer1.id,
@@ -187,6 +193,7 @@ void main() {
expect(score.change, 40);
});
// Verifies that updateScore returns false for a non-existent score entry.
test('Updating a non-existent score returns false', () async {
final updated = await database.scoreDao.updateScore(
playerId: testPlayer1.id,
@@ -199,6 +206,7 @@ void main() {
expect(updated, false);
});
// Verifies that deleteScore removes the score entry and returns true.
test('Deleting a score works correctly', () async {
await database.scoreDao.addScore(
playerId: testPlayer1.id,
@@ -225,6 +233,7 @@ void main() {
expect(score, isNull);
});
// Verifies that deleteScore returns false for a non-existent score entry.
test('Deleting a non-existent score returns false', () async {
final deleted = await database.scoreDao.deleteScore(
playerId: testPlayer1.id,
@@ -235,6 +244,7 @@ void main() {
expect(deleted, false);
});
// Verifies that deleteScoresForMatch removes all scores for a match but keeps other match scores.
test('Deleting scores for a match works correctly', () async {
await database.scoreDao.addScore(
playerId: testPlayer1.id,
@@ -275,6 +285,7 @@ void main() {
expect(match2Scores.length, 1);
});
// Verifies that deleteScoresForPlayer removes all scores for a player across all matches.
test('Deleting scores for a player works correctly', () async {
await database.scoreDao.addScore(
playerId: testPlayer1.id,
@@ -317,6 +328,7 @@ void main() {
expect(player2Scores.length, 1);
});
// Verifies that getLatestRoundNumber returns the highest round number for a match.
test('Getting latest round number works correctly', () async {
var latestRound = await database.scoreDao.getLatestRoundNumber(
matchId: testMatch1.id,
@@ -350,6 +362,7 @@ void main() {
expect(latestRound, 5);
});
// Verifies that getTotalScoreForPlayer returns the latest score (cumulative) for a player.
test('Getting total score for a player works correctly', () async {
var totalScore = await database.scoreDao.getTotalScoreForPlayer(
playerId: testPlayer1.id,
@@ -386,6 +399,7 @@ void main() {
expect(totalScore, 40);
});
// Verifies that adding a score with the same player/match/round replaces the existing one.
test('Adding the same score twice replaces the existing one', () async {
await database.scoreDao.addScore(
playerId: testPlayer1.id,
@@ -414,4 +428,3 @@ void main() {
});
});
}

View File

@@ -56,6 +56,8 @@ void main() {
});
group('Team Tests', () {
// Verifies that a single team can be added and retrieved with all fields intact.
test('Adding and fetching a single team works correctly', () async {
final added = await database.teamDao.addTeam(team: testTeam1);
expect(added, true);
@@ -69,6 +71,7 @@ void main() {
expect(fetchedTeam.createdAt, testTeam1.createdAt);
});
// Verifies that multiple teams can be added at once and retrieved correctly.
test('Adding and fetching multiple teams works correctly', () async {
await database.teamDao.addTeamsAsList(
teams: [testTeam1, testTeam2, testTeam3],
@@ -92,6 +95,7 @@ void main() {
}
});
// Verifies that adding the same team twice does not create duplicates and returns false.
test('Adding the same team twice does not create duplicates', () async {
await database.teamDao.addTeam(team: testTeam1);
final addedAgain = await database.teamDao.addTeam(team: testTeam1);
@@ -102,6 +106,7 @@ void main() {
expect(teamCount, 1);
});
// Verifies that teamExists returns correct boolean based on team presence.
test('Team existence check works correctly', () async {
var teamExists = await database.teamDao.teamExists(teamId: testTeam1.id);
expect(teamExists, false);
@@ -112,6 +117,7 @@ void main() {
expect(teamExists, true);
});
// Verifies that deleteTeam removes the team and returns true.
test('Deleting a team works correctly', () async {
await database.teamDao.addTeam(team: testTeam1);
@@ -126,6 +132,7 @@ void main() {
expect(teamExists, false);
});
// Verifies that deleteTeam returns false for a non-existent team ID.
test('Deleting a non-existent team returns false', () async {
final teamDeleted = await database.teamDao.deleteTeam(
teamId: 'non-existent-id',
@@ -133,6 +140,7 @@ void main() {
expect(teamDeleted, false);
});
// Verifies that getTeamCount returns correct count through add/delete operations.
test('Getting the team count works correctly', () async {
var teamCount = await database.teamDao.getTeamCount();
expect(teamCount, 0);
@@ -158,6 +166,7 @@ void main() {
expect(teamCount, 0);
});
// Verifies that updateTeamName correctly updates only the name field.
test('Updating team name works correctly', () async {
await database.teamDao.addTeam(team: testTeam1);
@@ -176,6 +185,7 @@ void main() {
expect(fetchedTeam.name, newName);
});
// Verifies that deleteAllTeams removes all teams from the database.
test('Deleting all teams works correctly', () async {
await database.teamDao.addTeamsAsList(
teams: [testTeam1, testTeam2, testTeam3],
@@ -191,16 +201,19 @@ void main() {
expect(teamCount, 0);
});
// Verifies that deleteAllTeams returns false when no teams exist.
test('Deleting all teams when empty returns false', () async {
final deleted = await database.teamDao.deleteAllTeams();
expect(deleted, false);
});
// Verifies that addTeamsAsList returns false when given an empty list.
test('Adding teams as list with empty list returns false', () async {
final added = await database.teamDao.addTeamsAsList(teams: []);
expect(added, false);
});
// Verifies that addTeamsAsList with duplicate IDs ignores duplicates and keeps the first.
test('Adding teams with duplicate IDs ignores duplicates', () async {
final duplicateTeam = Team(
id: testTeam1.id,
@@ -223,4 +236,3 @@ void main() {
});
});
}