From ff45e41c994e5c1a1a140963cbfadc207755e7aa Mon Sep 17 00:00:00 2001 From: mydearxym Date: Sun, 16 May 2021 11:22:59 +0800 Subject: [PATCH 01/11] chore(article-comments): missing repo tests --- .../cms/delegates/article_comment.ex | 13 +- .../cms/comments/repo_comment_test.exs | 167 +++++ .../query/cms/comments/job_comment_test.exs | 20 +- .../query/cms/comments/post_comment_test.exs | 17 +- .../query/cms/comments/repo_comment_test.exs | 654 ++++++++++++++++++ 5 files changed, 845 insertions(+), 26 deletions(-) create mode 100644 test/groupher_server_web/mutation/cms/comments/repo_comment_test.exs create mode 100644 test/groupher_server_web/query/cms/comments/repo_comment_test.exs diff --git a/lib/groupher_server/cms/delegates/article_comment.ex b/lib/groupher_server/cms/delegates/article_comment.ex index 168c208f1..59aa3f64f 100644 --- a/lib/groupher_server/cms/delegates/article_comment.ex +++ b/lib/groupher_server/cms/delegates/article_comment.ex @@ -18,7 +18,6 @@ defmodule GroupherServer.CMS.Delegate.ArticleComment do alias CMS.{ArticleComment, ArticlePinedComment, Embeds} alias Ecto.Multi - @supported_emotions get_config(:article, :comment_supported_emotions) @max_participator_count ArticleComment.max_participator_count() @default_emotions Embeds.ArticleCommentEmotion.default_emotions() @delete_hint ArticleComment.delete_hint() @@ -249,17 +248,13 @@ defmodule GroupherServer.CMS.Delegate.ArticleComment do _ -> preloaded_pined_comments = - Enum.slice(pined_comments, 0, @pined_comment_limit) - |> Repo.preload(reply_to: :author) - - updated_entries = Enum.concat(preloaded_pined_comments, entries) + Enum.slice(pined_comments, 0, @pined_comment_limit) |> Repo.preload(reply_to: :author) + entries = Enum.concat(preloaded_pined_comments, entries) pined_comment_count = length(pined_comments) - Map.merge(paged_comments, %{ - entries: updated_entries, - total_count: paged_comments.total_count + pined_comment_count - }) + total_count = paged_comments.total_count + pined_comment_count + paged_comments |> Map.merge(%{entries: entries, total_count: total_count}) end end end diff --git a/test/groupher_server_web/mutation/cms/comments/repo_comment_test.exs b/test/groupher_server_web/mutation/cms/comments/repo_comment_test.exs new file mode 100644 index 000000000..1800187ba --- /dev/null +++ b/test/groupher_server_web/mutation/cms/comments/repo_comment_test.exs @@ -0,0 +1,167 @@ +defmodule GroupherServer.Test.Mutation.Comments.RepoComment do + use GroupherServer.TestTools + + alias GroupherServer.CMS + + setup do + {:ok, repo} = db_insert(:repo) + {:ok, user} = db_insert(:user) + {:ok, community} = db_insert(:community) + + guest_conn = simu_conn(:guest) + user_conn = simu_conn(:user) + owner_conn = simu_conn(:user, user) + + {:ok, ~m(user_conn user guest_conn owner_conn community repo)a} + end + + describe "[article comment CURD]" do + @write_comment_query """ + mutation($thread: Thread!, $id: ID!, $content: String!) { + createArticleComment(thread: $thread,id: $id, content: $content) { + id + bodyHtml + } + } + """ + + test "write article comment to a exsit repo", ~m(repo user_conn)a do + comment = "a test comment" + variables = %{thread: "REPO", id: repo.id, content: comment} + + result = + user_conn |> mutation_result(@write_comment_query, variables, "createArticleComment") + + assert result["bodyHtml"] == comment + end + + @reply_comment_query """ + mutation($id: ID!, $content: String!) { + replyArticleComment(id: $id, content: $content) { + id + bodyHtml + } + } + """ + + test "login user can reply to a comment", ~m(repo user user_conn)a do + {:ok, comment} = CMS.create_article_comment(:repo, repo.id, "commment", user) + variables = %{id: comment.id, content: "reply content"} + + result = + user_conn + |> mutation_result(@reply_comment_query, variables, "replyArticleComment") + + assert result["bodyHtml"] == "reply content" + end + + @update_comment_query """ + mutation($id: ID!, $content: String!) { + updateArticleComment(id: $id, content: $content) { + id + bodyHtml + } + } + """ + + test "only owner can update a exsit comment", + ~m(repo user guest_conn user_conn owner_conn)a do + {:ok, comment} = CMS.create_article_comment(:repo, repo.id, "repo comment", user) + variables = %{id: comment.id, content: "updated comment"} + + assert user_conn |> mutation_get_error?(@update_comment_query, variables, ecode(:passport)) + + assert guest_conn + |> mutation_get_error?(@update_comment_query, variables, ecode(:account_login)) + + updated = + owner_conn |> mutation_result(@update_comment_query, variables, "updateArticleComment") + + assert updated["bodyHtml"] == "updated comment" + end + + @delete_comment_query """ + mutation($id: ID!) { + deleteArticleComment(id: $id) { + id + isDeleted + } + } + """ + + test "only owner can delete a exsit comment", + ~m(repo user guest_conn user_conn owner_conn)a do + {:ok, comment} = CMS.create_article_comment(:repo, repo.id, "repo comment", user) + variables = %{id: comment.id} + + assert user_conn |> mutation_get_error?(@delete_comment_query, variables, ecode(:passport)) + + assert guest_conn + |> mutation_get_error?(@delete_comment_query, variables, ecode(:account_login)) + + deleted = + owner_conn |> mutation_result(@delete_comment_query, variables, "deleteArticleComment") + + assert deleted["id"] == to_string(comment.id) + assert deleted["isDeleted"] + end + end + + describe "[article comment emotion]" do + @emotion_comment_query """ + mutation($id: ID!, $emotion: ArticleCommentEmotion!) { + emotionToComment(id: $id, emotion: $emotion) { + id + emotions { + beerCount + viewerHasBeered + latestBeerUsers { + login + nickname + } + } + } + } + """ + + test "login user can emotion to a comment", ~m(repo user user_conn)a do + {:ok, comment} = CMS.create_article_comment(:repo, repo.id, "repo comment", user) + variables = %{id: comment.id, emotion: "BEER"} + + comment = + user_conn |> mutation_result(@emotion_comment_query, variables, "emotionToComment") + + assert comment |> get_in(["emotions", "beerCount"]) == 1 + assert get_in(comment, ["emotions", "viewerHasBeered"]) + end + + @emotion_comment_query """ + mutation($id: ID!, $emotion: ArticleCommentEmotion!) { + undoEmotionToComment(id: $id, emotion: $emotion) { + id + emotions { + beerCount + viewerHasBeered + latestBeerUsers { + login + nickname + } + } + } + } + """ + + test "login user can undo emotion to a comment", ~m(repo user owner_conn)a do + {:ok, comment} = CMS.create_article_comment(:repo, repo.id, "repo comment", user) + {:ok, _} = CMS.emotion_to_comment(comment.id, :beer, user) + + variables = %{id: comment.id, emotion: "BEER"} + + comment = + owner_conn |> mutation_result(@emotion_comment_query, variables, "undoEmotionToComment") + + assert comment |> get_in(["emotions", "beerCount"]) == 0 + assert not get_in(comment, ["emotions", "viewerHasBeered"]) + end + end +end diff --git a/test/groupher_server_web/query/cms/comments/job_comment_test.exs b/test/groupher_server_web/query/cms/comments/job_comment_test.exs index 47af664eb..d586d9e77 100644 --- a/test/groupher_server_web/query/cms/comments/job_comment_test.exs +++ b/test/groupher_server_web/query/cms/comments/job_comment_test.exs @@ -243,8 +243,9 @@ defmodule GroupherServer.Test.Query.Comments.JobComment do assert results["totalCount"] == total_count end - @tag :wip - test "guest user can get paged comment with pined comment in it", ~m(guest_conn job user)a do + @tag :wip2 + test "guest user can get paged comment with pinned comment in it", + ~m(guest_conn job user)a do total_count = 20 thread = :job @@ -254,17 +255,17 @@ defmodule GroupherServer.Test.Query.Comments.JobComment do acc ++ [comment] end) - {:ok, comment} = CMS.create_article_comment(thread, job.id, "pined comment", user) - {:ok, pined_comment} = CMS.pin_article_comment(comment.id) + {:ok, comment} = CMS.create_article_comment(thread, job.id, "pinned comment", user) + {:ok, pinned_comment} = CMS.pin_article_comment(comment.id) - {:ok, comment} = CMS.create_article_comment(thread, job.id, "pined comment 2", user) - {:ok, pined_comment2} = CMS.pin_article_comment(comment.id) + {:ok, comment} = CMS.create_article_comment(thread, job.id, "pinned comment 2", user) + {:ok, pinned_comment2} = CMS.pin_article_comment(comment.id) variables = %{id: job.id, thread: "JOB", filter: %{page: 1, size: 10}} results = guest_conn |> query_result(@query, variables, "pagedArticleComments") - assert results["entries"] |> List.first() |> Map.get("id") == to_string(pined_comment.id) - assert results["entries"] |> Enum.at(1) |> Map.get("id") == to_string(pined_comment2.id) + assert results["entries"] |> List.first() |> Map.get("id") == to_string(pinned_comment.id) + assert results["entries"] |> Enum.at(1) |> Map.get("id") == to_string(pinned_comment2.id) assert results["totalCount"] == total_count + 2 end @@ -546,7 +547,7 @@ defmodule GroupherServer.Test.Query.Comments.JobComment do } } """ - + @tag :wip test "guest user can get paged participators", ~m(guest_conn job user)a do total_count = 30 page_size = 10 @@ -563,6 +564,7 @@ defmodule GroupherServer.Test.Query.Comments.JobComment do {:ok, _comment} = CMS.create_article_comment(:job, job.id, "commment", user) variables = %{id: job.id, thread: thread, filter: %{page: 1, size: page_size}} + results = guest_conn |> query_result(@query, variables, "pagedArticleCommentsParticipators") assert results |> is_valid_pagination? diff --git a/test/groupher_server_web/query/cms/comments/post_comment_test.exs b/test/groupher_server_web/query/cms/comments/post_comment_test.exs index e521733b2..91f500353 100644 --- a/test/groupher_server_web/query/cms/comments/post_comment_test.exs +++ b/test/groupher_server_web/query/cms/comments/post_comment_test.exs @@ -243,8 +243,9 @@ defmodule GroupherServer.Test.Query.Comments.PostComment do assert results["totalCount"] == total_count end - @tag :wip - test "guest user can get paged comment with pined comment in it", ~m(guest_conn post user)a do + @tag :wip2 + test "guest user can get paged comment with pinned comment in it", + ~m(guest_conn post user)a do total_count = 20 thread = :post @@ -254,17 +255,17 @@ defmodule GroupherServer.Test.Query.Comments.PostComment do acc ++ [comment] end) - {:ok, comment} = CMS.create_article_comment(thread, post.id, "pined comment", user) - {:ok, pined_comment} = CMS.pin_article_comment(comment.id) + {:ok, comment} = CMS.create_article_comment(thread, post.id, "pinned comment", user) + {:ok, pinned_comment} = CMS.pin_article_comment(comment.id) - {:ok, comment} = CMS.create_article_comment(thread, post.id, "pined comment 2", user) - {:ok, pined_comment2} = CMS.pin_article_comment(comment.id) + {:ok, comment} = CMS.create_article_comment(thread, post.id, "pinned comment 2", user) + {:ok, pinned_comment2} = CMS.pin_article_comment(comment.id) variables = %{id: post.id, thread: "POST", filter: %{page: 1, size: 10}} results = guest_conn |> query_result(@query, variables, "pagedArticleComments") - assert results["entries"] |> List.first() |> Map.get("id") == to_string(pined_comment.id) - assert results["entries"] |> Enum.at(1) |> Map.get("id") == to_string(pined_comment2.id) + assert results["entries"] |> List.first() |> Map.get("id") == to_string(pinned_comment.id) + assert results["entries"] |> Enum.at(1) |> Map.get("id") == to_string(pinned_comment2.id) assert results["totalCount"] == total_count + 2 end diff --git a/test/groupher_server_web/query/cms/comments/repo_comment_test.exs b/test/groupher_server_web/query/cms/comments/repo_comment_test.exs new file mode 100644 index 000000000..bd0b26138 --- /dev/null +++ b/test/groupher_server_web/query/cms/comments/repo_comment_test.exs @@ -0,0 +1,654 @@ +defmodule GroupherServer.Test.Query.Comments.RepoComment do + @moduledoc false + + use GroupherServer.TestTools + + alias GroupherServer.CMS + + setup do + {:ok, repo} = db_insert(:repo) + {:ok, user} = db_insert(:user) + {:ok, user2} = db_insert(:user) + + guest_conn = simu_conn(:guest) + user_conn = simu_conn(:user, user) + + {:ok, ~m(user_conn guest_conn repo user user2)a} + end + + describe "[baisc article repo comment]" do + @query """ + query($id: ID!) { + repo(id: $id) { + id + title + body + articleCommentsParticipators { + id + nickname + } + articleCommentsParticipatorsCount + } + } + """ + @tag :wip + test "guest user can get comment participators after comment created", + ~m(guest_conn repo user user2)a do + comment = "test comment" + total_count = 5 + thread = :repo + + Enum.reduce(1..total_count, [], fn _, acc -> + {:ok, comment} = CMS.create_article_comment(thread, repo.id, comment, user) + + acc ++ [comment] + end) + + {:ok, _} = CMS.create_article_comment(thread, repo.id, comment, user2) + + variables = %{id: repo.id} + results = guest_conn |> query_result(@query, variables, "repo") + + article_comments_participators = results["articleCommentsParticipators"] + article_comments_participators_count = results["articleCommentsParticipatorsCount"] + + assert is_list(article_comments_participators) + assert length(article_comments_participators) == 2 + assert article_comments_participators_count == 2 + end + + @query """ + query($id: ID!, $thread: Thread, $mode: ArticleCommentsMode, $filter: CommentsFilter!) { + pagedArticleComments(id: $id, thread: $thread, mode: $mode, filter: $filter) { + entries { + id + bodyHtml + author { + id + nickname + } + isPinned + floor + upvotesCount + + emotions { + downvoteCount + latestDownvoteUsers { + login + nickname + } + viewerHasDownvoteed + beerCount + latestBeerUsers { + login + nickname + } + viewerHasBeered + + popcornCount + viewerHasPopcorned + } + isArticleAuthor + meta { + isArticleAuthorUpvoted + } + replyTo { + id + bodyHtml + floor + isArticleAuthor + author { + id + login + } + } + viewerHasUpvoted + replies { + id + bodyHtml + author { + id + login + } + } + repliesCount + } + totalPages + totalCount + pageSize + pageNumber + } + } + """ + @tag :wip + test "list comments with default replies-mode", ~m(guest_conn repo user user2)a do + total_count = 10 + page_size = 20 + thread = :repo + + all_comments = + Enum.reduce(1..total_count, [], fn i, acc -> + {:ok, comment} = CMS.create_article_comment(thread, repo.id, "comment #{i}", user) + acc ++ [comment] + end) + + random_comment = all_comments |> Enum.at(Enum.random(0..(total_count - 1))) + {:ok, replyed_comment_1} = CMS.reply_article_comment(random_comment.id, "reply 1", user2) + {:ok, replyed_comment_2} = CMS.reply_article_comment(random_comment.id, "reply 2", user2) + + variables = %{id: repo.id, thread: "REPO", filter: %{page: 1, size: page_size}} + results = guest_conn |> query_result(@query, variables, "pagedArticleComments") + assert results["entries"] |> length == total_count + + assert not exist_in?(replyed_comment_1, results["entries"], :string_key) + assert not exist_in?(replyed_comment_2, results["entries"], :string_key) + + random_comment = Enum.find(results["entries"], &(&1["id"] == to_string(random_comment.id))) + assert random_comment["replies"] |> length == 2 + assert random_comment["repliesCount"] == 2 + + assert random_comment["replies"] |> List.first() |> Map.get("id") == + to_string(replyed_comment_1.id) + + assert random_comment["replies"] |> List.last() |> Map.get("id") == + to_string(replyed_comment_2.id) + end + + @tag :wip + test "timeline-mode paged comments", ~m(guest_conn repo user user2)a do + total_count = 3 + page_size = 20 + thread = :repo + + all_comments = + Enum.reduce(1..total_count, [], fn i, acc -> + {:ok, comment} = CMS.create_article_comment(thread, repo.id, "comment #{i}", user) + acc ++ [comment] + end) + + random_comment = all_comments |> Enum.at(Enum.random(0..(total_count - 1))) + + {:ok, replyed_comment_1} = CMS.reply_article_comment(random_comment.id, "reply 1", user2) + {:ok, replyed_comment_2} = CMS.reply_article_comment(random_comment.id, "reply 2", user2) + + variables = %{ + id: repo.id, + thread: "REPO", + mode: "TIMELINE", + filter: %{page: 1, size: page_size} + } + + results = guest_conn |> query_result(@query, variables, "pagedArticleComments") + assert results["entries"] |> length == total_count + 2 + + assert exist_in?(replyed_comment_1, results["entries"], :string_key) + assert exist_in?(replyed_comment_2, results["entries"], :string_key) + + random_comment = Enum.find(results["entries"], &(&1["id"] == to_string(random_comment.id))) + assert random_comment["replies"] |> length == 2 + assert random_comment["repliesCount"] == 2 + end + + @tag :wip + test "comment should have reply_to content if need", ~m(guest_conn repo user user2)a do + total_count = 2 + thread = :repo + + Enum.reduce(0..total_count, [], fn i, acc -> + {:ok, comment} = CMS.create_article_comment(thread, repo.id, "comment #{i}", user) + acc ++ [comment] + end) + + {:ok, parent_comment} = CMS.create_article_comment(:repo, repo.id, "parent_content", user) + + {:ok, replyed_comment_1} = CMS.reply_article_comment(parent_comment.id, "reply 1", user2) + {:ok, replyed_comment_2} = CMS.reply_article_comment(parent_comment.id, "reply 2", user2) + + variables = %{id: repo.id, thread: "REPO", filter: %{page: 1, size: 10}, mode: "TIMELINE"} + results = guest_conn |> query_result(@query, variables, "pagedArticleComments") + + replyed_comment_1 = + Enum.find(results["entries"], &(&1["id"] == to_string(replyed_comment_1.id))) + + assert replyed_comment_1 |> get_in(["replyTo", "id"]) == to_string(parent_comment.id) + + assert replyed_comment_1 |> get_in(["replyTo", "author", "id"]) == + to_string(parent_comment.author_id) + + replyed_comment_2 = + Enum.find(results["entries"], &(&1["id"] == to_string(replyed_comment_2.id))) + + assert replyed_comment_2 |> get_in(["replyTo", "id"]) == to_string(parent_comment.id) + + assert replyed_comment_2 |> get_in(["replyTo", "author", "id"]) == + to_string(parent_comment.author_id) + end + + @tag :wip + test "guest user can get paged comment for repo", ~m(guest_conn repo user)a do + comment = "test comment" + total_count = 30 + thread = :repo + + Enum.reduce(1..total_count, [], fn _, acc -> + {:ok, value} = CMS.create_article_comment(thread, repo.id, comment, user) + + acc ++ [value] + end) + + variables = %{id: repo.id, thread: "REPO", filter: %{page: 1, size: 10}} + results = guest_conn |> query_result(@query, variables, "pagedArticleComments") + + assert results |> is_valid_pagination? + assert results["totalCount"] == total_count + end + + @tag :wip2 + test "guest user can get paged comment with pinned comment in it", + ~m(guest_conn repo user)a do + total_count = 20 + thread = :repo + + Enum.reduce(1..total_count, [], fn _, acc -> + {:ok, comment} = CMS.create_article_comment(thread, repo.id, "test comment", user) + + acc ++ [comment] + end) + + {:ok, comment} = CMS.create_article_comment(thread, repo.id, "pinned comment", user) + {:ok, pinned_comment} = CMS.pin_article_comment(comment.id) + + {:ok, comment} = CMS.create_article_comment(thread, repo.id, "pinned comment 2", user) + {:ok, pinned_comment2} = CMS.pin_article_comment(comment.id) + + variables = %{id: repo.id, thread: "REPO", filter: %{page: 1, size: 10}} + results = guest_conn |> query_result(@query, variables, "pagedArticleComments") + + assert results["entries"] |> List.first() |> Map.get("id") == to_string(pinned_comment.id) + assert results["entries"] |> Enum.at(1) |> Map.get("id") == to_string(pinned_comment2.id) + + assert results["totalCount"] == total_count + 2 + end + + @tag :wip + test "guest user can get paged comment with floor it", ~m(guest_conn repo user)a do + total_count = 5 + thread = :repo + page_size = 10 + + Enum.reduce(1..total_count, [], fn _, acc -> + {:ok, comment} = CMS.create_article_comment(thread, repo.id, "test comment", user) + Process.sleep(1000) + acc ++ [comment] + end) + + variables = %{id: repo.id, thread: "REPO", filter: %{page: 1, size: page_size}} + results = guest_conn |> query_result(@query, variables, "pagedArticleComments") + + assert results["entries"] |> List.first() |> Map.get("floor") == 1 + assert results["entries"] |> List.last() |> Map.get("floor") == 5 + end + + test "the comments is loaded in default asc order", ~m(guest_conn repo user)a do + page_size = 10 + thread = :repo + + {:ok, comment} = CMS.create_article_comment(thread, repo.id, "test comment 1", user) + Process.sleep(1000) + {:ok, _comment2} = CMS.create_article_comment(thread, repo.id, "test comment 2", user) + Process.sleep(1000) + {:ok, comment3} = CMS.create_article_comment(thread, repo.id, "test comment 3", user) + + variables = %{ + id: repo.id, + thread: "REPO", + filter: %{page: 1, size: page_size}, + mode: "TIMELINE" + } + + results = guest_conn |> query_result(@query, variables, "pagedArticleComments") + + assert List.first(results["entries"]) |> Map.get("id") == to_string(comment.id) + assert List.last(results["entries"]) |> Map.get("id") == to_string(comment3.id) + end + + test "the comments can be loaded in desc order in timeline-mode", ~m(guest_conn repo user)a do + page_size = 10 + thread = :repo + + {:ok, comment} = CMS.create_article_comment(thread, repo.id, "test comment 1", user) + Process.sleep(1000) + {:ok, _comment2} = CMS.create_article_comment(thread, repo.id, "test comment 2", user) + Process.sleep(1000) + {:ok, comment3} = CMS.create_article_comment(thread, repo.id, "test comment 3", user) + + variables = %{ + id: repo.id, + thread: "REPO", + filter: %{page: 1, size: page_size, sort: "DESC_INSERTED"}, + mode: "TIMELINE" + } + + results = guest_conn |> query_result(@query, variables, "pagedArticleComments") + + assert List.first(results["entries"]) |> Map.get("id") == to_string(comment3.id) + assert List.last(results["entries"]) |> Map.get("id") == to_string(comment.id) + end + + test "the comments can be loaded in desc order in replies-mode", + ~m(guest_conn repo user user2)a do + page_size = 10 + thread = :repo + + {:ok, comment} = CMS.create_article_comment(thread, repo.id, "parent comment 1", user) + {:ok, _reply_comment} = CMS.reply_article_comment(comment.id, "reply 1", user) + {:ok, _reply_comment} = CMS.reply_article_comment(comment.id, "reply 2", user2) + Process.sleep(1000) + {:ok, comment2} = CMS.create_article_comment(thread, repo.id, "test comment 2", user) + {:ok, _reply_comment} = CMS.reply_article_comment(comment2.id, "reply 1", user) + {:ok, _reply_comment} = CMS.reply_article_comment(comment2.id, "reply 2", user2) + Process.sleep(1000) + {:ok, comment3} = CMS.create_article_comment(thread, repo.id, "test comment 3", user) + {:ok, _reply_comment} = CMS.reply_article_comment(comment3.id, "reply 1", user) + {:ok, _reply_comment} = CMS.reply_article_comment(comment3.id, "reply 2", user2) + + variables = %{ + id: repo.id, + thread: "REPO", + filter: %{page: 1, size: page_size, sort: "DESC_INSERTED"} + } + + results = guest_conn |> query_result(@query, variables, "pagedArticleComments") + + assert List.first(results["entries"]) |> Map.get("id") == to_string(comment3.id) + assert List.last(results["entries"]) |> Map.get("id") == to_string(comment.id) + end + + @tag :wip + test "guest user can get paged comment with upvotes_count", ~m(guest_conn repo user user2)a do + total_count = 10 + page_size = 10 + thread = :repo + + all_comment = + Enum.reduce(1..total_count, [], fn i, acc -> + {:ok, comment} = CMS.create_article_comment(thread, repo.id, "test comment #{i}", user) + Process.sleep(1000) + acc ++ [comment] + end) + + upvote_comment = all_comment |> Enum.at(3) + upvote_comment2 = all_comment |> Enum.at(4) + {:ok, _} = CMS.upvote_article_comment(upvote_comment.id, user) + {:ok, _} = CMS.upvote_article_comment(upvote_comment2.id, user) + {:ok, _} = CMS.upvote_article_comment(upvote_comment2.id, user2) + + variables = %{id: repo.id, thread: "REPO", filter: %{page: 1, size: page_size}} + results = guest_conn |> query_result(@query, variables, "pagedArticleComments") + + assert results["entries"] |> Enum.at(3) |> Map.get("upvotesCount") == 1 + assert results["entries"] |> Enum.at(4) |> Map.get("upvotesCount") == 2 + assert results["entries"] |> List.first() |> Map.get("upvotesCount") == 0 + assert results["entries"] |> List.last() |> Map.get("upvotesCount") == 0 + end + + @tag :wip + test "article author upvote a comment can get is_article_author and/or is_article_author_upvoted flag", + ~m(guest_conn repo user)a do + total_count = 5 + page_size = 12 + thread = :repo + + author_user = repo.author.user + + all_comments = + Enum.reduce(0..total_count, [], fn i, acc -> + {:ok, comment} = CMS.create_article_comment(thread, repo.id, "test comment #{i}", user) + acc ++ [comment] + end) + + random_comment = all_comments |> Enum.at(Enum.random(0..(total_count - 1))) + {:ok, _} = CMS.upvote_article_comment(random_comment.id, author_user) + + {:ok, author_comment} = + CMS.create_article_comment(thread, repo.id, "test comment", author_user) + + {:ok, _} = CMS.upvote_article_comment(author_comment.id, author_user) + + variables = %{id: repo.id, thread: "REPO", filter: %{page: 1, size: page_size}} + results = guest_conn |> query_result(@query, variables, "pagedArticleComments") + + the_author_comment = + Enum.find(results["entries"], &(&1["id"] == to_string(author_comment.id))) + + assert the_author_comment["isArticleAuthor"] + assert the_author_comment |> get_in(["meta", "isArticleAuthorUpvoted"]) + + the_random_comment = + Enum.find(results["entries"], &(&1["id"] == to_string(random_comment.id))) + + assert not the_random_comment["isArticleAuthor"] + assert the_random_comment |> get_in(["meta", "isArticleAuthorUpvoted"]) + end + + test "guest user can get paged comment with emotions info", + ~m(guest_conn repo user user2)a do + total_count = 2 + page_size = 10 + thread = :repo + + all_comment = + Enum.reduce(1..total_count, [], fn i, acc -> + {:ok, comment} = CMS.create_article_comment(thread, repo.id, "test comment #{i}", user) + Process.sleep(1000) + acc ++ [comment] + end) + + comment = all_comment |> Enum.at(0) + comment2 = all_comment |> Enum.at(1) + + {:ok, _} = CMS.emotion_to_comment(comment.id, :downvote, user) + {:ok, _} = CMS.emotion_to_comment(comment.id, :downvote, user2) + {:ok, _} = CMS.emotion_to_comment(comment2.id, :beer, user2) + + variables = %{id: repo.id, thread: "REPO", filter: %{page: 1, size: page_size}} + results = guest_conn |> query_result(@query, variables, "pagedArticleComments") + + comment_emotion = + Enum.find(results["entries"], &(&1["id"] == to_string(comment.id))) |> Map.get("emotions") + + assert comment_emotion["popcornCount"] == 0 + + assert comment_emotion["downvoteCount"] == 2 + assert comment_emotion["latestDownvoteUsers"] |> length == 2 + assert not comment_emotion["viewerHasDownvoteed"] + + latest_downvote_users_logins = + Enum.map(comment_emotion["latestDownvoteUsers"], & &1["login"]) + + assert user.login in latest_downvote_users_logins + assert user2.login in latest_downvote_users_logins + + comment2_emotion = + Enum.find(results["entries"], &(&1["id"] == to_string(comment2.id))) + |> Map.get("emotions") + + assert comment2_emotion["beerCount"] == 1 + assert comment2_emotion["latestBeerUsers"] |> length == 1 + assert not comment2_emotion["viewerHasBeered"] + + latest_beer_users_logins = Enum.map(comment2_emotion["latestBeerUsers"], & &1["login"]) + assert user2.login in latest_beer_users_logins + end + + @tag :wip + test "user make emotion can get paged comment with emotions has_motioned field", + ~m(user_conn repo user user2)a do + total_count = 10 + page_size = 12 + thread = :repo + + all_comment = + Enum.reduce(1..total_count, [], fn i, acc -> + {:ok, comment} = CMS.create_article_comment(thread, repo.id, "test comment #{i}", user) + Process.sleep(1000) + acc ++ [comment] + end) + + comment = all_comment |> Enum.at(0) + comment2 = all_comment |> Enum.at(1) + + {:ok, _} = CMS.emotion_to_comment(comment.id, :downvote, user) + {:ok, _} = CMS.emotion_to_comment(comment2.id, :downvote, user2) + + variables = %{id: repo.id, thread: "REPO", filter: %{page: 1, size: page_size}} + results = user_conn |> query_result(@query, variables, "pagedArticleComments") + + assert Enum.find(results["entries"], &(&1["id"] == to_string(comment.id))) + |> get_in(["emotions", "viewerHasDownvoteed"]) + end + + test "comment should have viewer has upvoted flag", ~m(user_conn repo user)a do + total_count = 10 + page_size = 12 + thread = :repo + + all_comments = + Enum.reduce(0..total_count, [], fn i, acc -> + {:ok, comment} = CMS.create_article_comment(thread, repo.id, "comment #{i}", user) + acc ++ [comment] + end) + + random_comment = all_comments |> Enum.at(Enum.random(0..(total_count - 1))) + + {:ok, _} = CMS.upvote_article_comment(random_comment.id, user) + + variables = %{id: repo.id, thread: "REPO", filter: %{page: 1, size: page_size}} + results = user_conn |> query_result(@query, variables, "pagedArticleComments") + + upvoted_comment = Enum.find(results["entries"], &(&1["id"] == to_string(random_comment.id))) + + assert upvoted_comment["viewerHasUpvoted"] + end + end + + describe "paged paticipators" do + @query """ + query($id: ID!, $thread: Thread, $filter: PagedFilter!) { + pagedArticleCommentsParticipators(id: $id, thread: $thread, filter: $filter) { + entries { + id + nickname + } + totalPages + totalCount + pageSize + pageNumber + } + } + """ + @tag :wip + test "guest user can get paged participators", ~m(guest_conn repo user)a do + total_count = 30 + page_size = 10 + thread = "REPO" + + Enum.reduce(1..total_count, [], fn _, acc -> + {:ok, new_user} = db_insert(:user) + {:ok, comment} = CMS.create_article_comment(:repo, repo.id, "commment", new_user) + + acc ++ [comment] + end) + + {:ok, _comment} = CMS.create_article_comment(:repo, repo.id, "commment", user) + {:ok, _comment} = CMS.create_article_comment(:repo, repo.id, "commment", user) + + variables = %{id: repo.id, thread: thread, filter: %{page: 1, size: page_size}} + + results = guest_conn |> query_result(@query, variables, "pagedArticleCommentsParticipators") + + assert results |> is_valid_pagination? + assert results["totalCount"] == total_count + 1 + end + end + + describe "paged replies" do + @query """ + query($id: ID!, $filter: CommentsFilter!) { + pagedCommentReplies(id: $id, filter: $filter) { + entries { + id + bodyHtml + author { + id + nickname + } + upvotesCount + emotions { + downvoteCount + latestDownvoteUsers { + login + nickname + } + viewerHasDownvoteed + beerCount + latestBeerUsers { + login + nickname + } + viewerHasBeered + } + isArticleAuthor + meta { + isArticleAuthorUpvoted + } + replyTo { + id + bodyHtml + floor + isArticleAuthor + author { + id + login + } + } + repliesCount + viewerHasUpvoted + } + totalPages + totalCount + pageSize + pageNumber + } + } + """ + @tag :wip + test "guest user can get paged replies", ~m(guest_conn repo user user2)a do + comment = "test comment" + total_count = 2 + page_size = 10 + thread = :repo + + author_user = repo.author.user + {:ok, parent_comment} = CMS.create_article_comment(thread, repo.id, comment, user) + + Enum.reduce(1..total_count, [], fn i, acc -> + {:ok, reply_comment} = CMS.reply_article_comment(parent_comment.id, "reply #{i}", user2) + + acc ++ [reply_comment] + end) + + {:ok, author_reply_comment} = + CMS.reply_article_comment(parent_comment.id, "author reply", author_user) + + variables = %{id: parent_comment.id, filter: %{page: 1, size: page_size}} + results = guest_conn |> query_result(@query, variables, "pagedCommentReplies") + + author_reply_comment = + Enum.find(results["entries"], &(&1["id"] == to_string(author_reply_comment.id))) + + assert author_reply_comment["isArticleAuthor"] + assert results["entries"] |> length == total_count + 1 + end + end +end From 95fab62852ef515a85a32e88dc687028b28e5e15 Mon Sep 17 00:00:00 2001 From: mydearxym Date: Sun, 16 May 2021 11:41:54 +0800 Subject: [PATCH 02/11] chore(article-comments): missing repo support in pinned comments --- lib/groupher_server/cms/article_pined_comment.ex | 14 +++++--------- .../cms/delegates/article_comment.ex | 2 +- .../cms/delegates/article_community.ex | 1 - ...033634_add_repo_in_pinned_artilce_comments.exs | 15 +++++++++++++++ 4 files changed, 21 insertions(+), 11 deletions(-) create mode 100644 priv/repo/migrations/20210516033634_add_repo_in_pinned_artilce_comments.exs diff --git a/lib/groupher_server/cms/article_pined_comment.ex b/lib/groupher_server/cms/article_pined_comment.ex index c448eab83..cee40da8f 100644 --- a/lib/groupher_server/cms/article_pined_comment.ex +++ b/lib/groupher_server/cms/article_pined_comment.ex @@ -8,12 +8,7 @@ defmodule GroupherServer.CMS.ArticlePinedComment do import Ecto.Changeset alias GroupherServer.CMS - - alias CMS.{ - Post, - Job, - ArticleComment - } + alias CMS.ArticleComment # alias Helper.HTML @@ -23,8 +18,9 @@ defmodule GroupherServer.CMS.ArticlePinedComment do @type t :: %ArticlePinedComment{} schema "articles_pined_comments" do belongs_to(:article_comment, ArticleComment, foreign_key: :article_comment_id) - belongs_to(:post, Post, foreign_key: :post_id) - belongs_to(:job, Job, foreign_key: :job_id) + belongs_to(:post, CMS.Post, foreign_key: :post_id) + belongs_to(:job, CMS.Job, foreign_key: :job_id) + belongs_to(:repo, CMS.Repo, foreign_key: :repo_id) timestamps(type: :utc_datetime) end @@ -39,6 +35,6 @@ defmodule GroupherServer.CMS.ArticlePinedComment do # @doc false def update_changeset(%ArticlePinedComment{} = article_pined_comment, attrs) do article_pined_comment - |> cast(attrs, @required_fields ++ @updatable_fields) + |> cast(attrs, @required_fields ++ @optional_fields) end end diff --git a/lib/groupher_server/cms/delegates/article_comment.ex b/lib/groupher_server/cms/delegates/article_comment.ex index 59aa3f64f..1d643cd0e 100644 --- a/lib/groupher_server/cms/delegates/article_comment.ex +++ b/lib/groupher_server/cms/delegates/article_comment.ex @@ -3,7 +3,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleComment do CURD and operations for article comments """ import Ecto.Query, warn: false - import Helper.Utils, only: [done: 1, get_config: 2] + import Helper.Utils, only: [done: 1] import Helper.ErrorCode import GroupherServer.CMS.Delegate.Helper, only: [mark_viewer_emotion_states: 3] diff --git a/lib/groupher_server/cms/delegates/article_community.ex b/lib/groupher_server/cms/delegates/article_community.ex index 19042c40a..7321d1590 100644 --- a/lib/groupher_server/cms/delegates/article_community.ex +++ b/lib/groupher_server/cms/delegates/article_community.ex @@ -7,7 +7,6 @@ defmodule GroupherServer.CMS.Delegate.ArticleCommunity do import Ecto.Query, warn: false import Helper.ErrorCode - import ShortMaps import Helper.Utils, only: [strip_struct: 1, done: 1] import GroupherServer.CMS.Helper.Matcher2 diff --git a/priv/repo/migrations/20210516033634_add_repo_in_pinned_artilce_comments.exs b/priv/repo/migrations/20210516033634_add_repo_in_pinned_artilce_comments.exs new file mode 100644 index 000000000..1314419e4 --- /dev/null +++ b/priv/repo/migrations/20210516033634_add_repo_in_pinned_artilce_comments.exs @@ -0,0 +1,15 @@ +defmodule GroupherServer.Repo.Migrations.AddRepoInPinnedArtilceComments do + use Ecto.Migration + + def change do + alter table(:articles_pined_comments) do + add(:repo_id, references(:cms_repos, on_delete: :delete_all)) + end + + create(index(:articles_pined_comments, [:repo_id])) + + create( + unique_index(:articles_pined_comments, [:post_id, :job_id, :repo_id, :article_comment_id]) + ) + end +end From d5ee7f06dac97b57ebe14039eaa8b8483ce94087 Mon Sep 17 00:00:00 2001 From: mydearxym Date: Sun, 16 May 2021 11:51:16 +0800 Subject: [PATCH 03/11] chore(article-comments): wip --- .../cms/delegates/article_comment_action.ex | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/groupher_server/cms/delegates/article_comment_action.ex b/lib/groupher_server/cms/delegates/article_comment_action.ex index c91d2115b..92a748ac8 100644 --- a/lib/groupher_server/cms/delegates/article_comment_action.ex +++ b/lib/groupher_server/cms/delegates/article_comment_action.ex @@ -256,6 +256,12 @@ defmodule GroupherServer.CMS.Delegate.ArticleCommentAction do end end + defp get_article(%ArticleComment{repo_id: repo_id} = comment) when not is_nil(job_id) do + with {:ok, article} <- ORM.find(CMS.Repo, comment.repo_id, preload: [author: :user]) do + {:job, article} + end + end + @spec get_full_comment(String.t()) :: {:ok, T.article_info()} | {:error, nil} defp get_full_comment(comment_id) do query = from(c in ArticleComment, where: c.id == ^comment_id, preload: :post, preload: :job) @@ -273,6 +279,10 @@ defmodule GroupherServer.CMS.Delegate.ArticleCommentAction do do_extract_article_info(:job, job) end + defp extract_article_info(%ArticleComment{repo: %CMS.Repo{} = repo}) when not is_nil(repo) do + do_extract_article_info(:repo, repo) + end + @spec do_extract_article_info(T.article_thread(), T.article_common()) :: {:ok, T.article_info()} defp do_extract_article_info(thread, article) do with {:ok, article_with_author} <- Repo.preload(article, author: :user) |> done(), From 9bfe042d538aefb0b87b2544ebf977b0ff6a97ea Mon Sep 17 00:00:00 2001 From: mydearxym Date: Sun, 16 May 2021 11:58:07 +0800 Subject: [PATCH 04/11] chore(article-comments): wip --- lib/groupher_server/cms/delegates/article_comment_action.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/groupher_server/cms/delegates/article_comment_action.ex b/lib/groupher_server/cms/delegates/article_comment_action.ex index 92a748ac8..d0a154229 100644 --- a/lib/groupher_server/cms/delegates/article_comment_action.ex +++ b/lib/groupher_server/cms/delegates/article_comment_action.ex @@ -256,7 +256,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleCommentAction do end end - defp get_article(%ArticleComment{repo_id: repo_id} = comment) when not is_nil(job_id) do + defp get_article(%ArticleComment{repo_id: repo_id} = comment) when not is_nil(repo_id) do with {:ok, article} <- ORM.find(CMS.Repo, comment.repo_id, preload: [author: :user]) do {:job, article} end From 7d65a6a2d1d922ee34931cd61099d678e52910d8 Mon Sep 17 00:00:00 2001 From: mydearxym Date: Sun, 16 May 2021 12:09:53 +0800 Subject: [PATCH 05/11] chore(article-comments): wip && clean up --- lib/groupher_server/cms/delegates/article_comment_action.ex | 4 +++- test/groupher_server_web/mutation/cms/cms_manager_test.exs | 2 +- .../groupher_server_web/mutation/cms/flags/post_flag_test.exs | 2 +- .../query/cms/comments/job_comment_test.exs | 1 - .../query/cms/comments/post_comment_test.exs | 1 - .../query/cms/comments/repo_comment_test.exs | 3 +-- test/groupher_server_web/query/cms/flags/jobs_flags_test.exs | 3 --- test/groupher_server_web/query/cms/flags/posts_flags_test.exs | 3 --- test/groupher_server_web/query/cms/flags/repos_flags_test.exs | 3 --- 9 files changed, 6 insertions(+), 16 deletions(-) diff --git a/lib/groupher_server/cms/delegates/article_comment_action.ex b/lib/groupher_server/cms/delegates/article_comment_action.ex index d0a154229..7e69f7d01 100644 --- a/lib/groupher_server/cms/delegates/article_comment_action.ex +++ b/lib/groupher_server/cms/delegates/article_comment_action.ex @@ -22,6 +22,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleCommentAction do ArticlePinedComment, ArticleCommentUpvote, ArticleCommentReply, + Community, # TODO: remove spec type Post, Job @@ -29,6 +30,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleCommentAction do alias Ecto.Multi + @article_threads Community.article_threads() @max_parent_replies_count ArticleComment.max_parent_replies_count() @pined_comment_limit ArticleComment.pined_comment_limit() @@ -264,7 +266,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleCommentAction do @spec get_full_comment(String.t()) :: {:ok, T.article_info()} | {:error, nil} defp get_full_comment(comment_id) do - query = from(c in ArticleComment, where: c.id == ^comment_id, preload: :post, preload: :job) + query = from(c in ArticleComment, where: c.id == ^comment_id, preload: ^@article_threads) with {:ok, comment} <- Repo.one(query) |> done() do extract_article_info(comment) diff --git a/test/groupher_server_web/mutation/cms/cms_manager_test.exs b/test/groupher_server_web/mutation/cms/cms_manager_test.exs index 3450015f2..c7b8f2cf0 100644 --- a/test/groupher_server_web/mutation/cms/cms_manager_test.exs +++ b/test/groupher_server_web/mutation/cms/cms_manager_test.exs @@ -28,7 +28,7 @@ defmodule GroupherServer.Test.Mutation.CMS.Manager do } } """ - @tag :wip2 + test "root can markDelete a post", ~m(community user)a do post_attrs = mock_attrs(:post, %{community_id: community.id}) {:ok, post} = CMS.create_article(community, :post, post_attrs, user) diff --git a/test/groupher_server_web/mutation/cms/flags/post_flag_test.exs b/test/groupher_server_web/mutation/cms/flags/post_flag_test.exs index 27f1b60e5..ec84802db 100644 --- a/test/groupher_server_web/mutation/cms/flags/post_flag_test.exs +++ b/test/groupher_server_web/mutation/cms/flags/post_flag_test.exs @@ -25,7 +25,7 @@ defmodule GroupherServer.Test.Mutation.Flags.PostFlag do } } """ - test "auth user can markDelete post", ~m(community post)a do + test "auth user can markDelete post", ~m(post)a do variables = %{id: post.id} passport_rules = %{"post.mark_delete" => true} diff --git a/test/groupher_server_web/query/cms/comments/job_comment_test.exs b/test/groupher_server_web/query/cms/comments/job_comment_test.exs index d586d9e77..c26792feb 100644 --- a/test/groupher_server_web/query/cms/comments/job_comment_test.exs +++ b/test/groupher_server_web/query/cms/comments/job_comment_test.exs @@ -243,7 +243,6 @@ defmodule GroupherServer.Test.Query.Comments.JobComment do assert results["totalCount"] == total_count end - @tag :wip2 test "guest user can get paged comment with pinned comment in it", ~m(guest_conn job user)a do total_count = 20 diff --git a/test/groupher_server_web/query/cms/comments/post_comment_test.exs b/test/groupher_server_web/query/cms/comments/post_comment_test.exs index 91f500353..cc2c9d476 100644 --- a/test/groupher_server_web/query/cms/comments/post_comment_test.exs +++ b/test/groupher_server_web/query/cms/comments/post_comment_test.exs @@ -243,7 +243,6 @@ defmodule GroupherServer.Test.Query.Comments.PostComment do assert results["totalCount"] == total_count end - @tag :wip2 test "guest user can get paged comment with pinned comment in it", ~m(guest_conn post user)a do total_count = 20 diff --git a/test/groupher_server_web/query/cms/comments/repo_comment_test.exs b/test/groupher_server_web/query/cms/comments/repo_comment_test.exs index bd0b26138..9e1a52d0e 100644 --- a/test/groupher_server_web/query/cms/comments/repo_comment_test.exs +++ b/test/groupher_server_web/query/cms/comments/repo_comment_test.exs @@ -243,7 +243,6 @@ defmodule GroupherServer.Test.Query.Comments.RepoComment do assert results["totalCount"] == total_count end - @tag :wip2 test "guest user can get paged comment with pinned comment in it", ~m(guest_conn repo user)a do total_count = 20 @@ -364,7 +363,7 @@ defmodule GroupherServer.Test.Query.Comments.RepoComment do assert List.last(results["entries"]) |> Map.get("id") == to_string(comment.id) end - @tag :wip + @tag :wip2 test "guest user can get paged comment with upvotes_count", ~m(guest_conn repo user user2)a do total_count = 10 page_size = 10 diff --git a/test/groupher_server_web/query/cms/flags/jobs_flags_test.exs b/test/groupher_server_web/query/cms/flags/jobs_flags_test.exs index 215d2e624..55ee648c3 100644 --- a/test/groupher_server_web/query/cms/flags/jobs_flags_test.exs +++ b/test/groupher_server_web/query/cms/flags/jobs_flags_test.exs @@ -4,9 +4,6 @@ defmodule GroupherServer.Test.Query.Flags.JobsFlags do import Helper.Utils, only: [get_config: 2] alias GroupherServer.CMS - # alias GroupherServer.Repo - - alias CMS.Job @total_count 35 @page_size get_config(:general, :page_size) diff --git a/test/groupher_server_web/query/cms/flags/posts_flags_test.exs b/test/groupher_server_web/query/cms/flags/posts_flags_test.exs index b7b2c3048..ac785f661 100644 --- a/test/groupher_server_web/query/cms/flags/posts_flags_test.exs +++ b/test/groupher_server_web/query/cms/flags/posts_flags_test.exs @@ -4,9 +4,6 @@ defmodule GroupherServer.Test.Query.Flags.PostsFlags do import Helper.Utils, only: [get_config: 2] alias GroupherServer.CMS - # alias GroupherServer.Repo - - alias CMS.Post @total_count 35 @page_size get_config(:general, :page_size) diff --git a/test/groupher_server_web/query/cms/flags/repos_flags_test.exs b/test/groupher_server_web/query/cms/flags/repos_flags_test.exs index dff4164af..fc787b537 100644 --- a/test/groupher_server_web/query/cms/flags/repos_flags_test.exs +++ b/test/groupher_server_web/query/cms/flags/repos_flags_test.exs @@ -4,9 +4,6 @@ defmodule GroupherServer.Test.Query.Flags.ReposFlags do import Helper.Utils, only: [get_config: 2] alias GroupherServer.CMS - # alias GroupherServer.Repo - - alias CMS.Repo @total_count 35 @page_size get_config(:general, :page_size) From d7368035b1c7409c9bfa479a00bf211024dfa26b Mon Sep 17 00:00:00 2001 From: mydearxym Date: Sun, 16 May 2021 13:16:00 +0800 Subject: [PATCH 06/11] chore(article-comments): wip && clean up --- lib/groupher_server/cms/delegates/article_comment.ex | 2 +- lib/groupher_server/cms/delegates/article_comment_action.ex | 2 +- lib/helper/types.ex | 1 - .../query/cms/comments/repo_comment_test.exs | 3 +-- 4 files changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/groupher_server/cms/delegates/article_comment.ex b/lib/groupher_server/cms/delegates/article_comment.ex index 1d643cd0e..a29726869 100644 --- a/lib/groupher_server/cms/delegates/article_comment.ex +++ b/lib/groupher_server/cms/delegates/article_comment.ex @@ -68,7 +68,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleComment do do_paged_comment_replies(comment_id, filters, user) end - @spec paged_article_comments_participators(T.comment_thread(), Integer.t(), T.paged_filter()) :: + @spec paged_article_comments_participators(T.article_thread(), Integer.t(), T.paged_filter()) :: {:ok, T.paged_users()} def paged_article_comments_participators(thread, article_id, filters) do %{page: page, size: size} = filters diff --git a/lib/groupher_server/cms/delegates/article_comment_action.ex b/lib/groupher_server/cms/delegates/article_comment_action.ex index 7e69f7d01..8234fd10f 100644 --- a/lib/groupher_server/cms/delegates/article_comment_action.ex +++ b/lib/groupher_server/cms/delegates/article_comment_action.ex @@ -260,7 +260,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleCommentAction do defp get_article(%ArticleComment{repo_id: repo_id} = comment) when not is_nil(repo_id) do with {:ok, article} <- ORM.find(CMS.Repo, comment.repo_id, preload: [author: :user]) do - {:job, article} + {:repo, article} end end diff --git a/lib/helper/types.ex b/lib/helper/types.ex index 1aae84773..3b040a9a8 100644 --- a/lib/helper/types.ex +++ b/lib/helper/types.ex @@ -34,7 +34,6 @@ defmodule Helper.Types do } @type article_thread :: :post | :job | :repo - @type comment_thread :: :post | :job @type paged_filter :: %{ page: Integer.t(), diff --git a/test/groupher_server_web/query/cms/comments/repo_comment_test.exs b/test/groupher_server_web/query/cms/comments/repo_comment_test.exs index 9e1a52d0e..755443a16 100644 --- a/test/groupher_server_web/query/cms/comments/repo_comment_test.exs +++ b/test/groupher_server_web/query/cms/comments/repo_comment_test.exs @@ -154,7 +154,7 @@ defmodule GroupherServer.Test.Query.Comments.RepoComment do to_string(replyed_comment_2.id) end - @tag :wip + @tag :wip2 test "timeline-mode paged comments", ~m(guest_conn repo user user2)a do total_count = 3 page_size = 20 @@ -363,7 +363,6 @@ defmodule GroupherServer.Test.Query.Comments.RepoComment do assert List.last(results["entries"]) |> Map.get("id") == to_string(comment.id) end - @tag :wip2 test "guest user can get paged comment with upvotes_count", ~m(guest_conn repo user user2)a do total_count = 10 page_size = 10 From 2217b567b43130fe1778a3aa6bfdf46d8670a674 Mon Sep 17 00:00:00 2001 From: mydearxym Date: Sun, 16 May 2021 13:46:51 +0800 Subject: [PATCH 07/11] chore(article-comments): wip && clean up --- lib/groupher_server/cms/repo.ex | 11 ++++++-- .../schema/cms/cms_types.ex | 1 + ...516052616_add_comment_support_for_repo.exs | 11 ++++++++ .../accounts/achievement_test.exs | 2 -- .../accounts/collect_folder_test.exs | 20 --------------- .../accounts/published_contents_test.exs | 1 - .../accounts/reacted_articles_test.exs | 3 --- test/groupher_server/accounts/utils_test.exs | 1 - .../cms/abuse_reports/comment_report_test.exs | 1 - .../cms/article_collect_test.exs | 6 ----- test/groupher_server/cms/article_pin_test.exs | 4 --- .../comments/job_comment_emotions_test.exs | 2 -- .../cms/comments/job_comment_replies_test.exs | 6 ----- .../cms/comments/job_comment_test.exs | 25 ++----------------- .../comments/post_comment_emotions_test.exs | 2 -- .../comments/post_comment_replies_test.exs | 5 ---- .../cms/comments/post_comment_test.exs | 25 +------------------ test/groupher_server/cms/post_meta_test.exs | 3 --- .../statistics/statistics_test.exs | 1 - .../mutation/accounts/collect_folder_test.exs | 12 ++++----- .../cms/article_community/job_test.exs | 7 ++---- .../cms/article_community/post_test.exs | 6 ++--- .../cms/article_community/repo_test.exs | 6 ++--- .../mutation/cms/articles/post_test.exs | 1 - .../mutation/cms/cms_test.exs | 2 +- .../query/accounts/achievement_test.exs | 5 ++-- .../query/accounts/colleced_articles_test.exs | 8 ++---- .../query/accounts/upvoteed_articles_test.exs | 3 +-- .../query/cms/comments/job_comment_test.exs | 15 +++-------- .../query/cms/comments/post_comment_test.exs | 15 +++-------- .../query/cms/comments/repo_comment_test.exs | 15 +++-------- .../query/cms/flags/jobs_flags_test.exs | 1 - .../query/cms/flags/posts_flags_test.exs | 1 - .../query/cms/flags/repos_flags_test.exs | 1 - .../query/cms/old_post_comment_test.exs | 2 +- test/helper/cache_test.exs | 4 --- .../editor_to_html_test/header_test.exs | 6 +---- .../editor_to_html_test/image_test.exs | 9 ------- .../editor_to_html_test/index_test.exs | 4 +-- .../editor_to_html_test/list_test.exs | 7 ------ .../editor_to_html_test/paragraph_test.exs | 4 +-- .../editor_to_html_test/people_test.exs | 2 -- .../editor_to_html_test/quote_test.exs | 5 ---- .../editor_to_html_test/table_test.exs | 3 --- test/helper/validator/schema_test.exs | 8 ------ 45 files changed, 58 insertions(+), 224 deletions(-) create mode 100644 priv/repo/migrations/20210516052616_add_comment_support_for_repo.exs diff --git a/lib/groupher_server/cms/repo.ex b/lib/groupher_server/cms/repo.ex index cdd28b2fb..b3be371b0 100644 --- a/lib/groupher_server/cms/repo.ex +++ b/lib/groupher_server/cms/repo.ex @@ -7,11 +7,12 @@ defmodule GroupherServer.CMS.Repo do import Ecto.Changeset - alias GroupherServer.CMS + alias GroupherServer.{CMS, Accounts} alias CMS.{ Author, Embeds, + ArticleComment, Community, RepoContributor, RepoLang, @@ -24,7 +25,7 @@ defmodule GroupherServer.CMS.Repo do @timestamps_opts [type: :utc_datetime_usec] @required_fields ~w(title owner_name owner_url repo_url desc readme star_count issues_count prs_count fork_count watch_count)a - @optional_fields ~w(original_community_id last_sync homepage_url release_tag license upvotes_count collects_count mark_delete)a + @optional_fields ~w(original_community_id last_sync homepage_url release_tag license upvotes_count collects_count mark_delete article_comments_count article_comments_participators_count)a @type t :: %Repo{} schema "cms_repos" do @@ -73,6 +74,12 @@ defmodule GroupherServer.CMS.Repo do field(:last_sync, :utc_datetime) + has_many(:article_comments, {"articles_comments", ArticleComment}) + field(:article_comments_count, :integer, default: 0) + field(:article_comments_participators_count, :integer, default: 0) + # 评论参与者,只保留最近 5 个 + embeds_many(:article_comments_participators, Accounts.User, on_replace: :delete) + many_to_many( :tags, Tag, diff --git a/lib/groupher_server_web/schema/cms/cms_types.ex b/lib/groupher_server_web/schema/cms/cms_types.ex index f41606ac7..2a5eb360c 100644 --- a/lib/groupher_server_web/schema/cms/cms_types.ex +++ b/lib/groupher_server_web/schema/cms/cms_types.ex @@ -178,6 +178,7 @@ defmodule GroupherServerWeb.Schema.CMS.Types do field(:original_community, :community, resolve: dataloader(CMS, :original_community)) field(:communities, list_of(:community), resolve: dataloader(CMS, :communities)) + article_comments_fields() viewer_has_state_fields() # comments_count # comments_participators diff --git a/priv/repo/migrations/20210516052616_add_comment_support_for_repo.exs b/priv/repo/migrations/20210516052616_add_comment_support_for_repo.exs new file mode 100644 index 000000000..4618df785 --- /dev/null +++ b/priv/repo/migrations/20210516052616_add_comment_support_for_repo.exs @@ -0,0 +1,11 @@ +defmodule GroupherServer.Repo.Migrations.AddCommentSupportForRepo do + use Ecto.Migration + + def change do + alter table(:cms_repos) do + add(:article_comments_participators_count, :integer, default: 0) + add(:article_comments_count, :integer, default: 0) + add(:article_comments_participators, :map) + end + end +end diff --git a/test/groupher_server/accounts/achievement_test.exs b/test/groupher_server/accounts/achievement_test.exs index 40b70410b..b57310e91 100644 --- a/test/groupher_server/accounts/achievement_test.exs +++ b/test/groupher_server/accounts/achievement_test.exs @@ -52,7 +52,6 @@ defmodule GroupherServer.Test.Accounts.Achievement do describe "[Accounts Achievement funtion]" do alias Accounts.Achievement - @tag :wip test "Accounts.achieve should inc / dec achievement by parts", ~m(user)a do user |> Accounts.achieve(:inc, :follow) user |> Accounts.achieve(:inc, :upvote) @@ -77,7 +76,6 @@ defmodule GroupherServer.Test.Accounts.Achievement do assert achievement.reputation == 0 end - @tag :wip test "Accounts.achieve can not minus count < 0", ~m(user)a do user |> Accounts.achieve(:dec, :follow) user |> Accounts.achieve(:dec, :upvote) diff --git a/test/groupher_server/accounts/collect_folder_test.exs b/test/groupher_server/accounts/collect_folder_test.exs index d22df386f..398ab0c13 100644 --- a/test/groupher_server/accounts/collect_folder_test.exs +++ b/test/groupher_server/accounts/collect_folder_test.exs @@ -22,7 +22,6 @@ defmodule GroupherServer.Test.Accounts.CollectFolder do end describe "[collect folder curd]" do - @tag :wip test "user can create collect folder", ~m(user)a do folder_title = "test folder" @@ -35,7 +34,6 @@ defmodule GroupherServer.Test.Accounts.CollectFolder do assert folder.meta |> Map.from_struct() |> Map.delete(:id) == @default_meta end - @tag :wip test "user create dup collect folder fails", ~m(user)a do {:ok, _folder} = Accounts.create_collect_folder(%{title: "test folder"}, user) {:error, reason} = Accounts.create_collect_folder(%{title: "test folder"}, user) @@ -43,7 +41,6 @@ defmodule GroupherServer.Test.Accounts.CollectFolder do assert reason |> is_error?(:already_exsit) end - @tag :wip test "user can delete a empty collect folder", ~m(user)a do {:ok, folder} = Accounts.create_collect_folder(%{title: "test folder"}, user) {:ok, _} = Accounts.delete_collect_folder(folder.id) @@ -51,7 +48,6 @@ defmodule GroupherServer.Test.Accounts.CollectFolder do assert {:error, _} = ORM.find(CMS.ArticleCollect, folder.id) end - @tag :wip test "user can not delete a non-empty collect folder", ~m(post user)a do {:ok, folder} = Accounts.create_collect_folder(%{title: "test folder"}, user) {:ok, _folder} = Accounts.add_to_collect(:post, post.id, folder.id, user) @@ -61,7 +57,6 @@ defmodule GroupherServer.Test.Accounts.CollectFolder do assert reason |> is_error?(:delete_no_empty_collect_folder) end - @tag :wip test "user can get public collect-folder list", ~m(user)a do {:ok, _folder} = Accounts.create_collect_folder(%{title: "test folder"}, user) {:ok, _folder} = Accounts.create_collect_folder(%{title: "test folder2"}, user) @@ -72,7 +67,6 @@ defmodule GroupherServer.Test.Accounts.CollectFolder do assert result.total_count == 2 end - @tag :wip test "user can get public collect-folder list by thread", ~m(user post)a do {:ok, folder} = Accounts.create_collect_folder(%{title: "test folder"}, user) {:ok, _folder} = Accounts.create_collect_folder(%{title: "test folder2"}, user) @@ -87,7 +81,6 @@ defmodule GroupherServer.Test.Accounts.CollectFolder do assert result.entries |> List.first() |> Map.get(:id) == folder.id end - @tag :wip test "user can not get private folder list of other user", ~m(user user2)a do {:ok, _folder} = Accounts.create_collect_folder(%{title: "test folder", private: true}, user2) @@ -100,7 +93,6 @@ defmodule GroupherServer.Test.Accounts.CollectFolder do assert result.total_count == 1 end - @tag :wip test "collect creator can get both public and private folder list", ~m(user)a do {:ok, _folder} = Accounts.create_collect_folder(%{title: "test folder", private: true}, user) @@ -112,7 +104,6 @@ defmodule GroupherServer.Test.Accounts.CollectFolder do assert result.total_count == 2 end - @tag :wip test "user can update a collect folder", ~m(user)a do {:ok, folder} = Accounts.create_collect_folder(%{title: "test folder", private: true}, user) @@ -128,7 +119,6 @@ defmodule GroupherServer.Test.Accounts.CollectFolder do end describe "[add/remove from collect]" do - @tag :wip test "can add post to exsit colect-folder", ~m(user post)a do {:ok, folder} = Accounts.create_collect_folder(%{title: "test folder"}, user) @@ -139,7 +129,6 @@ defmodule GroupherServer.Test.Accounts.CollectFolder do assert folder.collects |> List.first() |> Map.get(:post_id) == post.id end - @tag :wip test "can not collect some article in one collect-folder", ~m(user post)a do {:ok, folder} = Accounts.create_collect_folder(%{title: "test folder"}, user) {:ok, folder} = Accounts.add_to_collect(:post, post.id, folder.id, user) @@ -148,7 +137,6 @@ defmodule GroupherServer.Test.Accounts.CollectFolder do assert reason |> is_error?(:already_collected_in_folder) end - @tag :wip test "colect-folder should in article_collect's meta info too", ~m(user post)a do {:ok, folder} = Accounts.create_collect_folder(%{title: "test folder"}, user) {:ok, folder} = Accounts.add_to_collect(:post, post.id, folder.id, user) @@ -159,7 +147,6 @@ defmodule GroupherServer.Test.Accounts.CollectFolder do assert article_collect_folder.id == folder.id end - @tag :wip test "one article collected in different collect-folder should only have one article-collect record", ~m(user post)a do {:ok, folder} = Accounts.create_collect_folder(%{title: "test folder"}, user) @@ -175,7 +162,6 @@ defmodule GroupherServer.Test.Accounts.CollectFolder do assert result.total_count == 1 end - @tag :wip test "can remove post to exsit colect-folder", ~m(user post post2)a do {:ok, folder} = Accounts.create_collect_folder(%{title: "test folder"}, user) {:ok, _folder} = Accounts.add_to_collect(:post, post.id, folder.id, user) @@ -191,7 +177,6 @@ defmodule GroupherServer.Test.Accounts.CollectFolder do assert result.entries |> List.first() |> Map.get(:id) == post2.id end - @tag :wip test "can remove post to exsit colect-folder should update article collect meta", ~m(user post)a do {:ok, folder} = Accounts.create_collect_folder(%{title: "test folder"}, user) @@ -210,7 +195,6 @@ defmodule GroupherServer.Test.Accounts.CollectFolder do assert article_collect.id == folder2.id end - @tag :wip test "post belongs to other folder should keep article collect record", ~m(user post)a do {:ok, folder} = Accounts.create_collect_folder(%{title: "test folder"}, user) @@ -231,7 +215,6 @@ defmodule GroupherServer.Test.Accounts.CollectFolder do assert result.total_count == 0 end - @tag :wip test "add post to exsit colect-folder should update meta", ~m(user post post2 job)a do {:ok, folder} = Accounts.create_collect_folder(%{title: "test folder"}, user) @@ -248,7 +231,6 @@ defmodule GroupherServer.Test.Accounts.CollectFolder do assert folder.meta.job_count == 1 end - @tag :wip test "remove post to exsit colect-folder should update meta", ~m(user post post2 job)a do {:ok, folder} = Accounts.create_collect_folder(%{title: "test folder"}, user) {:ok, _folder} = Accounts.add_to_collect(:post, post.id, folder.id, user) @@ -270,7 +252,6 @@ defmodule GroupherServer.Test.Accounts.CollectFolder do assert not folder.meta.has_job end - @tag :wip test "can get articles of a collect folder", ~m(user post job)a do {:ok, folder} = Accounts.create_collect_folder(%{title: "test folder"}, user) {:ok, _folder} = Accounts.add_to_collect(:post, post.id, folder.id, user) @@ -291,7 +272,6 @@ defmodule GroupherServer.Test.Accounts.CollectFolder do assert collect_post.title == post.title end - @tag :wip test "can not get articles of a private collect folder if not owner", ~m(user user2 post job)a do {:ok, folder} = Accounts.create_collect_folder(%{title: "test folder", private: true}, user) diff --git a/test/groupher_server/accounts/published_contents_test.exs b/test/groupher_server/accounts/published_contents_test.exs index d8ef10778..a6406dd57 100644 --- a/test/groupher_server/accounts/published_contents_test.exs +++ b/test/groupher_server/accounts/published_contents_test.exs @@ -67,7 +67,6 @@ defmodule GroupherServer.Test.Accounts.PublishedContents do assert results.total_count == 0 end - @tag :wip test "user can get paged published jobs", ~m(user user2 community community2)a do pub_jobs = Enum.reduce(1..@publish_count, [], fn _, acc -> diff --git a/test/groupher_server/accounts/reacted_articles_test.exs b/test/groupher_server/accounts/reacted_articles_test.exs index 6310b62bf..3d90cc29d 100644 --- a/test/groupher_server/accounts/reacted_articles_test.exs +++ b/test/groupher_server/accounts/reacted_articles_test.exs @@ -14,7 +14,6 @@ defmodule GroupherServer.Test.Accounts.ReactedContents do end describe "[user upvoted articles]" do - @tag :wip test "user can get paged upvoted common articles", ~m(user post job)a do {:ok, _} = CMS.upvote_article(:post, post.id, user) {:ok, _} = CMS.upvote_article(:job, job.id, user) @@ -33,7 +32,6 @@ defmodule GroupherServer.Test.Accounts.ReactedContents do assert [:id, :thread, :title, :upvotes_count] == article_job |> Map.keys() end - @tag :wip test "user can get paged upvoted posts by thread filter", ~m(user post job)a do {:ok, _} = CMS.upvote_article(:post, post.id, user) {:ok, _} = CMS.upvote_article(:job, job.id, user) @@ -46,7 +44,6 @@ defmodule GroupherServer.Test.Accounts.ReactedContents do assert 1 == articles |> Map.get(:total_count) end - @tag :wip test "user can get paged upvoted jobs by thread filter", ~m(user post job)a do {:ok, _} = CMS.upvote_article(:post, post.id, user) {:ok, _} = CMS.upvote_article(:job, job.id, user) diff --git a/test/groupher_server/accounts/utils_test.exs b/test/groupher_server/accounts/utils_test.exs index 874f3640e..1e4862c61 100644 --- a/test/groupher_server/accounts/utils_test.exs +++ b/test/groupher_server/accounts/utils_test.exs @@ -8,7 +8,6 @@ defmodule GroupherServer.Test.Accounts.Utils do @cache_pool :user_login describe "[get userid]" do - @tag :wip test "get_userid_and_cache should work" do {:ok, user} = db_insert(:user) diff --git a/test/groupher_server/cms/abuse_reports/comment_report_test.exs b/test/groupher_server/cms/abuse_reports/comment_report_test.exs index 6027386c9..6ce9610b7 100644 --- a/test/groupher_server/cms/abuse_reports/comment_report_test.exs +++ b/test/groupher_server/cms/abuse_reports/comment_report_test.exs @@ -51,7 +51,6 @@ defmodule GroupherServer.Test.CMS.AbuseReports.CommentReport do assert List.last(report_cases).user.login == user2.login end - @tag :wip test "same user can not report a comment twice", ~m(user post)a do {:ok, comment} = CMS.create_article_comment(:post, post.id, "commment", user) {:ok, comment} = CMS.report_article_comment(comment.id, "reason", "attr", user) diff --git a/test/groupher_server/cms/article_collect_test.exs b/test/groupher_server/cms/article_collect_test.exs index c21a0c1e5..ca72fda4d 100644 --- a/test/groupher_server/cms/article_collect_test.exs +++ b/test/groupher_server/cms/article_collect_test.exs @@ -18,7 +18,6 @@ defmodule GroupherServer.Test.ArticleCollect do end describe "[cms post collect]" do - @tag :wip test "post can be collect && collects_count should inc by 1", ~m(user user2 community post_attrs)a do {:ok, post} = CMS.create_article(community, :post, post_attrs, user) @@ -35,7 +34,6 @@ defmodule GroupherServer.Test.ArticleCollect do assert article.collects_count == 2 end - @tag :wip test "post can be undo collect && collects_count should dec by 1", ~m(user community post_attrs)a do {:ok, post} = CMS.create_article(community, :post, post_attrs, user) @@ -50,7 +48,6 @@ defmodule GroupherServer.Test.ArticleCollect do assert article.collects_count == 0 end - @tag :wip test "can get collect_users", ~m(user user2 community post_attrs)a do {:ok, post} = CMS.create_article(community, :post, post_attrs, user) @@ -100,7 +97,6 @@ defmodule GroupherServer.Test.ArticleCollect do end describe "[cms job collect]" do - @tag :wip test "job can be collect && collects_count should inc by 1", ~m(user user2 community job_attrs)a do {:ok, job} = CMS.create_article(community, :job, job_attrs, user) @@ -116,7 +112,6 @@ defmodule GroupherServer.Test.ArticleCollect do assert article.collects_count == 2 end - @tag :wip test "job can be undo collect && collects_count should dec by 1", ~m(user community job_attrs)a do {:ok, job} = CMS.create_article(community, :job, job_attrs, user) @@ -132,7 +127,6 @@ defmodule GroupherServer.Test.ArticleCollect do assert article.collects_count == 0 end - @tag :wip test "can get collect_users", ~m(user user2 community job_attrs)a do {:ok, job} = CMS.create_article(community, :job, job_attrs, user) diff --git a/test/groupher_server/cms/article_pin_test.exs b/test/groupher_server/cms/article_pin_test.exs index 5a66a6b19..b2a144340 100644 --- a/test/groupher_server/cms/article_pin_test.exs +++ b/test/groupher_server/cms/article_pin_test.exs @@ -27,7 +27,6 @@ defmodule GroupherServer.Test.CMS.ArticlePin do end describe "[cms post pin]" do - @tag :wip test "can pin a post", ~m(community post)a do {:ok, _} = CMS.pin_article(:post, post.id, community.id) {:ok, pind_article} = ORM.find_by(PinnedArticle, %{post_id: post.id}) @@ -35,7 +34,6 @@ defmodule GroupherServer.Test.CMS.ArticlePin do assert pind_article.post_id == post.id end - @tag :wip test "one community & thread can only pin certern count of post", ~m(community user)a do Enum.reduce(1..@max_pinned_article_count_per_thread, [], fn _, acc -> {:ok, new_post} = CMS.create_article(community, :post, mock_attrs(:post), user) @@ -48,12 +46,10 @@ defmodule GroupherServer.Test.CMS.ArticlePin do assert reason |> Keyword.get(:code) == ecode(:too_much_pinned_article) end - @tag :wip test "can not pin a non-exsit post", ~m(community)a do assert {:error, _} = CMS.pin_article(:post, 8848, community.id) end - @tag :wip test "can undo pin to a post", ~m(community post)a do {:ok, _} = CMS.pin_article(:post, post.id, community.id) diff --git a/test/groupher_server/cms/comments/job_comment_emotions_test.exs b/test/groupher_server/cms/comments/job_comment_emotions_test.exs index 0791efbf4..e876aff6a 100644 --- a/test/groupher_server/cms/comments/job_comment_emotions_test.exs +++ b/test/groupher_server/cms/comments/job_comment_emotions_test.exs @@ -64,7 +64,6 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentEmotions do end describe "[basic article comment emotion]" do - @tag :wip test "comment has default emotions after created", ~m(job user)a do parent_content = "parent comment" @@ -163,7 +162,6 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentEmotions do assert user_exist_in?(user3, emotions.latest_beer_users) end - @tag :wip test "same user can make differcent emotions on same comment", ~m(job user)a do parent_content = "parent comment" {:ok, parent_comment} = CMS.create_article_comment(:job, job.id, parent_content, user) diff --git a/test/groupher_server/cms/comments/job_comment_replies_test.exs b/test/groupher_server/cms/comments/job_comment_replies_test.exs index 4d13a798c..a6cfa2799 100644 --- a/test/groupher_server/cms/comments/job_comment_replies_test.exs +++ b/test/groupher_server/cms/comments/job_comment_replies_test.exs @@ -19,7 +19,6 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentReplies do end describe "[basic article comment replies]" do - @tag :wip test "exsit comment can be reply", ~m(job user user2)a do parent_content = "parent comment" reply_content = "reply comment" @@ -43,7 +42,6 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentReplies do {:error, _} = CMS.reply_article_comment(parent_comment.id, reply_content, user2) end - @tag :wip test "multi reply should belong to one parent comment", ~m(job user user2)a do parent_content = "parent comment" reply_content_1 = "reply comment 1" @@ -129,7 +127,6 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentReplies do assert not exist_in?(List.last(reply_comment_list), parent_comment.replies) end - @tag :wip test "replyed user should appear in article comment participators", ~m(job user user2)a do {:ok, parent_comment} = CMS.create_article_comment(:job, job.id, "parent_conent", user) {:ok, _} = CMS.reply_article_comment(parent_comment.id, "reply_content", user2) @@ -140,7 +137,6 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentReplies do assert exist_in?(user2, article.article_comments_participators) end - @tag :wip test "replies count should inc by 1 after got replyed", ~m(job user user2)a do {:ok, parent_comment} = CMS.create_article_comment(:job, job.id, "parent_conent", user) assert parent_comment.replies_count === 0 @@ -156,7 +152,6 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentReplies do end describe "[paged article comment replies]" do - @tag :wip test "can get paged replies of a parent comment", ~m(job user)a do {:ok, parent_comment} = CMS.create_article_comment(:job, job.id, "parent_conent", user) {:ok, paged_replies} = CMS.paged_comment_replies(parent_comment.id, %{page: 1, size: 20}) @@ -183,7 +178,6 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentReplies do assert exist_in?(Enum.at(reply_comment_list, 3), paged_replies.entries) end - @tag :wip test "can get reply_to info of a parent comment", ~m(job user)a do page_number = 1 page_size = 10 diff --git a/test/groupher_server/cms/comments/job_comment_test.exs b/test/groupher_server/cms/comments/job_comment_test.exs index e9e3a33c9..d5adc2162 100644 --- a/test/groupher_server/cms/comments/job_comment_test.exs +++ b/test/groupher_server/cms/comments/job_comment_test.exs @@ -22,7 +22,6 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do end describe "[basic article comment]" do - @tag :wip test "job are supported by article comment.", ~m(user job)a do {:ok, job_comment_1} = CMS.create_article_comment(:job, job.id, "job_comment 1", user) {:ok, job_comment_2} = CMS.create_article_comment(:job, job.id, "job_comment 2", user) @@ -33,7 +32,6 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do assert exist_in?(job_comment_2, job.article_comments) end - @tag :wip test "comment should have default meta after create", ~m(user job)a do {:ok, comment} = CMS.create_article_comment(:job, job.id, "job comment", user) assert comment.meta |> Map.from_struct() |> Map.delete(:id) == @default_comment_meta @@ -49,7 +47,6 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do end describe "[article comment floor]" do - @tag :wip test "comment will have a floor number after created", ~m(user job)a do {:ok, job_comment} = CMS.create_article_comment(:job, job.id, "comment", user) {:ok, job_comment2} = CMS.create_article_comment(:job, job.id, "comment2", user) @@ -63,7 +60,6 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do end describe "[article comment participator for job]" do - @tag :wip test "job will have participator after comment created", ~m(user job)a do job_comment_1 = "job_comment 1" @@ -75,7 +71,6 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do assert participator.id == user.id end - @tag :wip test "psot participator will not contains same user", ~m(user job)a do job_comment_1 = "job_comment 1" @@ -87,7 +82,6 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do assert 1 == length(job.article_comments_participators) end - @tag :wip test "recent comment user should appear at first of the psot participators", ~m(user user2 job)a do job_comment_1 = "job_comment 1" @@ -104,7 +98,6 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do end describe "[article comment upvotes]" do - @tag :wip test "user can upvote a job comment", ~m(user job)a do comment = "job_comment" {:ok, comment} = CMS.create_article_comment(:job, job.id, comment, user) @@ -117,7 +110,6 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do assert List.first(comment.upvotes).user_id == user.id end - @tag :wip test "article author upvote job comment will have flag", ~m(job user)a do comment = "job_comment" {:ok, comment} = CMS.create_article_comment(:job, job.id, comment, user) @@ -153,7 +145,6 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do assert user2.id not in comment.meta.upvoted_user_ids end - @tag :wip test "user upvote a already-upvoted comment fails", ~m(user job)a do comment = "job_comment" {:ok, comment} = CMS.create_article_comment(:job, job.id, comment, user) @@ -162,7 +153,6 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do {:error, _} = CMS.upvote_article_comment(comment.id, user) end - @tag :wip test "upvote comment should inc the comment's upvotes_count", ~m(user user2 job)a do comment = "job_comment" {:ok, comment} = CMS.create_article_comment(:job, job.id, comment, user) @@ -176,7 +166,6 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do assert comment.upvotes_count == 2 end - @tag :wip test "user can undo upvote a job comment", ~m(user job)a do content = "job_comment" {:ok, comment} = CMS.create_article_comment(:job, job.id, content, user) @@ -189,7 +178,6 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do assert 0 == comment.upvotes_count end - @tag :wip test "user can undo upvote a job comment with no upvote", ~m(user job)a do content = "job_comment" {:ok, comment} = CMS.create_article_comment(:job, job.id, content, user) @@ -202,7 +190,6 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do end describe "[article comment fold/unfold]" do - @tag :wip test "user can fold a comment", ~m(user job)a do {:ok, comment} = CMS.create_article_comment(:job, job.id, "commment", user) {:ok, comment} = ORM.find(ArticleComment, comment.id) @@ -214,7 +201,6 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do assert comment.is_folded end - @tag :wip test "user can unfold a comment", ~m(user job)a do {:ok, comment} = CMS.create_article_comment(:job, job.id, "commment", user) {:ok, _comment} = CMS.fold_article_comment(comment.id, user) @@ -254,7 +240,6 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do assert {:error, _} = ArticlePinedComment |> ORM.find_by(%{article_comment_id: comment.id}) end - @tag :wip test "pined comments has a limit for each article", ~m(user job)a do {:ok, comment} = CMS.create_article_comment(:job, job.id, "commment", user) @@ -267,7 +252,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do end describe "[article comment report/unreport]" do - # @tag :wip + # # test "user can report a comment", ~m(user job)a do # {:ok, comment} = CMS.create_article_comment(:job, job.id, "commment", user) # {:ok, comment} = ORM.find(ArticleComment, comment.id) @@ -276,7 +261,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do # {:ok, comment} = ORM.find(ArticleComment, comment.id) # end - # @tag :wip + # # test "user can unreport a comment", ~m(user job)a do # {:ok, comment} = CMS.create_article_comment(:job, job.id, "commment", user) # {:ok, _comment} = CMS.report_article_comment(comment.id, "reason", "attr", user) @@ -327,7 +312,6 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do assert not comment.is_folded end - @tag :wip test "report user > @report_threshold_for_fold will cause comment fold", ~m(user job)a do {:ok, comment} = CMS.create_article_comment(:job, job.id, "commment", user) @@ -344,7 +328,6 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do end describe "paged article comments" do - @tag :wip test "can load paged comments participators of a article", ~m(user job)a do total_count = 30 page_size = 10 @@ -367,7 +350,6 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do assert results.total_count == total_count + 1 end - @tag :wip test "paged article comments folded flag should be false", ~m(user job)a do total_count = 30 page_number = 1 @@ -392,7 +374,6 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do assert total_count == paged_comments.total_count end - @tag :wip test "paged article comments should contains pined comments at top position", ~m(user job)a do total_count = 20 @@ -420,7 +401,6 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do assert paged_comments.total_count == total_count + 2 end - @tag :wip test "only page 1 have pined coments", ~m(user job)a do total_count = 20 @@ -481,7 +461,6 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do assert total_count - 3 == paged_comments.total_count end - @tag :wip test "can loaded paged folded comment", ~m(user job)a do total_count = 10 page_number = 1 diff --git a/test/groupher_server/cms/comments/post_comment_emotions_test.exs b/test/groupher_server/cms/comments/post_comment_emotions_test.exs index 588b75628..74a3729de 100644 --- a/test/groupher_server/cms/comments/post_comment_emotions_test.exs +++ b/test/groupher_server/cms/comments/post_comment_emotions_test.exs @@ -64,7 +64,6 @@ defmodule GroupherServer.Test.CMS.Comments.PostCommentEmotions do end describe "[basic article comment emotion]" do - @tag :wip test "comment has default emotions after created", ~m(post user)a do parent_content = "parent comment" @@ -163,7 +162,6 @@ defmodule GroupherServer.Test.CMS.Comments.PostCommentEmotions do assert user_exist_in?(user3, emotions.latest_beer_users) end - @tag :wip test "same user can make differcent emotions on same comment", ~m(post user)a do parent_content = "parent comment" {:ok, parent_comment} = CMS.create_article_comment(:post, post.id, parent_content, user) diff --git a/test/groupher_server/cms/comments/post_comment_replies_test.exs b/test/groupher_server/cms/comments/post_comment_replies_test.exs index d4399b4b8..9a558beea 100644 --- a/test/groupher_server/cms/comments/post_comment_replies_test.exs +++ b/test/groupher_server/cms/comments/post_comment_replies_test.exs @@ -19,7 +19,6 @@ defmodule GroupherServer.Test.CMS.Comments.PostCommentReplies do end describe "[basic article comment replies]" do - @tag :wip test "exsit comment can be reply", ~m(post user user2)a do parent_content = "parent comment" reply_content = "reply comment" @@ -43,7 +42,6 @@ defmodule GroupherServer.Test.CMS.Comments.PostCommentReplies do {:error, _} = CMS.reply_article_comment(parent_comment.id, reply_content, user2) end - @tag :wip test "multi reply should belong to one parent comment", ~m(post user user2)a do parent_content = "parent comment" reply_content_1 = "reply comment 1" @@ -129,7 +127,6 @@ defmodule GroupherServer.Test.CMS.Comments.PostCommentReplies do assert not exist_in?(List.last(reply_comment_list), parent_comment.replies) end - @tag :wip test "replyed user should appear in article comment participators", ~m(post user user2)a do {:ok, parent_comment} = CMS.create_article_comment(:post, post.id, "parent_conent", user) {:ok, _} = CMS.reply_article_comment(parent_comment.id, "reply_content", user2) @@ -140,7 +137,6 @@ defmodule GroupherServer.Test.CMS.Comments.PostCommentReplies do assert exist_in?(user2, article.article_comments_participators) end - @tag :wip test "replies count should inc by 1 after got replyed", ~m(post user user2)a do {:ok, parent_comment} = CMS.create_article_comment(:post, post.id, "parent_conent", user) assert parent_comment.replies_count === 0 @@ -182,7 +178,6 @@ defmodule GroupherServer.Test.CMS.Comments.PostCommentReplies do assert exist_in?(Enum.at(reply_comment_list, 3), paged_replies.entries) end - @tag :wip test "can get reply_to info of a parent comment", ~m(post user)a do page_number = 1 page_size = 10 diff --git a/test/groupher_server/cms/comments/post_comment_test.exs b/test/groupher_server/cms/comments/post_comment_test.exs index 797a0ac45..e996e33f1 100644 --- a/test/groupher_server/cms/comments/post_comment_test.exs +++ b/test/groupher_server/cms/comments/post_comment_test.exs @@ -22,7 +22,6 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do end describe "[basic article comment]" do - @tag :wip test "post are supported by article comment.", ~m(user post)a do {:ok, post_comment_1} = CMS.create_article_comment(:post, post.id, "post_comment 1", user) {:ok, post_comment_2} = CMS.create_article_comment(:post, post.id, "post_comment 2", user) @@ -33,7 +32,6 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do assert exist_in?(post_comment_2, post.article_comments) end - @tag :wip test "comment should have default meta after create", ~m(user post)a do {:ok, comment} = CMS.create_article_comment(:post, post.id, "post comment", user) assert comment.meta |> Map.from_struct() |> Map.delete(:id) == @default_comment_meta @@ -49,7 +47,6 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do end describe "[article comment floor]" do - @tag :wip test "comment will have a floor number after created", ~m(user post)a do {:ok, post_comment} = CMS.create_article_comment(:post, post.id, "comment", user) {:ok, post_comment2} = CMS.create_article_comment(:post, post.id, "comment2", user) @@ -63,7 +60,6 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do end describe "[article comment participator for post]" do - @tag :wip test "post will have participator after comment created", ~m(user post)a do post_comment_1 = "post_comment 1" @@ -75,7 +71,6 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do assert participator.id == user.id end - @tag :wip test "psot participator will not contains same user", ~m(user post)a do post_comment_1 = "post_comment 1" @@ -87,7 +82,6 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do assert 1 == length(post.article_comments_participators) end - @tag :wip test "recent comment user should appear at first of the psot participators", ~m(user user2 post)a do post_comment_1 = "post_comment 1" @@ -104,7 +98,6 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do end describe "[article comment upvotes]" do - @tag :wip test "user can upvote a post comment", ~m(user post)a do comment = "post_comment" {:ok, comment} = CMS.create_article_comment(:post, post.id, comment, user) @@ -117,7 +110,6 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do assert List.first(comment.upvotes).user_id == user.id end - @tag :wip test "article author upvote post comment will have flag", ~m(post user)a do comment = "post_comment" {:ok, comment} = CMS.create_article_comment(:post, post.id, comment, user) @@ -153,7 +145,6 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do assert user2.id not in comment.meta.upvoted_user_ids end - @tag :wip test "user upvote a already-upvoted comment fails", ~m(user post)a do comment = "post_comment" {:ok, comment} = CMS.create_article_comment(:post, post.id, comment, user) @@ -162,7 +153,6 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do {:error, _} = CMS.upvote_article_comment(comment.id, user) end - @tag :wip test "upvote comment should inc the comment's upvotes_count", ~m(user user2 post)a do comment = "post_comment" {:ok, comment} = CMS.create_article_comment(:post, post.id, comment, user) @@ -176,7 +166,6 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do assert comment.upvotes_count == 2 end - @tag :wip test "user can undo upvote a post comment", ~m(user post)a do content = "post_comment" {:ok, comment} = CMS.create_article_comment(:post, post.id, content, user) @@ -189,7 +178,6 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do assert 0 == comment.upvotes_count end - @tag :wip test "user can undo upvote a post comment with no upvote", ~m(user post)a do content = "post_comment" {:ok, comment} = CMS.create_article_comment(:post, post.id, content, user) @@ -202,7 +190,6 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do end describe "[article comment fold/unfold]" do - @tag :wip test "user can fold a comment", ~m(user post)a do {:ok, comment} = CMS.create_article_comment(:post, post.id, "commment", user) {:ok, comment} = ORM.find(ArticleComment, comment.id) @@ -214,7 +201,6 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do assert comment.is_folded end - @tag :wip test "user can unfold a comment", ~m(user post)a do {:ok, comment} = CMS.create_article_comment(:post, post.id, "commment", user) {:ok, _comment} = CMS.fold_article_comment(comment.id, user) @@ -254,7 +240,6 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do assert {:error, _} = ArticlePinedComment |> ORM.find_by(%{article_comment_id: comment.id}) end - @tag :wip test "pined comments has a limit for each article", ~m(user post)a do {:ok, comment} = CMS.create_article_comment(:post, post.id, "commment", user) @@ -267,7 +252,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do end describe "[article comment report/unreport]" do - # @tag :wip + # # test "user can report a comment", ~m(user post)a do # {:ok, comment} = CMS.create_article_comment(:post, post.id, "commment", user) # {:ok, comment} = ORM.find(ArticleComment, comment.id) @@ -286,7 +271,6 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do # {:ok, comment} = ORM.find(ArticleComment, comment.id) # end - @tag :wip test "can undo a report with other user report it too", ~m(user user2 post)a do {:ok, comment} = CMS.create_article_comment(:post, post.id, "commment", user) @@ -314,7 +298,6 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do assert Enum.any?(report.report_cases, &(&1.user.login == user2.login)) end - @tag :wip test "report user < @report_threshold_for_fold will not fold comment", ~m(user post)a do {:ok, comment} = CMS.create_article_comment(:post, post.id, "commment", user) @@ -329,7 +312,6 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do assert not comment.is_folded end - @tag :wip test "report user > @report_threshold_for_fold will cause comment fold", ~m(user post)a do {:ok, comment} = CMS.create_article_comment(:post, post.id, "commment", user) @@ -346,7 +328,6 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do end describe "paged article comments" do - @tag :wip test "can load paged comments participators of a article", ~m(user post)a do total_count = 30 page_size = 10 @@ -369,7 +350,6 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do assert results.total_count == total_count + 1 end - @tag :wip test "paged article comments folded flag should be false", ~m(user post)a do total_count = 30 page_number = 1 @@ -399,7 +379,6 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do assert total_count == paged_comments.total_count end - @tag :wip test "paged article comments should contains pined comments at top position", ~m(user post)a do total_count = 20 @@ -432,7 +411,6 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do assert paged_comments.total_count == total_count + 2 end - @tag :wip test "only page 1 have pined coments", ~m(user post)a do total_count = 20 @@ -503,7 +481,6 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do assert total_count - 3 == paged_comments.total_count end - @tag :wip test "can loaded paged folded comment", ~m(user post)a do total_count = 10 page_number = 1 diff --git a/test/groupher_server/cms/post_meta_test.exs b/test/groupher_server/cms/post_meta_test.exs index 697791beb..8db27ed26 100644 --- a/test/groupher_server/cms/post_meta_test.exs +++ b/test/groupher_server/cms/post_meta_test.exs @@ -20,7 +20,6 @@ defmodule GroupherServer.Test.CMS.PostMeta do end describe "[cms post meta info]" do - @tag :wip test "can get default meta info", ~m(user community post_attrs)a do assert {:error, _} = ORM.find_by(Author, user_id: user.id) @@ -31,7 +30,6 @@ defmodule GroupherServer.Test.CMS.PostMeta do assert @default_article_meta == meta end - @tag :wip test "is_edited flag should set to true after post updated", ~m(user community post_attrs)a do {:ok, post} = CMS.create_article(community, :post, post_attrs, user) {:ok, post} = ORM.find_by(Post, id: post.id) @@ -44,7 +42,6 @@ defmodule GroupherServer.Test.CMS.PostMeta do assert post.meta.is_edited end - @tag :wip test "post 's lock article should work", ~m(user community post_attrs)a do {:ok, post} = CMS.create_article(community, :post, post_attrs, user) assert not post.meta.is_comment_locked diff --git a/test/groupher_server/statistics/statistics_test.exs b/test/groupher_server/statistics/statistics_test.exs index acf81b5b8..90e899bcd 100644 --- a/test/groupher_server/statistics/statistics_test.exs +++ b/test/groupher_server/statistics/statistics_test.exs @@ -148,7 +148,6 @@ defmodule GroupherServer.Test.Statistics do assert length(contributes) == @community_contribute_days + 1 end - @tag :wip test "the contributes data should be cached after first query", ~m(community)a do scope = Cache.get_scope(:community_contributes, community.id) assert {:error, nil} = Cache.get(:common, scope) diff --git a/test/groupher_server_web/mutation/accounts/collect_folder_test.exs b/test/groupher_server_web/mutation/accounts/collect_folder_test.exs index e0b2331ee..f22674690 100644 --- a/test/groupher_server_web/mutation/accounts/collect_folder_test.exs +++ b/test/groupher_server_web/mutation/accounts/collect_folder_test.exs @@ -30,7 +30,7 @@ defmodule GroupherServer.Test.Mutation.Accounts.CollectFolder do } } """ - @tag :wip + test "login user can create collect folder", ~m(user_conn)a do variables = %{title: "test folder", desc: "cool folder"} created = user_conn |> mutation_result(@query, variables, "createCollectFolder") @@ -40,7 +40,6 @@ defmodule GroupherServer.Test.Mutation.Accounts.CollectFolder do assert created["lastUpdated"] != nil end - @tag :wip test "login user can create private collect folder", ~m(user_conn)a do variables = %{title: "test folder", desc: "cool folder", private: true} created = user_conn |> mutation_result(@query, variables, "createCollectFolder") @@ -50,7 +49,6 @@ defmodule GroupherServer.Test.Mutation.Accounts.CollectFolder do assert created |> Map.get("private") end - @tag :wip test "unauth user create category fails", ~m(guest_conn)a do variables = %{title: "test folder"} assert guest_conn |> mutation_get_error?(@query, variables, ecode(:account_login)) @@ -72,7 +70,7 @@ defmodule GroupherServer.Test.Mutation.Accounts.CollectFolder do } } """ - @tag :wip + test "login user can update own collect folder", ~m(user_conn user)a do args = %{title: "folder_title", private: false} {:ok, folder} = Accounts.create_collect_folder(args, user) @@ -93,7 +91,7 @@ defmodule GroupherServer.Test.Mutation.Accounts.CollectFolder do } } """ - @tag :wip + test "login user can delete own collect folder", ~m(user_conn user)a do args = %{title: "folder_title", private: false} {:ok, folder} = Accounts.create_collect_folder(args, user) @@ -124,7 +122,7 @@ defmodule GroupherServer.Test.Mutation.Accounts.CollectFolder do } } """ - @tag :wip + test "user can add a post to collect folder", ~m(user user_conn post)a do args = %{title: "folder_title", private: false} {:ok, folder} = Accounts.create_collect_folder(args, user) @@ -172,7 +170,7 @@ defmodule GroupherServer.Test.Mutation.Accounts.CollectFolder do } } """ - @tag :wip + test "user can remove a post from collect folder", ~m(user user_conn post)a do args = %{title: "folder_title", private: false} {:ok, folder} = Accounts.create_collect_folder(args, user) diff --git a/test/groupher_server_web/mutation/cms/article_community/job_test.exs b/test/groupher_server_web/mutation/cms/article_community/job_test.exs index ec7f15e01..539e30262 100644 --- a/test/groupher_server_web/mutation/cms/article_community/job_test.exs +++ b/test/groupher_server_web/mutation/cms/article_community/job_test.exs @@ -24,7 +24,6 @@ defmodule GroupherServer.Test.Mutation.ArticleCommunity.Job do } } """ - @tag :wip3 test "auth user can set a valid tag to job", ~m(job)a do {:ok, community} = db_insert(:community) {:ok, tag} = db_insert(:tag, %{thread: "job", community: community}) @@ -51,8 +50,6 @@ defmodule GroupherServer.Test.Mutation.ArticleCommunity.Job do # variables = %{id: job.id, tagId: tag.id, communityId: community.id} # assert rule_conn |> mutation_get_error?(@set_tag_query, variables) # end - - @tag :wip3 test "can set multi tag to a job", ~m(job)a do {:ok, community} = db_insert(:community) {:ok, tag} = db_insert(:tag, %{thread: "job", community: community}) @@ -82,7 +79,6 @@ defmodule GroupherServer.Test.Mutation.ArticleCommunity.Job do } } """ - @tag :wip3 test "can unset tag to a job", ~m(job)a do {:ok, community} = db_insert(:community) @@ -217,7 +213,8 @@ defmodule GroupherServer.Test.Mutation.ArticleCommunity.Job do } } """ - @tag :wip3 + 3 + test "auth user can move job to other community", ~m(job)a do passport_rules = %{"job.community.mirror" => true} rule_conn = simu_conn(:user, cms: passport_rules) diff --git a/test/groupher_server_web/mutation/cms/article_community/post_test.exs b/test/groupher_server_web/mutation/cms/article_community/post_test.exs index fcf0900ca..7906231bf 100644 --- a/test/groupher_server_web/mutation/cms/article_community/post_test.exs +++ b/test/groupher_server_web/mutation/cms/article_community/post_test.exs @@ -24,7 +24,6 @@ defmodule GroupherServer.Test.Mutation.ArticleCommunity.Post do } } """ - @tag :wip3 test "auth user can set a valid tag to post", ~m(post)a do {:ok, community} = db_insert(:community) {:ok, tag} = db_insert(:tag, %{thread: "post", community: community}) @@ -52,7 +51,6 @@ defmodule GroupherServer.Test.Mutation.ArticleCommunity.Post do # assert rule_conn |> mutation_get_error?(@set_tag_query, variables) # end - @tag :wip3 test "can set multi tag to a post", ~m(post)a do {:ok, community} = db_insert(:community) {:ok, tag} = db_insert(:tag, %{thread: "post", community: community}) @@ -82,7 +80,6 @@ defmodule GroupherServer.Test.Mutation.ArticleCommunity.Post do } } """ - @tag :wip3 test "can unset tag to a post", ~m(post)a do {:ok, community} = db_insert(:community) @@ -217,7 +214,8 @@ defmodule GroupherServer.Test.Mutation.ArticleCommunity.Post do } } """ - @tag :wip3 + 3 + test "auth user can move post to other community", ~m(post)a do passport_rules = %{"post.community.mirror" => true} rule_conn = simu_conn(:user, cms: passport_rules) diff --git a/test/groupher_server_web/mutation/cms/article_community/repo_test.exs b/test/groupher_server_web/mutation/cms/article_community/repo_test.exs index 3a0634060..fc865ee4d 100644 --- a/test/groupher_server_web/mutation/cms/article_community/repo_test.exs +++ b/test/groupher_server_web/mutation/cms/article_community/repo_test.exs @@ -24,7 +24,6 @@ defmodule GroupherServer.Test.Mutation.ArticleCommunity.Repo do } } """ - @tag :wip3 test "auth user can set a valid tag to repo", ~m(repo)a do {:ok, community} = db_insert(:community) {:ok, tag} = db_insert(:tag, %{thread: "repo", community: community}) @@ -52,7 +51,6 @@ defmodule GroupherServer.Test.Mutation.ArticleCommunity.Repo do # assert rule_conn |> mutation_get_error?(@set_tag_query, variables) # end - @tag :wip3 test "can set multi tag to a repo", ~m(repo)a do {:ok, community} = db_insert(:community) {:ok, tag} = db_insert(:tag, %{thread: "repo", community: community}) @@ -82,7 +80,6 @@ defmodule GroupherServer.Test.Mutation.ArticleCommunity.Repo do } } """ - @tag :wip3 test "can unset tag to a repo", ~m(repo)a do {:ok, community} = db_insert(:community) @@ -217,7 +214,8 @@ defmodule GroupherServer.Test.Mutation.ArticleCommunity.Repo do } } """ - @tag :wip3 + 3 + test "auth user can move repo to other community", ~m(repo)a do passport_rules = %{"repo.community.mirror" => true} rule_conn = simu_conn(:user, cms: passport_rules) diff --git a/test/groupher_server_web/mutation/cms/articles/post_test.exs b/test/groupher_server_web/mutation/cms/articles/post_test.exs index b1b02eeeb..eb7224218 100644 --- a/test/groupher_server_web/mutation/cms/articles/post_test.exs +++ b/test/groupher_server_web/mutation/cms/articles/post_test.exs @@ -251,7 +251,6 @@ defmodule GroupherServer.Test.Mutation.Articles.Post do assert updated_post["copyRight"] == variables.copyRight end - @tag :wip test "update post with valid attrs should have is_edited meta info update", ~m(owner_conn post)a do unique_num = System.unique_integer([:positive, :monotonic]) diff --git a/test/groupher_server_web/mutation/cms/cms_test.exs b/test/groupher_server_web/mutation/cms/cms_test.exs index d3ee8d27d..175c4fc59 100644 --- a/test/groupher_server_web/mutation/cms/cms_test.exs +++ b/test/groupher_server_web/mutation/cms/cms_test.exs @@ -216,7 +216,7 @@ defmodule GroupherServer.Test.Mutation.CMS.Basic do assert belong_community["id"] == to_string(community.id) end - # TODO: @tag :wip + # TODO: # test "auth user create duplicate tag fails", ~m(community)a do # variables = mock_attrs(:tag, %{communityId: community.id}) diff --git a/test/groupher_server_web/query/accounts/achievement_test.exs b/test/groupher_server_web/query/accounts/achievement_test.exs index 0ce41f536..27817b291 100644 --- a/test/groupher_server_web/query/accounts/achievement_test.exs +++ b/test/groupher_server_web/query/accounts/achievement_test.exs @@ -34,7 +34,7 @@ defmodule GroupherServer.Test.Query.Account.Achievement do } } """ - @tag :wip + test "empty user should get empty achievement", ~m(guest_conn user)a do variables = %{login: user.login} @@ -183,7 +183,7 @@ defmodule GroupherServer.Test.Query.Account.Achievement do } } """ - @tag :wip + test "inc user's achievement after user's post got collected", ~m(guest_conn user)a do {:ok, post} = db_insert(:post) {:ok, _article_collect} = CMS.collect_article(:post, post.id, user) @@ -198,7 +198,6 @@ defmodule GroupherServer.Test.Query.Account.Achievement do assert results["achievement"] |> Map.get("reputation") == @collect_weight end - @tag :wip test "minus user's acheiveements after user's post's collect cancled", ~m(guest_conn)a do total_count = 10 {:ok, post} = db_insert(:post) diff --git a/test/groupher_server_web/query/accounts/colleced_articles_test.exs b/test/groupher_server_web/query/accounts/colleced_articles_test.exs index bda0b151b..9a28be0d4 100644 --- a/test/groupher_server_web/query/accounts/colleced_articles_test.exs +++ b/test/groupher_server_web/query/accounts/colleced_articles_test.exs @@ -31,7 +31,7 @@ defmodule GroupherServer.Test.Query.Accounts.CollectedArticles do } } """ - @tag :wip + test "other user can get other user's paged collect folders", ~m(user_conn guest_conn)a do {:ok, user} = db_insert(:user) @@ -49,7 +49,6 @@ defmodule GroupherServer.Test.Query.Accounts.CollectedArticles do assert results2 |> is_valid_pagination?() end - @tag :wip test "other user can get other user's paged collect folders filter by thread", ~m(guest_conn)a do {:ok, user} = db_insert(:user) @@ -73,7 +72,6 @@ defmodule GroupherServer.Test.Query.Accounts.CollectedArticles do assert results["totalCount"] == 1 end - @tag :wip test "owner can get it's paged collect folders with private folders", ~m(user user_conn guest_conn)a do {:ok, _folder} = Accounts.create_collect_folder(%{title: "test folder", private: true}, user) @@ -101,7 +99,7 @@ defmodule GroupherServer.Test.Query.Accounts.CollectedArticles do } } """ - @tag :wip + test "can get paged articles inside a collect-folder", ~m(user_conn guest_conn user posts)a do {:ok, folder} = Accounts.create_collect_folder(%{title: "test folder"}, user) @@ -126,7 +124,6 @@ defmodule GroupherServer.Test.Query.Accounts.CollectedArticles do assert results == results2 end - @tag :wip test "can not get collect-folder articles when folder is private", ~m(guest_conn posts)a do {:ok, user2} = db_insert(:user) {:ok, folder} = Accounts.create_collect_folder(%{title: "test folder", private: true}, user2) @@ -140,7 +137,6 @@ defmodule GroupherServer.Test.Query.Accounts.CollectedArticles do assert guest_conn |> query_get_error?(@query, variables, ecode(:private_collect_folder)) end - @tag :wip test "owner can get collect-folder articles when folder is private", ~m(user_conn user posts)a do {:ok, folder} = Accounts.create_collect_folder(%{title: "test folder", private: true}, user) diff --git a/test/groupher_server_web/query/accounts/upvoteed_articles_test.exs b/test/groupher_server_web/query/accounts/upvoteed_articles_test.exs index e24580906..644b5ead0 100644 --- a/test/groupher_server_web/query/accounts/upvoteed_articles_test.exs +++ b/test/groupher_server_web/query/accounts/upvoteed_articles_test.exs @@ -30,7 +30,7 @@ defmodule GroupherServer.Test.Query.Accounts.UpvotedArticles do } } """ - @tag :wip + test "both login and unlogin user can get one's paged upvoteded posts", ~m(user_conn guest_conn posts)a do {:ok, user} = db_insert(:user) @@ -51,7 +51,6 @@ defmodule GroupherServer.Test.Query.Accounts.UpvotedArticles do assert results2["totalCount"] == @total_count end - @tag :wip test "if no thread filter will get alll paged upvoteded articles", ~m(guest_conn posts jobs)a do {:ok, user} = db_insert(:user) diff --git a/test/groupher_server_web/query/cms/comments/job_comment_test.exs b/test/groupher_server_web/query/cms/comments/job_comment_test.exs index c26792feb..97b06913d 100644 --- a/test/groupher_server_web/query/cms/comments/job_comment_test.exs +++ b/test/groupher_server_web/query/cms/comments/job_comment_test.exs @@ -31,7 +31,7 @@ defmodule GroupherServer.Test.Query.Comments.JobComment do } } """ - @tag :wip + test "guest user can get comment participators after comment created", ~m(guest_conn job user user2)a do comment = "test comment" @@ -120,7 +120,7 @@ defmodule GroupherServer.Test.Query.Comments.JobComment do } } """ - @tag :wip + test "list comments with default replies-mode", ~m(guest_conn job user user2)a do total_count = 10 page_size = 20 @@ -154,7 +154,6 @@ defmodule GroupherServer.Test.Query.Comments.JobComment do to_string(replyed_comment_2.id) end - @tag :wip test "timeline-mode paged comments", ~m(guest_conn job user user2)a do total_count = 3 page_size = 20 @@ -189,7 +188,6 @@ defmodule GroupherServer.Test.Query.Comments.JobComment do assert random_comment["repliesCount"] == 2 end - @tag :wip test "comment should have reply_to content if need", ~m(guest_conn job user user2)a do total_count = 2 thread = :job @@ -224,7 +222,6 @@ defmodule GroupherServer.Test.Query.Comments.JobComment do to_string(parent_comment.author_id) end - @tag :wip test "guest user can get paged comment for job", ~m(guest_conn job user)a do comment = "test comment" total_count = 30 @@ -269,7 +266,6 @@ defmodule GroupherServer.Test.Query.Comments.JobComment do assert results["totalCount"] == total_count + 2 end - @tag :wip test "guest user can get paged comment with floor it", ~m(guest_conn job user)a do total_count = 5 thread = :job @@ -363,7 +359,6 @@ defmodule GroupherServer.Test.Query.Comments.JobComment do assert List.last(results["entries"]) |> Map.get("id") == to_string(comment.id) end - @tag :wip test "guest user can get paged comment with upvotes_count", ~m(guest_conn job user user2)a do total_count = 10 page_size = 10 @@ -391,7 +386,6 @@ defmodule GroupherServer.Test.Query.Comments.JobComment do assert results["entries"] |> List.last() |> Map.get("upvotesCount") == 0 end - @tag :wip test "article author upvote a comment can get is_article_author and/or is_article_author_upvoted flag", ~m(guest_conn job user)a do total_count = 5 @@ -480,7 +474,6 @@ defmodule GroupherServer.Test.Query.Comments.JobComment do assert user2.login in latest_beer_users_logins end - @tag :wip test "user make emotion can get paged comment with emotions has_motioned field", ~m(user_conn job user user2)a do total_count = 10 @@ -546,7 +539,7 @@ defmodule GroupherServer.Test.Query.Comments.JobComment do } } """ - @tag :wip + test "guest user can get paged participators", ~m(guest_conn job user)a do total_count = 30 page_size = 10 @@ -621,7 +614,7 @@ defmodule GroupherServer.Test.Query.Comments.JobComment do } } """ - @tag :wip + test "guest user can get paged replies", ~m(guest_conn job user user2)a do comment = "test comment" total_count = 2 diff --git a/test/groupher_server_web/query/cms/comments/post_comment_test.exs b/test/groupher_server_web/query/cms/comments/post_comment_test.exs index cc2c9d476..076f3157e 100644 --- a/test/groupher_server_web/query/cms/comments/post_comment_test.exs +++ b/test/groupher_server_web/query/cms/comments/post_comment_test.exs @@ -31,7 +31,7 @@ defmodule GroupherServer.Test.Query.Comments.PostComment do } } """ - @tag :wip + test "guest user can get comment participators after comment created", ~m(guest_conn post user user2)a do comment = "test comment" @@ -120,7 +120,7 @@ defmodule GroupherServer.Test.Query.Comments.PostComment do } } """ - @tag :wip + test "list comments with default replies-mode", ~m(guest_conn post user user2)a do total_count = 10 page_size = 20 @@ -154,7 +154,6 @@ defmodule GroupherServer.Test.Query.Comments.PostComment do to_string(replyed_comment_2.id) end - @tag :wip test "timeline-mode paged comments", ~m(guest_conn post user user2)a do total_count = 3 page_size = 20 @@ -189,7 +188,6 @@ defmodule GroupherServer.Test.Query.Comments.PostComment do assert random_comment["repliesCount"] == 2 end - @tag :wip test "comment should have reply_to content if need", ~m(guest_conn post user user2)a do total_count = 2 thread = :post @@ -224,7 +222,6 @@ defmodule GroupherServer.Test.Query.Comments.PostComment do to_string(parent_comment.author_id) end - @tag :wip test "guest user can get paged comment for post", ~m(guest_conn post user)a do comment = "test comment" total_count = 30 @@ -269,7 +266,6 @@ defmodule GroupherServer.Test.Query.Comments.PostComment do assert results["totalCount"] == total_count + 2 end - @tag :wip test "guest user can get paged comment with floor it", ~m(guest_conn post user)a do total_count = 5 thread = :post @@ -363,7 +359,6 @@ defmodule GroupherServer.Test.Query.Comments.PostComment do assert List.last(results["entries"]) |> Map.get("id") == to_string(comment.id) end - @tag :wip test "guest user can get paged comment with upvotes_count", ~m(guest_conn post user user2)a do total_count = 10 page_size = 10 @@ -391,7 +386,6 @@ defmodule GroupherServer.Test.Query.Comments.PostComment do assert results["entries"] |> List.last() |> Map.get("upvotesCount") == 0 end - @tag :wip test "article author upvote a comment can get is_article_author and/or is_article_author_upvoted flag", ~m(guest_conn post user)a do total_count = 5 @@ -480,7 +474,6 @@ defmodule GroupherServer.Test.Query.Comments.PostComment do assert user2.login in latest_beer_users_logins end - @tag :wip test "user make emotion can get paged comment with emotions has_motioned field", ~m(user_conn post user user2)a do total_count = 10 @@ -546,7 +539,7 @@ defmodule GroupherServer.Test.Query.Comments.PostComment do } } """ - @tag :wip + test "guest user can get paged participators", ~m(guest_conn post user)a do total_count = 30 page_size = 10 @@ -621,7 +614,7 @@ defmodule GroupherServer.Test.Query.Comments.PostComment do } } """ - @tag :wip + test "guest user can get paged replies", ~m(guest_conn post user user2)a do comment = "test comment" total_count = 2 diff --git a/test/groupher_server_web/query/cms/comments/repo_comment_test.exs b/test/groupher_server_web/query/cms/comments/repo_comment_test.exs index 755443a16..62ce92df9 100644 --- a/test/groupher_server_web/query/cms/comments/repo_comment_test.exs +++ b/test/groupher_server_web/query/cms/comments/repo_comment_test.exs @@ -22,7 +22,6 @@ defmodule GroupherServer.Test.Query.Comments.RepoComment do repo(id: $id) { id title - body articleCommentsParticipators { id nickname @@ -31,7 +30,7 @@ defmodule GroupherServer.Test.Query.Comments.RepoComment do } } """ - @tag :wip + @tag :wip2 test "guest user can get comment participators after comment created", ~m(guest_conn repo user user2)a do comment = "test comment" @@ -120,7 +119,7 @@ defmodule GroupherServer.Test.Query.Comments.RepoComment do } } """ - @tag :wip + test "list comments with default replies-mode", ~m(guest_conn repo user user2)a do total_count = 10 page_size = 20 @@ -154,7 +153,6 @@ defmodule GroupherServer.Test.Query.Comments.RepoComment do to_string(replyed_comment_2.id) end - @tag :wip2 test "timeline-mode paged comments", ~m(guest_conn repo user user2)a do total_count = 3 page_size = 20 @@ -189,7 +187,6 @@ defmodule GroupherServer.Test.Query.Comments.RepoComment do assert random_comment["repliesCount"] == 2 end - @tag :wip test "comment should have reply_to content if need", ~m(guest_conn repo user user2)a do total_count = 2 thread = :repo @@ -224,7 +221,6 @@ defmodule GroupherServer.Test.Query.Comments.RepoComment do to_string(parent_comment.author_id) end - @tag :wip test "guest user can get paged comment for repo", ~m(guest_conn repo user)a do comment = "test comment" total_count = 30 @@ -269,7 +265,6 @@ defmodule GroupherServer.Test.Query.Comments.RepoComment do assert results["totalCount"] == total_count + 2 end - @tag :wip test "guest user can get paged comment with floor it", ~m(guest_conn repo user)a do total_count = 5 thread = :repo @@ -390,7 +385,6 @@ defmodule GroupherServer.Test.Query.Comments.RepoComment do assert results["entries"] |> List.last() |> Map.get("upvotesCount") == 0 end - @tag :wip test "article author upvote a comment can get is_article_author and/or is_article_author_upvoted flag", ~m(guest_conn repo user)a do total_count = 5 @@ -479,7 +473,6 @@ defmodule GroupherServer.Test.Query.Comments.RepoComment do assert user2.login in latest_beer_users_logins end - @tag :wip test "user make emotion can get paged comment with emotions has_motioned field", ~m(user_conn repo user user2)a do total_count = 10 @@ -545,7 +538,7 @@ defmodule GroupherServer.Test.Query.Comments.RepoComment do } } """ - @tag :wip + test "guest user can get paged participators", ~m(guest_conn repo user)a do total_count = 30 page_size = 10 @@ -620,7 +613,7 @@ defmodule GroupherServer.Test.Query.Comments.RepoComment do } } """ - @tag :wip + test "guest user can get paged replies", ~m(guest_conn repo user user2)a do comment = "test comment" total_count = 2 diff --git a/test/groupher_server_web/query/cms/flags/jobs_flags_test.exs b/test/groupher_server_web/query/cms/flags/jobs_flags_test.exs index 55ee648c3..0a84ab2bc 100644 --- a/test/groupher_server_web/query/cms/flags/jobs_flags_test.exs +++ b/test/groupher_server_web/query/cms/flags/jobs_flags_test.exs @@ -70,7 +70,6 @@ defmodule GroupherServer.Test.Query.Flags.JobsFlags do assert entries_first["isPinned"] == true end - @tag :wip test "pind jobs should not appear when page > 1", ~m(guest_conn community)a do variables = %{filter: %{page: 2, size: 20}} results = guest_conn |> query_result(@query, variables, "pagedJobs") diff --git a/test/groupher_server_web/query/cms/flags/posts_flags_test.exs b/test/groupher_server_web/query/cms/flags/posts_flags_test.exs index ac785f661..84007b754 100644 --- a/test/groupher_server_web/query/cms/flags/posts_flags_test.exs +++ b/test/groupher_server_web/query/cms/flags/posts_flags_test.exs @@ -70,7 +70,6 @@ defmodule GroupherServer.Test.Query.Flags.PostsFlags do assert entries_first["isPinned"] == true end - @tag :wip test "pind posts should not appear when page > 1", ~m(guest_conn community)a do variables = %{filter: %{page: 2, size: 20}} results = guest_conn |> query_result(@query, variables, "pagedPosts") diff --git a/test/groupher_server_web/query/cms/flags/repos_flags_test.exs b/test/groupher_server_web/query/cms/flags/repos_flags_test.exs index fc787b537..c7df53147 100644 --- a/test/groupher_server_web/query/cms/flags/repos_flags_test.exs +++ b/test/groupher_server_web/query/cms/flags/repos_flags_test.exs @@ -70,7 +70,6 @@ defmodule GroupherServer.Test.Query.Flags.ReposFlags do assert entries_first["isPinned"] == true end - @tag :wip test "pind repos should not appear when page > 1", ~m(guest_conn community)a do variables = %{filter: %{page: 2, size: 20}} results = guest_conn |> query_result(@query, variables, "pagedRepos") diff --git a/test/groupher_server_web/query/cms/old_post_comment_test.exs b/test/groupher_server_web/query/cms/old_post_comment_test.exs index 60da56485..2718ed48b 100644 --- a/test/groupher_server_web/query/cms/old_post_comment_test.exs +++ b/test/groupher_server_web/query/cms/old_post_comment_test.exs @@ -181,7 +181,7 @@ defmodule GroupherServer.Test.Query.OldPostComment do } } """ - @tag :wip + test "guest user can get a paged comment", ~m(guest_conn post user community)a do body = "test comment" diff --git a/test/helper/cache_test.exs b/test/helper/cache_test.exs index 4d2db0c2a..dfcf06186 100644 --- a/test/helper/cache_test.exs +++ b/test/helper/cache_test.exs @@ -7,13 +7,11 @@ defmodule GroupherServer.Test.Helper.Cache do @pool :common describe "[cache test]" do - @tag :wip test "cache get unexsit key should get nil" do assert {:error, nil} = Cache.get(@pool, "no exsit") assert {:error, nil} = Cache.get(@pool, :no_exsit) end - @tag :wip test "cache put should work" do assert {:error, nil} = Cache.get(@pool, :data) @@ -29,7 +27,6 @@ defmodule GroupherServer.Test.Helper.Cache do assert {:ok, [1, %{a: "2"}]} = Cache.get(@pool, "namespace.aaa.bbb") end - @tag :wip test "cache can be clear" do assert {:ok, true} = Cache.put(@pool, :data, "value") assert {:ok, "value"} = Cache.get(@pool, :data) @@ -38,7 +35,6 @@ defmodule GroupherServer.Test.Helper.Cache do assert {:error, nil} = Cache.get(@pool, :data) end - @tag :wip test "cache expire should work" do assert {:ok, true} = Cache.put(@pool, :data, "value", expire_sec: 1) assert {:ok, "value"} = Cache.get(@pool, :data) diff --git a/test/helper/converter/editor_to_html_test/header_test.exs b/test/helper/converter/editor_to_html_test/header_test.exs index da2398433..7c8602f22 100644 --- a/test/helper/converter/editor_to_html_test/header_test.exs +++ b/test/helper/converter/editor_to_html_test/header_test.exs @@ -51,7 +51,7 @@ defmodule GroupherServer.Test.Helper.Converter.EditorToHTML.Header do ], "version" => "2.15.0" } - @tag :wip + test "header parse should work" do {:ok, editor_string} = Jason.encode(@editor_json) {:ok, converted} = Parser.to_html(editor_string) @@ -61,7 +61,6 @@ defmodule GroupherServer.Test.Helper.Converter.EditorToHTML.Header do assert Utils.str_occurence(converted, "header3 content") == 1 end - @tag :wip test "full header parse should work" do editor_json = set_data(%{ @@ -81,7 +80,6 @@ defmodule GroupherServer.Test.Helper.Converter.EditorToHTML.Header do assert Utils.str_occurence(converted, @class["footer_title"]) == 1 end - @tag :wip test "edit exsit block will not change id value" do editor_json = set_data(%{ @@ -98,7 +96,6 @@ defmodule GroupherServer.Test.Helper.Converter.EditorToHTML.Header do assert Utils.str_occurence(converted, ~s(id="exist")) == 1 end - @tag :wip test "optional field should valid properly" do editor_json = set_data(%{ @@ -127,7 +124,6 @@ defmodule GroupherServer.Test.Helper.Converter.EditorToHTML.Header do assert Utils.str_occurence(converted, @class["footer_title"]) == 1 end - @tag :wip test "wrong header format data should have invalid hint" do editor_json = set_data(%{ diff --git a/test/helper/converter/editor_to_html_test/image_test.exs b/test/helper/converter/editor_to_html_test/image_test.exs index b23f8bb34..69b2a08c3 100644 --- a/test/helper/converter/editor_to_html_test/image_test.exs +++ b/test/helper/converter/editor_to_html_test/image_test.exs @@ -29,7 +29,6 @@ defmodule GroupherServer.Test.Helper.Converter.EditorToHTML.Image do } end - @tag :wip test "single image parse should work" do editor_json = set_items("single", [ @@ -58,7 +57,6 @@ defmodule GroupherServer.Test.Helper.Converter.EditorToHTML.Image do assert Utils.str_occurence(converted, "this is a caption") == 2 end - @tag :wip test "single image parse should work without wight && height" do editor_json = set_items("single", [ @@ -81,7 +79,6 @@ defmodule GroupherServer.Test.Helper.Converter.EditorToHTML.Image do assert Utils.str_occurence(converted, single_image_wrapper_class) == 1 end - @tag :wip test "single image parse should work without caption" do editor_json = set_items("single", [ @@ -106,7 +103,6 @@ defmodule GroupherServer.Test.Helper.Converter.EditorToHTML.Image do assert Utils.str_occurence(converted, image_caption_class) == 0 end - @tag :wip test "jiugongge image parse should work" do editor_json = set_items( @@ -132,7 +128,6 @@ defmodule GroupherServer.Test.Helper.Converter.EditorToHTML.Image do assert Utils.str_occurence(converted, jiugongge_image_class) == length(mock_images(9)) end - @tag :wip test "gallery image parse should work" do editor_json = set_items( @@ -158,7 +153,6 @@ defmodule GroupherServer.Test.Helper.Converter.EditorToHTML.Image do assert Utils.str_occurence(converted, gallery_mini_image_class) == length(mock_images(9)) end - @tag :wip test "edit exsit block will not change id value" do editor_json = set_items( @@ -181,7 +175,6 @@ defmodule GroupherServer.Test.Helper.Converter.EditorToHTML.Image do assert Utils.str_occurence(converted, "id=\"exsit\"") == 1 end - @tag :wip test "invalid mode parse should raise error message" do editor_json = set_items("invalid-mode", []) {:ok, editor_string} = Jason.encode(editor_json) @@ -197,7 +190,6 @@ defmodule GroupherServer.Test.Helper.Converter.EditorToHTML.Image do ] == err_msg end - @tag :wip test "invalid data parse should raise error message" do editor_json = set_items("single", [ @@ -220,7 +212,6 @@ defmodule GroupherServer.Test.Helper.Converter.EditorToHTML.Image do ] end - @tag :wip test "src should starts with https://" do editor_json = set_items("single", [ diff --git a/test/helper/converter/editor_to_html_test/index_test.exs b/test/helper/converter/editor_to_html_test/index_test.exs index 417579257..240311aab 100644 --- a/test/helper/converter/editor_to_html_test/index_test.exs +++ b/test/helper/converter/editor_to_html_test/index_test.exs @@ -37,14 +37,13 @@ defmodule GroupherServer.Test.Helper.Converter.EditorToHTML do "blocks" => [], "version" => "2.15.0" } - @tag :wip + test "valid editorjs json fmt should work" do {:ok, editor_string} = Jason.encode(@editor_json) assert {:ok, _} = Parser.to_html(editor_string) end - @tag :wip test "invalid editorjs json fmt should raise error" do editor_json = %{ "invalid_time" => 1_567_250_876_713, @@ -114,7 +113,6 @@ defmodule GroupherServer.Test.Helper.Converter.EditorToHTML do end describe "[secure issues]" do - @tag :wip test "code block should avoid potential xss script attack" do editor_json = %{ "time" => 1_567_250_876_713, diff --git a/test/helper/converter/editor_to_html_test/list_test.exs b/test/helper/converter/editor_to_html_test/list_test.exs index 88938e54c..07e1bae07 100644 --- a/test/helper/converter/editor_to_html_test/list_test.exs +++ b/test/helper/converter/editor_to_html_test/list_test.exs @@ -64,7 +64,6 @@ defmodule GroupherServer.Test.Helper.Converter.EditorToHTML.List do assert Utils.str_occurence(converted, @class["unorder_list_prefix"]) == 3 end - @tag :wip test "basic order list parse should work" do editor_json = set_items("order_list", [ @@ -106,7 +105,6 @@ defmodule GroupherServer.Test.Helper.Converter.EditorToHTML.List do assert Utils.str_occurence(converted, @class["order_list_prefix"]) == 3 end - @tag :wip test "edit exsit block will not change id value" do editor_json = set_items( @@ -132,7 +130,6 @@ defmodule GroupherServer.Test.Helper.Converter.EditorToHTML.List do assert Utils.str_occurence(converted, "id=\"exsit\"") == 1 end - @tag :wip test "basic checklist parse should work" do editor_json = set_items("checklist", [ @@ -177,7 +174,6 @@ defmodule GroupherServer.Test.Helper.Converter.EditorToHTML.List do assert Utils.str_occurence(converted, @class["checklist_checkbox_checked"]) == 1 end - @tag :wip test "checklist without label parse should work" do editor_json = set_items("checklist", [ @@ -205,7 +201,6 @@ defmodule GroupherServer.Test.Helper.Converter.EditorToHTML.List do assert Utils.str_occurence(converted, @class["label"]) == 0 end - @tag :wip test "invalid list mode parse should raise error message" do editor_json = set_items("invalid-mode", []) {:ok, editor_string} = Jason.encode(editor_json) @@ -221,7 +216,6 @@ defmodule GroupherServer.Test.Helper.Converter.EditorToHTML.List do ] == err_msg end - @tag :wip test "invalid list data parse should raise error message" do editor_json = set_items("checklist", [ @@ -253,7 +247,6 @@ defmodule GroupherServer.Test.Helper.Converter.EditorToHTML.List do ] end - @tag :wip test "invalid indent field should get error" do editor_json = set_items("checklist", [ diff --git a/test/helper/converter/editor_to_html_test/paragraph_test.exs b/test/helper/converter/editor_to_html_test/paragraph_test.exs index d5f2a4364..a5f2ce506 100644 --- a/test/helper/converter/editor_to_html_test/paragraph_test.exs +++ b/test/helper/converter/editor_to_html_test/paragraph_test.exs @@ -21,7 +21,7 @@ defmodule GroupherServer.Test.Helper.Converter.EditorToHTML.Paragraph do ], "version" => "2.15.0" } - @tag :wip + test "paragraph parse should work" do {:ok, editor_string} = Jason.encode(@editor_json) {:ok, converted} = Parser.to_html(editor_string) @@ -41,7 +41,7 @@ defmodule GroupherServer.Test.Helper.Converter.EditorToHTML.Paragraph do ], "version" => "2.15.0" } - @tag :wip + test "invalid paragraph should have invalid hint" do {:ok, editor_string} = Jason.encode(@editor_json) {:error, error} = Parser.to_html(editor_string) diff --git a/test/helper/converter/editor_to_html_test/people_test.exs b/test/helper/converter/editor_to_html_test/people_test.exs index 8ac392959..28b552448 100644 --- a/test/helper/converter/editor_to_html_test/people_test.exs +++ b/test/helper/converter/editor_to_html_test/people_test.exs @@ -29,7 +29,6 @@ defmodule GroupherServer.Test.Helper.Converter.EditorToHTML.People do } end - @tag :wip test "multi people should have previewer" do editor_json = set_items("gallery", [ @@ -78,7 +77,6 @@ defmodule GroupherServer.Test.Helper.Converter.EditorToHTML.People do assert Utils.str_occurence(converted, mock_image()) == 4 end - @tag :wip test "one people should not have previewer bar" do editor_json = set_items("gallery", [ diff --git a/test/helper/converter/editor_to_html_test/quote_test.exs b/test/helper/converter/editor_to_html_test/quote_test.exs index 467871f5a..9bc0c39c0 100644 --- a/test/helper/converter/editor_to_html_test/quote_test.exs +++ b/test/helper/converter/editor_to_html_test/quote_test.exs @@ -41,7 +41,6 @@ defmodule GroupherServer.Test.Helper.Converter.EditorToHTML.Quote do } end - @tag :wip test "short quote parse should work" do editor_json = set_data("short", "short quote") {:ok, editor_string} = Jason.encode(editor_json) @@ -54,7 +53,6 @@ defmodule GroupherServer.Test.Helper.Converter.EditorToHTML.Quote do assert Utils.str_occurence(converted, @class["caption"]) == 0 end - @tag :wip test "long quote parse should work" do editor_json = set_data("long", "long quote", "caption") {:ok, editor_string} = Jason.encode(editor_json) @@ -65,7 +63,6 @@ defmodule GroupherServer.Test.Helper.Converter.EditorToHTML.Quote do assert Utils.str_occurence(converted, @class["caption_text"]) == 1 end - @tag :wip test "long quote without caption parse should work" do editor_json = set_data("long", "long quote") {:ok, editor_string} = Jason.encode(editor_json) @@ -76,7 +73,6 @@ defmodule GroupherServer.Test.Helper.Converter.EditorToHTML.Quote do assert Utils.str_occurence(converted, @class["caption_text"]) == 0 end - @tag :wip test "long quote without empty caption parse should work" do editor_json = set_data("long", "long quote", "") {:ok, editor_string} = Jason.encode(editor_json) @@ -87,7 +83,6 @@ defmodule GroupherServer.Test.Helper.Converter.EditorToHTML.Quote do assert Utils.str_occurence(converted, @class["caption_text"]) == 0 end - @tag :wip test "invalid quote should have invalid hint" do editor_json = set_data("none_exsit", "long quote", "") {:ok, editor_string} = Jason.encode(editor_json) diff --git a/test/helper/converter/editor_to_html_test/table_test.exs b/test/helper/converter/editor_to_html_test/table_test.exs index 8596190f6..70765e301 100644 --- a/test/helper/converter/editor_to_html_test/table_test.exs +++ b/test/helper/converter/editor_to_html_test/table_test.exs @@ -28,7 +28,6 @@ defmodule GroupherServer.Test.Helper.Converter.EditorToHTML.Table do } end - @tag :wip test "basic table parse should work" do editor_json = set_items(4, [ @@ -104,7 +103,6 @@ defmodule GroupherServer.Test.Helper.Converter.EditorToHTML.Table do assert Utils.str_occurence(converted, @class["td_stripe"]) == 3 end - @tag :wip test "edit exsit block will not change id value" do editor_json = set_items( @@ -133,7 +131,6 @@ defmodule GroupherServer.Test.Helper.Converter.EditorToHTML.Table do assert Utils.str_occurence(converted, ~s(id="exist")) == 1 end - @tag :wip test "invalid table field parse should raise error message" do editor_json = set_items("aa", "bb") {:ok, editor_string} = Jason.encode(editor_json) diff --git a/test/helper/validator/schema_test.exs b/test/helper/validator/schema_test.exs index ee63fc3f7..e0649836b 100644 --- a/test/helper/validator/schema_test.exs +++ b/test/helper/validator/schema_test.exs @@ -6,7 +6,6 @@ defmodule GroupherServer.Test.Helper.Validator.Schema do alias Helper.Validator.Schema describe "[basic schema]" do - @tag :wip test "string with options" do schema = %{"text" => [:string, required: false]} data = %{"no_exsit" => "text"} @@ -59,7 +58,6 @@ defmodule GroupherServer.Test.Helper.Validator.Schema do # IO.inspect(Schema.cast(schema, data), label: "schema result") end - @tag :wip test "number with options" do schema = %{"text" => [:number, required: false]} data = %{"no_exsit" => 1} @@ -98,7 +96,6 @@ defmodule GroupherServer.Test.Helper.Validator.Schema do # hello world end - @tag :wip test "number with wrong option" do schema = %{"text" => [:number, required: true, min: "5"]} data = %{"text" => 1} @@ -113,7 +110,6 @@ defmodule GroupherServer.Test.Helper.Validator.Schema do assert error == [%{field: "text", message: "unknow option: no_exsit_option: xxx", value: 1}] end - @tag :wip test "number with options edage case" do schema = %{"text" => [:number, min: 2]} data = %{"text" => "aa"} @@ -122,7 +118,6 @@ defmodule GroupherServer.Test.Helper.Validator.Schema do assert error == [%{field: "text", message: "should be: number", value: "aa"}] end - @tag :wip test "list with options" do schema = %{"text" => [:list, required: false]} data = %{"no_exsit" => []} @@ -159,7 +154,6 @@ defmodule GroupherServer.Test.Helper.Validator.Schema do # IO.inspect(Schema.cast(schema, data), label: "schema result") end - @tag :wip test "boolean with options" do schema = %{"text" => [:boolean, required: false]} data = %{"no_exsit" => false} @@ -175,7 +169,6 @@ defmodule GroupherServer.Test.Helper.Validator.Schema do assert {:ok, _} = Schema.cast(schema, data) end - @tag :wip test "enum with options" do schema = %{"text" => [enum: [1, 2, 3], required: false]} data = %{"no_exsit" => false} @@ -194,7 +187,6 @@ defmodule GroupherServer.Test.Helper.Validator.Schema do # hello world end - @tag :wip test "schema invalid option should got error" do schema = %{"text" => [:number, allow_empty: false]} data = %{"text" => 1} From 4cf6972f067b6b432468b375a4e45ac7a5625876 Mon Sep 17 00:00:00 2001 From: mydearxym Date: Sun, 16 May 2021 13:57:26 +0800 Subject: [PATCH 08/11] fix(article-comments): repo pinned comment --- lib/groupher_server/cms/article_pined_comment.ex | 2 +- .../query/cms/comments/repo_comment_test.exs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/groupher_server/cms/article_pined_comment.ex b/lib/groupher_server/cms/article_pined_comment.ex index cee40da8f..15e90eaba 100644 --- a/lib/groupher_server/cms/article_pined_comment.ex +++ b/lib/groupher_server/cms/article_pined_comment.ex @@ -13,7 +13,7 @@ defmodule GroupherServer.CMS.ArticlePinedComment do # alias Helper.HTML @required_fields ~w(article_comment_id)a - @optional_fields ~w(post_id job_id)a + @optional_fields ~w(post_id job_id repo_id)a @type t :: %ArticlePinedComment{} schema "articles_pined_comments" do diff --git a/test/groupher_server_web/query/cms/comments/repo_comment_test.exs b/test/groupher_server_web/query/cms/comments/repo_comment_test.exs index 62ce92df9..3201b8d60 100644 --- a/test/groupher_server_web/query/cms/comments/repo_comment_test.exs +++ b/test/groupher_server_web/query/cms/comments/repo_comment_test.exs @@ -30,7 +30,6 @@ defmodule GroupherServer.Test.Query.Comments.RepoComment do } } """ - @tag :wip2 test "guest user can get comment participators after comment created", ~m(guest_conn repo user user2)a do comment = "test comment" @@ -239,6 +238,7 @@ defmodule GroupherServer.Test.Query.Comments.RepoComment do assert results["totalCount"] == total_count end + @tag :wip2 test "guest user can get paged comment with pinned comment in it", ~m(guest_conn repo user)a do total_count = 20 From bf74d0f8e4b085a6a6b757e29c4bf9fbc638b5ba Mon Sep 17 00:00:00 2001 From: mydearxym Date: Sun, 16 May 2021 14:01:46 +0800 Subject: [PATCH 09/11] fix(article-comments): rename pined -> pinned --- ...icle_pined_comment.ex => article_pinned_comment.ex} | 10 +++++----- lib/groupher_server/cms/delegates/article_comment.ex | 6 +++--- .../cms/delegates/article_comment_action.ex | 8 ++++---- lib/groupher_server/cms/post.ex | 2 -- .../20210516055842_rename_articles_pined_comments.exs | 7 +++++++ test/groupher_server/cms/comments/job_comment_test.exs | 8 ++++---- .../groupher_server/cms/comments/post_comment_test.exs | 8 ++++---- 7 files changed, 27 insertions(+), 22 deletions(-) rename lib/groupher_server/cms/{article_pined_comment.ex => article_pinned_comment.ex} (73%) create mode 100644 priv/repo/migrations/20210516055842_rename_articles_pined_comments.exs diff --git a/lib/groupher_server/cms/article_pined_comment.ex b/lib/groupher_server/cms/article_pinned_comment.ex similarity index 73% rename from lib/groupher_server/cms/article_pined_comment.ex rename to lib/groupher_server/cms/article_pinned_comment.ex index 15e90eaba..9473a5420 100644 --- a/lib/groupher_server/cms/article_pined_comment.ex +++ b/lib/groupher_server/cms/article_pinned_comment.ex @@ -1,4 +1,4 @@ -defmodule GroupherServer.CMS.ArticlePinedComment do +defmodule GroupherServer.CMS.ArticlePinnedComment do @moduledoc false alias __MODULE__ @@ -15,8 +15,8 @@ defmodule GroupherServer.CMS.ArticlePinedComment do @required_fields ~w(article_comment_id)a @optional_fields ~w(post_id job_id repo_id)a - @type t :: %ArticlePinedComment{} - schema "articles_pined_comments" do + @type t :: %ArticlePinnedComment{} + schema "articles_pinned_comments" do belongs_to(:article_comment, ArticleComment, foreign_key: :article_comment_id) belongs_to(:post, CMS.Post, foreign_key: :post_id) belongs_to(:job, CMS.Job, foreign_key: :job_id) @@ -26,14 +26,14 @@ defmodule GroupherServer.CMS.ArticlePinedComment do end @doc false - def changeset(%ArticlePinedComment{} = article_pined_comment, attrs) do + def changeset(%ArticlePinnedComment{} = article_pined_comment, attrs) do article_pined_comment |> cast(attrs, @required_fields ++ @optional_fields) |> validate_required(@required_fields) end # @doc false - def update_changeset(%ArticlePinedComment{} = article_pined_comment, attrs) do + def update_changeset(%ArticlePinnedComment{} = article_pined_comment, attrs) do article_pined_comment |> cast(attrs, @required_fields ++ @optional_fields) end diff --git a/lib/groupher_server/cms/delegates/article_comment.ex b/lib/groupher_server/cms/delegates/article_comment.ex index a29726869..f3884f4da 100644 --- a/lib/groupher_server/cms/delegates/article_comment.ex +++ b/lib/groupher_server/cms/delegates/article_comment.ex @@ -15,7 +15,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleComment do alias GroupherServer.{Accounts, CMS, Repo} alias Accounts.User - alias CMS.{ArticleComment, ArticlePinedComment, Embeds} + alias CMS.{ArticleComment, ArticlePinnedComment, Embeds} alias Ecto.Multi @max_participator_count ArticleComment.max_participator_count() @@ -124,7 +124,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleComment do update_article_comments_count(comment, :dec) end) |> Multi.run(:remove_pined_comment, fn _, _ -> - ORM.findby_delete(ArticlePinedComment, %{article_comment_id: comment.id}) + ORM.findby_delete(ArticlePinnedComment, %{article_comment_id: comment.id}) end) |> Multi.run(:delete_article_comment, fn _, _ -> ORM.update(comment, %{body_html: @delete_hint, is_deleted: true}) @@ -235,7 +235,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleComment do }) do with {:ok, info} <- match(thread), query <- - from(p in ArticlePinedComment, + from(p in ArticlePinnedComment, join: c in ArticleComment, on: p.article_comment_id == c.id, where: field(p, ^info.foreign_key) == ^article_id, diff --git a/lib/groupher_server/cms/delegates/article_comment_action.ex b/lib/groupher_server/cms/delegates/article_comment_action.ex index 8234fd10f..0e4302feb 100644 --- a/lib/groupher_server/cms/delegates/article_comment_action.ex +++ b/lib/groupher_server/cms/delegates/article_comment_action.ex @@ -19,7 +19,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleCommentAction do alias CMS.{ ArticleComment, - ArticlePinedComment, + ArticlePinnedComment, ArticleCommentUpvote, ArticleCommentReply, Community, @@ -43,7 +43,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleCommentAction do Multi.new() |> Multi.run(:checked_pined_comments_count, fn _, _ -> count_query = - from(p in ArticlePinedComment, + from(p in ArticlePinnedComment, where: field(p, ^info.foreign_key) == ^full_comment.article.id ) @@ -58,7 +58,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleCommentAction do ORM.update(comment, %{is_pinned: true}) end) |> Multi.run(:add_pined_comment, fn _, _ -> - ArticlePinedComment + ArticlePinnedComment |> ORM.create( %{article_comment_id: comment.id} |> Map.put(info.foreign_key, full_comment.article.id) @@ -76,7 +76,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleCommentAction do ORM.update(comment, %{is_pinned: false}) end) |> Multi.run(:remove_pined_comment, fn _, _ -> - ORM.findby_delete(ArticlePinedComment, %{article_comment_id: comment.id}) + ORM.findby_delete(ArticlePinnedComment, %{article_comment_id: comment.id}) end) |> Repo.transaction() |> result() diff --git a/lib/groupher_server/cms/post.ex b/lib/groupher_server/cms/post.ex index 0b18883ab..42c0d045e 100644 --- a/lib/groupher_server/cms/post.ex +++ b/lib/groupher_server/cms/post.ex @@ -13,7 +13,6 @@ defmodule GroupherServer.CMS.Post do Embeds, Author, ArticleComment, - ArticlePinedComment, Community, PostComment, Tag, @@ -63,7 +62,6 @@ defmodule GroupherServer.CMS.Post do has_many(:comments, {"posts_comments", PostComment}) has_many(:article_comments, {"articles_comments", ArticleComment}) - has_many(:article_pined_comments, {"articles_pined_comments", ArticlePinedComment}) field(:article_comments_count, :integer, default: 0) field(:article_comments_participators_count, :integer, default: 0) # 评论参与者,只保留最近 5 个 diff --git a/priv/repo/migrations/20210516055842_rename_articles_pined_comments.exs b/priv/repo/migrations/20210516055842_rename_articles_pined_comments.exs new file mode 100644 index 000000000..85df7212f --- /dev/null +++ b/priv/repo/migrations/20210516055842_rename_articles_pined_comments.exs @@ -0,0 +1,7 @@ +defmodule GroupherServer.Repo.Migrations.RenameArticlesPinedComments do + use Ecto.Migration + + def change do + rename(table("articles_pined_comments"), to: table("articles_pinned_comments")) + end +end diff --git a/test/groupher_server/cms/comments/job_comment_test.exs b/test/groupher_server/cms/comments/job_comment_test.exs index d5adc2162..2785050be 100644 --- a/test/groupher_server/cms/comments/job_comment_test.exs +++ b/test/groupher_server/cms/comments/job_comment_test.exs @@ -6,7 +6,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do alias Helper.ORM alias GroupherServer.{Accounts, CMS} - alias CMS.{ArticleComment, ArticlePinedComment, Embeds, Job} + alias CMS.{ArticleComment, ArticlePinnedComment, Embeds, Job} @delete_hint CMS.ArticleComment.delete_hint() @report_threshold_for_fold ArticleComment.report_threshold_for_fold() @@ -226,7 +226,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do assert comment.is_pinned - {:ok, pined_record} = ArticlePinedComment |> ORM.find_by(%{job_id: job.id}) + {:ok, pined_record} = ArticlePinnedComment |> ORM.find_by(%{job_id: job.id}) assert pined_record.job_id == job.id end @@ -237,7 +237,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do {:ok, comment} = CMS.undo_pin_article_comment(comment.id) assert not comment.is_pinned - assert {:error, _} = ArticlePinedComment |> ORM.find_by(%{article_comment_id: comment.id}) + assert {:error, _} = ArticlePinnedComment |> ORM.find_by(%{article_comment_id: comment.id}) end test "pined comments has a limit for each article", ~m(user job)a do @@ -549,7 +549,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do {:ok, _comment} = ORM.find(ArticleComment, random_comment.id) {:ok, _} = CMS.delete_article_comment(random_comment) - assert {:error, _comment} = ORM.find(ArticlePinedComment, random_comment.id) + assert {:error, _comment} = ORM.find(ArticlePinnedComment, random_comment.id) end end diff --git a/test/groupher_server/cms/comments/post_comment_test.exs b/test/groupher_server/cms/comments/post_comment_test.exs index e996e33f1..4099db83b 100644 --- a/test/groupher_server/cms/comments/post_comment_test.exs +++ b/test/groupher_server/cms/comments/post_comment_test.exs @@ -6,7 +6,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do alias Helper.ORM alias GroupherServer.{Accounts, CMS} - alias CMS.{ArticleComment, ArticlePinedComment, Embeds, Post} + alias CMS.{ArticleComment, ArticlePinnedComment, Embeds, Post} @delete_hint CMS.ArticleComment.delete_hint() @report_threshold_for_fold ArticleComment.report_threshold_for_fold() @@ -226,7 +226,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do assert comment.is_pinned - {:ok, pined_record} = ArticlePinedComment |> ORM.find_by(%{post_id: post.id}) + {:ok, pined_record} = ArticlePinnedComment |> ORM.find_by(%{post_id: post.id}) assert pined_record.post_id == post.id end @@ -237,7 +237,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do {:ok, comment} = CMS.undo_pin_article_comment(comment.id) assert not comment.is_pinned - assert {:error, _} = ArticlePinedComment |> ORM.find_by(%{article_comment_id: comment.id}) + assert {:error, _} = ArticlePinnedComment |> ORM.find_by(%{article_comment_id: comment.id}) end test "pined comments has a limit for each article", ~m(user post)a do @@ -574,7 +574,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do {:ok, _comment} = ORM.find(ArticleComment, random_comment.id) {:ok, _} = CMS.delete_article_comment(random_comment) - assert {:error, _comment} = ORM.find(ArticlePinedComment, random_comment.id) + assert {:error, _comment} = ORM.find(ArticlePinnedComment, random_comment.id) end end From cf14d5132a178d663bc8ee03c234c8174618c653 Mon Sep 17 00:00:00 2001 From: mydearxym Date: Sun, 16 May 2021 14:07:30 +0800 Subject: [PATCH 10/11] fix(article-comments): rename pined -> pinned --- lib/groupher_server/cms/article_comment.ex | 4 ++-- lib/groupher_server/cms/delegates/article_comment.ex | 5 +++-- .../cms/delegates/article_comment_action.ex | 6 +++--- .../cms/delegates/article_community.ex | 2 +- lib/groupher_server/cms/delegates/article_curd.ex | 4 ++-- .../cms/comments/job_comment_test.exs | 12 ++++++------ .../cms/comments/post_comment_test.exs | 12 ++++++------ .../query/cms/flags/jobs_flags_test.exs | 2 +- .../query/cms/flags/posts_flags_test.exs | 2 +- .../query/cms/flags/repos_flags_test.exs | 2 +- 10 files changed, 26 insertions(+), 25 deletions(-) diff --git a/lib/groupher_server/cms/article_comment.ex b/lib/groupher_server/cms/article_comment.ex index f4af65240..b996772ae 100644 --- a/lib/groupher_server/cms/article_comment.ex +++ b/lib/groupher_server/cms/article_comment.ex @@ -33,7 +33,7 @@ defmodule GroupherServer.CMS.ArticleComment do @report_threshold_for_fold 5 # 每篇文章最多含有置顶评论的条数 - @pined_comment_limit 10 + @pinned_comment_limit 10 @doc "latest participators stores in article article_comment_participators field" def max_participator_count(), do: @max_participator_count @@ -47,7 +47,7 @@ defmodule GroupherServer.CMS.ArticleComment do def delete_hint(), do: @delete_hint def report_threshold_for_fold, do: @report_threshold_for_fold - def pined_comment_limit, do: @pined_comment_limit + def pinned_comment_limit, do: @pinned_comment_limit @type t :: %ArticleComment{} schema "articles_comments" do diff --git a/lib/groupher_server/cms/delegates/article_comment.ex b/lib/groupher_server/cms/delegates/article_comment.ex index f3884f4da..6fdcf9dc6 100644 --- a/lib/groupher_server/cms/delegates/article_comment.ex +++ b/lib/groupher_server/cms/delegates/article_comment.ex @@ -23,7 +23,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleComment do @delete_hint ArticleComment.delete_hint() @default_comment_meta Embeds.ArticleCommentMeta.default_meta() - @pined_comment_limit ArticleComment.pined_comment_limit() + @pinned_comment_limit ArticleComment.pinned_comment_limit() @doc """ [timeline-mode] list paged article comments @@ -248,7 +248,8 @@ defmodule GroupherServer.CMS.Delegate.ArticleComment do _ -> preloaded_pined_comments = - Enum.slice(pined_comments, 0, @pined_comment_limit) |> Repo.preload(reply_to: :author) + Enum.slice(pined_comments, 0, @pinned_comment_limit) + |> Repo.preload(reply_to: :author) entries = Enum.concat(preloaded_pined_comments, entries) pined_comment_count = length(pined_comments) diff --git a/lib/groupher_server/cms/delegates/article_comment_action.ex b/lib/groupher_server/cms/delegates/article_comment_action.ex index 0e4302feb..eb6f4239b 100644 --- a/lib/groupher_server/cms/delegates/article_comment_action.ex +++ b/lib/groupher_server/cms/delegates/article_comment_action.ex @@ -32,7 +32,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleCommentAction do @article_threads Community.article_threads() @max_parent_replies_count ArticleComment.max_parent_replies_count() - @pined_comment_limit ArticleComment.pined_comment_limit() + @pinned_comment_limit ArticleComment.pinned_comment_limit() @spec pin_article_comment(Integer.t()) :: {:ok, ArticleComment.t()} @doc "pin a comment" @@ -49,8 +49,8 @@ defmodule GroupherServer.CMS.Delegate.ArticleCommentAction do pined_comments_count = Repo.aggregate(count_query, :count) - case pined_comments_count >= @pined_comment_limit do - true -> {:error, "only support #{@pined_comment_limit} pined comment for each article"} + case pined_comments_count >= @pinned_comment_limit do + true -> {:error, "only support #{@pinned_comment_limit} pinned comment for each article"} false -> {:ok, :pass} end end) diff --git a/lib/groupher_server/cms/delegates/article_community.ex b/lib/groupher_server/cms/delegates/article_community.ex index 7321d1590..e88bc4699 100644 --- a/lib/groupher_server/cms/delegates/article_community.ex +++ b/lib/groupher_server/cms/delegates/article_community.ex @@ -201,7 +201,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleCommunity do def lock_article_comment(content), do: {:ok, content} - # check if the thread has aready enough pined articles + # check if the thread has aready enough pinned articles defp check_pinned_article_count(community_id, thread) do thread_upcase = thread |> to_string |> String.upcase() diff --git a/lib/groupher_server/cms/delegates/article_curd.ex b/lib/groupher_server/cms/delegates/article_curd.ex index 6b813fa8e..32cacb65c 100644 --- a/lib/groupher_server/cms/delegates/article_curd.ex +++ b/lib/groupher_server/cms/delegates/article_curd.ex @@ -305,7 +305,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleCURD do |> join(:inner, [p], article in assoc(p, ^thread)) |> where([p, c, article], c.raw == ^community) |> select([p, c, article], article) - # 10 pined articles per community/thread, at most + # 10 pinned articles per community/thread, at most |> ORM.find_all(%{page: 1, size: 10}) do concat_articles(pinned_articles, articles) else @@ -334,7 +334,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleCURD do normal_count = non_pinned_articles |> Map.get(:total_count) - # remote the pined article from normal_entries (if have) + # remote the pinned article from normal_entries (if have) pind_ids = pick_by(pinned_entries, :id) normal_entries = Enum.reject(normal_entries, &(&1.id in pind_ids)) diff --git a/test/groupher_server/cms/comments/job_comment_test.exs b/test/groupher_server/cms/comments/job_comment_test.exs index 2785050be..6f7c15e2f 100644 --- a/test/groupher_server/cms/comments/job_comment_test.exs +++ b/test/groupher_server/cms/comments/job_comment_test.exs @@ -11,7 +11,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do @delete_hint CMS.ArticleComment.delete_hint() @report_threshold_for_fold ArticleComment.report_threshold_for_fold() @default_comment_meta Embeds.ArticleCommentMeta.default_meta() - @pined_comment_limit ArticleComment.pined_comment_limit() + @pinned_comment_limit ArticleComment.pinned_comment_limit() setup do {:ok, user} = db_insert(:user) @@ -240,10 +240,10 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do assert {:error, _} = ArticlePinnedComment |> ORM.find_by(%{article_comment_id: comment.id}) end - test "pined comments has a limit for each article", ~m(user job)a do + test "pinned comments has a limit for each article", ~m(user job)a do {:ok, comment} = CMS.create_article_comment(:job, job.id, "commment", user) - Enum.reduce(0..(@pined_comment_limit - 1), [], fn _, _acc -> + Enum.reduce(0..(@pinned_comment_limit - 1), [], fn _, _acc -> {:ok, _comment} = CMS.pin_article_comment(comment.id) end) @@ -374,7 +374,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do assert total_count == paged_comments.total_count end - test "paged article comments should contains pined comments at top position", + test "paged article comments should contains pinned comments at top position", ~m(user job)a do total_count = 20 page_number = 1 @@ -401,7 +401,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do assert paged_comments.total_count == total_count + 2 end - test "only page 1 have pined coments", + test "only page 1 have pinned coments", ~m(user job)a do total_count = 20 page_number = 2 @@ -533,7 +533,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do assert job.article_comments_count == 4 end - test "delete comment still delete pined record if needed", ~m(user job)a do + test "delete comment still delete pinned record if needed", ~m(user job)a do total_count = 10 all_comments = diff --git a/test/groupher_server/cms/comments/post_comment_test.exs b/test/groupher_server/cms/comments/post_comment_test.exs index 4099db83b..69210d99a 100644 --- a/test/groupher_server/cms/comments/post_comment_test.exs +++ b/test/groupher_server/cms/comments/post_comment_test.exs @@ -11,7 +11,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do @delete_hint CMS.ArticleComment.delete_hint() @report_threshold_for_fold ArticleComment.report_threshold_for_fold() @default_comment_meta Embeds.ArticleCommentMeta.default_meta() - @pined_comment_limit ArticleComment.pined_comment_limit() + @pinned_comment_limit ArticleComment.pinned_comment_limit() setup do {:ok, user} = db_insert(:user) @@ -240,10 +240,10 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do assert {:error, _} = ArticlePinnedComment |> ORM.find_by(%{article_comment_id: comment.id}) end - test "pined comments has a limit for each article", ~m(user post)a do + test "pinned comments has a limit for each article", ~m(user post)a do {:ok, comment} = CMS.create_article_comment(:post, post.id, "commment", user) - Enum.reduce(0..(@pined_comment_limit - 1), [], fn _, _acc -> + Enum.reduce(0..(@pinned_comment_limit - 1), [], fn _, _acc -> {:ok, _comment} = CMS.pin_article_comment(comment.id) end) @@ -379,7 +379,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do assert total_count == paged_comments.total_count end - test "paged article comments should contains pined comments at top position", + test "paged article comments should contains pinned comments at top position", ~m(user post)a do total_count = 20 page_number = 1 @@ -411,7 +411,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do assert paged_comments.total_count == total_count + 2 end - test "only page 1 have pined coments", + test "only page 1 have pinned coments", ~m(user post)a do total_count = 20 page_number = 2 @@ -558,7 +558,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do assert post.article_comments_count == 4 end - test "delete comment still delete pined record if needed", ~m(user post)a do + test "delete comment still delete pinned record if needed", ~m(user post)a do total_count = 10 all_comments = diff --git a/test/groupher_server_web/query/cms/flags/jobs_flags_test.exs b/test/groupher_server_web/query/cms/flags/jobs_flags_test.exs index 0a84ab2bc..d2a3fca28 100644 --- a/test/groupher_server_web/query/cms/flags/jobs_flags_test.exs +++ b/test/groupher_server_web/query/cms/flags/jobs_flags_test.exs @@ -49,7 +49,7 @@ defmodule GroupherServer.Test.Query.Flags.JobsFlags do } """ - test "if have pined jobs, the pined jobs should at the top of entries", + test "if have pinned jobs, the pinned jobs should at the top of entries", ~m(guest_conn community job_m)a do variables = %{filter: %{community: community.raw}} # variables = %{filter: %{}} diff --git a/test/groupher_server_web/query/cms/flags/posts_flags_test.exs b/test/groupher_server_web/query/cms/flags/posts_flags_test.exs index 84007b754..9f50a33df 100644 --- a/test/groupher_server_web/query/cms/flags/posts_flags_test.exs +++ b/test/groupher_server_web/query/cms/flags/posts_flags_test.exs @@ -49,7 +49,7 @@ defmodule GroupherServer.Test.Query.Flags.PostsFlags do } """ - test "if have pined posts, the pined posts should at the top of entries", + test "if have pinned posts, the pinned posts should at the top of entries", ~m(guest_conn community post_m)a do variables = %{filter: %{community: community.raw}} # variables = %{filter: %{}} diff --git a/test/groupher_server_web/query/cms/flags/repos_flags_test.exs b/test/groupher_server_web/query/cms/flags/repos_flags_test.exs index c7df53147..24484a2f9 100644 --- a/test/groupher_server_web/query/cms/flags/repos_flags_test.exs +++ b/test/groupher_server_web/query/cms/flags/repos_flags_test.exs @@ -49,7 +49,7 @@ defmodule GroupherServer.Test.Query.Flags.ReposFlags do } """ - test "if have pined repos, the pined repos should at the top of entries", + test "if have pinned repos, the pinned repos should at the top of entries", ~m(guest_conn community repo_m)a do variables = %{filter: %{community: community.raw}} # variables = %{filter: %{}} From d567d52efaaa1ae963f7343766fb7e332a1f51f0 Mon Sep 17 00:00:00 2001 From: mydearxym Date: Sun, 16 May 2021 14:07:59 +0800 Subject: [PATCH 11/11] fix(article-comments): rename pined -> pinned --- .../cms/delegates/article_comment_action.ex | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/groupher_server/cms/delegates/article_comment_action.ex b/lib/groupher_server/cms/delegates/article_comment_action.ex index eb6f4239b..0041d07cb 100644 --- a/lib/groupher_server/cms/delegates/article_comment_action.ex +++ b/lib/groupher_server/cms/delegates/article_comment_action.ex @@ -50,8 +50,11 @@ defmodule GroupherServer.CMS.Delegate.ArticleCommentAction do pined_comments_count = Repo.aggregate(count_query, :count) case pined_comments_count >= @pinned_comment_limit do - true -> {:error, "only support #{@pinned_comment_limit} pinned comment for each article"} - false -> {:ok, :pass} + true -> + {:error, "only support #{@pinned_comment_limit} pinned comment for each article"} + + false -> + {:ok, :pass} end end) |> Multi.run(:update_comment_flag, fn _, _ ->