Skip to content

Commit

Permalink
test: user_repository 테스트
Browse files Browse the repository at this point in the history
  • Loading branch information
w8385 committed Jan 7, 2024
1 parent 0a9f6b3 commit 02858e0
Showing 1 changed file with 162 additions and 0 deletions.
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);
});
});
});
}

0 comments on commit 02858e0

Please sign in to comment.