Updated match dao + tests

This commit is contained in:
2026-05-01 11:57:03 +02:00
parent 785873d3c8
commit be6b968a43
3 changed files with 438 additions and 347 deletions

View File

@@ -15,74 +15,13 @@ part 'match_dao.g.dart';
class MatchDao extends DatabaseAccessor<AppDatabase> with _$MatchDaoMixin { class MatchDao extends DatabaseAccessor<AppDatabase> with _$MatchDaoMixin {
MatchDao(super.db); MatchDao(super.db);
/// Retrieves all matches from the database. /* Create */
Future<List<Match>> getAllMatches() async {
final query = select(matchTable);
final result = await query.get();
return Future.wait(
result.map((row) async {
final game = await db.gameDao.getGameById(gameId: row.gameId);
Group? group;
if (row.groupId != null) {
group = await db.groupDao.getGroupById(groupId: row.groupId!);
}
final players =
await db.playerMatchDao.getPlayersOfMatch(matchId: row.id) ?? [];
final scores = await db.scoreEntryDao.getAllMatchScores(
matchId: row.id,
);
return Match(
id: row.id,
name: row.name,
game: game,
group: group,
players: players,
notes: row.notes ?? '',
createdAt: row.createdAt,
endedAt: row.endedAt,
scores: scores,
);
}),
);
}
/// Retrieves a [Match] by its [matchId].
Future<Match> getMatchById({required String matchId}) async {
final query = select(matchTable)..where((g) => g.id.equals(matchId));
final result = await query.getSingle();
final game = await db.gameDao.getGameById(gameId: result.gameId);
Group? group;
if (result.groupId != null) {
group = await db.groupDao.getGroupById(groupId: result.groupId!);
}
final players =
await db.playerMatchDao.getPlayersOfMatch(matchId: matchId) ?? [];
final scores = await db.scoreEntryDao.getAllMatchScores(matchId: matchId);
return Match(
id: result.id,
name: result.name,
game: game,
group: group,
players: players,
notes: result.notes ?? '',
createdAt: result.createdAt,
endedAt: result.endedAt,
scores: scores,
);
}
/// Adds a new [Match] to the database. Also adds players associations. /// Adds a new [Match] to the database. Also adds players associations.
/// This method assumes that the game and group (if any) are already present /// This method assumes that the game and group (if any) are already present
/// in the database. /// in the database.
Future<void> addMatch({required Match match}) async { Future<bool> addMatch({required Match match}) async {
if (await matchExists(matchId: match.id)) return false;
await db.transaction(() async { await db.transaction(() async {
await into(matchTable).insert( await into(matchTable).insert(
MatchTableCompanion.insert( MatchTableCompanion.insert(
@@ -114,15 +53,17 @@ class MatchDao extends DatabaseAccessor<AppDatabase> with _$MatchDaoMixin {
); );
} }
} }
print('Return true');
}); });
return true;
} }
/// Adds multiple [Match]es to the database in a batch operation. /// Adds multiple [Match]es to the database in a batch operation.
/// Also adds associated players and groups if they exist. /// Also adds associated players and groups if they exist.
/// If the [matches] list is empty, the method returns immediately. /// If the [matches] list is empty, the method returns immediately.
/// This method should only be used to import matches from a different device. /// This method should only be used to import matches from a different device.
Future<void> addMatchAsList({required List<Match> matches}) async { Future<bool> addMatchesAsList({required List<Match> matches}) async {
if (matches.isEmpty) return; if (matches.isEmpty) return false;
await db.transaction(() async { await db.transaction(() async {
// Add all games first (deduplicated) // Add all games first (deduplicated)
final uniqueGames = <String, Game>{}; final uniqueGames = <String, Game>{};
@@ -280,14 +221,17 @@ class MatchDao extends DatabaseAccessor<AppDatabase> with _$MatchDaoMixin {
} }
}); });
}); });
return true;
} }
/// Deletes the match with the given [matchId] from the database. /* Read */
/// Returns `true` if more than 0 rows were affected, otherwise `false`.
Future<bool> deleteMatch({required String matchId}) async { /// Checks if a match with the given [matchId] exists in the database.
final query = delete(matchTable)..where((g) => g.id.equals(matchId)); /// Returns `true` if the match exists, otherwise `false`.
final rowsAffected = await query.go(); Future<bool> matchExists({required String matchId}) async {
return rowsAffected > 0; final query = select(matchTable)..where((g) => g.id.equals(matchId));
final result = await query.getSingleOrNull();
return result != null;
} }
/// Retrieves the number of matches in the database. /// Retrieves the number of matches in the database.
@@ -299,6 +243,70 @@ class MatchDao extends DatabaseAccessor<AppDatabase> with _$MatchDaoMixin {
return count ?? 0; return count ?? 0;
} }
/// Retrieves all matches from the database.
Future<List<Match>> getAllMatches() async {
final query = select(matchTable);
final result = await query.get();
return Future.wait(
result.map((row) async {
final game = await db.gameDao.getGameById(gameId: row.gameId);
Group? group;
if (row.groupId != null) {
group = await db.groupDao.getGroupById(groupId: row.groupId!);
}
final players =
await db.playerMatchDao.getPlayersOfMatch(matchId: row.id) ?? [];
final scores = await db.scoreEntryDao.getAllMatchScores(
matchId: row.id,
);
return Match(
id: row.id,
name: row.name,
game: game,
group: group,
players: players,
notes: row.notes ?? '',
createdAt: row.createdAt,
endedAt: row.endedAt,
scores: scores,
);
}),
);
}
/// Retrieves a [Match] by its [matchId].
Future<Match> getMatchById({required String matchId}) async {
final query = select(matchTable)..where((g) => g.id.equals(matchId));
final result = await query.getSingle();
final game = await db.gameDao.getGameById(gameId: result.gameId);
Group? group;
if (result.groupId != null) {
group = await db.groupDao.getGroupById(groupId: result.groupId!);
}
final players =
await db.playerMatchDao.getPlayersOfMatch(matchId: matchId) ?? [];
final scores = await db.scoreEntryDao.getAllMatchScores(matchId: matchId);
return Match(
id: result.id,
name: result.name,
game: game,
group: group,
players: players,
notes: result.notes ?? '',
createdAt: result.createdAt,
endedAt: result.endedAt,
scores: scores,
);
}
/// Retrieves all matches associated with the given [groupId]. /// Retrieves all matches associated with the given [groupId].
/// Queries the database directly, filtering by [groupId]. /// Queries the database directly, filtering by [groupId].
Future<List<Match>> getGroupMatches({required String groupId}) async { Future<List<Match>> getGroupMatches({required String groupId}) async {
@@ -325,34 +333,7 @@ class MatchDao extends DatabaseAccessor<AppDatabase> with _$MatchDaoMixin {
); );
} }
/// Checks if a match with the given [matchId] exists in the database. /* Update */
/// Returns `true` if the match exists, otherwise `false`.
Future<bool> matchExists({required String matchId}) async {
final query = select(matchTable)..where((g) => g.id.equals(matchId));
final result = await query.getSingleOrNull();
return result != null;
}
/// Deletes all matches from the database.
/// Returns `true` if more than 0 rows were affected, otherwise `false`.
Future<bool> deleteAllMatches() async {
final query = delete(matchTable);
final rowsAffected = await query.go();
return rowsAffected > 0;
}
/// Updates the notes of the match with the given [matchId].
/// Returns `true` if more than 0 rows were affected, otherwise `false`.
Future<bool> updateMatchNotes({
required String matchId,
required String? notes,
}) async {
final query = update(matchTable)..where((g) => g.id.equals(matchId));
final rowsAffected = await query.write(
MatchTableCompanion(notes: Value(notes)),
);
return rowsAffected > 0;
}
/// Changes the name of the match with the given [matchId] to [newName]. /// Changes the name of the match with the given [matchId] to [newName].
/// Returns `true` if more than 0 rows were affected, otherwise `false`. /// Returns `true` if more than 0 rows were affected, otherwise `false`.
@@ -367,19 +348,6 @@ class MatchDao extends DatabaseAccessor<AppDatabase> with _$MatchDaoMixin {
return rowsAffected > 0; return rowsAffected > 0;
} }
/// Updates the game of the match with the given [matchId].
/// Returns `true` if more than 0 rows were affected, otherwise `false`.
Future<bool> updateMatchGame({
required String matchId,
required String gameId,
}) async {
final query = update(matchTable)..where((g) => g.id.equals(matchId));
final rowsAffected = await query.write(
MatchTableCompanion(gameId: Value(gameId)),
);
return rowsAffected > 0;
}
/// Updates the group of the match with the given [matchId]. /// Updates the group of the match with the given [matchId].
/// Replaces the existing group association with the new group specified by [newGroupId]. /// Replaces the existing group association with the new group specified by [newGroupId].
/// Pass null to remove the group association. /// Pass null to remove the group association.
@@ -395,6 +363,19 @@ class MatchDao extends DatabaseAccessor<AppDatabase> with _$MatchDaoMixin {
return rowsAffected > 0; return rowsAffected > 0;
} }
/// Updates the notes of the match with the given [matchId].
/// Returns `true` if more than 0 rows were affected, otherwise `false`.
Future<bool> updateMatchNotes({
required String matchId,
required String notes,
}) async {
final query = update(matchTable)..where((g) => g.id.equals(matchId));
final rowsAffected = await query.write(
MatchTableCompanion(notes: Value(notes)),
);
return rowsAffected > 0;
}
/// Removes the group association of the match with the given [matchId]. /// Removes the group association of the match with the given [matchId].
/// Sets the groupId to null. /// Sets the groupId to null.
/// Returns `true` if more than 0 rows were affected, otherwise `false`. /// Returns `true` if more than 0 rows were affected, otherwise `false`.
@@ -406,25 +387,12 @@ class MatchDao extends DatabaseAccessor<AppDatabase> with _$MatchDaoMixin {
return rowsAffected > 0; return rowsAffected > 0;
} }
/// Updates the createdAt timestamp of the match with the given [matchId].
/// Returns `true` if more than 0 rows were affected, otherwise `false`.
Future<bool> updateMatchCreatedAt({
required String matchId,
required DateTime createdAt,
}) async {
final query = update(matchTable)..where((g) => g.id.equals(matchId));
final rowsAffected = await query.write(
MatchTableCompanion(createdAt: Value(createdAt)),
);
return rowsAffected > 0;
}
/// Updates the endedAt timestamp of the match with the given [matchId]. /// Updates the endedAt timestamp of the match with the given [matchId].
/// Pass null to remove the ended time (mark match as ongoing). /// Pass null to remove the ended time (mark match as ongoing).
/// Returns `true` if more than 0 rows were affected, otherwise `false`. /// Returns `true` if more than 0 rows were affected, otherwise `false`.
Future<bool> updateMatchEndedAt({ Future<bool> updateMatchEndedAt({
required String matchId, required String matchId,
required DateTime? endedAt, required DateTime endedAt,
}) async { }) async {
final query = update(matchTable)..where((g) => g.id.equals(matchId)); final query = update(matchTable)..where((g) => g.id.equals(matchId));
final rowsAffected = await query.write( final rowsAffected = await query.write(
@@ -436,7 +404,7 @@ class MatchDao extends DatabaseAccessor<AppDatabase> with _$MatchDaoMixin {
/// Replaces all players in a match with the provided list of players. /// Replaces all players in a match with the provided list of players.
/// Removes all existing players from the match and adds the new players. /// Removes all existing players from the match and adds the new players.
/// Also adds any new players to the player table if they don't exist. /// Also adds any new players to the player table if they don't exist.
Future<void> replaceMatchPlayers({ Future<void> updateMatchPlayers({
required String matchId, required String matchId,
required List<Player> newPlayers, required List<Player> newPlayers,
}) async { }) async {
@@ -466,4 +434,22 @@ class MatchDao extends DatabaseAccessor<AppDatabase> with _$MatchDaoMixin {
); );
}); });
} }
/* Delete */
/// Deletes the match with the given [matchId] from the database.
/// Returns `true` if more than 0 rows were affected, otherwise `false`.
Future<bool> deleteMatch({required String matchId}) async {
final query = delete(matchTable)..where((g) => g.id.equals(matchId));
final rowsAffected = await query.go();
return rowsAffected > 0;
}
/// Deletes all matches from the database.
/// Returns `true` if more than 0 rows were affected, otherwise `false`.
Future<bool> deleteAllMatches() async {
final query = delete(matchTable);
final rowsAffected = await query.go();
return rowsAffected > 0;
}
} }

