Skip to content

Commit

Permalink
updated index_test.dart
Browse files Browse the repository at this point in the history
  • Loading branch information
AyadLaouissi committed Apr 8, 2024
1 parent a9a9db8 commit 9e1494f
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions api/test/routes/game/leaderboard/initials/index_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,32 @@ void main() {
expect(response.statusCode, equals(HttpStatus.noContent));
});

test('responds with a 400 when mascot is not correct', () async {
final leaderboardPlayer = LeaderboardPlayer(
userId: 'user-id',
initials: 'AAA',
score: 10,
mascot: Mascots.dash,
streak: 2,
);

when(() => request.method).thenReturn(HttpMethod.post);

when(
() => leaderboardRepository.addPlayerToLeaderboard(
leaderboardPlayer: leaderboardPlayer,
),
).thenAnswer((_) async {});

when(request.json).thenAnswer(
(_) async => leaderboardPlayer.toJson()
..update('mascot', (value) => 'no-real-mascot'),
);

final response = await route.onRequest(context);
expect(response.statusCode, equals(HttpStatus.badRequest));
});

test('responds with a 400 when request is invalid', () async {
when(() => request.method).thenReturn(HttpMethod.post);
when(request.json).thenAnswer((_) async => {'test': 'test'});
Expand All @@ -106,6 +132,8 @@ void main() {
'userId': 'user-id',
'initials': 'CCC',
'score': 10,
'mascot': 'dash',
'streak': 2,
},
);

Expand All @@ -121,6 +149,8 @@ void main() {
'userId': 'user-id',
'initials': 'ccc',
'score': 10,
'mascot': 'dash',
'streak': 2,
},
);

Expand All @@ -137,6 +167,8 @@ void main() {
'userId': 'user-id',
'initials': 'aa',
'score': 10,
'mascot': 'dash',
'streak': 2,
},
);

Expand All @@ -154,6 +186,8 @@ void main() {
'userId': 'user-id',
'initials': 'aaaa',
'score': 10,
'mascot': 'dash',
'streak': 2,
},
);

Expand Down

0 comments on commit 9e1494f

Please sign in to comment.