-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
162 additions
and
0 deletions.
There are no files selected for viewing
162 changes: 162 additions & 0 deletions
162
my_solved/packages/repositories/user_repository/test/user_repository_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,163 @@ | ||
import 'package:mocktail/mocktail.dart'; | ||
import 'package:solved_api/solved_api.dart' as solved_api; | ||
import 'package:test/test.dart'; | ||
import 'package:user_repository/user_repository.dart'; | ||
|
||
class MockSolvedApiClient extends Mock implements solved_api.SolvedApiClient {} | ||
|
||
class MockUser extends Mock implements solved_api.User {} | ||
|
||
class MockOrganization extends Mock implements solved_api.Organization {} | ||
|
||
class MockBadge extends Mock implements solved_api.Badge {} | ||
|
||
class MockStreak extends Mock implements solved_api.Streak {} | ||
|
||
class MockProblem extends Mock implements solved_api.Problem {} | ||
|
||
class MockTagRating extends Mock implements solved_api.TagRating {} | ||
|
||
void main() { | ||
group('UserRepository', () { | ||
late solved_api.SolvedApiClient solvedApiClient; | ||
late UserRepository userRepository; | ||
|
||
setUp(() { | ||
solvedApiClient = MockSolvedApiClient(); | ||
userRepository = UserRepository(solvedApiClient: solvedApiClient); | ||
}); | ||
|
||
group('getUser', () { | ||
const handle = 'w8385'; | ||
|
||
test('calls userShow with correct handle', () async { | ||
final user = MockUser(); | ||
when(() => solvedApiClient.userShow(handle)) | ||
.thenAnswer((_) async => user); | ||
|
||
await userRepository.getUser(handle); | ||
|
||
verify(() => solvedApiClient.userShow(handle)).called(1); | ||
}); | ||
|
||
test('returns correct user on success', () async { | ||
final user = MockUser(); | ||
when(() => solvedApiClient.userShow(handle)) | ||
.thenAnswer((_) async => user); | ||
|
||
expect(await userRepository.getUser(handle), user); | ||
}); | ||
}); | ||
|
||
group('getOrganizations', () { | ||
const handle = 'w8385'; | ||
|
||
test('calls userOrganizations with correct handle', () async { | ||
final organizations = [MockOrganization()]; | ||
when(() => solvedApiClient.userOrganizations(handle)) | ||
.thenAnswer((_) async => organizations); | ||
|
||
await userRepository.getOrganizations(handle); | ||
|
||
verify(() => solvedApiClient.userOrganizations(handle)).called(1); | ||
}); | ||
|
||
test('returns correct organizations on success', () async { | ||
final organizations = [MockOrganization()]; | ||
when(() => solvedApiClient.userOrganizations(handle)) | ||
.thenAnswer((_) async => organizations); | ||
|
||
expect(await userRepository.getOrganizations(handle), organizations); | ||
}); | ||
}); | ||
|
||
group('getBadges', () { | ||
const handle = 'w8385'; | ||
|
||
test('calls userAvailableBadges with correct handle', () async { | ||
final badges = [MockBadge()]; | ||
when(() => solvedApiClient.userAvailableBadges(handle)) | ||
.thenAnswer((_) async => badges); | ||
|
||
await userRepository.getBadges(handle); | ||
|
||
verify(() => solvedApiClient.userAvailableBadges(handle)).called(1); | ||
}); | ||
|
||
test('returns correct badges on success', () async { | ||
final badges = [MockBadge()]; | ||
when(() => solvedApiClient.userAvailableBadges(handle)) | ||
.thenAnswer((_) async => badges); | ||
|
||
expect(await userRepository.getBadges(handle), badges); | ||
}); | ||
}); | ||
|
||
group('getStreak', () { | ||
const handle = 'w8385'; | ||
const topic = 'default'; | ||
|
||
test('calls userGrass with correct handle and topic', () async { | ||
final streak = MockStreak(); | ||
when(() => solvedApiClient.userGrass(handle, topic)) | ||
.thenAnswer((_) async => streak); | ||
|
||
await userRepository.getStreak(handle, topic); | ||
|
||
verify(() => solvedApiClient.userGrass(handle, topic)).called(1); | ||
}); | ||
|
||
test('returns correct streak on success', () async { | ||
final streak = MockStreak(); | ||
when(() => solvedApiClient.userGrass(handle, topic)) | ||
.thenAnswer((_) async => streak); | ||
|
||
expect(await userRepository.getStreak(handle, topic), streak); | ||
}); | ||
}); | ||
|
||
group('getTopProblems', () { | ||
const handle = 'w8385'; | ||
|
||
test('calls userTop100 with correct handle', () async { | ||
final problems = [MockProblem()]; | ||
when(() => solvedApiClient.userTop100(handle)) | ||
.thenAnswer((_) async => problems); | ||
|
||
await userRepository.getTopProblems(handle); | ||
|
||
verify(() => solvedApiClient.userTop100(handle)).called(1); | ||
}); | ||
|
||
test('returns correct problems on success', () async { | ||
final problems = [MockProblem()]; | ||
when(() => solvedApiClient.userTop100(handle)) | ||
.thenAnswer((_) async => problems); | ||
|
||
expect(await userRepository.getTopProblems(handle), problems); | ||
}); | ||
}); | ||
|
||
group('getTagRatings', () { | ||
const handle = 'w8385'; | ||
|
||
test('calls userTagRatings with correct handle', () async { | ||
final tagRatings = [MockTagRating()]; | ||
when(() => solvedApiClient.userTagRatings(handle)) | ||
.thenAnswer((_) async => tagRatings); | ||
|
||
await userRepository.getTagRatings(handle); | ||
|
||
verify(() => solvedApiClient.userTagRatings(handle)).called(1); | ||
}); | ||
|
||
test('returns correct tagRatings on success', () async { | ||
final tagRatings = [MockTagRating()]; | ||
when(() => solvedApiClient.userTagRatings(handle)) | ||
.thenAnswer((_) async => tagRatings); | ||
|
||
expect(await userRepository.getTagRatings(handle), tagRatings); | ||
}); | ||
}); | ||
}); | ||
} |