View File

@@ -143,7 +143,7 @@ class DataTransferService {
await db.gameDao.addGamesAsList(games: importedGames); await db.gameDao.addGamesAsList(games: importedGames);
await db.groupDao.addGroupsAsList(groups: importedGroups); await db.groupDao.addGroupsAsList(groups: importedGroups);
await db.teamDao.addTeamsAsList(teams: importedTeams); await db.teamDao.addTeamsAsList(teams: importedTeams);
await db.matchDao.addMatchAsList(matches: importedMatches); await db.matchDao.addMatchesAsList(matches: importedMatches);
} }
/* Parsing Methods */ /* Parsing Methods */

View File

@@ -101,7 +101,7 @@ void main() {
}); });
group('Match Tests', () { group('Match Tests', () {
// Verifies that a single match can be added and retrieved with all fields, group, and players intact. group('CREATE', () {
test('Adding and fetching single match works correctly', () async { test('Adding and fetching single match works correctly', () async {
await database.matchDao.addMatch(match: testMatch1); await database.matchDao.addMatch(match: testMatch1);
@@ -132,9 +132,8 @@ 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 { test('Adding and fetching multiple matches works correctly', () async {
await database.matchDao.addMatchAsList( await database.matchDao.addMatchesAsList(
matches: [ matches: [
testMatch1, testMatch1,
testMatch2, testMatch2,
@@ -168,9 +167,15 @@ void main() {
expect(match.group!.createdAt, testMatch.group!.createdAt); expect(match.group!.createdAt, testMatch.group!.createdAt);
// Group Members-Checks // Group Members-Checks
expect(match.group!.members.length, testMatch.group!.members.length); expect(
match.group!.members.length,
testMatch.group!.members.length,
);
for (int i = 0; i < testMatch.group!.members.length; i++) { for (int i = 0; i < testMatch.group!.members.length; i++) {
expect(match.group!.members[i].id, testMatch.group!.members[i].id); expect(
match.group!.members[i].id,
testMatch.group!.members[i].id,
);
expect( expect(
match.group!.members[i].name, match.group!.members[i].name,
testMatch.group!.members[i].name, testMatch.group!.members[i].name,
@@ -194,44 +199,216 @@ void main() {
} }
}); });
// Verifies that adding the same match twice does not create duplicates. test('addMatch() ignores duplicate games', () async {
test('Adding the same match twice does not create duplicates', () async { var added = await database.matchDao.addMatch(match: testMatch1);
await database.matchDao.addMatch(match: testMatch1); expect(added, isTrue);
await database.matchDao.addMatch(match: testMatch1);
added = await database.matchDao.addMatch(match: testMatch1);
expect(added, isFalse);
final matchCount = await database.matchDao.getMatchCount(); final matchCount = await database.matchDao.getMatchCount();
expect(matchCount, 1); expect(matchCount, 1);
}); });
// Verifies that matchExists returns correct boolean based on match presence. test('addMatchesAsList() returns isFalse for empty list', () async {
test('Match existence check works correctly', () async { var added = await database.matchDao.addMatchesAsList(matches: []);
expect(added, isFalse);
});
test('addMatchesAsList() ignores duplicate games', () async {
final added = await database.matchDao.addMatchesAsList(
matches: [testMatch1, testMatch2, testMatch1],
);
expect(added, isTrue);
final matchCount = await database.matchDao.getMatchCount();
expect(matchCount, 2);
});
});
group('READ', () {
test('matchExists() works correctly', () async {
var matchExists = await database.matchDao.matchExists( var matchExists = await database.matchDao.matchExists(
matchId: testMatch1.id, matchId: testMatch1.id,
); );
expect(matchExists, false); expect(matchExists, isFalse);
await database.matchDao.addMatch(match: testMatch1); await database.matchDao.addMatch(match: testMatch1);
matchExists = await database.matchDao.matchExists(matchId: testMatch1.id); matchExists = await database.matchDao.matchExists(
expect(matchExists, true); matchId: testMatch1.id,
);
expect(matchExists, isTrue);
}); });
// Verifies that deleteMatch removes the match and returns true. test('getGroupMatches() works correctly', () async {
test('Deleting a match works correctly', () async { var matches = await database.matchDao.getGroupMatches(
groupId: 'non-existing-id',
);
expect(matches, isEmpty);
await database.matchDao.addMatch(match: testMatch1);
matches = await database.matchDao.getGroupMatches(
groupId: testGroup1.id,
);
expect(matches, isNotEmpty);
final match = matches.first;
expect(match.id, testMatch1.id);
expect(match.group, isNotNull);
expect(match.group!.id, testGroup1.id);
});
});
group('UPDATE', () {
test('updateMatchName() works correctly', () async {
await database.matchDao.addMatch(match: testMatch1); await database.matchDao.addMatch(match: testMatch1);
final matchDeleted = await database.matchDao.deleteMatch( const newName = 'New name';
await database.matchDao.updateMatchName(
matchId: testMatch1.id, matchId: testMatch1.id,
newName: newName,
); );
expect(matchDeleted, true);
final matchExists = await database.matchDao.matchExists( final fetchedMatch = await database.matchDao.getMatchById(
matchId: testMatch1.id, matchId: testMatch1.id,
); );
expect(matchExists, false); expect(fetchedMatch.name, newName);
});
test('updateMatchName() does nothing for non-existent match', () async {
final updated = await database.matchDao.updateMatchName(
matchId: 'non-existing-id',
newName: 'New Name',
);
expect(updated, isFalse);
final allMatches = await database.matchDao.getAllMatches();
expect(allMatches, isEmpty);
});
test('updateMatchGroup() works correctly', () async {
await database.matchDao.addMatch(match: testMatch1);
await database.groupDao.addGroup(group: testGroup2);
await database.matchDao.updateMatchGroup(
matchId: testMatch1.id,
newGroupId: testGroup2.id,
);
final fetchedMatch = await database.matchDao.getMatchById(
matchId: testMatch1.id,
);
expect(fetchedMatch.group?.id, testGroup2.id);
});
test('updateMatchGroup() does nothing for non-existent match', () async {
final updated = await database.matchDao.updateMatchGroup(
matchId: 'non-existing-id',
newGroupId: 'group-id',
);
expect(updated, isFalse);
final allMatches = await database.matchDao.getAllMatches();
expect(allMatches, isEmpty);
});
test('removeMatchGroup() works correctly', () async {
expect(testMatch1.group, isNotNull);
await database.matchDao.addMatch(match: testMatch1);
final removed = await database.matchDao.removeMatchGroup(
matchId: testMatch1.id,
);
expect(removed, isTrue);
final updatedMatch = await database.matchDao.getMatchById(
matchId: testMatch1.id,
);
expect(updatedMatch.group, null);
});
test(
'removeMatchGroup() on match that already has no group still succeeds',
() async {
await database.matchDao.addMatch(match: testMatchOnlyPlayers);
final removed = await database.matchDao.removeMatchGroup(
matchId: testMatchOnlyPlayers.id,
);
expect(removed, isTrue);
final updatedMatch = await database.matchDao.getMatchById(
matchId: testMatchOnlyPlayers.id,
);
expect(updatedMatch.group, null);
},
);
test(
'removeMatchGroup() on non-existing match returns isFalse',
() async {
final removed = await database.matchDao.removeMatchGroup(
matchId: 'non-existing-id',
);
expect(removed, isFalse);
},
);
test('updateMatchNotes() works correctly', () async {
await database.matchDao.addMatch(match: testMatch1);
const newName = 'New name';
await database.matchDao.updateMatchName(
matchId: testMatch1.id,
newName: newName,
);
final fetchedMatch = await database.matchDao.getMatchById(
matchId: testMatch1.id,
);
expect(fetchedMatch.name, newName);
});
test('updateMatchNotes() does nothing for non-existent game', () async {
final updated = await database.matchDao.updateMatchNotes(
matchId: 'non-existing-id',
notes: 'New notes',
);
expect(updated, isFalse);
final allMatches = await database.matchDao.getAllMatches();
expect(allMatches, isEmpty);
});
test('updateMatchEndedAt() works correctly', () async {
await database.matchDao.addMatch(match: testMatch1);
DateTime newEndedAt = DateTime(2030, 1, 1, 12, 0, 0);
print(newEndedAt);
await database.matchDao.updateMatchEndedAt(
matchId: testMatch1.id,
endedAt: newEndedAt,
);
final fetchedMatch = await database.matchDao.getMatchById(
matchId: testMatch1.id,
);
expect(fetchedMatch.endedAt, newEndedAt);
});
test('updateMatchEndedAt() does nothing for non-existent game', () async {
final updated = await database.matchDao.updateMatchEndedAt(
matchId: 'non-existing-id',
endedAt: DateTime.now(),
);
expect(updated, isFalse);
final allMatches = await database.matchDao.getAllMatches();
expect(allMatches, isEmpty);
}); });
// Verifies that getMatchCount returns correct count through add/delete operations.
test('Getting the match count works correctly', () async { test('Getting the match count works correctly', () async {
var matchCount = await database.matchDao.getMatchCount(); var matchCount = await database.matchDao.getMatchCount();
expect(matchCount, 0); expect(matchCount, 0);
@@ -256,115 +433,43 @@ void main() {
matchCount = await database.matchDao.getMatchCount(); matchCount = await database.matchDao.getMatchCount();
expect(matchCount, 0); expect(matchCount, 0);
}); });
// Verifies that updateMatchName correctly updates only the name field.
test('Renaming a match works correctly', () async {
await database.matchDao.addMatch(match: testMatch1);
var fetchedMatch = await database.matchDao.getMatchById(
matchId: testMatch1.id,
);
expect(fetchedMatch.name, testMatch1.name);
const newName = 'Updated Match Name';
await database.matchDao.updateMatchName(
matchId: testMatch1.id,
newName: newName,
);
fetchedMatch = await database.matchDao.getMatchById(
matchId: testMatch1.id,
);
expect(fetchedMatch.name, newName);
}); });
test('Fetching a winner works correctly', () async { group('DELETE', () {
test('deleteMatch() works correctly', () async {
await database.matchDao.addMatch(match: testMatch1); await database.matchDao.addMatch(match: testMatch1);
var fetchedMatch = await database.matchDao.getMatchById( var deleted = await database.matchDao.deleteMatch(
matchId: testMatch1.id, matchId: testMatch1.id,
); );
expect(deleted, isTrue);
expect(fetchedMatch.mvp, isNotNull); final matchExists = await database.matchDao.matchExists(
expect(fetchedMatch.mvp.first.id, testPlayer4.id); matchId: testMatch1.id,
);
expect(matchExists, isFalse);
deleted = await database.matchDao.deleteMatch(matchId: testMatch1.id);
expect(deleted, isFalse);
}); });
test('Setting a winner works correctly', () async { test('deleteAllMatches() works correctly', () async {
await database.matchDao.addMatch(match: testMatch1); await database.matchDao.addMatchesAsList(
matches: [testMatch1, testMatch2, testMatchOnlyPlayers],
await database.scoreEntryDao.setWinner(
matchId: testMatch1.id,
playerId: testPlayer5.id,
); );
final fetchedMatch = await database.matchDao.getMatchById( var count = await database.matchDao.getMatchCount();
matchId: testMatch1.id, expect(count, 3);
);
expect(fetchedMatch.mvp, isNotNull); var deleted = await database.matchDao.deleteAllMatches();
expect(fetchedMatch.mvp.first.id, testPlayer5.id); expect(deleted, isTrue);
count = await database.matchDao.getMatchCount();
expect(count, 0);
deleted = await database.matchDao.deleteAllMatches();
expect(deleted, isFalse);
}); });
test(
'removeMatchGroup removes group from match with existing group',
() async {
await database.matchDao.addMatch(match: testMatch1);
final removed = await database.matchDao.removeMatchGroup(
matchId: testMatch1.id,
);
expect(removed, isTrue);
final updatedMatch = await database.matchDao.getMatchById(
matchId: testMatch1.id,
);
expect(updatedMatch.group, null);
expect(updatedMatch.game.id, testMatch1.game.id);
expect(updatedMatch.name, testMatch1.name);
expect(updatedMatch.notes, testMatch1.notes);
},
);
test(
'removeMatchGroup on match that already has no group still succeeds',
() async {
await database.matchDao.addMatch(match: testMatchOnlyPlayers);
final removed = await database.matchDao.removeMatchGroup(
matchId: testMatchOnlyPlayers.id,
);
expect(removed, isTrue);
final updatedMatch = await database.matchDao.getMatchById(
matchId: testMatchOnlyPlayers.id,
);
expect(updatedMatch.group, null);
},
);
test('removeMatchGroup on non-existing match returns false', () async {
final removed = await database.matchDao.removeMatchGroup(
matchId: 'non-existing-id',
);
expect(removed, isFalse);
});
test('Fetching all matches related to a group', () async {
var matches = await database.matchDao.getGroupMatches(
groupId: 'non-existing-id',
);
expect(matches, isEmpty);
await database.matchDao.addMatch(match: testMatch1);
matches = await database.matchDao.getGroupMatches(groupId: testGroup1.id);
expect(matches, isNotEmpty);
final match = matches.first;
expect(match.id, testMatch1.id);
expect(match.group, isNotNull);
expect(match.group!.id, testGroup1.id);
}); });
}); });
} }