diff --git a/test/viewmodels/home_view_model_integration_test.dart b/test/viewmodels/home_view_model_integration_test.dart index 94c40941..a717b199 100644 --- a/test/viewmodels/home_view_model_integration_test.dart +++ b/test/viewmodels/home_view_model_integration_test.dart @@ -23,8 +23,6 @@ void main() { late MockGeoLocationService geoLocationService; late FakeFirebaseFirestore fakeFireStore; - late MockPostFirestore mockPostFirestore; - late MockUserFirestore mockUserFirestore; late UserRepositoryService userRepo; late PostRepositoryService postRepo; @@ -52,9 +50,6 @@ void main() { ], ); - mockPostFirestore = MockPostFirestore(); - mockUserFirestore = MockUserFirestore(); - when(geoLocationService.getCurrentPosition()).thenAnswer( (_) async => userPosition, ); @@ -67,7 +62,7 @@ void main() { }); test("No posts are returned when they are far way from the user", () async { - final postData = mockPostFirestore.generatePostData(1)[0]; + final postData = MockPostFirestore.generatePostData(1)[0]; await postRepo.addPost( postData, @@ -81,11 +76,11 @@ void main() { test("Single near post returned correctly", () async { // Add the post owner to the database - final owner = mockUserFirestore.generateUserFirestore(1)[0]; + final owner = MockUserFirestore.generateUserFirestore(1)[0]; await userRepo.setUser(owner.uid, owner.data); // Add the post to the database - final postData = mockPostFirestore.generatePostData(1).map((postData) { + final postData = MockPostFirestore.generatePostData(1).map((postData) { return PostData( ownerId: owner.uid, // Map to the owner title: postData.title, @@ -121,7 +116,7 @@ void main() { test("Throws an exception when the owner of a post is not found", () async { // Add the post to the database - final postData = mockPostFirestore.generatePostData(1).first; + final postData = MockPostFirestore.generatePostData(1).first; await postRepo.addPost( postData, @@ -140,14 +135,13 @@ void main() { const nbPosts = 10; // Add the post owners to the database - final owners = mockUserFirestore.generateUserFirestore(nbOwners); + final owners = MockUserFirestore.generateUserFirestore(nbOwners); for (final owner in owners) { await userRepo.setUser(owner.uid, owner.data); } // Add the posts to the database - final postDatas = mockPostFirestore - .generatePostData(nbPosts) + final postDatas = MockPostFirestore.generatePostData(nbPosts) .mapIndexed( (index, element) => PostData( ownerId: owners[index % nbOwners].uid, // Map to an owner diff --git a/test/viewmodels/home_view_model_unit_test.dart b/test/viewmodels/home_view_model_unit_test.dart index 1fde3004..bb57c397 100644 --- a/test/viewmodels/home_view_model_unit_test.dart +++ b/test/viewmodels/home_view_model_unit_test.dart @@ -23,8 +23,6 @@ void main() { late UserRepositoryService userRepository; late ProviderContainer container; - late MockPostFirestore mockPostFirestore; - late MockUserFirestore mockUserFirestore; const point = GeoPoint(0, 0); @@ -46,9 +44,6 @@ void main() { ), ], ); - - mockPostFirestore = MockPostFirestore(); - mockUserFirestore = MockUserFirestore(); }); test("No posts are returned when no posts returned by the repository", @@ -69,9 +64,8 @@ void main() { test( "Post is returned correctly when single post is returned by the repository", () async { - final owner = mockUserFirestore.generateUserFirestore(1)[0]; - final postData = mockPostFirestore - .generatePostData(1) + final owner = MockUserFirestore.generateUserFirestore(1)[0]; + final postData = MockPostFirestore.generatePostData(1) .map( (postData) => PostData( ownerId: owner.uid, @@ -82,7 +76,7 @@ void main() { ), ) .toList()[0]; - final post = mockPostFirestore.createPostAt(postData, point); + final post = MockPostFirestore.createPostAt(postData, point); when(userRepository.getUser(post.data.ownerId)).thenAnswer( (_) async => owner, @@ -118,9 +112,8 @@ void main() { "Posts are returned correctly when multiple posts are returned by the repository with all posts corresponding to the same owner", () async { // Generate the data for the test - final owner = mockUserFirestore.generateUserFirestore(1)[0]; - final postsData = mockPostFirestore - .generatePostData(10) + final owner = MockUserFirestore.generateUserFirestore(1)[0]; + final postsData = MockPostFirestore.generatePostData(10) .map( (postData) => PostData( ownerId: owner.uid, @@ -133,7 +126,7 @@ void main() { .toList(); final posts = postsData.map((data) { - return mockPostFirestore.createPostAt(data, point); + return MockPostFirestore.createPostAt(data, point); }).toList(); final expectedPosts = postsData.map((data) { @@ -172,20 +165,20 @@ void main() { const numberOfPosts = 10; // Generate the data for the test - final owners = mockUserFirestore.generateUserFirestore(numberOfPosts); + final owners = MockUserFirestore.generateUserFirestore(numberOfPosts); final postsData = - mockPostFirestore.generatePostData(numberOfPosts).mapIndexed( - (index, element) => PostData( - ownerId: owners[index].uid, - title: element.title, - description: element.description, - publicationTime: element.publicationTime, - voteScore: element.voteScore, - ), - ); + MockPostFirestore.generatePostData(numberOfPosts).mapIndexed( + (index, element) => PostData( + ownerId: owners[index].uid, + title: element.title, + description: element.description, + publicationTime: element.publicationTime, + voteScore: element.voteScore, + ), + ); final posts = postsData.map((data) { - return mockPostFirestore.createPostAt(data, point); + return MockPostFirestore.createPostAt(data, point); }).toList(); final expectedPosts = postsData.mapIndexed(