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

Commit 4654731

Browse files
committed
refactor(article-comment): wip
1 parent 37e9581 commit 4654731

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

lib/groupher_server_web/resolvers/cms_resolver.ex

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,10 @@ defmodule GroupherServerWeb.Resolvers.CMS do
326326
CMS.emotion_to_comment(id, emotion, user)
327327
end
328328

329+
def undo_emotion_to_comment(_root, ~m(id emotion)a, %{context: %{cur_user: user}}) do
330+
CMS.undo_emotion_to_comment(id, emotion, user)
331+
end
332+
329333
############
330334
############
331335
############

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,15 @@ defmodule GroupherServerWeb.Schema.CMS.Mutations.Comment do
5353
resolve(&R.CMS.emotion_to_comment/3)
5454
end
5555

56+
@desc "undo emotion to a comment"
57+
field :undo_emotion_to_comment, :article_comment do
58+
arg(:id, non_null(:id))
59+
arg(:emotion, non_null(:article_comment_emotion))
60+
61+
middleware(M.Authorize, :login)
62+
resolve(&R.CMS.undo_emotion_to_comment/3)
63+
end
64+
5665
############################
5766
############################
5867
############################

test/groupher_server_web/mutation/cms/article_comment_test.exs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,5 +114,34 @@ defmodule GroupherServer.Test.Mutation.ArticleComment do
114114
assert comment |> get_in(["emotions", "beerCount"]) == 1
115115
assert get_in(comment, ["emotions", "viewerHasBeered"])
116116
end
117+
118+
@emotion_comment_query """
119+
mutation($id: ID!, $emotion: ArticleCommentEmotion!) {
120+
undoEmotionToComment(id: $id, emotion: $emotion) {
121+
id
122+
emotions {
123+
beerCount
124+
viewerHasBeered
125+
latestBeerUsers {
126+
login
127+
nickname
128+
}
129+
}
130+
}
131+
}
132+
"""
133+
@tag :wip2
134+
test "login user can undo emotion to a comment", ~m(post user owner_conn)a do
135+
{:ok, comment} = CMS.create_article_comment(:post, post.id, "post comment", user)
136+
{:ok, _} = CMS.emotion_to_comment(comment.id, :beer, user)
137+
138+
variables = %{id: comment.id, emotion: "BEER"}
139+
140+
comment =
141+
owner_conn |> mutation_result(@emotion_comment_query, variables, "undoEmotionToComment")
142+
143+
assert comment |> get_in(["emotions", "beerCount"]) == 0
144+
assert not get_in(comment, ["emotions", "viewerHasBeered"])
145+
end
117146
end
118147
end

0 commit comments

Comments
 (0)