Implemented correct score handling

This commit is contained in:
2026-04-21 22:11:45 +02:00
parent 571d32f07a
commit 543b4d949e

View File

@@ -296,46 +296,25 @@ void main() {
final scoresJson = matchData['scores'] as Map<String, dynamic>; final scoresJson = matchData['scores'] as Map<String, dynamic>;
expect(scoresJson, isA<Map<String, dynamic>>()); expect(scoresJson, isA<Map<String, dynamic>>());
final scores = scoresJson.map( // Verify scores are properly structured (single score per player, not list)
(playerId, scoreList) => MapEntry( expect(scoresJson[testPlayer1.id], isNotNull);
playerId, expect(scoresJson[testPlayer2.id], isNotNull);
(scoreList as List)
.map((s) => ScoreEntry.fromJson(s as Map<String, dynamic>))
.toList(),
),
);
expect(scores, isA<Map<String, List<ScoreEntry>>>()); // Parse player 1 score
final player1ScoreJson =
scoresJson[testPlayer1.id] as Map<String, dynamic>;
final player1Score = ScoreEntry.fromJson(player1ScoreJson);
expect(player1Score.roundNumber, 1);
expect(player1Score.score, 10);
expect(player1Score.change, 10);
/* Player 1 scores */ // Parse player 2 score
// General structure final player2ScoreJson =
expect(scores[testPlayer1.id], isNotNull); scoresJson[testPlayer2.id] as Map<String, dynamic>;
expect(scores[testPlayer1.id]!.length, 2); final player2Score = ScoreEntry.fromJson(player2ScoreJson);
expect(player2Score.roundNumber, 1);
// Round 1 expect(player2Score.score, 15);
expect(scores[testPlayer1.id]![0].roundNumber, 1); expect(player2Score.change, 15);
expect(scores[testPlayer1.id]![0].score, 10);
expect(scores[testPlayer1.id]![0].change, 10);
// Round 2
expect(scores[testPlayer1.id]![1].roundNumber, 2);
expect(scores[testPlayer1.id]![1].score, 20);
expect(scores[testPlayer1.id]![1].change, 10);
/* Player 2 scores */
// General structure
expect(scores[testPlayer2.id], isNotNull);
expect(scores[testPlayer2.id]!.length, 2);
// Round 1
expect(scores[testPlayer2.id]![0].roundNumber, 1);
expect(scores[testPlayer2.id]![0].score, 15);
expect(scores[testPlayer2.id]![0].change, 15);
// Round 2
expect(scores[testPlayer2.id]![1].roundNumber, 2);
expect(scores[testPlayer2.id]![1].score, 25);
expect(scores[testPlayer2.id]![1].change, 10);
}); });
testWidgets('Match without group is handled correctly', (tester) async { testWidgets('Match without group is handled correctly', (tester) async {
@@ -898,14 +877,8 @@ void main() {
'playerIds': [testPlayer1.id, testPlayer2.id], 'playerIds': [testPlayer1.id, testPlayer2.id],
'notes': testMatch.notes, 'notes': testMatch.notes,
'scores': { 'scores': {
testPlayer1.id: [ testPlayer1.id: {'roundNumber': 1, 'score': 10, 'change': 10},
{'roundNumber': 1, 'score': 10, 'change': 10}, testPlayer2.id: {'roundNumber': 1, 'score': 15, 'change': 15},
{'roundNumber': 2, 'score': 20, 'change': 10},
],
testPlayer2.id: [
{'roundNumber': 1, 'score': 15, 'change': 15},
{'roundNumber': 2, 'score': 25, 'change': 10},
],
}, },
'createdAt': testMatch.createdAt.toIso8601String(), 'createdAt': testMatch.createdAt.toIso8601String(),
'endedAt': null, 'endedAt': null,