Skip to content

Commit

Permalink
fix(mock): make methods of MockPostFirestore static
Browse files Browse the repository at this point in the history
  • Loading branch information
yoannLafore committed Apr 8, 2024
1 parent dcc541d commit 14fec27
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
4 changes: 2 additions & 2 deletions test/models/database/post/mock_post_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import "package:proxima/models/database/user/user_id_firestore.dart";

/// Helper class to create mock post data to be used in tests
class MockPostFirestore {
PostFirestore createPostAt(
static PostFirestore createPostAt(
PostData data,
GeoPoint location, {
id = "post_id",
Expand All @@ -25,7 +25,7 @@ class MockPostFirestore {
);
}

List<PostData> generatePostData(int count) {
static List<PostData> generatePostData(int count) {
return List.generate(count, (i) {
return PostData(
description: "description_$i",
Expand Down
24 changes: 11 additions & 13 deletions test/services/database/post_repository_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ void main() {
group("Post Repository testing", () {
late FakeFirebaseFirestore firestore;
late PostRepositoryService postRepository;
late MockPostFirestore mockPostFirstore;

const kmRadius = 0.1;

Expand Down Expand Up @@ -46,7 +45,6 @@ void main() {
postRepository = PostRepositoryService(
firestore: firestore,
);
mockPostFirstore = MockPostFirestore();
});

final post = PostFirestore(
Expand Down Expand Up @@ -93,8 +91,8 @@ void main() {
const userPosition = GeoPoint(40, 20);
const postPoint = GeoPoint(40.0001, 20.0001); // 14m away

final postData = mockPostFirstore.generatePostData(1).first;
final expectedPost = mockPostFirstore.createPostAt(postData, postPoint);
final postData = MockPostFirestore.generatePostData(1).first;
final expectedPost = MockPostFirestore.createPostAt(postData, postPoint);

await setPostFirestore(expectedPost);

Expand All @@ -108,8 +106,8 @@ void main() {

const postPoint = GeoPoint(40.001, 20.001); // about 140m away

final postData = mockPostFirstore.generatePostData(1).first;
final expectedPost = mockPostFirstore.createPostAt(postData, postPoint);
final postData = MockPostFirestore.generatePostData(1).first;
final expectedPost = MockPostFirestore.createPostAt(postData, postPoint);

await setPostFirestore(expectedPost);

Expand All @@ -125,8 +123,8 @@ void main() {
52.001188563379976 - 1e-5,
); // just below 100m away

final postData = mockPostFirstore.generatePostData(1).first;
final expectedPost = mockPostFirstore.createPostAt(postData, postPoint);
final postData = MockPostFirestore.generatePostData(1).first;
final expectedPost = MockPostFirestore.createPostAt(postData, postPoint);

await setPostFirestore(expectedPost);

Expand All @@ -142,8 +140,8 @@ void main() {
52.001188563379976 + 1e-5,
); // just above 100m away

final postData = mockPostFirstore.generatePostData(1).first;
final expectedPost = mockPostFirstore.createPostAt(postData, postPoint);
final postData = MockPostFirestore.generatePostData(1).first;
final expectedPost = MockPostFirestore.createPostAt(postData, postPoint);

await setPostFirestore(expectedPost);

Expand All @@ -157,7 +155,7 @@ void main() {
final userGeoFirePoint =
GeoFirePoint(userPosition.latitude, userPosition.longitude);

final postData = mockPostFirstore.generatePostData(1).first;
final postData = MockPostFirestore.generatePostData(1).first;

await postRepository.addPost(postData, userPosition);

Expand Down Expand Up @@ -186,10 +184,10 @@ void main() {
return GeoPoint(40.0001 + i * 0.0001, 20.0001 + i * 0.0001);
});

final postsData = mockPostFirstore.generatePostData(nbPosts);
final postsData = MockPostFirestore.generatePostData(nbPosts);

final allPosts = List.generate(nbPosts, (i) {
return mockPostFirstore.createPostAt(
return MockPostFirestore.createPostAt(
postsData[i],
pointList[i],
id: "post_$i",
Expand Down

0 comments on commit 14fec27

Please sign in to comment.