Skip to content
This repository was archived by the owner on Nov 8, 2022. It is now read-only.

Commit ea2598f

Browse files
committed
refactor(article-comments): fix broken tests
1 parent a0ac4be commit ea2598f

File tree

7 files changed

+5
-119
lines changed

7 files changed

+5
-119
lines changed

lib/groupher_server/cms/cms.ex

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,6 @@ defmodule GroupherServer.CMS do
146146
# >> like / undo like
147147
defdelegate like_comment(thread, comment, user), to: CommentReaction
148148
defdelegate undo_like_comment(thread, comment, user), to: CommentReaction
149-
# >> dislike / undo dislike
150-
defdelegate dislike_comment(thread, comment, user), to: CommentReaction
151-
defdelegate undo_dislike_comment(thread, comment, user), to: CommentReaction
152149

153150
# Passport CURD
154151
defdelegate stamp_passport(rules, user), to: PassportCURD

lib/groupher_server/cms/delegates/comment_reaction.ex

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,6 @@ defmodule GroupherServer.CMS.Delegate.CommentReaction do
1212
undo_feel_comment(thread, comment_id, user_id, :like)
1313
end
1414

15-
def dislike_comment(thread, comment_id, %Accounts.User{id: user_id}) do
16-
feel_comment(thread, comment_id, user_id, :dislike)
17-
end
18-
19-
def undo_dislike_comment(thread, comment_id, %Accounts.User{id: user_id}) do
20-
undo_feel_comment(thread, comment_id, user_id, :dislike)
21-
end
22-
2315
defp merge_thread_comment_id(:post_comment, comment_id), do: %{post_comment_id: comment_id}
2416
defp merge_thread_comment_id(:job_comment, comment_id), do: %{job_comment_id: comment_id}
2517
defp merge_thread_comment_id(:repo_comment, comment_id), do: %{repo_comment_id: comment_id}

lib/groupher_server/cms/embeds/article_comment_meta.ex

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ defmodule GroupherServer.CMS.Embeds.ArticleCommentMeta do
77
alias CMS.Embeds
88

99
@default_meta %{
10+
is_article_author_upvoted: false,
11+
is_solution: false,
1012
report_count: 0,
1113
report_users: []
1214
}
@@ -15,6 +17,9 @@ defmodule GroupherServer.CMS.Embeds.ArticleCommentMeta do
1517
def default_meta(), do: @default_meta
1618

1719
embedded_schema do
20+
field(:is_article_author_upvoted, :boolean, default: false)
21+
field(:is_solution, :boolean, default: false)
22+
1823
field(:report_count, :integer, default: 0)
1924
embeds_many(:report_users, Embeds.User, on_replace: :delete)
2025
end

lib/groupher_server_web/resolvers/cms_resolver.ex

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -386,14 +386,6 @@ defmodule GroupherServerWeb.Resolvers.CMS do
386386
CMS.undo_like_comment(thread, id, user)
387387
end
388388

389-
def dislike_comment(_root, ~m(thread id)a, %{context: %{cur_user: user}}) do
390-
CMS.dislike_comment(thread, id, user)
391-
end
392-
393-
def undo_dislike_comment(_root, ~m(thread id)a, %{context: %{cur_user: user}}) do
394-
CMS.undo_dislike_comment(thread, id, user)
395-
end
396-
397389
def stamp_passport(_root, ~m(user_id rules)a, %{context: %{cur_user: _user}}) do
398390
CMS.stamp_passport(rules, %User{id: user_id})
399391
end

lib/groupher_server_web/schema/cms/mutations/comment.ex

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -94,21 +94,5 @@ defmodule GroupherServerWeb.Schema.CMS.Mutations.Comment do
9494
middleware(M.Authorize, :login)
9595
resolve(&R.CMS.undo_like_comment/3)
9696
end
97-
98-
field :dislike_comment, :comment do
99-
arg(:thread, non_null(:cms_comment), default_value: :post_comment)
100-
arg(:id, non_null(:id))
101-
102-
middleware(M.Authorize, :login)
103-
resolve(&R.CMS.dislike_comment/3)
104-
end
105-
106-
field :undo_dislike_comment, :comment do
107-
arg(:thread, non_null(:cms_comment), default_value: :post_comment)
108-
arg(:id, non_null(:id))
109-
110-
middleware(M.Authorize, :login)
111-
resolve(&R.CMS.undo_dislike_comment/3)
112-
end
11397
end
11498
end

test/groupher_server/cms/post_comment_test.exs

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -211,23 +211,6 @@ defmodule GroupherServer.Test.PostComment do
211211
assert false == comment_preload.likes |> Enum.any?(&(&1.id == like.id))
212212
end
213213

