Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
up2code committed Jan 13, 2021
1 parent ce3a95c commit 232b2b8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
4 changes: 3 additions & 1 deletion lib/src/services/auth_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ class AuthService extends GetxService {

final currentUser = UserModel().obs;

AuthService({this.httpService, this.appDirectory});
AuthService({this.httpService, this.appDirectory})
: assert(httpService != null),
assert(appDirectory != null);

Future<UserCookie> login({
String username,
Expand Down
11 changes: 9 additions & 2 deletions test/services/auth_service_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ import 'package:matcher/matcher.dart';
import 'package:mockito/mockito.dart';
import 'package:vocadb_app/models.dart';
import 'package:vocadb_app/services.dart';
import 'package:vocadb_app/utils.dart';

class MockHttpService extends Mock implements HttpService {}

class MockAppDirectory extends Mock implements AppDirectory {}

void main() {
group('assertion', () {
test('should assert if null', () {
Expand All @@ -19,7 +22,9 @@ void main() {

group('login', () {
final mockHttpService = MockHttpService();
final mockAuthService = AuthService(httpService: mockHttpService);
final mockAppDirectory = MockAppDirectory();
final mockAuthService = AuthService(
httpService: mockHttpService, appDirectory: mockAppDirectory);

test('should return user cookie', () async {
final UserCookie mockUserCookie = UserCookie(cookies: []);
Expand All @@ -34,7 +39,9 @@ void main() {

group('getCurrent', () {
final mockHttpService = MockHttpService();
final mockAuthService = AuthService(httpService: mockHttpService);
final mockAppDirectory = MockAppDirectory();
final mockAuthService = AuthService(
httpService: mockHttpService, appDirectory: mockAppDirectory);

test('should return current user', () async {
UserModel mockUser = UserModel.fromJson({"id": 1, "name": "up2up"});
Expand Down

0 comments on commit 232b2b8

Please sign in to comment.