|
|
@ -245,73 +245,10 @@ void main() {
|
|
|
|
);
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
test(
|
|
|
|
|
|
|
|
'throws DeleteLeaderboardException '
|
|
|
|
|
|
|
|
'when deleting scores outside the top 10 fails', () async {
|
|
|
|
|
|
|
|
final deleteQuery = _MockQuery();
|
|
|
|
|
|
|
|
final deleteQuerySnapshot = _MockQuerySnapshot();
|
|
|
|
|
|
|
|
final newScore = LeaderboardEntryData(
|
|
|
|
|
|
|
|
playerInitials: 'ABC',
|
|
|
|
|
|
|
|
score: 15000,
|
|
|
|
|
|
|
|
character: CharacterType.android,
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
final leaderboardScores = [
|
|
|
|
|
|
|
|
10000,
|
|
|
|
|
|
|
|
9500,
|
|
|
|
|
|
|
|
9000,
|
|
|
|
|
|
|
|
8500,
|
|
|
|
|
|
|
|
8000,
|
|
|
|
|
|
|
|
7500,
|
|
|
|
|
|
|
|
7000,
|
|
|
|
|
|
|
|
6500,
|
|
|
|
|
|
|
|
6000,
|
|
|
|
|
|
|
|
5500,
|
|
|
|
|
|
|
|
5000,
|
|
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
final deleteDocumentSnapshots = [5500, 5000].map((score) {
|
|
|
|
|
|
|
|
final queryDocumentSnapshot = _MockQueryDocumentSnapshot();
|
|
|
|
|
|
|
|
when(queryDocumentSnapshot.data).thenReturn(<String, dynamic>{
|
|
|
|
|
|
|
|
'character': 'dash',
|
|
|
|
|
|
|
|
'playerInitials': 'AAA',
|
|
|
|
|
|
|
|
'score': score
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
when(() => queryDocumentSnapshot.id).thenReturn('id$score');
|
|
|
|
|
|
|
|
when(() => queryDocumentSnapshot.reference)
|
|
|
|
|
|
|
|
.thenReturn(documentReference);
|
|
|
|
|
|
|
|
return queryDocumentSnapshot;
|
|
|
|
|
|
|
|
}).toList();
|
|
|
|
|
|
|
|
when(deleteQuery.get).thenAnswer((_) async => deleteQuerySnapshot);
|
|
|
|
|
|
|
|
when(() => deleteQuerySnapshot.docs)
|
|
|
|
|
|
|
|
.thenReturn(deleteDocumentSnapshots);
|
|
|
|
|
|
|
|
final queryDocumentSnapshots = leaderboardScores.map((score) {
|
|
|
|
|
|
|
|
final queryDocumentSnapshot = _MockQueryDocumentSnapshot();
|
|
|
|
|
|
|
|
when(queryDocumentSnapshot.data).thenReturn(<String, dynamic>{
|
|
|
|
|
|
|
|
'character': 'dash',
|
|
|
|
|
|
|
|
'playerInitials': 'AAA',
|
|
|
|
|
|
|
|
'score': score
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
when(() => queryDocumentSnapshot.id).thenReturn('id$score');
|
|
|
|
|
|
|
|
when(() => queryDocumentSnapshot.reference)
|
|
|
|
|
|
|
|
.thenReturn(documentReference);
|
|
|
|
|
|
|
|
return queryDocumentSnapshot;
|
|
|
|
|
|
|
|
}).toList();
|
|
|
|
|
|
|
|
when(
|
|
|
|
|
|
|
|
() => collectionReference.where('score', isLessThanOrEqualTo: 5500),
|
|
|
|
|
|
|
|
).thenAnswer((_) => deleteQuery);
|
|
|
|
|
|
|
|
when(() => documentReference.delete()).thenThrow(Exception('oops'));
|
|
|
|
|
|
|
|
when(() => querySnapshot.docs).thenReturn(queryDocumentSnapshots);
|
|
|
|
|
|
|
|
expect(
|
|
|
|
|
|
|
|
() => leaderboardRepository.addLeaderboardEntry(newScore),
|
|
|
|
|
|
|
|
throwsA(isA<DeleteLeaderboardException>()),
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
test(
|
|
|
|
test(
|
|
|
|
'saves the new score when there are more than 10 scores in the '
|
|
|
|
'saves the new score when there are more than 10 scores in the '
|
|
|
|
'leaderboard and the new score is higher than the lowest top 10, and '
|
|
|
|
'leaderboard and the new score is higher than the lowest top 10',
|
|
|
|
'deletes the scores that are not in the top 10 anymore', () async {
|
|
|
|
() async {
|
|
|
|
final deleteQuery = _MockQuery();
|
|
|
|
|
|
|
|
final deleteQuerySnapshot = _MockQuerySnapshot();
|
|
|
|
|
|
|
|
final newScore = LeaderboardEntryData(
|
|
|
|
final newScore = LeaderboardEntryData(
|
|
|
|
playerInitials: 'ABC',
|
|
|
|
playerInitials: 'ABC',
|
|
|
|
score: 15000,
|
|
|
|
score: 15000,
|
|
|
@ -330,21 +267,6 @@ void main() {
|
|
|
|
5500,
|
|
|
|
5500,
|
|
|
|
5000,
|
|
|
|
5000,
|
|
|
|
];
|
|
|
|
];
|
|
|
|
final deleteDocumentSnapshots = [5500, 5000].map((score) {
|
|
|
|
|
|
|
|
final queryDocumentSnapshot = _MockQueryDocumentSnapshot();
|
|
|
|
|
|
|
|
when(queryDocumentSnapshot.data).thenReturn(<String, dynamic>{
|
|
|
|
|
|
|
|
'character': 'dash',
|
|
|
|
|
|
|
|
'playerInitials': 'AAA',
|
|
|
|
|
|
|
|
'score': score
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
when(() => queryDocumentSnapshot.id).thenReturn('id$score');
|
|
|
|
|
|
|
|
when(() => queryDocumentSnapshot.reference)
|
|
|
|
|
|
|
|
.thenReturn(documentReference);
|
|
|
|
|
|
|
|
return queryDocumentSnapshot;
|
|
|
|
|
|
|
|
}).toList();
|
|
|
|
|
|
|
|
when(deleteQuery.get).thenAnswer((_) async => deleteQuerySnapshot);
|
|
|
|
|
|
|
|
when(() => deleteQuerySnapshot.docs)
|
|
|
|
|
|
|
|
.thenReturn(deleteDocumentSnapshots);
|
|
|
|
|
|
|
|
final queryDocumentSnapshots = leaderboardScores.map((score) {
|
|
|
|
final queryDocumentSnapshots = leaderboardScores.map((score) {
|
|
|
|
final queryDocumentSnapshot = _MockQueryDocumentSnapshot();
|
|
|
|
final queryDocumentSnapshot = _MockQueryDocumentSnapshot();
|
|
|
|
when(queryDocumentSnapshot.data).thenReturn(<String, dynamic>{
|
|
|
|
when(queryDocumentSnapshot.data).thenReturn(<String, dynamic>{
|
|
|
@ -357,15 +279,10 @@ void main() {
|
|
|
|
.thenReturn(documentReference);
|
|
|
|
.thenReturn(documentReference);
|
|
|
|
return queryDocumentSnapshot;
|
|
|
|
return queryDocumentSnapshot;
|
|
|
|
}).toList();
|
|
|
|
}).toList();
|
|
|
|
when(
|
|
|
|
|
|
|
|
() => collectionReference.where('score', isLessThanOrEqualTo: 5500),
|
|
|
|
|
|
|
|
).thenAnswer((_) => deleteQuery);
|
|
|
|
|
|
|
|
when(() => documentReference.delete())
|
|
|
|
|
|
|
|
.thenAnswer((_) async => Future.value());
|
|
|
|
|
|
|
|
when(() => querySnapshot.docs).thenReturn(queryDocumentSnapshots);
|
|
|
|
when(() => querySnapshot.docs).thenReturn(queryDocumentSnapshots);
|
|
|
|
await leaderboardRepository.addLeaderboardEntry(newScore);
|
|
|
|
await leaderboardRepository.addLeaderboardEntry(newScore);
|
|
|
|
verify(() => collectionReference.add(newScore.toJson())).called(1);
|
|
|
|
verify(() => collectionReference.add(newScore.toJson())).called(1);
|
|
|
|
verify(() => documentReference.delete()).called(2);
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|