214-
test "user can dislike a comment", ~m(comment user)a do
215-
# {:ok, like} = CMS.reaction(:post_comment, :like, comment.id, user.id)
216-
{:ok, disliked_comment} = CMS.dislike_comment(:post_comment, comment.id, user)
217-
218-
{:ok, comment_preload} = ORM.find(PostComment, disliked_comment.id, preload: :dislikes)
219-
220-
assert comment_preload.dislikes |> Enum.any?(&(&1.post_comment_id == comment.id))
221-
end
222-
223-
test "user can undo a dislike action", ~m(comment user)a do
224-
{:ok, dislike} = CMS.dislike_comment(:post_comment, comment.id, user)
225-
{:ok, _} = CMS.undo_dislike_comment(:post_comment, comment.id, user)
226-
227-
{:ok, comment_preload} = ORM.find(PostComment, comment.id, preload: :dislikes)
228-
assert false == comment_preload.dislikes |> Enum.any?(&(&1.id == dislike.id))
229-
end
230-
231214
test "user can get paged likes of a post comment", ~m(comment)a do
232215
{:ok, user1} = db_insert(:user)
233216
{:ok, user2} = db_insert(:user)

test/groupher_server_web/mutation/cms/post_comment_test.exs

Lines changed: 0 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -267,72 +267,5 @@ defmodule GroupherServer.Test.Mutation.PostComment do
267267

268268
assert found.likes |> Enum.any?(&(&1.post_comment_id == comment.id))
269269
end
270-
271-
@undo_like_comment_query """
272-
mutation($thread: CmsComment!, $id: ID!) {
273-
undoLikeComment(thread: $thread, id: $id) {
274-
id
275-
}
276-
}
277-
"""
278-
test "login user can undo a like action to comment", ~m(user comment)a do
279-
variables = %{thread: "POST_COMMENT", id: comment.id}
280-
user_conn = simu_conn(:user, user)
281-
user_conn |> mutation_result(@like_comment_query, variables, "likeComment")
282-
283-
{:ok, found} = CMS.PostComment |> ORM.find(comment.id, preload: :likes)
284-
assert found.likes |> Enum.any?(&(&1.post_comment_id == comment.id))
285-
286-
user_conn |> mutation_result(@undo_like_comment_query, variables, "undoLikeComment")
287-
288-
{:ok, found} = CMS.PostComment |> ORM.find(comment.id, preload: :likes)
289-
assert false == found.likes |> Enum.any?(&(&1.post_comment_id == comment.id))
290-
end
291-
292-
@dislike_comment_query """
293-
mutation($thread: CmsComment!, $id: ID!) {
294-
dislikeComment(thread: $thread, id: $id) {
295-
id
296-
}
297-
}
298-
"""
299-
test "login user can dislike a comment", ~m(user_conn comment)a do
300-
variables = %{thread: "POST_COMMENT", id: comment.id}
301-
user_conn |> mutation_result(@dislike_comment_query, variables, "dislikeComment")
302-
303-
{:ok, found} = CMS.PostComment |> ORM.find(comment.id, preload: :dislikes)
304-
305-
assert found.dislikes |> Enum.any?(&(&1.post_comment_id == comment.id))
306-
end
307-
308-
@undo_dislike_comment_query """
309-
mutation($thread: CmsComment!, $id: ID!) {
310-
undoDislikeComment(thread: $thread, id: $id) {
311-
id
312-
}
313-
}
314-
"""
315-
test "login user can undo dislike a comment", ~m(user comment)a do
316-
variables = %{thread: "POST_COMMENT", id: comment.id}
317-
user_conn = simu_conn(:user, user)
318-
user_conn |> mutation_result(@dislike_comment_query, variables, "dislikeComment")
319-
{:ok, found} = CMS.PostComment |> ORM.find(comment.id, preload: :dislikes)
320-
assert found.dislikes |> Enum.any?(&(&1.post_comment_id == comment.id))
321-
322-
user_conn |> mutation_result(@undo_dislike_comment_query, variables, "undoDislikeComment")
323-
324-
{:ok, found} = CMS.PostComment |> ORM.find(comment.id, preload: :dislikes)
325-
assert false == found.dislikes |> Enum.any?(&(&1.post_comment_id == comment.id))
326-
end
327-
328-
test "unloged user do/undo like/dislike comment fails", ~m(guest_conn comment)a do
329-
variables = %{thread: "POST_COMMENT", id: comment.id}
330-
331-
assert guest_conn |> mutation_get_error?(@like_comment_query, variables)
332-
assert guest_conn |> mutation_get_error?(@dislike_comment_query, variables)
333-
334-
assert guest_conn |> mutation_get_error?(@undo_like_comment_query, variables)
335-
assert guest_conn |> mutation_get_error?(@undo_dislike_comment_query, variables)
336-
end
337270
end
338271
end

0 commit comments

Comments
 (0)