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

Commit d772a78

Browse files
committed
refactor(post-meta): fix ci tests & warnings
1 parent ea2598f commit d772a78

File tree

9 files changed

+8
-114
lines changed

9 files changed

+8
-114
lines changed

lib/groupher_server/cms/delegates/article_comment.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleComment do
458458
defp upsert_comment_result({:ok, %{add_reply_to: result}}), do: {:ok, result}
459459
defp upsert_comment_result({:ok, %{inc_upvotes_count: result}}), do: {:ok, result}
460460
defp upsert_comment_result({:ok, %{update_report_flag: result}}), do: {:ok, result}
461+
defp upsert_comment_result({:ok, %{update_comment_emotion: result}}), do: {:ok, result}
461462

462463
defp upsert_comment_result({:error, :create_comment, result, _steps}) do
463464
{:error, result}

lib/groupher_server_web/resolvers/cms_resolver.ex

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ defmodule GroupherServerWeb.Resolvers.CMS do
1111
alias CMS.{Post, Repo, Job, Community, Category, Tag, Thread}
1212

1313
alias Helper.ORM
14-
alias Helper.Utils
1514

1615
# #######################
1716
# community ..

lib/groupher_server_web/schema/cms/cms_types.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ defmodule GroupherServerWeb.Schema.CMS.Types do
88
import Ecto.Query, warn: false
99
import Absinthe.Resolution.Helpers, only: [dataloader: 2, on_load: 2]
1010

11-
alias GroupherServer.{CMS, Accounts}
11+
alias GroupherServer.CMS
1212
alias GroupherServerWeb.Schema
1313

1414
import_types(Schema.CMS.Misc)

lib/groupher_server_web/schema/utils/helper.ex

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -215,30 +215,6 @@ defmodule GroupherServerWeb.Schema.Utils.Helper do
215215
middleware(M.ViewerDidConvert)
216216
end
217217

218-
field :dislikes, list_of(:user) do
219-
arg(:filter, :members_filter)
220-
221-
middleware(M.PageSizeProof)
222-
resolve(dataloader(CMS, :dislikes))
223-
end
224-
225-
field :viewer_has_disliked, :boolean do
226-
arg(:viewer_did, :viewer_did_type, default_value: :viewer_did)
227-
228-
middleware(M.Authorize, :login)
229-
# put current user into dataloader's args
230-
middleware(M.PutCurrentUser)
231-
resolve(dataloader(CMS, :dislikes))
232-
middleware(M.ViewerDidConvert)
233-
end
234-
235-
field :dislikes_count, :integer do
236-
arg(:count, :count_type, default_value: :count)
237-
238-
resolve(dataloader(CMS, :dislikes))
239-
middleware(M.ConvertToInt)
240-
end
241-
242218
field :replies, list_of(:comment) do
243219
arg(:filter, :members_filter)
244220

lib/helper/query_builder.ex

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,6 @@ defmodule Helper.QueryBuilder do
133133
{:sort, :most_likes}, queryable ->
134134
queryable |> sort_by_count(:likes, :desc)
135135

136-
{:sort, :most_dislikes}, queryable ->
137-
queryable |> sort_by_count(:dislikes, :desc)
138-
139136
{:length, :most_words}, queryable ->
140137
queryable |> order_by(desc: :length)
141138

test/groupher_server/cms/article_comment_replies_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ defmodule GroupherServer.Test.CMS.ArticleCommentReplies do
134134

135135
describe "[paged article comment replies]" do
136136
@tag :wip
137-
test "can get paged replies of a parent comment", ~m(post user user2)a do
137+
test "can get paged replies of a parent comment", ~m(post user)a do
138138
{:ok, parent_comment} = CMS.create_article_comment(:post, post.id, "parent_conent", user)
139139
{:ok, paged_replies} = CMS.list_comment_replies(parent_comment.id, %{page: 1, size: 20})
140140
assert is_valid_pagination?(paged_replies, :raw, :empty)

test/groupher_server/cms/article_comment_test.exs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ defmodule GroupherServer.Test.CMS.ArticleComment do
66
alias Helper.ORM
77
alias GroupherServer.CMS
88

9-
alias CMS.{ArticleComment, Post}
9+
alias CMS.{ArticleComment, Post, Job}
1010

1111
@delete_hint CMS.ArticleComment.delete_hint()
1212
@report_threshold_for_fold ArticleComment.report_threshold_for_fold()
@@ -21,7 +21,7 @@ defmodule GroupherServer.Test.CMS.ArticleComment do
2121
end
2222

2323
describe "[basic article comment]" do
24-
@tag :wip
24+
@tag :wip2
2525
test "post, job are supported by article comment.", ~m(user post job)a do
2626
post_comment_1 = "post_comment 1"
2727
post_comment_2 = "post_comment 2"
@@ -209,7 +209,7 @@ defmodule GroupherServer.Test.CMS.ArticleComment do
209209
assert not comment.is_reported
210210
assert not comment.is_folded
211211

