From 38682c8319b7b3a82e62f87e0b37e139a65d95bd Mon Sep 17 00:00:00 2001 From: Shivam Gupta Date: Sun, 4 Feb 2024 01:16:07 +0530 Subject: [PATCH] Post comments were invisible in Individual Post Page with Image (#2350) * Fixed Comment * Fixed Comment * Fixed Comment * Fixed Comment * Fixed Comment --- lib/services/comment_service.dart | 3 +- lib/utils/comment_queries.dart | 36 +++++++++++------ lib/utils/post_queries.dart | 2 +- test/service_tests/comment_service_test.dart | 11 +++--- test/utils/comment_queries_test.dart | 20 +++++----- test/utils/post_queries_test.dart | 41 ++++++++++++++++++++ 6 files changed, 82 insertions(+), 31 deletions(-) diff --git a/lib/services/comment_service.dart b/lib/services/comment_service.dart index 7b25338eb..b118b6c00 100644 --- a/lib/services/comment_service.dart +++ b/lib/services/comment_service.dart @@ -4,7 +4,6 @@ import 'package:talawa/locator.dart'; import 'package:talawa/services/database_mutation_functions.dart'; import 'package:talawa/services/navigation_service.dart'; import 'package:talawa/utils/comment_queries.dart'; -import 'package:talawa/utils/post_queries.dart'; /// CommentService class have different member functions which provides service in the context of commenting. /// @@ -62,7 +61,7 @@ class CommentService { /// * `Future>`: promise that will be fulfilled with list of comments. /// Future> getCommentsForPost(String postId) async { - final String getCommmentQuery = PostQueries().getPostById(postId); + final String getCommmentQuery = CommentQueries().getPostsComments(postId); final dynamic result = await _dbFunctions.gqlAuthMutation(getCommmentQuery); diff --git a/lib/utils/comment_queries.dart b/lib/utils/comment_queries.dart index 6c6b36bc3..fa11f6c18 100644 --- a/lib/utils/comment_queries.dart +++ b/lib/utils/comment_queries.dart @@ -1,9 +1,12 @@ -// ignore_for_file: talawa_api_doc -// ignore_for_file: talawa_good_doc_comments - ///This class creates the queries dealing with comments. class CommentQueries { - //Returns a query for creating a comment + /// Creating a comment. + /// + /// **params**: + /// None + /// + /// **returns**: + /// * `String`: The query for creating a comment String createComment() { return """ mutation createComment(\$postId: ID!, \$text: String!) { @@ -18,20 +21,29 @@ class CommentQueries { """; } - //Returns a query to get the comments of a post + /// Get all comments for a post. + /// + /// **params**: + /// * `postId`: The id of the post to get comments for. + /// + /// **returns**: + /// * `String`: The query for getting all comments for a post. String getPostsComments(String postId) { return """ - query{ - commentsByPost(id: "$postId"){ - _id - text - createdAt + query { + post(id: "$postId") + { _id, + comments{ + _id, + text, + createdAt creator{ firstName lastName } + } + } } - } - """; +"""; } } diff --git a/lib/utils/post_queries.dart b/lib/utils/post_queries.dart index 365c940d0..4d763032d 100644 --- a/lib/utils/post_queries.dart +++ b/lib/utils/post_queries.dart @@ -73,7 +73,7 @@ class PostQueries { _id } comments{ - _id, + _id, text, createdAt creator{ diff --git a/test/service_tests/comment_service_test.dart b/test/service_tests/comment_service_test.dart index 71233621d..4a8af5695 100644 --- a/test/service_tests/comment_service_test.dart +++ b/test/service_tests/comment_service_test.dart @@ -6,7 +6,6 @@ import 'package:talawa/locator.dart'; import 'package:talawa/services/comment_service.dart'; import 'package:talawa/services/database_mutation_functions.dart'; import 'package:talawa/utils/comment_queries.dart'; -import 'package:talawa/utils/post_queries.dart'; import '../helpers/test_helpers.dart'; void main() { @@ -75,7 +74,7 @@ void main() { test('test for getCommentsForPost', () async { final dataBaseMutationFunctions = locator(); final String getCommmentQuery = - PostQueries().getPostById('Ayush s postid'); + CommentQueries().getPostsComments('Ayush s postid'); when( dataBaseMutationFunctions.gqlAuthMutation(getCommmentQuery), @@ -167,7 +166,7 @@ void main() { final dataBaseMutationFunctions = locator(); final String getCommmentQuery = - PostQueries().getPostById('Ayush s postid'); + CommentQueries().getPostsComments('Ayush s postid'); when( dataBaseMutationFunctions.gqlAuthMutation(getCommmentQuery), ).thenAnswer( @@ -221,7 +220,7 @@ void main() { final dataBaseMutationFunctions = locator(); final String getCommmentQuery = - PostQueries().getPostById('Ayush s postid'); + CommentQueries().getPostsComments('Ayush s postid'); when( dataBaseMutationFunctions.gqlAuthMutation(getCommmentQuery), ).thenAnswer( @@ -273,7 +272,7 @@ void main() { final dataBaseMutationFunctions = locator(); final String getCommmentQuery = - PostQueries().getPostById('Ayush s postid'); + CommentQueries().getPostsComments('Ayush s postid'); when( dataBaseMutationFunctions.gqlAuthMutation(getCommmentQuery), ).thenAnswer( @@ -325,7 +324,7 @@ void main() { final dataBaseMutationFunctions = locator(); final String getCommmentQuery = - PostQueries().getPostById('Ayush s postid'); + CommentQueries().getPostsComments('Ayush s postid'); when( dataBaseMutationFunctions.gqlAuthMutation(getCommmentQuery), ).thenAnswer( diff --git a/test/utils/comment_queries_test.dart b/test/utils/comment_queries_test.dart index f73df7de7..d9b34b9b7 100644 --- a/test/utils/comment_queries_test.dart +++ b/test/utils/comment_queries_test.dart @@ -1,6 +1,3 @@ -// ignore_for_file: talawa_api_doc -// ignore_for_file: talawa_good_doc_comments - import 'package:flutter_test/flutter_test.dart'; import 'package:talawa/utils/comment_queries.dart'; @@ -8,18 +5,21 @@ void main() { group("Tests for comment_queries.dart", () { test("Check if getPostsComments works correctly", () { const data = """ - query{ - commentsByPost(id: "abc"){ - _id - text - createdAt + query { + post(id: "abc") + { _id, + comments{ + _id, + text, + createdAt creator{ firstName lastName } + } + } } - } - """; +"""; final fnData = CommentQueries().getPostsComments("abc"); expect(fnData, data); }); diff --git a/test/utils/post_queries_test.dart b/test/utils/post_queries_test.dart index 5f5029d24..203d193ab 100644 --- a/test/utils/post_queries_test.dart +++ b/test/utils/post_queries_test.dart @@ -54,6 +54,47 @@ void main() { expect(fnData, data); }); + test("Check if getPostById works correctly", () { + const data = """ + query { + post(id: "abc") + { + _id + text + createdAt + imageUrl + videoUrl + title + commentCount + likeCount + creator{ + _id + firstName + lastName + image + } + organization{ + _id + } + likedBy{ + _id + } + comments{ + _id, + text, + createdAt + creator{ + firstName + lastName + } + } + } + } +"""; + final fnData = PostQueries().getPostById("abc"); + expect(fnData, data); + }); + test("Check if removeLike works correctly", () { const data = """ mutation unlikePost(\$postID: ID!) {