-
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.
Merge branch 'mock-repositories' into new-post-view-model
Need the mock post repositorie to write the tests.
- Loading branch information
Showing
5 changed files
with
146 additions
and
15 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import "package:cloud_firestore/cloud_firestore.dart"; | ||
import "package:collection/collection.dart"; | ||
import "package:proxima/models/database/user/user_data.dart"; | ||
import "package:proxima/models/database/user/user_firestore.dart"; | ||
import "package:proxima/models/database/user/user_id_firestore.dart"; | ||
|
||
/// Helper class to generate mock user data to be used in tests | ||
class MockUserFirestore { | ||
List<UserData> generateUserData(int count) { | ||
return List.generate(count, (i) { | ||
return UserData( | ||
displayName: "display_name_$i", | ||
username: "username_$i", | ||
joinTime: Timestamp.fromMillisecondsSinceEpoch(1000 * i), | ||
); | ||
}); | ||
} | ||
|
||
List<UserFirestore> generateUserFirestore(int count) { | ||
return generateUserData(count).mapIndexed((i, data) { | ||
return UserFirestore( | ||
uid: UserIdFirestore(value: "user_id_$i"), | ||
data: data, | ||
); | ||
}).toList(); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import "package:cloud_firestore/cloud_firestore.dart"; | ||
import "package:flutter_test/flutter_test.dart"; | ||
import "package:mockito/mockito.dart"; | ||
import "package:proxima/models/database/post/post_data.dart"; | ||
import "package:proxima/models/database/post/post_firestore.dart"; | ||
import "package:proxima/models/database/post/post_id_firestore.dart"; | ||
import "package:proxima/models/database/post/post_location_firestore.dart"; | ||
import "package:proxima/models/database/user/user_id_firestore.dart"; | ||
import "package:proxima/services/database/post_repository_service.dart"; | ||
|
||
/// Not a coherent representation of a [PostFirestore] | ||
/// This is just here as a placeholder value that will be overridden in the tests | ||
final _mockEmptyFirestorePost = PostFirestore( | ||
id: const PostIdFirestore(value: ""), | ||
location: const PostLocationFirestore( | ||
geoPoint: GeoPoint(0, 0), | ||
geohash: "", | ||
), | ||
data: PostData( | ||
ownerId: const UserIdFirestore(value: ""), | ||
title: "", | ||
description: "", | ||
publicationTime: Timestamp.fromMillisecondsSinceEpoch(0), | ||
voteScore: 0, | ||
), | ||
); | ||
|
||
class MockPostRepositoryService extends Mock implements PostRepositoryService { | ||
@override | ||
Future<void> addPost(PostData postData, GeoPoint position) { | ||
return super.noSuchMethod( | ||
Invocation.method(#addPost, [postData, position]), | ||
returnValue: Future.value(), | ||
); | ||
} | ||
|
||
@override | ||
Future<void> deletePost(PostIdFirestore postId) { | ||
return super.noSuchMethod( | ||
Invocation.method(#deletePost, [postId]), | ||
returnValue: Future.value(), | ||
); | ||
} | ||
|
||
@override | ||
Future<PostFirestore> getPost(PostIdFirestore postId) { | ||
return super.noSuchMethod( | ||
Invocation.method(#getPost, [postId]), | ||
returnValue: Future.value(_mockEmptyFirestorePost), | ||
); | ||
} | ||
|
||
@override | ||
Future<List<PostFirestore>> getNearPosts(GeoPoint point, double radius) { | ||
return super.noSuchMethod( | ||
Invocation.method(#getNearPosts, [point, radius]), | ||
returnValue: Future.value(List<PostFirestore>.empty()), | ||
); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import "package:cloud_firestore/cloud_firestore.dart"; | ||
import "package:mockito/mockito.dart"; | ||
import "package:proxima/models/database/user/user_data.dart"; | ||
import "package:proxima/models/database/user/user_firestore.dart"; | ||
import "package:proxima/models/database/user/user_id_firestore.dart"; | ||
import "package:proxima/services/database/user_repository_service.dart"; | ||
|
||
/// Not a coherent representation of a [UserFirestore] | ||
/// This is just here as a placeholder value that will be overridden in the tests | ||
final _mockEmptyFirestoreUser = UserFirestore( | ||
data: UserData( | ||
displayName: "", | ||
username: "", | ||
joinTime: Timestamp.fromMillisecondsSinceEpoch(0), | ||
), | ||
uid: const UserIdFirestore(value: ""), | ||
); | ||
|
||
class MockUserRepositoryService extends Mock implements UserRepositoryService { | ||
@override | ||
Future<UserFirestore> getUser(UserIdFirestore uid) { | ||
return super.noSuchMethod( | ||
Invocation.method(#getUser, [uid]), | ||
returnValue: Future.value(_mockEmptyFirestoreUser), | ||
); | ||
} | ||
|
||
@override | ||
Future<void> setUser(UserIdFirestore uid, UserData userData) { | ||
return super.noSuchMethod( | ||
Invocation.method(#setUser, [uid, userData]), | ||
returnValue: Future.value(), | ||
); | ||
} | ||
|
||
@override | ||
Future<bool> doesUserExist(UserIdFirestore uid) { | ||
return super.noSuchMethod( | ||
Invocation.method(#doesUserExist, [uid]), | ||
returnValue: Future.value(false), | ||
); | ||
} | ||
} |
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