Skip to content

Commit

Permalink
Post comments were invisible in Individual Post Page with Image (Pali…
Browse files Browse the repository at this point in the history
…sadoesFoundation#2350)

* Fixed Comment

* Fixed Comment

* Fixed Comment

* Fixed Comment

* Fixed Comment
  • Loading branch information
imshivam-gupta authored and Peter Harrison committed Feb 4, 2024
1 parent a1ed23c commit c9fa1a7
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 31 deletions.
3 changes: 1 addition & 2 deletions lib/services/comment_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down Expand Up @@ -62,7 +61,7 @@ class CommentService {
/// * `Future<List<dynamic>>`: promise that will be fulfilled with list of comments.
///
Future<List<dynamic>> getCommentsForPost(String postId) async {
final String getCommmentQuery = PostQueries().getPostById(postId);
final String getCommmentQuery = CommentQueries().getPostsComments(postId);

final dynamic result = await _dbFunctions.gqlAuthMutation(getCommmentQuery);

Expand Down
36 changes: 24 additions & 12 deletions lib/utils/comment_queries.dart
Original file line number Diff line number Diff line change
@@ -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!) {
Expand All @@ -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
}
}
}
}
}
""";
""";
}
}
2 changes: 1 addition & 1 deletion lib/utils/post_queries.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class PostQueries {
_id
}
comments{
_id,
_id,
text,
createdAt
creator{
Expand Down
11 changes: 5 additions & 6 deletions test/service_tests/comment_service_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -75,7 +74,7 @@ void main() {
test('test for getCommentsForPost', () async {
final dataBaseMutationFunctions = locator<DataBaseMutationFunctions>();
final String getCommmentQuery =
PostQueries().getPostById('Ayush s postid');
CommentQueries().getPostsComments('Ayush s postid');

when(
dataBaseMutationFunctions.gqlAuthMutation(getCommmentQuery),
Expand Down Expand Up @@ -167,7 +166,7 @@ void main() {
final dataBaseMutationFunctions = locator<DataBaseMutationFunctions>();

final String getCommmentQuery =
PostQueries().getPostById('Ayush s postid');
CommentQueries().getPostsComments('Ayush s postid');
when(
dataBaseMutationFunctions.gqlAuthMutation(getCommmentQuery),
).thenAnswer(
Expand Down Expand Up @@ -221,7 +220,7 @@ void main() {
final dataBaseMutationFunctions = locator<DataBaseMutationFunctions>();

final String getCommmentQuery =
PostQueries().getPostById('Ayush s postid');
CommentQueries().getPostsComments('Ayush s postid');
when(
dataBaseMutationFunctions.gqlAuthMutation(getCommmentQuery),
).thenAnswer(
Expand Down Expand Up @@ -273,7 +272,7 @@ void main() {
final dataBaseMutationFunctions = locator<DataBaseMutationFunctions>();

final String getCommmentQuery =
PostQueries().getPostById('Ayush s postid');
CommentQueries().getPostsComments('Ayush s postid');
when(
dataBaseMutationFunctions.gqlAuthMutation(getCommmentQuery),
).thenAnswer(
Expand Down Expand Up @@ -325,7 +324,7 @@ void main() {
final dataBaseMutationFunctions = locator<DataBaseMutationFunctions>();

final String getCommmentQuery =
PostQueries().getPostById('Ayush s postid');
CommentQueries().getPostsComments('Ayush s postid');
when(
dataBaseMutationFunctions.gqlAuthMutation(getCommmentQuery),
).thenAnswer(
Expand Down
20 changes: 10 additions & 10 deletions test/utils/comment_queries_test.dart
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
// 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';

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);
});
Expand Down
41 changes: 41 additions & 0 deletions test/utils/post_queries_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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!) {
Expand Down

0 comments on commit c9fa1a7

Please sign in to comment.