Fixed references
All checks were successful
Pull Request Pipeline / test (pull_request) Successful in 42s
Pull Request Pipeline / lint (pull_request) Successful in 47s

This commit is contained in:
2026-04-13 22:53:39 +02:00
parent 73c85b1ff2
commit e827f4c527
5 changed files with 146 additions and 121 deletions

View File

@@ -30,9 +30,11 @@ class MatchDao extends DatabaseAccessor<AppDatabase> with _$MatchDaoMixin {
final players = final players =
await db.playerMatchDao.getPlayersOfMatch(matchId: row.id) ?? []; await db.playerMatchDao.getPlayersOfMatch(matchId: row.id) ?? [];
final scores = await db.scoreDao.getAllMatchScores(matchId: row.id); final scores = await db.scoreEntryDao.getAllMatchScores(
matchId: row.id,
);
final winner = await db.scoreDao.getWinner(matchId: row.id); final winner = await db.scoreEntryDao.getWinner(matchId: row.id);
return Match( return Match(
id: row.id, id: row.id,
name: row.name, name: row.name,
@@ -64,9 +66,9 @@ class MatchDao extends DatabaseAccessor<AppDatabase> with _$MatchDaoMixin {
final players = final players =
await db.playerMatchDao.getPlayersOfMatch(matchId: matchId) ?? []; await db.playerMatchDao.getPlayersOfMatch(matchId: matchId) ?? [];
final scores = await db.scoreDao.getAllMatchScores(matchId: matchId); final scores = await db.scoreEntryDao.getAllMatchScores(matchId: matchId);
final winner = await db.scoreDao.getWinner(matchId: matchId); final winner = await db.scoreEntryDao.getWinner(matchId: matchId);
return Match( return Match(
id: result.id, id: result.id,
@@ -109,7 +111,7 @@ class MatchDao extends DatabaseAccessor<AppDatabase> with _$MatchDaoMixin {
for (final pid in match.scores.keys) { for (final pid in match.scores.keys) {
final playerScores = match.scores[pid]!; final playerScores = match.scores[pid]!;
await db.scoreDao.addScoresAsList( await db.scoreEntryDao.addScoresAsList(
entrys: playerScores, entrys: playerScores,
playerId: pid, playerId: pid,
matchId: match.id, matchId: match.id,
@@ -117,7 +119,7 @@ class MatchDao extends DatabaseAccessor<AppDatabase> with _$MatchDaoMixin {
} }
if (match.winner != null) { if (match.winner != null) {
await db.scoreDao.setWinner( await db.scoreEntryDao.setWinner(
matchId: match.id, matchId: match.id,
playerId: match.winner!.id, playerId: match.winner!.id,
); );
@@ -298,7 +300,7 @@ class MatchDao extends DatabaseAccessor<AppDatabase> with _$MatchDaoMixin {
final group = await db.groupDao.getGroupById(groupId: groupId); final group = await db.groupDao.getGroupById(groupId: groupId);
final players = final players =
await db.playerMatchDao.getPlayersOfMatch(matchId: row.id) ?? []; await db.playerMatchDao.getPlayersOfMatch(matchId: row.id) ?? [];
final winner = await db.scoreDao.getWinner(matchId: row.id); final winner = await db.scoreEntryDao.getWinner(matchId: row.id);
return Match( return Match(
id: row.id, id: row.id,
name: row.name, name: row.name,

View File

@@ -227,7 +227,7 @@ class _HomeViewState extends State<HomeView> {
/// Updates the winner information for a specific match in the recent matches list. /// Updates the winner information for a specific match in the recent matches list.
Future<void> updatedWinnerInRecentMatches(String matchId) async { Future<void> updatedWinnerInRecentMatches(String matchId) async {
final db = Provider.of<AppDatabase>(context, listen: false); final db = Provider.of<AppDatabase>(context, listen: false);
final winner = await db.scoreDao.getWinner(matchId: matchId); final winner = await db.scoreEntryDao.getWinner(matchId: matchId);
final matchIndex = recentMatches.indexWhere((match) => match.id == matchId); final matchIndex = recentMatches.indexWhere((match) => match.id == matchId);
if (matchIndex != -1) { if (matchIndex != -1) {
setState(() { setState(() {

View File

@@ -139,9 +139,9 @@ class _MatchResultViewState extends State<MatchResultView> {
/// based on the current selection. /// based on the current selection.
Future<void> _handleWinnerSaving() async { Future<void> _handleWinnerSaving() async {
if (_selectedPlayer == null) { if (_selectedPlayer == null) {
await db.scoreDao.removeWinner(matchId: widget.match.id); await db.scoreEntryDao.removeWinner(matchId: widget.match.id);
} else { } else {
await db.scoreDao.setWinner( await db.scoreEntryDao.setWinner(
matchId: widget.match.id, matchId: widget.match.id,
playerId: _selectedPlayer!.id, playerId: _selectedPlayer!.id,
); );

View File

@@ -296,7 +296,7 @@ void main() {
test('Setting a winner works correctly', () async { test('Setting a winner works correctly', () async {
await database.matchDao.addMatch(match: testMatch1); await database.matchDao.addMatch(match: testMatch1);
await database.scoreDao.setWinner( await database.scoreEntryDao.setWinner(
matchId: testMatch1.id, matchId: testMatch1.id,
playerId: testPlayer5.id, playerId: testPlayer5.id,
); );

View File

@@ -70,13 +70,13 @@ void main() {
group('Adding and Fetching scores', () { group('Adding and Fetching scores', () {
test('Single Score', () async { test('Single Score', () async {
ScoreEntry entry = ScoreEntry(roundNumber: 1, score: 10, change: 10); ScoreEntry entry = ScoreEntry(roundNumber: 1, score: 10, change: 10);
await database.scoreDao.addScore( await database.scoreEntryDao.addScore(
playerId: testPlayer1.id, playerId: testPlayer1.id,
matchId: testMatch1.id, matchId: testMatch1.id,
entry: entry, entry: entry,
); );
final score = await database.scoreDao.getScore( final score = await database.scoreEntryDao.getScore(
playerId: testPlayer1.id, playerId: testPlayer1.id,
matchId: testMatch1.id, matchId: testMatch1.id,
roundNumber: 1, roundNumber: 1,
@@ -95,13 +95,13 @@ void main() {
ScoreEntry(roundNumber: 3, score: 18, change: 6), ScoreEntry(roundNumber: 3, score: 18, change: 6),
]; ];
await database.scoreDao.addScoresAsList( await database.scoreEntryDao.addScoresAsList(
entrys: entryList, entrys: entryList,
playerId: testPlayer1.id, playerId: testPlayer1.id,
matchId: testMatch1.id, matchId: testMatch1.id,
); );
final scores = await database.scoreDao.getAllPlayerScoresInMatch( final scores = await database.scoreEntryDao.getAllPlayerScoresInMatch(
playerId: testPlayer1.id, playerId: testPlayer1.id,
matchId: testMatch1.id, matchId: testMatch1.id,
); );
@@ -120,13 +120,13 @@ void main() {
group('Undesirable values', () { group('Undesirable values', () {
test('Score & Round can have negative values', () async { test('Score & Round can have negative values', () async {
ScoreEntry entry = ScoreEntry(roundNumber: -2, score: -10, change: -10); ScoreEntry entry = ScoreEntry(roundNumber: -2, score: -10, change: -10);
await database.scoreDao.addScore( await database.scoreEntryDao.addScore(
playerId: testPlayer1.id, playerId: testPlayer1.id,
matchId: testMatch1.id, matchId: testMatch1.id,
entry: entry, entry: entry,
); );
final score = await database.scoreDao.getScore( final score = await database.scoreEntryDao.getScore(
playerId: testPlayer1.id, playerId: testPlayer1.id,
matchId: testMatch1.id, matchId: testMatch1.id,
roundNumber: -2, roundNumber: -2,
@@ -140,13 +140,13 @@ void main() {
test('Score & Round can have zero values', () async { test('Score & Round can have zero values', () async {
ScoreEntry entry = ScoreEntry(roundNumber: 0, score: 0, change: 0); ScoreEntry entry = ScoreEntry(roundNumber: 0, score: 0, change: 0);
await database.scoreDao.addScore( await database.scoreEntryDao.addScore(
playerId: testPlayer1.id, playerId: testPlayer1.id,
matchId: testMatch1.id, matchId: testMatch1.id,
entry: entry, entry: entry,
); );
final score = await database.scoreDao.getScore( final score = await database.scoreEntryDao.getScore(
playerId: testPlayer1.id, playerId: testPlayer1.id,
matchId: testMatch1.id, matchId: testMatch1.id,
roundNumber: 0, roundNumber: 0,
@@ -158,7 +158,7 @@ void main() {
}); });
test('Getting score for a non-existent entities returns null', () async { test('Getting score for a non-existent entities returns null', () async {
var score = await database.scoreDao.getScore( var score = await database.scoreEntryDao.getScore(
playerId: testPlayer1.id, playerId: testPlayer1.id,
matchId: testMatch1.id, matchId: testMatch1.id,
roundNumber: -1, roundNumber: -1,
@@ -166,14 +166,14 @@ void main() {
expect(score, isNull); expect(score, isNull);
score = await database.scoreDao.getScore( score = await database.scoreEntryDao.getScore(
playerId: 'non-existin-player', playerId: 'non-existin-player',
matchId: testMatch1.id, matchId: testMatch1.id,
); );
expect(score, isNull); expect(score, isNull);
score = await database.scoreDao.getScore( score = await database.scoreEntryDao.getScore(
playerId: testPlayer1.id, playerId: testPlayer1.id,
matchId: 'non-existing-match', matchId: 'non-existing-match',
); );
@@ -183,19 +183,19 @@ void main() {
test('Getting score for a non-match player returns null', () async { test('Getting score for a non-match player returns null', () async {
ScoreEntry entry = ScoreEntry(roundNumber: 1, score: 10, change: 10); ScoreEntry entry = ScoreEntry(roundNumber: 1, score: 10, change: 10);
await database.scoreDao.addScore( await database.scoreEntryDao.addScore(
playerId: testPlayer1.id, playerId: testPlayer1.id,
matchId: testMatch1.id, matchId: testMatch1.id,
entry: entry, entry: entry,
); );
await database.scoreDao.addScore( await database.scoreEntryDao.addScore(
playerId: testPlayer3.id, playerId: testPlayer3.id,
matchId: testMatch2.id, matchId: testMatch2.id,
entry: entry, entry: entry,
); );
var score = await database.scoreDao.getScore( var score = await database.scoreEntryDao.getScore(
playerId: testPlayer1.id, playerId: testPlayer1.id,
matchId: testMatch2.id, matchId: testMatch2.id,
roundNumber: 1, roundNumber: 1,
@@ -210,23 +210,23 @@ void main() {
ScoreEntry entry1 = ScoreEntry(roundNumber: 1, score: 10, change: 10); ScoreEntry entry1 = ScoreEntry(roundNumber: 1, score: 10, change: 10);
ScoreEntry entry2 = ScoreEntry(roundNumber: 1, score: 20, change: 20); ScoreEntry entry2 = ScoreEntry(roundNumber: 1, score: 20, change: 20);
ScoreEntry entry3 = ScoreEntry(roundNumber: 2, score: 25, change: 15); ScoreEntry entry3 = ScoreEntry(roundNumber: 2, score: 25, change: 15);
await database.scoreDao.addScore( await database.scoreEntryDao.addScore(
playerId: testPlayer1.id, playerId: testPlayer1.id,
matchId: testMatch1.id, matchId: testMatch1.id,
entry: entry1, entry: entry1,
); );
await database.scoreDao.addScore( await database.scoreEntryDao.addScore(
playerId: testPlayer2.id, playerId: testPlayer2.id,
matchId: testMatch1.id, matchId: testMatch1.id,
entry: entry2, entry: entry2,
); );
await database.scoreDao.addScore( await database.scoreEntryDao.addScore(
playerId: testPlayer1.id, playerId: testPlayer1.id,
matchId: testMatch1.id, matchId: testMatch1.id,
entry: entry3, entry: entry3,
); );
final scores = await database.scoreDao.getAllMatchScores( final scores = await database.scoreEntryDao.getAllMatchScores(
matchId: testMatch1.id, matchId: testMatch1.id,
); );
@@ -236,7 +236,7 @@ void main() {
}); });
test('getAllMatchScores() with no scores saved', () async { test('getAllMatchScores() with no scores saved', () async {
final scores = await database.scoreDao.getAllMatchScores( final scores = await database.scoreEntryDao.getAllMatchScores(
matchId: testMatch1.id, matchId: testMatch1.id,
); );
@@ -247,21 +247,22 @@ void main() {
ScoreEntry entry1 = ScoreEntry(roundNumber: 1, score: 10, change: 10); ScoreEntry entry1 = ScoreEntry(roundNumber: 1, score: 10, change: 10);
ScoreEntry entry2 = ScoreEntry(roundNumber: 2, score: 25, change: 15); ScoreEntry entry2 = ScoreEntry(roundNumber: 2, score: 25, change: 15);
ScoreEntry entry3 = ScoreEntry(roundNumber: 1, score: 30, change: 30); ScoreEntry entry3 = ScoreEntry(roundNumber: 1, score: 30, change: 30);
await database.scoreDao.addScoresAsList( await database.scoreEntryDao.addScoresAsList(
playerId: testPlayer1.id, playerId: testPlayer1.id,
matchId: testMatch1.id, matchId: testMatch1.id,
entrys: [entry1, entry2], entrys: [entry1, entry2],
); );
await database.scoreDao.addScore( await database.scoreEntryDao.addScore(
playerId: testPlayer2.id, playerId: testPlayer2.id,
matchId: testMatch1.id, matchId: testMatch1.id,
entry: entry3, entry: entry3,
); );
final playerScores = await database.scoreDao.getAllPlayerScoresInMatch( final playerScores = await database.scoreEntryDao
playerId: testPlayer1.id, .getAllPlayerScoresInMatch(
matchId: testMatch1.id, playerId: testPlayer1.id,
); matchId: testMatch1.id,
);
expect(playerScores.length, 2); expect(playerScores.length, 2);
expect(playerScores[0].roundNumber, 1); expect(playerScores[0].roundNumber, 1);
@@ -273,10 +274,11 @@ void main() {
}); });
test('getAllPlayerScoresInMatch() with no scores saved', () async { test('getAllPlayerScoresInMatch() with no scores saved', () async {
final playerScores = await database.scoreDao.getAllPlayerScoresInMatch( final playerScores = await database.scoreEntryDao
playerId: testPlayer1.id, .getAllPlayerScoresInMatch(
matchId: testMatch1.id, playerId: testPlayer1.id,
); matchId: testMatch1.id,
);
expect(playerScores.isEmpty, true); expect(playerScores.isEmpty, true);
}); });
@@ -284,30 +286,32 @@ void main() {
test('Scores are isolated across different matches', () async { test('Scores are isolated across different matches', () async {
ScoreEntry entry1 = ScoreEntry(roundNumber: 1, score: 10, change: 10); ScoreEntry entry1 = ScoreEntry(roundNumber: 1, score: 10, change: 10);
ScoreEntry entry2 = ScoreEntry(roundNumber: 1, score: 50, change: 50); ScoreEntry entry2 = ScoreEntry(roundNumber: 1, score: 50, change: 50);
await database.scoreDao.addScore( await database.scoreEntryDao.addScore(
playerId: testPlayer1.id, playerId: testPlayer1.id,
matchId: testMatch1.id, matchId: testMatch1.id,
entry: entry1, entry: entry1,
); );
await database.scoreDao.addScore( await database.scoreEntryDao.addScore(
playerId: testPlayer1.id, playerId: testPlayer1.id,
matchId: testMatch2.id, matchId: testMatch2.id,
entry: entry2, entry: entry2,
); );
final match1Scores = await database.scoreDao.getAllPlayerScoresInMatch( final match1Scores = await database.scoreEntryDao
playerId: testPlayer1.id, .getAllPlayerScoresInMatch(
matchId: testMatch1.id, playerId: testPlayer1.id,
); matchId: testMatch1.id,
);
expect(match1Scores.length, 1); expect(match1Scores.length, 1);
expect(match1Scores[0].score, 10); expect(match1Scores[0].score, 10);
expect(match1Scores[0].change, 10); expect(match1Scores[0].change, 10);
final match2Scores = await database.scoreDao.getAllPlayerScoresInMatch( final match2Scores = await database.scoreEntryDao
playerId: testPlayer1.id, .getAllPlayerScoresInMatch(
matchId: testMatch2.id, playerId: testPlayer1.id,
); matchId: testMatch2.id,
);
expect(match2Scores.length, 1); expect(match2Scores.length, 1);
expect(match2Scores[0].score, 50); expect(match2Scores[0].score, 50);
@@ -319,19 +323,19 @@ void main() {
test('updateScore()', () async { test('updateScore()', () async {
ScoreEntry entry1 = ScoreEntry(roundNumber: 1, score: 10, change: 10); ScoreEntry entry1 = ScoreEntry(roundNumber: 1, score: 10, change: 10);
ScoreEntry entry2 = ScoreEntry(roundNumber: 2, score: 15, change: 5); ScoreEntry entry2 = ScoreEntry(roundNumber: 2, score: 15, change: 5);
await database.scoreDao.addScore( await database.scoreEntryDao.addScore(
playerId: testPlayer1.id, playerId: testPlayer1.id,
matchId: testMatch1.id, matchId: testMatch1.id,
entry: entry1, entry: entry1,
); );
await database.scoreDao.addScore( await database.scoreEntryDao.addScore(
playerId: testPlayer1.id, playerId: testPlayer1.id,
matchId: testMatch1.id, matchId: testMatch1.id,
entry: entry2, entry: entry2,
); );
final updated = await database.scoreDao.updateScore( final updated = await database.scoreEntryDao.updateScore(
playerId: testPlayer1.id, playerId: testPlayer1.id,
matchId: testMatch1.id, matchId: testMatch1.id,
newEntry: ScoreEntry(roundNumber: 2, score: 50, change: 40), newEntry: ScoreEntry(roundNumber: 2, score: 50, change: 40),
@@ -339,7 +343,7 @@ void main() {
expect(updated, true); expect(updated, true);
final score = await database.scoreDao.getScore( final score = await database.scoreEntryDao.getScore(
playerId: testPlayer1.id, playerId: testPlayer1.id,
matchId: testMatch1.id, matchId: testMatch1.id,
roundNumber: 2, roundNumber: 2,
@@ -351,7 +355,7 @@ void main() {
}); });
test('Updating a non-existent score returns false', () async { test('Updating a non-existent score returns false', () async {
final updated = await database.scoreDao.updateScore( final updated = await database.scoreEntryDao.updateScore(
playerId: testPlayer1.id, playerId: testPlayer1.id,
matchId: testMatch1.id, matchId: testMatch1.id,
newEntry: ScoreEntry(roundNumber: 1, score: 20, change: 20), newEntry: ScoreEntry(roundNumber: 1, score: 20, change: 20),
@@ -363,13 +367,13 @@ void main() {
group('Deleting scores', () { group('Deleting scores', () {
test('deleteScore() ', () async { test('deleteScore() ', () async {
await database.scoreDao.addScore( await database.scoreEntryDao.addScore(
playerId: testPlayer1.id, playerId: testPlayer1.id,
matchId: testMatch1.id, matchId: testMatch1.id,
entry: ScoreEntry(roundNumber: 1, score: 10, change: 10), entry: ScoreEntry(roundNumber: 1, score: 10, change: 10),
); );
final deleted = await database.scoreDao.deleteScore( final deleted = await database.scoreEntryDao.deleteScore(
playerId: testPlayer1.id, playerId: testPlayer1.id,
matchId: testMatch1.id, matchId: testMatch1.id,
roundNumber: 1, roundNumber: 1,
@@ -377,7 +381,7 @@ void main() {
expect(deleted, true); expect(deleted, true);
final score = await database.scoreDao.getScore( final score = await database.scoreEntryDao.getScore(
playerId: testPlayer1.id, playerId: testPlayer1.id,
matchId: testMatch1.id, matchId: testMatch1.id,
roundNumber: 1, roundNumber: 1,
@@ -387,7 +391,7 @@ void main() {
}); });
test('Deleting a non-existent score returns false', () async { test('Deleting a non-existent score returns false', () async {
final deleted = await database.scoreDao.deleteScore( final deleted = await database.scoreEntryDao.deleteScore(
playerId: testPlayer1.id, playerId: testPlayer1.id,
matchId: testMatch1.id, matchId: testMatch1.id,
roundNumber: 1, roundNumber: 1,
@@ -397,127 +401,130 @@ void main() {
}); });
test('deleteAllScoresForMatch() works correctly', () async { test('deleteAllScoresForMatch() works correctly', () async {
await database.scoreDao.addScore( await database.scoreEntryDao.addScore(
playerId: testPlayer1.id, playerId: testPlayer1.id,
matchId: testMatch1.id, matchId: testMatch1.id,
entry: ScoreEntry(roundNumber: 1, score: 10, change: 10), entry: ScoreEntry(roundNumber: 1, score: 10, change: 10),
); );
await database.scoreDao.addScore( await database.scoreEntryDao.addScore(
playerId: testPlayer2.id, playerId: testPlayer2.id,
matchId: testMatch1.id, matchId: testMatch1.id,
entry: ScoreEntry(roundNumber: 1, score: 20, change: 20), entry: ScoreEntry(roundNumber: 1, score: 20, change: 20),
); );
await database.scoreDao.addScore( await database.scoreEntryDao.addScore(
playerId: testPlayer1.id, playerId: testPlayer1.id,
matchId: testMatch2.id, matchId: testMatch2.id,
entry: ScoreEntry(roundNumber: 1, score: 15, change: 15), entry: ScoreEntry(roundNumber: 1, score: 15, change: 15),
); );
final deleted = await database.scoreDao.deleteAllScoresForMatch( final deleted = await database.scoreEntryDao.deleteAllScoresForMatch(
matchId: testMatch1.id, matchId: testMatch1.id,
); );
expect(deleted, true); expect(deleted, true);
final match1Scores = await database.scoreDao.getAllMatchScores( final match1Scores = await database.scoreEntryDao.getAllMatchScores(
matchId: testMatch1.id, matchId: testMatch1.id,
); );
expect(match1Scores.length, 0); expect(match1Scores.length, 0);
final match2Scores = await database.scoreDao.getAllMatchScores( final match2Scores = await database.scoreEntryDao.getAllMatchScores(
matchId: testMatch2.id, matchId: testMatch2.id,
); );
expect(match2Scores.length, 1); expect(match2Scores.length, 1);
}); });
test('deleteAllScoresForPlayerInMatch() works correctly', () async { test('deleteAllScoresForPlayerInMatch() works correctly', () async {
await database.scoreDao.addScore( await database.scoreEntryDao.addScore(
playerId: testPlayer1.id, playerId: testPlayer1.id,
matchId: testMatch1.id, matchId: testMatch1.id,
entry: ScoreEntry(roundNumber: 1, score: 10, change: 10), entry: ScoreEntry(roundNumber: 1, score: 10, change: 10),
); );
await database.scoreDao.addScore( await database.scoreEntryDao.addScore(
playerId: testPlayer1.id, playerId: testPlayer1.id,
matchId: testMatch1.id, matchId: testMatch1.id,
entry: ScoreEntry(roundNumber: 2, score: 15, change: 5), entry: ScoreEntry(roundNumber: 2, score: 15, change: 5),
); );
await database.scoreDao.addScore( await database.scoreEntryDao.addScore(
playerId: testPlayer2.id, playerId: testPlayer2.id,
matchId: testMatch1.id, matchId: testMatch1.id,
entry: ScoreEntry(roundNumber: 1, score: 6, change: 6), entry: ScoreEntry(roundNumber: 1, score: 6, change: 6),
); );
final deleted = await database.scoreDao.deleteAllScoresForPlayerInMatch( final deleted = await database.scoreEntryDao
playerId: testPlayer1.id, .deleteAllScoresForPlayerInMatch(
matchId: testMatch1.id, playerId: testPlayer1.id,
); matchId: testMatch1.id,
);
expect(deleted, true); expect(deleted, true);
final player1Scores = await database.scoreDao.getAllPlayerScoresInMatch( final player1Scores = await database.scoreEntryDao
playerId: testPlayer1.id, .getAllPlayerScoresInMatch(
matchId: testMatch1.id, playerId: testPlayer1.id,
); matchId: testMatch1.id,
);
expect(player1Scores.length, 0); expect(player1Scores.length, 0);
final player2Scores = await database.scoreDao.getAllPlayerScoresInMatch( final player2Scores = await database.scoreEntryDao
playerId: testPlayer2.id, .getAllPlayerScoresInMatch(
matchId: testMatch1.id, playerId: testPlayer2.id,
); matchId: testMatch1.id,
);
expect(player2Scores.length, 1); expect(player2Scores.length, 1);
}); });
}); });
group('Score Aggregations & Edge Cases', () { group('Score Aggregations & Edge Cases', () {
test('getLatestRoundNumber()', () async { test('getLatestRoundNumber()', () async {
var latestRound = await database.scoreDao.getLatestRoundNumber( var latestRound = await database.scoreEntryDao.getLatestRoundNumber(
matchId: testMatch1.id, matchId: testMatch1.id,
); );
expect(latestRound, isNull); expect(latestRound, isNull);
await database.scoreDao.addScore( await database.scoreEntryDao.addScore(
playerId: testPlayer1.id, playerId: testPlayer1.id,
matchId: testMatch1.id, matchId: testMatch1.id,
entry: ScoreEntry(roundNumber: 1, score: 10, change: 10), entry: ScoreEntry(roundNumber: 1, score: 10, change: 10),
); );
latestRound = await database.scoreDao.getLatestRoundNumber( latestRound = await database.scoreEntryDao.getLatestRoundNumber(
matchId: testMatch1.id, matchId: testMatch1.id,
); );
expect(latestRound, 1); expect(latestRound, 1);
await database.scoreDao.addScore( await database.scoreEntryDao.addScore(
playerId: testPlayer1.id, playerId: testPlayer1.id,
matchId: testMatch1.id, matchId: testMatch1.id,
entry: ScoreEntry(roundNumber: 5, score: 50, change: 40), entry: ScoreEntry(roundNumber: 5, score: 50, change: 40),
); );
latestRound = await database.scoreDao.getLatestRoundNumber( latestRound = await database.scoreEntryDao.getLatestRoundNumber(
matchId: testMatch1.id, matchId: testMatch1.id,
); );
expect(latestRound, 5); expect(latestRound, 5);
}); });
test('getLatestRoundNumber() with non-consecutive rounds', () async { test('getLatestRoundNumber() with non-consecutive rounds', () async {
await database.scoreDao.addScore( await database.scoreEntryDao.addScore(
playerId: testPlayer1.id, playerId: testPlayer1.id,
matchId: testMatch1.id, matchId: testMatch1.id,
entry: ScoreEntry(roundNumber: 1, score: 10, change: 10), entry: ScoreEntry(roundNumber: 1, score: 10, change: 10),
); );
await database.scoreDao.addScore( await database.scoreEntryDao.addScore(
playerId: testPlayer1.id, playerId: testPlayer1.id,
matchId: testMatch1.id, matchId: testMatch1.id,
entry: ScoreEntry(roundNumber: 5, score: 50, change: 40), entry: ScoreEntry(roundNumber: 5, score: 50, change: 40),
); );
await database.scoreDao.addScore( await database.scoreEntryDao.addScore(
playerId: testPlayer1.id, playerId: testPlayer1.id,
matchId: testMatch1.id, matchId: testMatch1.id,
entry: ScoreEntry(roundNumber: 3, score: 30, change: 20), entry: ScoreEntry(roundNumber: 3, score: 30, change: 20),
); );
final latestRound = await database.scoreDao.getLatestRoundNumber( final latestRound = await database.scoreEntryDao.getLatestRoundNumber(
matchId: testMatch1.id, matchId: testMatch1.id,
); );
@@ -525,29 +532,29 @@ void main() {
}); });
test('getTotalScoreForPlayer()', () async { test('getTotalScoreForPlayer()', () async {
var totalScore = await database.scoreDao.getTotalScoreForPlayer( var totalScore = await database.scoreEntryDao.getTotalScoreForPlayer(
playerId: testPlayer1.id, playerId: testPlayer1.id,
matchId: testMatch1.id, matchId: testMatch1.id,
); );
expect(totalScore, 0); expect(totalScore, 0);
await database.scoreDao.addScore( await database.scoreEntryDao.addScore(
playerId: testPlayer1.id, playerId: testPlayer1.id,
matchId: testMatch1.id, matchId: testMatch1.id,
entry: ScoreEntry(roundNumber: 1, score: 10, change: 10), entry: ScoreEntry(roundNumber: 1, score: 10, change: 10),
); );
await database.scoreDao.addScore( await database.scoreEntryDao.addScore(
playerId: testPlayer1.id, playerId: testPlayer1.id,
matchId: testMatch1.id, matchId: testMatch1.id,
entry: ScoreEntry(roundNumber: 2, score: 25, change: 15), entry: ScoreEntry(roundNumber: 2, score: 25, change: 15),
); );
await database.scoreDao.addScore( await database.scoreEntryDao.addScore(
playerId: testPlayer1.id, playerId: testPlayer1.id,
matchId: testMatch1.id, matchId: testMatch1.id,
entry: ScoreEntry(roundNumber: 3, score: 40, change: 15), entry: ScoreEntry(roundNumber: 3, score: 40, change: 15),
); );
totalScore = await database.scoreDao.getTotalScoreForPlayer( totalScore = await database.scoreEntryDao.getTotalScoreForPlayer(
playerId: testPlayer1.id, playerId: testPlayer1.id,
matchId: testMatch1.id, matchId: testMatch1.id,
); );
@@ -555,23 +562,23 @@ void main() {
}); });
test('getTotalScoreForPlayer() ignores round score', () async { test('getTotalScoreForPlayer() ignores round score', () async {
await database.scoreDao.addScore( await database.scoreEntryDao.addScore(
playerId: testPlayer1.id, playerId: testPlayer1.id,
matchId: testMatch1.id, matchId: testMatch1.id,
entry: ScoreEntry(roundNumber: 2, score: 25, change: 25), entry: ScoreEntry(roundNumber: 2, score: 25, change: 25),
); );
await database.scoreDao.addScore( await database.scoreEntryDao.addScore(
playerId: testPlayer1.id, playerId: testPlayer1.id,
matchId: testMatch1.id, matchId: testMatch1.id,
entry: ScoreEntry(roundNumber: 1, score: 25, change: 10), entry: ScoreEntry(roundNumber: 1, score: 25, change: 10),
); );
await database.scoreDao.addScore( await database.scoreEntryDao.addScore(
playerId: testPlayer1.id, playerId: testPlayer1.id,
matchId: testMatch1.id, matchId: testMatch1.id,
entry: ScoreEntry(roundNumber: 3, score: 25, change: 25), entry: ScoreEntry(roundNumber: 3, score: 25, change: 25),
); );
final totalScore = await database.scoreDao.getTotalScoreForPlayer( final totalScore = await database.scoreEntryDao.getTotalScoreForPlayer(
playerId: testPlayer1.id, playerId: testPlayer1.id,
matchId: testMatch1.id, matchId: testMatch1.id,
); );
@@ -581,18 +588,18 @@ void main() {
}); });
test('Adding the same score twice replaces the existing one', () async { test('Adding the same score twice replaces the existing one', () async {
await database.scoreDao.addScore( await database.scoreEntryDao.addScore(
playerId: testPlayer1.id, playerId: testPlayer1.id,
matchId: testMatch1.id, matchId: testMatch1.id,
entry: ScoreEntry(roundNumber: 1, score: 10, change: 10), entry: ScoreEntry(roundNumber: 1, score: 10, change: 10),
); );
await database.scoreDao.addScore( await database.scoreEntryDao.addScore(
playerId: testPlayer1.id, playerId: testPlayer1.id,
matchId: testMatch1.id, matchId: testMatch1.id,
entry: ScoreEntry(roundNumber: 1, score: 20, change: 20), entry: ScoreEntry(roundNumber: 1, score: 20, change: 20),
); );
final score = await database.scoreDao.getScore( final score = await database.scoreEntryDao.getScore(
playerId: testPlayer1.id, playerId: testPlayer1.id,
matchId: testMatch1.id, matchId: testMatch1.id,
roundNumber: 1, roundNumber: 1,
@@ -606,100 +613,116 @@ void main() {
group('Handling Winner', () { group('Handling Winner', () {
test('hasWinner() works correctly', () async { test('hasWinner() works correctly', () async {
var hasWinner = await database.scoreDao.hasWinner( var hasWinner = await database.scoreEntryDao.hasWinner(
matchId: testMatch1.id, matchId: testMatch1.id,
); );
expect(hasWinner, false); expect(hasWinner, false);
await database.scoreDao.setWinner( await database.scoreEntryDao.setWinner(
playerId: testPlayer1.id, playerId: testPlayer1.id,
matchId: testMatch1.id, matchId: testMatch1.id,
); );
hasWinner = await database.scoreDao.hasWinner(matchId: testMatch1.id); hasWinner = await database.scoreEntryDao.hasWinner(
matchId: testMatch1.id,
);
expect(hasWinner, true); expect(hasWinner, true);
}); });
test('getWinnersForMatch() returns correct winner', () async { test('getWinnersForMatch() returns correct winner', () async {
var winner = await database.scoreDao.getWinner(matchId: testMatch1.id); var winner = await database.scoreEntryDao.getWinner(
matchId: testMatch1.id,
);
expect(winner, isNull); expect(winner, isNull);
await database.scoreDao.setWinner( await database.scoreEntryDao.setWinner(
playerId: testPlayer1.id, playerId: testPlayer1.id,
matchId: testMatch1.id, matchId: testMatch1.id,
); );
winner = await database.scoreDao.getWinner(matchId: testMatch1.id); winner = await database.scoreEntryDao.getWinner(matchId: testMatch1.id);
expect(winner, isNotNull); expect(winner, isNotNull);
expect(winner!.id, testPlayer1.id); expect(winner!.id, testPlayer1.id);
}); });
test('removeWinner() works correctly', () async { test('removeWinner() works correctly', () async {
var removed = await database.scoreDao.removeWinner( var removed = await database.scoreEntryDao.removeWinner(
matchId: testMatch1.id, matchId: testMatch1.id,
); );
expect(removed, false); expect(removed, false);
await database.scoreDao.setWinner( await database.scoreEntryDao.setWinner(
playerId: testPlayer1.id, playerId: testPlayer1.id,
matchId: testMatch1.id, matchId: testMatch1.id,
); );
removed = await database.scoreDao.removeWinner(matchId: testMatch1.id); removed = await database.scoreEntryDao.removeWinner(
matchId: testMatch1.id,
);
expect(removed, true); expect(removed, true);
var winner = await database.scoreDao.getWinner(matchId: testMatch1.id); var winner = await database.scoreEntryDao.getWinner(
matchId: testMatch1.id,
);
expect(winner, isNull); expect(winner, isNull);
}); });
}); });
group('Handling Looser', () { group('Handling Looser', () {
test('hasLooser() works correctly', () async { test('hasLooser() works correctly', () async {
var hasLooser = await database.scoreDao.hasLooser( var hasLooser = await database.scoreEntryDao.hasLooser(
matchId: testMatch1.id, matchId: testMatch1.id,
); );
expect(hasLooser, false); expect(hasLooser, false);
await database.scoreDao.setLooser( await database.scoreEntryDao.setLooser(
playerId: testPlayer1.id, playerId: testPlayer1.id,
matchId: testMatch1.id, matchId: testMatch1.id,
); );
hasLooser = await database.scoreDao.hasLooser(matchId: testMatch1.id); hasLooser = await database.scoreEntryDao.hasLooser(
matchId: testMatch1.id,
);
expect(hasLooser, true); expect(hasLooser, true);
}); });
test('getLooser() returns correct winner', () async { test('getLooser() returns correct winner', () async {
var looser = await database.scoreDao.getLooser(matchId: testMatch1.id); var looser = await database.scoreEntryDao.getLooser(
matchId: testMatch1.id,
);
expect(looser, isNull); expect(looser, isNull);
await database.scoreDao.setLooser( await database.scoreEntryDao.setLooser(
playerId: testPlayer1.id, playerId: testPlayer1.id,
matchId: testMatch1.id, matchId: testMatch1.id,
); );
looser = await database.scoreDao.getLooser(matchId: testMatch1.id); looser = await database.scoreEntryDao.getLooser(matchId: testMatch1.id);
expect(looser, isNotNull); expect(looser, isNotNull);
expect(looser!.id, testPlayer1.id); expect(looser!.id, testPlayer1.id);
}); });
test('removeLooser() works correctly', () async { test('removeLooser() works correctly', () async {
var removed = await database.scoreDao.removeLooser( var removed = await database.scoreEntryDao.removeLooser(
matchId: testMatch1.id, matchId: testMatch1.id,
); );
expect(removed, false); expect(removed, false);
await database.scoreDao.setLooser( await database.scoreEntryDao.setLooser(
playerId: testPlayer1.id, playerId: testPlayer1.id,
matchId: testMatch1.id, matchId: testMatch1.id,
); );
removed = await database.scoreDao.removeLooser(matchId: testMatch1.id); removed = await database.scoreEntryDao.removeLooser(
matchId: testMatch1.id,
);
expect(removed, true); expect(removed, true);
var looser = await database.scoreDao.getLooser(matchId: testMatch1.id); var looser = await database.scoreEntryDao.getLooser(
matchId: testMatch1.id,
);
expect(looser, isNull); expect(looser, isNull);
}); });
}); });