212-
Enum.reduce(1..(@report_threshold_for_fold - 1), [], fn _, acc ->
212+
Enum.reduce(1..(@report_threshold_for_fold - 1), [], fn _, _acc ->
213213
{:ok, user} = db_insert(:user)
214214
{:ok, _comment} = CMS.report_article_comment(comment.id, user)
215215
end)
@@ -226,7 +226,7 @@ defmodule GroupherServer.Test.CMS.ArticleComment do
226226
assert not comment.is_reported
227227
assert not comment.is_folded
228228

229-
Enum.reduce(1..(@report_threshold_for_fold + 1), [], fn _, acc ->
229+
Enum.reduce(1..(@report_threshold_for_fold + 1), [], fn _, _acc ->
230230
{:ok, user} = db_insert(:user)
231231
{:ok, _comment} = CMS.report_article_comment(comment.id, user)
232232
end)

test/groupher_server_web/mutation/cms/post_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ defmodule GroupherServer.Test.Mutation.Post do
631631
}
632632
"""
633633
@tag :wip
634-
test "write comment to a exsit post", ~m(post user_conn community)a do
634+
test "write comment to a exsit post", ~m(post user_conn)a do
635635
comment = "a test comment"
636636
variables = %{thread: "POST", id: post.id, content: comment}
637637

test/groupher_server_web/query/cms/post_comment_test.exs

Lines changed: 0 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,6 @@ defmodule GroupherServer.Test.Query.PostComment do
222222
entries {
223223
id
224224
likesCount
225-
dislikesCount
226225
}
227226
totalPages
228227
totalCount
@@ -286,43 +285,6 @@ defmodule GroupherServer.Test.Query.PostComment do
286285
assert entries |> Enum.at(1) |> Map.get("likesCount") == 4
287286
end
288287

289-
test "MOST_DISLIKES filter should work", ~m(guest_conn post user community)a do
290-
body = "test comment"
291-
292-
comments =
293-
Enum.reduce(1..10, [], fn _, acc ->
294-
{:ok, value} =
295-
CMS.create_comment(:post, post.id, %{community: community.raw, body: body}, user)
296-
297-
acc ++ [value]
298-
end)
299-
300-
[comment_1, _comment_2, comment_3, _comment_last] = comments |> firstn_and_last(3)
301-
{:ok, [user_1, user_2, user_3, user_4, user_5]} = db_insert_multi(:user, 5)
302-
303-
# comment_3 is most likes
304-
{:ok, _} = CMS.dislike_comment(:post_comment, comment_3.id, user_1)
305-
{:ok, _} = CMS.dislike_comment(:post_comment, comment_3.id, user_2)
306-
{:ok, _} = CMS.dislike_comment(:post_comment, comment_3.id, user_3)
307-
{:ok, _} = CMS.dislike_comment(:post_comment, comment_3.id, user_4)
308-
{:ok, _} = CMS.dislike_comment(:post_comment, comment_3.id, user_5)
309-
310-
{:ok, _} = CMS.dislike_comment(:post_comment, comment_1.id, user_1)
311-
{:ok, _} = CMS.dislike_comment(:post_comment, comment_1.id, user_2)
312-
{:ok, _} = CMS.dislike_comment(:post_comment, comment_1.id, user_3)
313-
{:ok, _} = CMS.dislike_comment(:post_comment, comment_1.id, user_4)
314-
315-
variables = %{id: post.id, filter: %{page: 1, size: 10, sort: "MOST_DISLIKES"}}
316-
results = guest_conn |> query_result(@query, variables, "pagedComments")
317-
entries = results["entries"]
318-
319-
assert entries |> Enum.at(0) |> Map.get("id") == to_string(comment_3.id)
320-
assert entries |> Enum.at(0) |> Map.get("dislikesCount") == 5
321-
322-
assert entries |> Enum.at(1) |> Map.get("id") == to_string(comment_1.id)
323-
assert entries |> Enum.at(1) |> Map.get("dislikesCount") == 4
324-
end
325-
326288
@query """
327289
query($id: ID!, $filter: CommentsFilter!) {
328290
pagedComments(id: $id, filter: $filter) {
@@ -399,47 +361,6 @@ defmodule GroupherServer.Test.Query.PostComment do
399361
assert found["likes"] |> Enum.any?(&(&1["id"] == to_string(user.id)))
400362
end
401363

402-
@query """
403-
query($id: ID!, $filter: CommentsFilter!) {
404-
pagedComments(id: $id, filter: $filter) {
405-
entries {
406-
id
407-
body
408-
author {
409-
id
410-
nickname
411-
}
412-
dislikesCount
413-
dislikes {
414-
id
415-
nickname
416-
}
417-
}
418-
}
419-
}
420-
"""
421-
test "guest user can get dislikes info", ~m(guest_conn post user community)a do
422-
body = "test comment"
423-
424-
{:ok, comment} =
425-
CMS.create_comment(:post, post.id, %{community: community.raw, body: body}, user)
426-
427-
{:ok, _like} = CMS.dislike_comment(:post_comment, comment.id, user)
428-
429-
variables = %{id: post.id, filter: %{page: 1, size: 10}}
430-
results = guest_conn |> query_result(@query, variables, "pagedComments")
431-
432-
found =
433-
results["entries"] |> Enum.filter(&(&1["id"] == to_string(comment.id))) |> List.first()
434-
435-
author = found |> Map.get("author")
436-
437-
assert author["id"] == to_string(user.id)
438-
assert found["dislikesCount"] == 1
439-
440-
assert found["dislikes"] |> Enum.any?(&(&1["id"] == to_string(user.id)))
441-
end
442-
443364
@query """
444365
query($id: ID!, $filter: CommentsFilter!) {
445366
pagedComments(id: $id, filter: $filter) {

0 commit comments

Comments
 (0)