From 4fc36ef38a62846c5d9c3ff3f6681c029c247105 Mon Sep 17 00:00:00 2001 From: mydearxym Date: Wed, 12 May 2021 11:38:22 +0800 Subject: [PATCH 01/13] refactor(abuse-report): wip --- lib/groupher_server/cms/cms.ex | 1 + .../cms/delegates/abuse_report.ex | 80 ++++++++++++++++++- .../cms/abuse_reports/comment_report_test.exs | 4 +- .../cms/abuse_reports/job_report_test.exs | 10 +-- .../cms/abuse_reports/post_report_test.exs | 26 +++++- .../comments/job_comment_emotions_test.exs | 12 +-- .../cms/comments/job_comment_replies_test.exs | 8 +- .../cms/comments/job_comment_test.exs | 18 ++--- .../comments/post_comment_emotions_test.exs | 12 +-- .../comments/post_comment_replies_test.exs | 10 +-- .../cms/comments/post_comment_test.exs | 18 ++--- .../cms/emotions/job_emotions_test.exs | 16 ++-- .../cms/emotions/post_emotions_test.exs | 16 ++-- test/groupher_server/cms/job_test.exs | 2 +- test/groupher_server/cms/post_test.exs | 4 +- test/groupher_server/cms/repo_test.exs | 4 +- .../cms/upvotes/job_upvote_test.exs | 10 +-- .../cms/upvotes/post_upvote_test.exs | 10 +-- .../mutation/accounts/customization_test.exs | 2 +- .../cms/articles/job_emotion_test.exs | 4 +- .../mutation/cms/articles/job_report_test.exs | 4 +- .../mutation/cms/articles/job_test.exs | 2 +- .../cms/articles/post_emotion_test.exs | 4 +- .../cms/articles/post_report_test.exs | 4 +- .../mutation/cms/articles/post_test.exs | 2 +- .../cms/articles/repo_report_test.exs | 4 +- .../mutation/cms/articles/repo_test.exs | 6 +- .../mutation/cms/cms_test.exs | 4 +- .../cms/comments/job_comment_test.exs | 12 +-- .../cms/comments/post_comment_test.exs | 12 +-- .../mutation/cms/flags/job_flag_test.exs | 14 ++-- .../mutation/cms/flags/post_flag_test.exs | 16 ++-- .../mutation/cms/flags/repo_flag_test.exs | 16 ++-- .../mutation/cms/upvotes/job_upvote_test.exs | 8 +- .../mutation/cms/upvotes/post_upvote_test.exs | 8 +- .../query/cms/collects/job_collect_test.exs | 2 +- .../query/cms/collects/post_collect_test.exs | 2 +- .../query/cms/comments/job_comment_test.exs | 12 +-- .../query/cms/comments/post_comment_test.exs | 10 +-- .../query/cms/job_test.exs | 4 +- .../query/cms/jobs_flags_test.exs | 2 +- .../query/cms/paged_jobs_test.exs | 2 +- .../query/cms/paged_posts_test.exs | 2 +- .../query/cms/paged_repos_test.exs | 2 +- .../query/cms/post_test.exs | 4 +- .../query/cms/posts_flags_test.exs | 2 +- .../query/cms/repo_test.exs | 4 +- .../query/cms/repos_flags_test.exs | 2 +- .../query/cms/upvotes/post_upvote_test.exs | 2 +- 49 files changed, 264 insertions(+), 171 deletions(-) diff --git a/lib/groupher_server/cms/cms.ex b/lib/groupher_server/cms/cms.ex index 284dcd35d..ac8782015 100644 --- a/lib/groupher_server/cms/cms.ex +++ b/lib/groupher_server/cms/cms.ex @@ -164,6 +164,7 @@ defmodule GroupherServer.CMS do defdelegate report_article(thread, article_id, reason, attr, user), to: AbuseReport defdelegate undo_report_article(thread, article_id, user), to: AbuseReport defdelegate list_reports(type, content_id, filter), to: AbuseReport + defdelegate list_reports(filter), to: AbuseReport defdelegate report_article_comment(comment_id, reason, attr, user), to: ArticleCommentAction defdelegate undo_report_article_comment(comment_id, user), to: AbuseReport diff --git a/lib/groupher_server/cms/delegates/abuse_report.ex b/lib/groupher_server/cms/delegates/abuse_report.ex index 0f93ed115..7b46d3515 100644 --- a/lib/groupher_server/cms/delegates/abuse_report.ex +++ b/lib/groupher_server/cms/delegates/abuse_report.ex @@ -17,12 +17,86 @@ defmodule GroupherServer.CMS.Delegate.AbuseReport do alias Ecto.Multi + # filter = %{ + # contentType: account | post | job | repo | article_comment + # contentId: ... + # operate_user_id, + # min_case_count, + # max_case_count, + # is_closed + # page + # size + # } + + # def list_all_reports(thread, filter) + # def list_all_reports(community, filter) + # def list_all_reports(filter) + @article_threads [:post, :job, :repo] + @export_report_keys = [ + :id, + :deal_with, + :is_closed, + :operate_user, + :report_cases, + :report_cases_count, + :inserted_at, + :updated_at + ] + + def list_reports(%{content_type: thread, content_id: content_id} = filter) + when thread in @article_threads do + %{page: page, size: size} = filter + + with {:ok, info} <- match(thread) do + query = + from(r in AbuseReport, + where: field(r, ^info.foreign_key) == ^content_id, + preload: [^thread, :operate_user] + ) + + query + |> QueryBuilder.filter_pack(filter) + |> ORM.paginater(~m(page size)a) + |> reports_formater(thread) + |> done() + end + end + + defp reports_formater(%{entries: entries} = paged_reports, thread) + when thread in @article_threads do + paged_reports + |> Map.put( + :entries, + Enum.map(entries, fn report -> + basic_report = report |> Map.take(@export_report_keys) + basic_report |> Map.put(:article, extract_article_info(thread, report)) + end) + ) + end + + defp extract_article_info(thread, %AbuseReport{} = report) do + article = Map.get(report, thread) + + %{ + thread: thread, + id: article.id, + title: article.title, + digest: article.digest, + upvotes_count: article.upvotes_count, + views: article.views + } + end + @doc """ list paged reports for both comment and article """ - def list_reports(type, content_id, %{page: page, size: size} = filter) do - with {:ok, info} <- match(type) do - query = from(r in AbuseReport, where: field(r, ^info.foreign_key) == ^content_id) + def list_reports(thread, content_id, %{page: page, size: size} = filter) do + with {:ok, info} <- match(thread) do + query = + from(r in AbuseReport, + where: field(r, ^info.foreign_key) == ^content_id, + preload: [^thread, :operate_user] + ) query |> QueryBuilder.filter_pack(filter) 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 dd920db44..a3c7a7594 100644 --- a/test/groupher_server/cms/abuse_reports/comment_report_test.exs +++ b/test/groupher_server/cms/abuse_reports/comment_report_test.exs @@ -15,7 +15,7 @@ defmodule GroupherServer.Test.CMS.AbuseReports.CommentReport do end describe "[article comment report/unreport]" do - @tag :wip2 + @tag :wip3 test "report a comment should have a abuse report record", ~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) @@ -30,7 +30,7 @@ defmodule GroupherServer.Test.CMS.AbuseReports.CommentReport do assert List.first(report_cases).user.login == user.login end - @tag :wip2 + @tag :wip3 test "different user report a comment should have same report with different report cases", ~m(user user2 post)a do {:ok, comment} = CMS.create_article_comment(:post, post.id, "commment", user) diff --git a/test/groupher_server/cms/abuse_reports/job_report_test.exs b/test/groupher_server/cms/abuse_reports/job_report_test.exs index 5034335cd..fb9d938e3 100644 --- a/test/groupher_server/cms/abuse_reports/job_report_test.exs +++ b/test/groupher_server/cms/abuse_reports/job_report_test.exs @@ -17,7 +17,7 @@ defmodule GroupherServer.Test.CMS.AbuseReports.JobReport do end describe "[article job report/unreport]" do - @tag :wip2 + @tag :wip3 test "report a job should have a abuse report record", ~m(community user job_attrs)a do {:ok, job} = CMS.create_content(community, :job, job_attrs, user) {:ok, _report} = CMS.report_article(:job, job.id, "reason", "attr_info", user) @@ -37,7 +37,7 @@ defmodule GroupherServer.Test.CMS.AbuseReports.JobReport do assert job.meta.reported_count == 1 end - @tag :wip2 + @tag :wip3 test "can undo a report", ~m(community user job_attrs)a do {:ok, job} = CMS.create_content(community, :job, job_attrs, user) {:ok, _report} = CMS.report_article(:job, job.id, "reason", "attr_info", user) @@ -47,7 +47,7 @@ defmodule GroupherServer.Test.CMS.AbuseReports.JobReport do assert all_reports.total_count == 0 end - @tag :wip2 + @tag :wip3 test "can undo a report with other user report it too", ~m(community user user2 job_attrs)a do {:ok, job} = CMS.create_content(community, :job, job_attrs, user) @@ -72,7 +72,7 @@ defmodule GroupherServer.Test.CMS.AbuseReports.JobReport do assert Enum.any?(report.report_cases, &(&1.user.login == user2.login)) end - @tag :wip2 + @tag :wip3 test "different user report a comment should have same report with different report cases", ~m(community user user2 job_attrs)a do {:ok, job} = CMS.create_content(community, :job, job_attrs, user) @@ -93,7 +93,7 @@ defmodule GroupherServer.Test.CMS.AbuseReports.JobReport do assert List.last(report_cases).user.login == user2.login end - @tag :wip2 + @tag :wip3 test "same user can not report a comment twice", ~m(community job_attrs user)a do {:ok, job} = CMS.create_content(community, :job, job_attrs, user) diff --git a/test/groupher_server/cms/abuse_reports/post_report_test.exs b/test/groupher_server/cms/abuse_reports/post_report_test.exs index c2945b192..ff2d70ba9 100644 --- a/test/groupher_server/cms/abuse_reports/post_report_test.exs +++ b/test/groupher_server/cms/abuse_reports/post_report_test.exs @@ -18,6 +18,24 @@ defmodule GroupherServer.Test.CMS.AbuseReports.PostReport do describe "[article post report/unreport]" do @tag :wip2 + test "list article reports should work", ~m(community user user2 post_attrs)a do + {:ok, post} = CMS.create_content(community, :post, post_attrs, user) + {:ok, _report} = CMS.report_article(:post, post.id, "reason", "attr_info", user) + {:ok, _report} = CMS.report_article(:post, post.id, "reason", "attr_info", user2) + + filter = %{content_type: :post, content_id: post.id, page: 1, size: 20} + {:ok, all_reports} = CMS.list_reports(filter) + IO.inspect(all_reports, label: "all_reports -- ") + + # report = all_reports.entries |> List.first() + # IO.inspect(Map.keys(report), label: "report keys") + # # [:deal_with, :id, :inserted_at, :is_closed, :operate_user, :post, :report_cases, + # # :report_cases_count, :updated_at] + # assert report |> Map.get(:post) |> Map.get(:id) == post.id + # assert report |> Map.get(:report_cases) |> length == 2 + end + + @tag :wip3 test "report a post should have a abuse report record", ~m(community user post_attrs)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) {:ok, _report} = CMS.report_article(:post, post.id, "reason", "attr_info", user) @@ -37,7 +55,7 @@ defmodule GroupherServer.Test.CMS.AbuseReports.PostReport do assert post.meta.reported_count == 1 end - @tag :wip2 + @tag :wip3 test "can undo a report", ~m(community user post_attrs)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) {:ok, _report} = CMS.report_article(:post, post.id, "reason", "attr_info", user) @@ -47,7 +65,7 @@ defmodule GroupherServer.Test.CMS.AbuseReports.PostReport do assert all_reports.total_count == 0 end - @tag :wip2 + @tag :wip3 test "can undo a report with other user report it too", ~m(community user user2 post_attrs)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) @@ -72,7 +90,7 @@ defmodule GroupherServer.Test.CMS.AbuseReports.PostReport do assert Enum.any?(report.report_cases, &(&1.user.login == user2.login)) end - @tag :wip2 + @tag :wip3 test "different user report a comment should have same report with different report cases", ~m(community user user2 post_attrs)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) @@ -93,7 +111,7 @@ defmodule GroupherServer.Test.CMS.AbuseReports.PostReport do assert List.last(report_cases).user.login == user2.login end - @tag :wip2 + @tag :wip3 test "same user can not report a comment twice", ~m(community post_attrs user)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) 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 3cc538cc6..7c3cc5369 100644 --- a/test/groupher_server/cms/comments/job_comment_emotions_test.exs +++ b/test/groupher_server/cms/comments/job_comment_emotions_test.exs @@ -21,7 +21,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentEmotions do end describe "[emotion in paged article comment]" do - @tag :wip2 + @tag :wip3 test "login user should got viewer has emotioned status", ~m(job user)a do total_count = 0 page_number = 10 @@ -76,7 +76,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentEmotions do assert @default_emotions == emotions end - @tag :wip2 + @tag :wip3 test "can make emotion to comment", ~m(job user user2)a do parent_content = "parent comment" {:ok, parent_comment} = CMS.create_article_comment(:job, job.id, parent_content, user) @@ -91,7 +91,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentEmotions do assert user_exist_in?(user2, emotions.latest_downvote_users) end - @tag :wip2 + @tag :wip3 test "can undo emotion to comment", ~m(job user user2)a do parent_content = "parent comment" {:ok, parent_comment} = CMS.create_article_comment(:job, job.id, parent_content, user) @@ -114,7 +114,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentEmotions do assert not user_exist_in?(user2, emotions.latest_downvote_users) end - @tag :wip2 + @tag :wip3 test "same user make same emotion to same comment.", ~m(job user)a do parent_content = "parent comment" {:ok, parent_comment} = CMS.create_article_comment(:job, job.id, parent_content, user) @@ -128,7 +128,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentEmotions do assert user_exist_in?(user, parent_comment.emotions.latest_downvote_users) end - @tag :wip2 + @tag :wip3 test "same user same emotion to same comment only have one user_emotion record", ~m(job user)a do parent_content = "parent comment" @@ -152,7 +152,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentEmotions do assert record.heart end - @tag :wip2 + @tag :wip3 test "different user can make same emotions on same comment", ~m(job user user2 user3)a do {:ok, parent_comment} = CMS.create_article_comment(:job, job.id, "parent comment", 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 67081286f..6a127ca62 100644 --- a/test/groupher_server/cms/comments/job_comment_replies_test.exs +++ b/test/groupher_server/cms/comments/job_comment_replies_test.exs @@ -33,7 +33,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentReplies do assert exist_in?(replyed_comment, parent_comment.replies) end - @tag :wip2 + @tag :wip3 test "deleted comment can not be reply", ~m(job user user2)a do parent_content = "parent comment" reply_content = "reply comment" @@ -64,7 +64,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentReplies do assert exist_in?(replyed_comment_2, parent_comment.replies) end - @tag :wip2 + @tag :wip3 test "reply to reply inside a comment should belong same parent comment", ~m(job user user2)a do {:ok, parent_comment} = CMS.create_article_comment(:job, job.id, "parent comment", user) @@ -90,7 +90,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentReplies do assert replyed_comment_3.reply_to_id == replyed_comment_2.id end - @tag :wip2 + @tag :wip3 test "reply to reply inside a comment should have is_reply_to_others flag in meta", ~m(job user user2)a do {:ok, parent_comment} = CMS.create_article_comment(:job, job.id, "parent comment", user) @@ -110,7 +110,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentReplies do assert replyed_comment_3.meta.is_reply_to_others end - @tag :wip2 + @tag :wip3 test "comment replies only contains @max_parent_replies_count replies", ~m(job user)a do total_reply_count = @max_parent_replies_count + 1 diff --git a/test/groupher_server/cms/comments/job_comment_test.exs b/test/groupher_server/cms/comments/job_comment_test.exs index df8b9a941..fe2980a3b 100644 --- a/test/groupher_server/cms/comments/job_comment_test.exs +++ b/test/groupher_server/cms/comments/job_comment_test.exs @@ -39,7 +39,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do assert comment.meta |> Map.from_struct() |> Map.delete(:id) == @default_comment_meta end - @tag :wip2 + @tag :wip3 test "comment can be updated", ~m(job user)a do {:ok, comment} = CMS.create_article_comment(:job, job.id, "job comment", user) @@ -130,7 +130,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do assert comment.meta.is_article_author_upvoted end - @tag :wip2 + @tag :wip3 test "user upvote job comment will add id to upvoted_user_ids", ~m(job user)a do comment = "job_comment" {:ok, comment} = CMS.create_article_comment(:job, job.id, comment, user) @@ -139,7 +139,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do assert user.id in comment.meta.upvoted_user_ids end - @tag :wip2 + @tag :wip3 test "user undo upvote job comment will remove id from upvoted_user_ids", ~m(job user user2)a do comment = "job_comment" @@ -295,7 +295,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do assert not comment.is_reported end - @tag :wip2 + @tag :wip3 test "can undo a report with other user report it too", ~m(user user2 job)a do {:ok, comment} = CMS.create_article_comment(:job, job.id, "commment", user) @@ -321,7 +321,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do assert Enum.any?(report.report_cases, &(&1.user.login == user2.login)) end - @tag :wip2 + @tag :wip3 test "report user < @report_threshold_for_fold will not fold comment", ~m(user job)a do {:ok, comment} = CMS.create_article_comment(:job, job.id, "commment", user) @@ -461,7 +461,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do assert paged_comments.total_count == total_count end - @tag :wip2 + @tag :wip3 test "paged article comments should not contains folded and repoted comments", ~m(user job)a do total_count = 15 @@ -569,7 +569,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do end describe "[article comment delete]" do - @tag :wip2 + @tag :wip3 test "delete comment still exsit in paged list and content is gone", ~m(user job)a do total_count = 10 page_number = 1 @@ -594,7 +594,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do assert deleted_comment.body_html == @delete_hint end - @tag :wip2 + @tag :wip3 test "delete comment still update article's comments_count field", ~m(user job)a do {:ok, _comment} = CMS.create_article_comment(:job, job.id, "commment", user) {:ok, _comment} = CMS.create_article_comment(:job, job.id, "commment", user) @@ -612,7 +612,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do assert job.article_comments_count == 4 end - @tag :wip2 + @tag :wip3 test "delete comment still delete pined record if needed", ~m(user job)a do total_count = 10 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 02665c31c..0e55ecfd3 100644 --- a/test/groupher_server/cms/comments/post_comment_emotions_test.exs +++ b/test/groupher_server/cms/comments/post_comment_emotions_test.exs @@ -21,7 +21,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostCommentEmotions do end describe "[emotion in paged article comment]" do - @tag :wip2 + @tag :wip3 test "login user should got viewer has emotioned status", ~m(post user)a do total_count = 0 page_number = 10 @@ -76,7 +76,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostCommentEmotions do assert @default_emotions == emotions end - @tag :wip2 + @tag :wip3 test "can make emotion to comment", ~m(post user user2)a do parent_content = "parent comment" {:ok, parent_comment} = CMS.create_article_comment(:post, post.id, parent_content, user) @@ -91,7 +91,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostCommentEmotions do assert user_exist_in?(user2, emotions.latest_downvote_users) end - @tag :wip2 + @tag :wip3 test "can undo emotion to comment", ~m(post user user2)a do parent_content = "parent comment" {:ok, parent_comment} = CMS.create_article_comment(:post, post.id, parent_content, user) @@ -114,7 +114,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostCommentEmotions do assert not user_exist_in?(user2, emotions.latest_downvote_users) end - @tag :wip2 + @tag :wip3 test "same user make same emotion to same comment.", ~m(post user)a do parent_content = "parent comment" {:ok, parent_comment} = CMS.create_article_comment(:post, post.id, parent_content, user) @@ -128,7 +128,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostCommentEmotions do assert user_exist_in?(user, parent_comment.emotions.latest_downvote_users) end - @tag :wip2 + @tag :wip3 test "same user same emotion to same comment only have one user_emotion record", ~m(post user)a do parent_content = "parent comment" @@ -152,7 +152,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostCommentEmotions do assert record.heart end - @tag :wip2 + @tag :wip3 test "different user can make same emotions on same comment", ~m(post user user2 user3)a do {:ok, parent_comment} = CMS.create_article_comment(:post, post.id, "parent comment", 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 fc968d208..d7508fa62 100644 --- a/test/groupher_server/cms/comments/post_comment_replies_test.exs +++ b/test/groupher_server/cms/comments/post_comment_replies_test.exs @@ -33,7 +33,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostCommentReplies do assert exist_in?(replyed_comment, parent_comment.replies) end - @tag :wip2 + @tag :wip3 test "deleted comment can not be reply", ~m(post user user2)a do parent_content = "parent comment" reply_content = "reply comment" @@ -64,7 +64,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostCommentReplies do assert exist_in?(replyed_comment_2, parent_comment.replies) end - @tag :wip2 + @tag :wip3 test "reply to reply inside a comment should belong same parent comment", ~m(post user user2)a do {:ok, parent_comment} = CMS.create_article_comment(:post, post.id, "parent comment", user) @@ -90,7 +90,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostCommentReplies do assert replyed_comment_3.reply_to_id == replyed_comment_2.id end - @tag :wip2 + @tag :wip3 test "reply to reply inside a comment should have is_reply_to_others flag in meta", ~m(post user user2)a do {:ok, parent_comment} = CMS.create_article_comment(:post, post.id, "parent comment", user) @@ -110,7 +110,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostCommentReplies do assert replyed_comment_3.meta.is_reply_to_others end - @tag :wip2 + @tag :wip3 test "comment replies only contains @max_parent_replies_count replies", ~m(post user)a do total_reply_count = @max_parent_replies_count + 1 @@ -160,7 +160,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostCommentReplies do end describe "[paged article comment replies]" do - @tag :wip2 + @tag :wip3 test "can get paged replies of a parent comment", ~m(post user)a do {:ok, parent_comment} = CMS.create_article_comment(:post, post.id, "parent_conent", user) {:ok, paged_replies} = CMS.list_comment_replies(parent_comment.id, %{page: 1, size: 20}) diff --git a/test/groupher_server/cms/comments/post_comment_test.exs b/test/groupher_server/cms/comments/post_comment_test.exs index 7d48c0a64..8a87401d1 100644 --- a/test/groupher_server/cms/comments/post_comment_test.exs +++ b/test/groupher_server/cms/comments/post_comment_test.exs @@ -39,7 +39,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do assert comment.meta |> Map.from_struct() |> Map.delete(:id) == @default_comment_meta end - @tag :wip2 + @tag :wip3 test "comment can be updated", ~m(post user)a do {:ok, comment} = CMS.create_article_comment(:post, post.id, "post comment", user) @@ -130,7 +130,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do assert comment.meta.is_article_author_upvoted end - @tag :wip2 + @tag :wip3 test "user upvote post comment will add id to upvoted_user_ids", ~m(post user)a do comment = "post_comment" {:ok, comment} = CMS.create_article_comment(:post, post.id, comment, user) @@ -139,7 +139,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do assert user.id in comment.meta.upvoted_user_ids end - @tag :wip2 + @tag :wip3 test "user undo upvote post comment will remove id from upvoted_user_ids", ~m(post user user2)a do comment = "post_comment" @@ -282,7 +282,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do assert comment.is_reported end - @tag :wip2 + @tag :wip3 test "user can unreport a comment", ~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) @@ -295,7 +295,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do assert not comment.is_reported end - @tag :wip2 + @tag :wip3 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) @@ -461,7 +461,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do assert paged_comments.total_count == total_count end - @tag :wip2 + @tag :wip3 test "paged article comments should not contains folded and repoted comments", ~m(user post)a do total_count = 15 @@ -569,7 +569,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do end describe "[article comment delete]" do - @tag :wip2 + @tag :wip3 test "delete comment still exsit in paged list and content is gone", ~m(user post)a do total_count = 10 page_number = 1 @@ -594,7 +594,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do assert deleted_comment.body_html == @delete_hint end - @tag :wip2 + @tag :wip3 test "delete comment still update article's comments_count field", ~m(user post)a do {:ok, _comment} = CMS.create_article_comment(:post, post.id, "commment", user) {:ok, _comment} = CMS.create_article_comment(:post, post.id, "commment", user) @@ -612,7 +612,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do assert post.article_comments_count == 4 end - @tag :wip2 + @tag :wip3 test "delete comment still delete pined record if needed", ~m(user post)a do total_count = 10 diff --git a/test/groupher_server/cms/emotions/job_emotions_test.exs b/test/groupher_server/cms/emotions/job_emotions_test.exs index bd822186b..699214674 100644 --- a/test/groupher_server/cms/emotions/job_emotions_test.exs +++ b/test/groupher_server/cms/emotions/job_emotions_test.exs @@ -22,7 +22,7 @@ defmodule GroupherServer.Test.CMS.Emotions.JobEmotions do end describe "[emotion in paged jobs]" do - @tag :wip2 + @tag :wip3 test "login user should got viewer has emotioned status", ~m(community job_attrs user)a do total_count = 10 @@ -61,7 +61,7 @@ defmodule GroupherServer.Test.CMS.Emotions.JobEmotions do end describe "[basic article emotion]" do - @tag :wip2 + @tag :wip3 test "job has default emotions after created", ~m(community job_attrs user)a do {:ok, job} = CMS.create_content(community, :job, job_attrs, user) @@ -69,7 +69,7 @@ defmodule GroupherServer.Test.CMS.Emotions.JobEmotions do assert @default_emotions == emotions end - @tag :wip2 + @tag :wip3 test "can make emotion to job", ~m(community job_attrs user user2)a do {:ok, job} = CMS.create_content(community, :job, job_attrs, user) @@ -83,7 +83,7 @@ defmodule GroupherServer.Test.CMS.Emotions.JobEmotions do assert user_exist_in?(user2, emotions.latest_downvote_users) end - @tag :wip2 + @tag :wip3 test "can undo emotion to job", ~m(community job_attrs user user2)a do {:ok, job} = CMS.create_content(community, :job, job_attrs, user) @@ -100,7 +100,7 @@ defmodule GroupherServer.Test.CMS.Emotions.JobEmotions do assert not user_exist_in?(user2, emotions.latest_downvote_users) end - @tag :wip2 + @tag :wip3 test "same user make same emotion to same job.", ~m(community job_attrs user)a do {:ok, job} = CMS.create_content(community, :job, job_attrs, user) @@ -113,7 +113,7 @@ defmodule GroupherServer.Test.CMS.Emotions.JobEmotions do assert user_exist_in?(user, job.emotions.latest_downvote_users) end - @tag :wip2 + @tag :wip3 test "same user same emotion to same job only have one user_emotion record", ~m(community job_attrs user)a do {:ok, job} = CMS.create_content(community, :job, job_attrs, user) @@ -131,7 +131,7 @@ defmodule GroupherServer.Test.CMS.Emotions.JobEmotions do assert record.heart end - @tag :wip2 + @tag :wip3 test "different user can make same emotions on same job", ~m(community job_attrs user user2 user3)a do {:ok, job} = CMS.create_content(community, :job, job_attrs, user) @@ -148,7 +148,7 @@ defmodule GroupherServer.Test.CMS.Emotions.JobEmotions do assert user_exist_in?(user3, emotions.latest_beer_users) end - @tag :wip2 + @tag :wip3 test "same user can make differcent emotions on same job", ~m(community job_attrs user)a do {:ok, job} = CMS.create_content(community, :job, job_attrs, user) diff --git a/test/groupher_server/cms/emotions/post_emotions_test.exs b/test/groupher_server/cms/emotions/post_emotions_test.exs index 2624b43d3..24a10fce8 100644 --- a/test/groupher_server/cms/emotions/post_emotions_test.exs +++ b/test/groupher_server/cms/emotions/post_emotions_test.exs @@ -22,7 +22,7 @@ defmodule GroupherServer.Test.CMS.Emotions.PostEmotions do end describe "[emotion in paged posts]" do - @tag :wip2 + @tag :wip3 test "login user should got viewer has emotioned status", ~m(community post_attrs user)a do total_count = 10 @@ -61,7 +61,7 @@ defmodule GroupherServer.Test.CMS.Emotions.PostEmotions do end describe "[basic article emotion]" do - @tag :wip2 + @tag :wip3 test "post has default emotions after created", ~m(community post_attrs user)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) @@ -69,7 +69,7 @@ defmodule GroupherServer.Test.CMS.Emotions.PostEmotions do assert @default_emotions == emotions end - @tag :wip2 + @tag :wip3 test "can make emotion to post", ~m(community post_attrs user user2)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) @@ -83,7 +83,7 @@ defmodule GroupherServer.Test.CMS.Emotions.PostEmotions do assert user_exist_in?(user2, emotions.latest_downvote_users) end - @tag :wip2 + @tag :wip3 test "can undo emotion to post", ~m(community post_attrs user user2)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) @@ -100,7 +100,7 @@ defmodule GroupherServer.Test.CMS.Emotions.PostEmotions do assert not user_exist_in?(user2, emotions.latest_downvote_users) end - @tag :wip2 + @tag :wip3 test "same user make same emotion to same post.", ~m(community post_attrs user)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) @@ -113,7 +113,7 @@ defmodule GroupherServer.Test.CMS.Emotions.PostEmotions do assert user_exist_in?(user, post.emotions.latest_downvote_users) end - @tag :wip2 + @tag :wip3 test "same user same emotion to same post only have one user_emotion record", ~m(community post_attrs user)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) @@ -131,7 +131,7 @@ defmodule GroupherServer.Test.CMS.Emotions.PostEmotions do assert record.heart end - @tag :wip2 + @tag :wip3 test "different user can make same emotions on same post", ~m(community post_attrs user user2 user3)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) @@ -148,7 +148,7 @@ defmodule GroupherServer.Test.CMS.Emotions.PostEmotions do assert user_exist_in?(user3, emotions.latest_beer_users) end - @tag :wip2 + @tag :wip3 test "same user can make differcent emotions on same post", ~m(community post_attrs user)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) diff --git a/test/groupher_server/cms/job_test.exs b/test/groupher_server/cms/job_test.exs index 297468cd6..6d924a25f 100644 --- a/test/groupher_server/cms/job_test.exs +++ b/test/groupher_server/cms/job_test.exs @@ -25,7 +25,7 @@ defmodule GroupherServer.Test.Job do assert found.title == job.title end - @tag :wip2 + @tag :wip3 test "read job should update views and meta viewed_user_list", ~m(job_attrs community user user2)a do {:ok, job} = CMS.create_content(community, :job, job_attrs, user) diff --git a/test/groupher_server/cms/post_test.exs b/test/groupher_server/cms/post_test.exs index f028aece3..eae07914a 100644 --- a/test/groupher_server/cms/post_test.exs +++ b/test/groupher_server/cms/post_test.exs @@ -18,7 +18,7 @@ defmodule GroupherServer.Test.CMS.Post do describe "[cms post curd]" do alias CMS.{Author, Community} - @tag :wip2 + @tag :wip3 test "can create post with valid attrs", ~m(user community post_attrs)a do assert {:error, _} = ORM.find_by(Author, user_id: user.id) @@ -27,7 +27,7 @@ defmodule GroupherServer.Test.CMS.Post do assert post.title == post_attrs.title end - @tag :wip2 + @tag :wip3 test "read post should update views and meta viewed_user_list", ~m(post_attrs community user user2)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) diff --git a/test/groupher_server/cms/repo_test.exs b/test/groupher_server/cms/repo_test.exs index 69b65a579..0446b00c5 100644 --- a/test/groupher_server/cms/repo_test.exs +++ b/test/groupher_server/cms/repo_test.exs @@ -17,7 +17,7 @@ defmodule GroupherServer.Test.Repo do describe "[cms repo curd]" do alias CMS.{Author, Community} - @tag :wip2 + @tag :wip3 test "can create repo with valid attrs", ~m(user community repo_attrs)a do assert {:error, _} = ORM.find_by(Author, user_id: user.id) @@ -27,7 +27,7 @@ defmodule GroupherServer.Test.Repo do assert repo.contributors |> length !== 0 end - @tag :wip2 + @tag :wip3 test "read repo should update views and meta viewed_user_list", ~m(repo_attrs community user user2)a do {:ok, repo} = CMS.create_content(community, :repo, repo_attrs, user) diff --git a/test/groupher_server/cms/upvotes/job_upvote_test.exs b/test/groupher_server/cms/upvotes/job_upvote_test.exs index daf36dd6c..18286922b 100644 --- a/test/groupher_server/cms/upvotes/job_upvote_test.exs +++ b/test/groupher_server/cms/upvotes/job_upvote_test.exs @@ -15,7 +15,7 @@ defmodule GroupherServer.Test.Upvotes.JobUpvote do end describe "[cms job upvote]" do - @tag :wip2 + @tag :wip3 test "job can be upvote && upvotes_count should inc by 1", ~m(user user2 community job_attrs)a do {:ok, job} = CMS.create_content(community, :job, job_attrs, user) @@ -28,7 +28,7 @@ defmodule GroupherServer.Test.Upvotes.JobUpvote do assert article.upvotes_count == 2 end - @tag :wip2 + @tag :wip3 test "job can be undo upvote && upvotes_count should dec by 1", ~m(user user2 community job_attrs)a do {:ok, job} = CMS.create_content(community, :job, job_attrs, user) @@ -41,7 +41,7 @@ defmodule GroupherServer.Test.Upvotes.JobUpvote do assert article.upvotes_count == 0 end - @tag :wip2 + @tag :wip3 test "can get upvotes_users", ~m(user user2 community job_attrs)a do {:ok, job} = CMS.create_content(community, :job, job_attrs, user) @@ -55,7 +55,7 @@ defmodule GroupherServer.Test.Upvotes.JobUpvote do assert user_exist_in?(user2, users.entries) end - @tag :wip2 + @tag :wip3 test "job meta history should be updated after upvote", ~m(user user2 community job_attrs)a do {:ok, job} = CMS.create_content(community, :job, job_attrs, user) @@ -67,7 +67,7 @@ defmodule GroupherServer.Test.Upvotes.JobUpvote do assert user2.id in article.meta.upvoted_user_ids end - @tag :wip2 + @tag :wip3 test "job meta history should be updated after undo upvote", ~m(user user2 community job_attrs)a do {:ok, job} = CMS.create_content(community, :job, job_attrs, user) diff --git a/test/groupher_server/cms/upvotes/post_upvote_test.exs b/test/groupher_server/cms/upvotes/post_upvote_test.exs index fda68d1d1..5cf2c8ed8 100644 --- a/test/groupher_server/cms/upvotes/post_upvote_test.exs +++ b/test/groupher_server/cms/upvotes/post_upvote_test.exs @@ -15,7 +15,7 @@ defmodule GroupherServer.Test.Upvotes.PostUpvote do end describe "[cms post upvote]" do - @tag :wip2 + @tag :wip3 test "post can be upvote && upvotes_count should inc by 1", ~m(user user2 community post_attrs)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) @@ -28,7 +28,7 @@ defmodule GroupherServer.Test.Upvotes.PostUpvote do assert article.upvotes_count == 2 end - @tag :wip2 + @tag :wip3 test "post can be undo upvote && upvotes_count should dec by 1", ~m(user user2 community post_attrs)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) @@ -41,7 +41,7 @@ defmodule GroupherServer.Test.Upvotes.PostUpvote do assert article.upvotes_count == 0 end - @tag :wip2 + @tag :wip3 test "can get upvotes_users", ~m(user user2 community post_attrs)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) @@ -55,7 +55,7 @@ defmodule GroupherServer.Test.Upvotes.PostUpvote do assert user_exist_in?(user2, users.entries) end - @tag :wip2 + @tag :wip3 test "post meta history should be updated after upvote", ~m(user user2 community post_attrs)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) @@ -67,7 +67,7 @@ defmodule GroupherServer.Test.Upvotes.PostUpvote do assert user2.id in article.meta.upvoted_user_ids end - @tag :wip2 + @tag :wip3 test "post meta history should be updated after undo upvote", ~m(user user2 community post_attrs)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) diff --git a/test/groupher_server_web/mutation/accounts/customization_test.exs b/test/groupher_server_web/mutation/accounts/customization_test.exs index de3de03cd..8f42ad231 100644 --- a/test/groupher_server_web/mutation/accounts/customization_test.exs +++ b/test/groupher_server_web/mutation/accounts/customization_test.exs @@ -72,7 +72,7 @@ defmodule GroupherServer.Test.Mutation.Account.Customization do } } """ - @tag :wip2 + @tag :wip3 test "PageSizeProof middleware should lint c11n displayDensity size", ~m(user)a do user_conn = simu_conn(:user, user) db_insert_multi(:post, 50) diff --git a/test/groupher_server_web/mutation/cms/articles/job_emotion_test.exs b/test/groupher_server_web/mutation/cms/articles/job_emotion_test.exs index 428036419..b822aff94 100644 --- a/test/groupher_server_web/mutation/cms/articles/job_emotion_test.exs +++ b/test/groupher_server_web/mutation/cms/articles/job_emotion_test.exs @@ -32,7 +32,7 @@ defmodule GroupherServer.Test.Mutation.Articles.JobEmotion do } } """ - @tag :wip2 + @tag :wip3 test "login user can emotion to a pjob", ~m(community job_attrs user user_conn)a do {:ok, job} = CMS.create_content(community, :job, job_attrs, user) @@ -58,7 +58,7 @@ defmodule GroupherServer.Test.Mutation.Articles.JobEmotion do } } """ - @tag :wip2 + @tag :wip3 test "login user can undo emotion to a job", ~m(community job_attrs user owner_conn)a do {:ok, job} = CMS.create_content(community, :job, job_attrs, user) {:ok, _} = CMS.emotion_to_article(:job, job.id, :beer, user) diff --git a/test/groupher_server_web/mutation/cms/articles/job_report_test.exs b/test/groupher_server_web/mutation/cms/articles/job_report_test.exs index 310226193..4e17dd534 100644 --- a/test/groupher_server_web/mutation/cms/articles/job_report_test.exs +++ b/test/groupher_server_web/mutation/cms/articles/job_report_test.exs @@ -26,7 +26,7 @@ defmodule GroupherServer.Test.Mutation.Articles.JobReport do } } """ - @tag :wip2 + @tag :wip3 test "login user can report a job", ~m(community job_attrs user user_conn)a do {:ok, job} = CMS.create_content(community, :job, job_attrs, user) @@ -46,7 +46,7 @@ defmodule GroupherServer.Test.Mutation.Articles.JobReport do } } """ - @tag :wip2 + @tag :wip3 test "login user can undo report a job", ~m(community job_attrs user user_conn)a do {:ok, job} = CMS.create_content(community, :job, job_attrs, user) diff --git a/test/groupher_server_web/mutation/cms/articles/job_test.exs b/test/groupher_server_web/mutation/cms/articles/job_test.exs index e8875e3be..c269abc50 100644 --- a/test/groupher_server_web/mutation/cms/articles/job_test.exs +++ b/test/groupher_server_web/mutation/cms/articles/job_test.exs @@ -282,7 +282,7 @@ defmodule GroupherServer.Test.Mutation.Articles.Job do } } """ - @tag :wip2 + @tag :wip3 test "can delete a job by job's owner", ~m(owner_conn job)a do deleted = owner_conn |> mutation_result(@query, %{id: job.id}, "deleteJob") diff --git a/test/groupher_server_web/mutation/cms/articles/post_emotion_test.exs b/test/groupher_server_web/mutation/cms/articles/post_emotion_test.exs index 0d4196d7d..30c37a5e4 100644 --- a/test/groupher_server_web/mutation/cms/articles/post_emotion_test.exs +++ b/test/groupher_server_web/mutation/cms/articles/post_emotion_test.exs @@ -32,7 +32,7 @@ defmodule GroupherServer.Test.Mutation.Articles.PostEmotion do } } """ - @tag :wip2 + @tag :wip3 test "login user can emotion to a ppost", ~m(community post_attrs user user_conn)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) @@ -58,7 +58,7 @@ defmodule GroupherServer.Test.Mutation.Articles.PostEmotion do } } """ - @tag :wip2 + @tag :wip3 test "login user can undo emotion to a post", ~m(community post_attrs user owner_conn)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) {:ok, _} = CMS.emotion_to_article(:post, post.id, :beer, user) diff --git a/test/groupher_server_web/mutation/cms/articles/post_report_test.exs b/test/groupher_server_web/mutation/cms/articles/post_report_test.exs index 876b38f16..2596bdbcb 100644 --- a/test/groupher_server_web/mutation/cms/articles/post_report_test.exs +++ b/test/groupher_server_web/mutation/cms/articles/post_report_test.exs @@ -26,7 +26,7 @@ defmodule GroupherServer.Test.Mutation.Articles.PostReport do } } """ - @tag :wip2 + @tag :wip3 test "login user can report a post", ~m(community post_attrs user user_conn)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) @@ -46,7 +46,7 @@ defmodule GroupherServer.Test.Mutation.Articles.PostReport do } } """ - @tag :wip2 + @tag :wip3 test "login user can undo report a post", ~m(community post_attrs user user_conn)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) 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 8def50861..ac96ddaa2 100644 --- a/test/groupher_server_web/mutation/cms/articles/post_test.exs +++ b/test/groupher_server_web/mutation/cms/articles/post_test.exs @@ -142,7 +142,7 @@ defmodule GroupherServer.Test.Mutation.Articles.Post do } } """ - @tag :wip2 + @tag :wip3 test "delete a post by post's owner", ~m(owner_conn post)a do deleted = owner_conn |> mutation_result(@query, %{id: post.id}, "deletePost") diff --git a/test/groupher_server_web/mutation/cms/articles/repo_report_test.exs b/test/groupher_server_web/mutation/cms/articles/repo_report_test.exs index 2802f7a22..99a085be1 100644 --- a/test/groupher_server_web/mutation/cms/articles/repo_report_test.exs +++ b/test/groupher_server_web/mutation/cms/articles/repo_report_test.exs @@ -26,7 +26,7 @@ defmodule GroupherServer.Test.Mutation.Articles.RepoReport do } } """ - @tag :wip2 + @tag :wip3 test "login user can report a repo", ~m(community repo_attrs user user_conn)a do {:ok, repo} = CMS.create_content(community, :repo, repo_attrs, user) @@ -46,7 +46,7 @@ defmodule GroupherServer.Test.Mutation.Articles.RepoReport do } } """ - @tag :wip2 + @tag :wip3 test "login user can undo report a repo", ~m(community repo_attrs user user_conn)a do {:ok, repo} = CMS.create_content(community, :repo, repo_attrs, user) diff --git a/test/groupher_server_web/mutation/cms/articles/repo_test.exs b/test/groupher_server_web/mutation/cms/articles/repo_test.exs index ff70a48e0..afedc0217 100644 --- a/test/groupher_server_web/mutation/cms/articles/repo_test.exs +++ b/test/groupher_server_web/mutation/cms/articles/repo_test.exs @@ -193,7 +193,7 @@ defmodule GroupherServer.Test.Mutation.Articles.Repo do } } """ - @tag :wip2 + @tag :wip3 test "delete a repo by repo's owner", ~m(owner_conn repo)a do deleted = owner_conn |> mutation_result(@query, %{id: repo.id}, "deleteRepo") @@ -201,7 +201,7 @@ defmodule GroupherServer.Test.Mutation.Articles.Repo do assert {:error, _} = ORM.find(CMS.Repo, deleted["id"]) end - @tag :wip2 + @tag :wip3 test "can delete a repo by auth user", ~m(repo)a do belongs_community_title = repo.communities |> List.first() |> Map.get(:title) rule_conn = simu_conn(:user, cms: %{belongs_community_title => %{"repo.delete" => true}}) @@ -212,7 +212,7 @@ defmodule GroupherServer.Test.Mutation.Articles.Repo do assert {:error, _} = ORM.find(CMS.Repo, deleted["id"]) end - @tag :wip2 + @tag :wip3 test "delete a repo without login user fails", ~m(guest_conn repo)a do assert guest_conn |> mutation_get_error?(@query, %{id: repo.id}, ecode(:account_login)) end diff --git a/test/groupher_server_web/mutation/cms/cms_test.exs b/test/groupher_server_web/mutation/cms/cms_test.exs index 9a2bd8d88..158431643 100644 --- a/test/groupher_server_web/mutation/cms/cms_test.exs +++ b/test/groupher_server_web/mutation/cms/cms_test.exs @@ -431,7 +431,7 @@ defmodule GroupherServer.Test.Mutation.CMS.Basic do } } """ - @tag :wip2 + @tag :wip3 test "auth user can create thread", ~m(user)a do title = "post" raw = "POST" @@ -445,7 +445,7 @@ defmodule GroupherServer.Test.Mutation.CMS.Basic do assert result["title"] == title end - @tag :wip2 + @tag :wip3 test "unauth user create thread fails", ~m(user_conn guest_conn)a do title = "psot" raw = "POST" diff --git a/test/groupher_server_web/mutation/cms/comments/job_comment_test.exs b/test/groupher_server_web/mutation/cms/comments/job_comment_test.exs index aea2e5a99..3161d7018 100644 --- a/test/groupher_server_web/mutation/cms/comments/job_comment_test.exs +++ b/test/groupher_server_web/mutation/cms/comments/job_comment_test.exs @@ -24,7 +24,7 @@ defmodule GroupherServer.Test.Mutation.Comments.JobComment do } } """ - @tag :wip2 + @tag :wip3 test "write article comment to a exsit job", ~m(job user_conn)a do comment = "a test comment" variables = %{thread: "JOB", id: job.id, content: comment} @@ -43,7 +43,7 @@ defmodule GroupherServer.Test.Mutation.Comments.JobComment do } } """ - @tag :wip2 + @tag :wip3 test "login user can reply to a comment", ~m(job user user_conn)a do {:ok, comment} = CMS.create_article_comment(:job, job.id, "commment", user) variables = %{id: comment.id, content: "reply content"} @@ -63,7 +63,7 @@ defmodule GroupherServer.Test.Mutation.Comments.JobComment do } } """ - @tag :wip2 + @tag :wip3 test "only owner can update a exsit comment", ~m(job user guest_conn user_conn owner_conn)a do {:ok, comment} = CMS.create_article_comment(:job, job.id, "job comment", user) @@ -88,7 +88,7 @@ defmodule GroupherServer.Test.Mutation.Comments.JobComment do } } """ - @tag :wip2 + @tag :wip3 test "only owner can delete a exsit comment", ~m(job user guest_conn user_conn owner_conn)a do {:ok, comment} = CMS.create_article_comment(:job, job.id, "job comment", user) @@ -123,7 +123,7 @@ defmodule GroupherServer.Test.Mutation.Comments.JobComment do } } """ - @tag :wip2 + @tag :wip3 test "login user can emotion to a comment", ~m(job user user_conn)a do {:ok, comment} = CMS.create_article_comment(:job, job.id, "job comment", user) variables = %{id: comment.id, emotion: "BEER"} @@ -150,7 +150,7 @@ defmodule GroupherServer.Test.Mutation.Comments.JobComment do } } """ - @tag :wip2 + @tag :wip3 test "login user can undo emotion to a comment", ~m(job user owner_conn)a do {:ok, comment} = CMS.create_article_comment(:job, job.id, "job comment", user) {:ok, _} = CMS.emotion_to_comment(comment.id, :beer, user) diff --git a/test/groupher_server_web/mutation/cms/comments/post_comment_test.exs b/test/groupher_server_web/mutation/cms/comments/post_comment_test.exs index 2e4fad36e..9a8ec7d86 100644 --- a/test/groupher_server_web/mutation/cms/comments/post_comment_test.exs +++ b/test/groupher_server_web/mutation/cms/comments/post_comment_test.exs @@ -24,7 +24,7 @@ defmodule GroupherServer.Test.Mutation.Comments.PostComment do } } """ - @tag :wip2 + @tag :wip3 test "write article comment to a exsit post", ~m(post user_conn)a do comment = "a test comment" variables = %{thread: "POST", id: post.id, content: comment} @@ -43,7 +43,7 @@ defmodule GroupherServer.Test.Mutation.Comments.PostComment do } } """ - @tag :wip2 + @tag :wip3 test "login user can reply to a comment", ~m(post user user_conn)a do {:ok, comment} = CMS.create_article_comment(:post, post.id, "commment", user) variables = %{id: comment.id, content: "reply content"} @@ -63,7 +63,7 @@ defmodule GroupherServer.Test.Mutation.Comments.PostComment do } } """ - @tag :wip2 + @tag :wip3 test "only owner can update a exsit comment", ~m(post user guest_conn user_conn owner_conn)a do {:ok, comment} = CMS.create_article_comment(:post, post.id, "post comment", user) @@ -88,7 +88,7 @@ defmodule GroupherServer.Test.Mutation.Comments.PostComment do } } """ - @tag :wip2 + @tag :wip3 test "only owner can delete a exsit comment", ~m(post user guest_conn user_conn owner_conn)a do {:ok, comment} = CMS.create_article_comment(:post, post.id, "post comment", user) @@ -123,7 +123,7 @@ defmodule GroupherServer.Test.Mutation.Comments.PostComment do } } """ - @tag :wip2 + @tag :wip3 test "login user can emotion to a comment", ~m(post user user_conn)a do {:ok, comment} = CMS.create_article_comment(:post, post.id, "post comment", user) variables = %{id: comment.id, emotion: "BEER"} @@ -150,7 +150,7 @@ defmodule GroupherServer.Test.Mutation.Comments.PostComment do } } """ - @tag :wip2 + @tag :wip3 test "login user can undo emotion to a comment", ~m(post user owner_conn)a do {:ok, comment} = CMS.create_article_comment(:post, post.id, "post comment", user) {:ok, _} = CMS.emotion_to_comment(comment.id, :beer, user) diff --git a/test/groupher_server_web/mutation/cms/flags/job_flag_test.exs b/test/groupher_server_web/mutation/cms/flags/job_flag_test.exs index d91b8591e..c9c0fb219 100644 --- a/test/groupher_server_web/mutation/cms/flags/job_flag_test.exs +++ b/test/groupher_server_web/mutation/cms/flags/job_flag_test.exs @@ -25,7 +25,7 @@ defmodule GroupherServer.Test.Mutation.Flags.JobFlag do } } """ - @tag :wip2 + @tag :wip3 test "auth user can trash job", ~m(community job)a do variables = %{id: job.id, communityId: community.id} @@ -38,7 +38,7 @@ defmodule GroupherServer.Test.Mutation.Flags.JobFlag do assert updated["trash"] == true end - @tag :wip2 + @tag :wip3 test "unauth user trash job fails", ~m(user_conn guest_conn job community)a do variables = %{id: job.id, communityId: community.id} rule_conn = simu_conn(:user, cms: %{"what.ever" => true}) @@ -56,7 +56,7 @@ defmodule GroupherServer.Test.Mutation.Flags.JobFlag do } } """ - @tag :wip2 + @tag :wip3 test "auth user can undo trash job", ~m(community job)a do variables = %{id: job.id, communityId: community.id} @@ -87,7 +87,7 @@ defmodule GroupherServer.Test.Mutation.Flags.JobFlag do } } """ - @tag :wip2 + @tag :wip3 test "auth user can pin job", ~m(community job)a do variables = %{id: job.id, communityId: community.id} @@ -99,7 +99,7 @@ defmodule GroupherServer.Test.Mutation.Flags.JobFlag do assert updated["id"] == to_string(job.id) end - @tag :wip2 + @tag :wip3 test "unauth user pin job fails", ~m(user_conn guest_conn community job)a do variables = %{id: job.id, communityId: community.id} rule_conn = simu_conn(:user, cms: %{"what.ever" => true}) @@ -117,7 +117,7 @@ defmodule GroupherServer.Test.Mutation.Flags.JobFlag do } } """ - @tag :wip2 + @tag :wip3 test "auth user can undo pin job", ~m(community job)a do variables = %{id: job.id, communityId: community.id} @@ -131,7 +131,7 @@ defmodule GroupherServer.Test.Mutation.Flags.JobFlag do assert updated["isPinned"] == false end - @tag :wip2 + @tag :wip3 test "unauth user undo pin job fails", ~m(user_conn guest_conn community job)a do variables = %{id: job.id, communityId: community.id} rule_conn = simu_conn(:user, cms: %{"what.ever" => true}) 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 f54f9f9e2..61d6eacb0 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 } } """ - @tag :wip2 + @tag :wip3 test "auth user can trash post", ~m(community post)a do variables = %{id: post.id, communityId: community.id} @@ -38,7 +38,7 @@ defmodule GroupherServer.Test.Mutation.Flags.PostFlag do assert updated["trash"] == true end - @tag :wip2 + @tag :wip3 test "unauth user trash post fails", ~m(user_conn guest_conn post community)a do variables = %{id: post.id, communityId: community.id} rule_conn = simu_conn(:user, cms: %{"what.ever" => true}) @@ -56,7 +56,7 @@ defmodule GroupherServer.Test.Mutation.Flags.PostFlag do } } """ - @tag :wip2 + @tag :wip3 test "auth user can undo trash post", ~m(community post)a do variables = %{id: post.id, communityId: community.id} @@ -71,7 +71,7 @@ defmodule GroupherServer.Test.Mutation.Flags.PostFlag do assert updated["trash"] == false end - @tag :wip2 + @tag :wip3 test "unauth user undo trash post fails", ~m(user_conn guest_conn community post)a do variables = %{id: post.id, communityId: community.id} rule_conn = simu_conn(:user, cms: %{"what.ever" => true}) @@ -88,7 +88,7 @@ defmodule GroupherServer.Test.Mutation.Flags.PostFlag do } } """ - @tag :wip2 + @tag :wip3 test "auth user can pin post", ~m(community post)a do variables = %{id: post.id, communityId: community.id} @@ -100,7 +100,7 @@ defmodule GroupherServer.Test.Mutation.Flags.PostFlag do assert updated["id"] == to_string(post.id) end - @tag :wip2 + @tag :wip3 test "unauth user pin post fails", ~m(user_conn guest_conn community post)a do variables = %{id: post.id, communityId: community.id} rule_conn = simu_conn(:user, cms: %{"what.ever" => true}) @@ -118,7 +118,7 @@ defmodule GroupherServer.Test.Mutation.Flags.PostFlag do } } """ - @tag :wip2 + @tag :wip3 test "auth user can undo pin post", ~m(community post)a do variables = %{id: post.id, communityId: community.id} @@ -131,7 +131,7 @@ defmodule GroupherServer.Test.Mutation.Flags.PostFlag do assert updated["id"] == to_string(post.id) end - @tag :wip2 + @tag :wip3 test "unauth user undo pin post fails", ~m(user_conn guest_conn community post)a do variables = %{id: post.id, communityId: community.id} rule_conn = simu_conn(:user, cms: %{"what.ever" => true}) diff --git a/test/groupher_server_web/mutation/cms/flags/repo_flag_test.exs b/test/groupher_server_web/mutation/cms/flags/repo_flag_test.exs index 2243a0125..6a3c5270c 100644 --- a/test/groupher_server_web/mutation/cms/flags/repo_flag_test.exs +++ b/test/groupher_server_web/mutation/cms/flags/repo_flag_test.exs @@ -25,7 +25,7 @@ defmodule GroupherServer.Test.Mutation.Flags.RepoFlag do } } """ - @tag :wip2 + @tag :wip3 test "auth user can trash repo", ~m(community repo)a do variables = %{id: repo.id, communityId: community.id} @@ -38,7 +38,7 @@ defmodule GroupherServer.Test.Mutation.Flags.RepoFlag do assert updated["trash"] == true end - @tag :wip2 + @tag :wip3 test "unauth user trash repo fails", ~m(user_conn guest_conn repo community)a do variables = %{id: repo.id, communityId: community.id} rule_conn = simu_conn(:user, cms: %{"what.ever" => true}) @@ -56,7 +56,7 @@ defmodule GroupherServer.Test.Mutation.Flags.RepoFlag do } } """ - @tag :wip2 + @tag :wip3 test "auth user can undo trash repo", ~m(community repo)a do variables = %{id: repo.id, communityId: community.id} @@ -71,7 +71,7 @@ defmodule GroupherServer.Test.Mutation.Flags.RepoFlag do assert updated["trash"] == false end - @tag :wip2 + @tag :wip3 test "unauth user undo trash repo fails", ~m(user_conn guest_conn community repo)a do variables = %{id: repo.id, communityId: community.id} rule_conn = simu_conn(:user, cms: %{"what.ever" => true}) @@ -88,7 +88,7 @@ defmodule GroupherServer.Test.Mutation.Flags.RepoFlag do } } """ - @tag :wip2 + @tag :wip3 test "auth user can pin repo", ~m(community repo)a do variables = %{id: repo.id, communityId: community.id} @@ -100,7 +100,7 @@ defmodule GroupherServer.Test.Mutation.Flags.RepoFlag do assert updated["id"] == to_string(repo.id) end - @tag :wip2 + @tag :wip3 test "unauth user pin repo fails", ~m(user_conn guest_conn community repo)a do variables = %{id: repo.id, communityId: community.id} rule_conn = simu_conn(:user, cms: %{"what.ever" => true}) @@ -118,7 +118,7 @@ defmodule GroupherServer.Test.Mutation.Flags.RepoFlag do } } """ - @tag :wip2 + @tag :wip3 test "auth user can undo pin repo", ~m(community repo)a do variables = %{id: repo.id, communityId: community.id} @@ -131,7 +131,7 @@ defmodule GroupherServer.Test.Mutation.Flags.RepoFlag do assert updated["id"] == to_string(repo.id) end - @tag :wip2 + @tag :wip3 test "unauth user undo pin repo fails", ~m(user_conn guest_conn community repo)a do variables = %{id: repo.id, communityId: community.id} rule_conn = simu_conn(:user, cms: %{"what.ever" => true}) diff --git a/test/groupher_server_web/mutation/cms/upvotes/job_upvote_test.exs b/test/groupher_server_web/mutation/cms/upvotes/job_upvote_test.exs index ff32d1cc7..7c1f8869c 100644 --- a/test/groupher_server_web/mutation/cms/upvotes/job_upvote_test.exs +++ b/test/groupher_server_web/mutation/cms/upvotes/job_upvote_test.exs @@ -22,7 +22,7 @@ defmodule GroupherServer.Test.Mutation.Upvotes.JobUpvote do } } """ - @tag :wip2 + @tag :wip3 test "login user can upvote a job", ~m(user_conn job)a do variables = %{id: job.id} created = user_conn |> mutation_result(@query, variables, "upvoteJob") @@ -30,7 +30,7 @@ defmodule GroupherServer.Test.Mutation.Upvotes.JobUpvote do assert created["id"] == to_string(job.id) end - @tag :wip2 + @tag :wip3 test "unauth user upvote a job fails", ~m(guest_conn job)a do variables = %{id: job.id} @@ -45,7 +45,7 @@ defmodule GroupherServer.Test.Mutation.Upvotes.JobUpvote do } } """ - @tag :wip2 + @tag :wip3 test "login user can undo upvote to a job", ~m(user_conn job user)a do {:ok, _} = CMS.upvote_article(:job, job.id, user) @@ -55,7 +55,7 @@ defmodule GroupherServer.Test.Mutation.Upvotes.JobUpvote do assert updated["id"] == to_string(job.id) end - @tag :wip2 + @tag :wip3 test "unauth user undo upvote a job fails", ~m(guest_conn job)a do variables = %{id: job.id} diff --git a/test/groupher_server_web/mutation/cms/upvotes/post_upvote_test.exs b/test/groupher_server_web/mutation/cms/upvotes/post_upvote_test.exs index 002ff0e2f..7d85684c1 100644 --- a/test/groupher_server_web/mutation/cms/upvotes/post_upvote_test.exs +++ b/test/groupher_server_web/mutation/cms/upvotes/post_upvote_test.exs @@ -22,7 +22,7 @@ defmodule GroupherServer.Test.Mutation.Upvotes.PostUpvote do } } """ - @tag :wip2 + @tag :wip3 test "login user can upvote a post", ~m(user_conn post)a do variables = %{id: post.id} created = user_conn |> mutation_result(@query, variables, "upvotePost") @@ -30,7 +30,7 @@ defmodule GroupherServer.Test.Mutation.Upvotes.PostUpvote do assert created["id"] == to_string(post.id) end - @tag :wip2 + @tag :wip3 test "unauth user upvote a post fails", ~m(guest_conn post)a do variables = %{id: post.id} @@ -44,7 +44,7 @@ defmodule GroupherServer.Test.Mutation.Upvotes.PostUpvote do } } """ - @tag :wip2 + @tag :wip3 test "login user can undo upvote to a post", ~m(user_conn post user)a do {:ok, _} = CMS.upvote_article(:post, post.id, user) @@ -54,7 +54,7 @@ defmodule GroupherServer.Test.Mutation.Upvotes.PostUpvote do assert updated["id"] == to_string(post.id) end - @tag :wip2 + @tag :wip3 test "unauth user undo upvote a post fails", ~m(guest_conn post)a do variables = %{id: post.id} diff --git a/test/groupher_server_web/query/cms/collects/job_collect_test.exs b/test/groupher_server_web/query/cms/collects/job_collect_test.exs index 8ad1a03b1..3e889f3a7 100644 --- a/test/groupher_server_web/query/cms/collects/job_collect_test.exs +++ b/test/groupher_server_web/query/cms/collects/job_collect_test.exs @@ -35,7 +35,7 @@ defmodule GroupherServer.Test.Query.Collects.JobCollect do } } """ - @tag :wip2 + @tag :wip3 test "guest can get collected users list after collect a job", ~m(guest_conn job user user2)a do {:ok, _} = CMS.collect_article(:job, job.id, user) diff --git a/test/groupher_server_web/query/cms/collects/post_collect_test.exs b/test/groupher_server_web/query/cms/collects/post_collect_test.exs index b1f9d7199..bbad70c01 100644 --- a/test/groupher_server_web/query/cms/collects/post_collect_test.exs +++ b/test/groupher_server_web/query/cms/collects/post_collect_test.exs @@ -35,7 +35,7 @@ defmodule GroupherServer.Test.Query.Collects.PostCollect do } } """ - @tag :wip2 + @tag :wip3 test "guest can get collected users list after collect a post", ~m(guest_conn post user user2)a do {:ok, _} = CMS.collect_article(:post, post.id, 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 548e2e12f..d8a925471 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 @@ -288,7 +288,7 @@ defmodule GroupherServer.Test.Query.Comments.JobComment do assert results["entries"] |> List.last() |> Map.get("floor") == 5 end - @tag :wip2 + @tag :wip3 test "the comments is loaded in default asc order", ~m(guest_conn job user)a do page_size = 10 thread = :job @@ -312,7 +312,7 @@ defmodule GroupherServer.Test.Query.Comments.JobComment do assert List.last(results["entries"]) |> Map.get("id") == to_string(comment3.id) end - @tag :wip2 + @tag :wip3 test "the comments can be loaded in desc order in timeline-mode", ~m(guest_conn job user)a do page_size = 10 thread = :job @@ -336,7 +336,7 @@ defmodule GroupherServer.Test.Query.Comments.JobComment do assert List.last(results["entries"]) |> Map.get("id") == to_string(comment.id) end - @tag :wip2 + @tag :wip3 test "the comments can be loaded in desc order in replies-mode", ~m(guest_conn job user user2)a do page_size = 10 @@ -433,7 +433,7 @@ defmodule GroupherServer.Test.Query.Comments.JobComment do assert the_random_comment |> get_in(["meta", "isArticleAuthorUpvoted"]) end - @tag :wip2 + @tag :wip3 test "guest user can get paged comment with emotions info", ~m(guest_conn job user user2)a do total_count = 2 @@ -511,7 +511,7 @@ defmodule GroupherServer.Test.Query.Comments.JobComment do |> get_in(["emotions", "viewerHasDownvoteed"]) end - @tag :wip2 + @tag :wip3 test "comment should have viewer has upvoted flag", ~m(user_conn job user)a do total_count = 10 page_size = 12 @@ -551,7 +551,7 @@ defmodule GroupherServer.Test.Query.Comments.JobComment do } } """ - @tag :wip2 + @tag :wip3 test "guest user can get paged participators", ~m(guest_conn job user)a do total_count = 30 page_size = 10 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 5a7e69eb6..8fc646754 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 @@ -288,7 +288,7 @@ defmodule GroupherServer.Test.Query.Comments.PostComment do assert results["entries"] |> List.last() |> Map.get("floor") == 5 end - @tag :wip2 + @tag :wip3 test "the comments is loaded in default asc order", ~m(guest_conn post user)a do page_size = 10 thread = :post @@ -312,7 +312,7 @@ defmodule GroupherServer.Test.Query.Comments.PostComment do assert List.last(results["entries"]) |> Map.get("id") == to_string(comment3.id) end - @tag :wip2 + @tag :wip3 test "the comments can be loaded in desc order in timeline-mode", ~m(guest_conn post user)a do page_size = 10 thread = :post @@ -336,7 +336,7 @@ defmodule GroupherServer.Test.Query.Comments.PostComment do assert List.last(results["entries"]) |> Map.get("id") == to_string(comment.id) end - @tag :wip2 + @tag :wip3 test "the comments can be loaded in desc order in replies-mode", ~m(guest_conn post user user2)a do page_size = 10 @@ -433,7 +433,7 @@ defmodule GroupherServer.Test.Query.Comments.PostComment do assert the_random_comment |> get_in(["meta", "isArticleAuthorUpvoted"]) end - @tag :wip2 + @tag :wip3 test "guest user can get paged comment with emotions info", ~m(guest_conn post user user2)a do total_count = 2 @@ -511,7 +511,7 @@ defmodule GroupherServer.Test.Query.Comments.PostComment do |> get_in(["emotions", "viewerHasDownvoteed"]) end - @tag :wip2 + @tag :wip3 test "comment should have viewer has upvoted flag", ~m(user_conn post user)a do total_count = 10 page_size = 12 diff --git a/test/groupher_server_web/query/cms/job_test.exs b/test/groupher_server_web/query/cms/job_test.exs index eebf90599..417d8e867 100644 --- a/test/groupher_server_web/query/cms/job_test.exs +++ b/test/groupher_server_web/query/cms/job_test.exs @@ -19,7 +19,7 @@ defmodule GroupherServer.Test.Query.Job do } } """ - @tag :wip2 + @tag :wip3 test "basic graphql query on job with logined user", ~m(user_conn job)a do variables = %{id: job.id} results = user_conn |> query_result(@query, variables, "job") @@ -30,7 +30,7 @@ defmodule GroupherServer.Test.Query.Job do assert length(Map.keys(results)) == 3 end - @tag :wip2 + @tag :wip3 test "basic graphql query on job with stranger(unloged user)", ~m(guest_conn job)a do variables = %{id: job.id} results = guest_conn |> query_result(@query, variables, "job") diff --git a/test/groupher_server_web/query/cms/jobs_flags_test.exs b/test/groupher_server_web/query/cms/jobs_flags_test.exs index de9eb4adf..e977f1a87 100644 --- a/test/groupher_server_web/query/cms/jobs_flags_test.exs +++ b/test/groupher_server_web/query/cms/jobs_flags_test.exs @@ -51,7 +51,7 @@ defmodule GroupherServer.Test.Query.JobsFlags do } } """ - @tag :wip2 + @tag :wip3 test "if have pined jobs, the pined jobs should at the top of entries", ~m(guest_conn community job_m)a do variables = %{filter: %{community: community.raw}} diff --git a/test/groupher_server_web/query/cms/paged_jobs_test.exs b/test/groupher_server_web/query/cms/paged_jobs_test.exs index c68f415bd..b1254dde5 100644 --- a/test/groupher_server_web/query/cms/paged_jobs_test.exs +++ b/test/groupher_server_web/query/cms/paged_jobs_test.exs @@ -97,7 +97,7 @@ defmodule GroupherServer.Test.Query.PagedJobs do } } """ - @tag :wip2 + @tag :wip3 test "has_xxx state should work", ~m(user)a do user_conn = simu_conn(:user, user) {:ok, community} = db_insert(:community) diff --git a/test/groupher_server_web/query/cms/paged_posts_test.exs b/test/groupher_server_web/query/cms/paged_posts_test.exs index b09740e57..bde4c3b74 100644 --- a/test/groupher_server_web/query/cms/paged_posts_test.exs +++ b/test/groupher_server_web/query/cms/paged_posts_test.exs @@ -170,7 +170,7 @@ defmodule GroupherServer.Test.Query.PagedPosts do } } """ - @tag :wip2 + @tag :wip3 test "has_xxx state should work", ~m(user)a do user_conn = simu_conn(:user, user) {:ok, community} = db_insert(:community) diff --git a/test/groupher_server_web/query/cms/paged_repos_test.exs b/test/groupher_server_web/query/cms/paged_repos_test.exs index c50aa0e6f..e725b7a0f 100644 --- a/test/groupher_server_web/query/cms/paged_repos_test.exs +++ b/test/groupher_server_web/query/cms/paged_repos_test.exs @@ -93,7 +93,7 @@ defmodule GroupherServer.Test.Query.PagedRepos do } } """ - @tag :wip2 + @tag :wip3 test "has_xxx state should work", ~m(user)a do user_conn = simu_conn(:user, user) {:ok, community} = db_insert(:community) diff --git a/test/groupher_server_web/query/cms/post_test.exs b/test/groupher_server_web/query/cms/post_test.exs index 5e92fbb0e..3c53e9c6e 100644 --- a/test/groupher_server_web/query/cms/post_test.exs +++ b/test/groupher_server_web/query/cms/post_test.exs @@ -28,7 +28,7 @@ defmodule GroupherServer.Test.Query.Post do } } """ - @tag :wip2 + @tag :wip3 test "basic graphql query on post with logined user", ~m(user_conn community user post_attrs)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) @@ -43,7 +43,7 @@ defmodule GroupherServer.Test.Query.Post do assert length(Map.keys(results)) == 4 end - @tag :wip2 + @tag :wip3 test "basic graphql query on post with stranger(unloged user)", ~m(guest_conn post)a do variables = %{id: post.id} results = guest_conn |> query_result(@query, variables, "post") diff --git a/test/groupher_server_web/query/cms/posts_flags_test.exs b/test/groupher_server_web/query/cms/posts_flags_test.exs index 0cd6f01ec..a63fa5d41 100644 --- a/test/groupher_server_web/query/cms/posts_flags_test.exs +++ b/test/groupher_server_web/query/cms/posts_flags_test.exs @@ -51,7 +51,7 @@ defmodule GroupherServer.Test.Query.PostsFlags do } } """ - @tag :wip2 + @tag :wip3 test "if have pined posts, the pined posts should at the top of entries", ~m(guest_conn community post_m)a do variables = %{filter: %{community: community.raw}} diff --git a/test/groupher_server_web/query/cms/repo_test.exs b/test/groupher_server_web/query/cms/repo_test.exs index dc982deb0..a4c82f63a 100644 --- a/test/groupher_server_web/query/cms/repo_test.exs +++ b/test/groupher_server_web/query/cms/repo_test.exs @@ -19,7 +19,7 @@ defmodule GroupherServer.Test.Query.Repo do } } """ - @tag :wip2 + @tag :wip3 test "basic graphql query on repo with logined user", ~m(user_conn repo)a do variables = %{id: repo.id} results = user_conn |> query_result(@query, variables, "repo") @@ -30,7 +30,7 @@ defmodule GroupherServer.Test.Query.Repo do assert length(Map.keys(results)) == 3 end - @tag :wip2 + @tag :wip3 test "basic graphql query on repo with stranger(unloged user)", ~m(guest_conn repo)a do variables = %{id: repo.id} results = guest_conn |> query_result(@query, variables, "repo") diff --git a/test/groupher_server_web/query/cms/repos_flags_test.exs b/test/groupher_server_web/query/cms/repos_flags_test.exs index c013d9b29..c0cf8707a 100644 --- a/test/groupher_server_web/query/cms/repos_flags_test.exs +++ b/test/groupher_server_web/query/cms/repos_flags_test.exs @@ -50,7 +50,7 @@ defmodule GroupherServer.Test.Query.ReposFlags do } } """ - @tag :wip2 + @tag :wip3 test "if have pined repos, the pined repos should at the top of entries", ~m(guest_conn community repo_m)a do variables = %{filter: %{community: community.raw}} diff --git a/test/groupher_server_web/query/cms/upvotes/post_upvote_test.exs b/test/groupher_server_web/query/cms/upvotes/post_upvote_test.exs index 5a62315ee..47b311cde 100644 --- a/test/groupher_server_web/query/cms/upvotes/post_upvote_test.exs +++ b/test/groupher_server_web/query/cms/upvotes/post_upvote_test.exs @@ -35,7 +35,7 @@ defmodule GroupherServer.Test.Query.Upvotes.PostUpvote do } } """ - @tag :wip2 + @tag :wip3 test "guest can get upvoted users list after upvote to a post", ~m(guest_conn post user user2)a do {:ok, _} = CMS.upvote_article(:post, post.id, user) From ab14775f2106ac2c5b2baabada88043bcf6f761e Mon Sep 17 00:00:00 2001 From: mydearxym Date: Wed, 12 May 2021 11:38:52 +0800 Subject: [PATCH 02/13] refactor(abuse-report): wip --- lib/groupher_server/cms/delegates/abuse_report.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/groupher_server/cms/delegates/abuse_report.ex b/lib/groupher_server/cms/delegates/abuse_report.ex index 7b46d3515..e14dde2b1 100644 --- a/lib/groupher_server/cms/delegates/abuse_report.ex +++ b/lib/groupher_server/cms/delegates/abuse_report.ex @@ -32,7 +32,7 @@ defmodule GroupherServer.CMS.Delegate.AbuseReport do # def list_all_reports(community, filter) # def list_all_reports(filter) @article_threads [:post, :job, :repo] - @export_report_keys = [ + @export_report_keys [ :id, :deal_with, :is_closed, From 6fdecc09f8b264dfe949ca5fa1634cc1a039534f Mon Sep 17 00:00:00 2001 From: mydearxym Date: Wed, 12 May 2021 15:08:37 +0800 Subject: [PATCH 03/13] refactor(abuse-report): wip --- lib/groupher_server/cms/article_comment.ex | 5 +- lib/groupher_server/cms/cms.ex | 1 - .../cms/delegates/abuse_report.ex | 110 ++++++++++++------ ...0512041939_add_repo_to_article_comment.exs | 11 ++ .../cms/abuse_reports/comment_report_test.exs | 11 +- .../cms/abuse_reports/job_report_test.exs | 31 ++++- .../cms/abuse_reports/post_report_test.exs | 31 ++--- .../cms/comments/job_comment_test.exs | 10 +- .../cms/comments/post_comment_test.exs | 8 +- 9 files changed, 150 insertions(+), 68 deletions(-) create mode 100644 priv/repo/migrations/20210512041939_add_repo_to_article_comment.exs diff --git a/lib/groupher_server/cms/article_comment.ex b/lib/groupher_server/cms/article_comment.ex index ea8177991..53d58702b 100644 --- a/lib/groupher_server/cms/article_comment.ex +++ b/lib/groupher_server/cms/article_comment.ex @@ -12,6 +12,7 @@ defmodule GroupherServer.CMS.ArticleComment do alias CMS.{ Post, Job, + Repo, Embeds, ArticleCommentUpvote } @@ -19,7 +20,7 @@ defmodule GroupherServer.CMS.ArticleComment do # alias Helper.HTML @required_fields ~w(body_html author_id)a - @optional_fields ~w(post_id job_id reply_to_id replies_count is_folded is_reported is_deleted floor is_article_author)a + @optional_fields ~w(post_id job_id repo_id reply_to_id replies_count is_folded is_reported is_deleted floor is_article_author)a @updatable_fields ~w(is_folded is_reported is_deleted floor upvotes_count is_pinned)a @max_participator_count 5 @@ -72,6 +73,8 @@ defmodule GroupherServer.CMS.ArticleComment do belongs_to(:post, Post, foreign_key: :post_id) belongs_to(:job, Job, foreign_key: :job_id) + belongs_to(:repo, Repo, foreign_key: :repo_id) + belongs_to(:reply_to, ArticleComment, foreign_key: :reply_to_id) embeds_many(:replies, ArticleComment, on_replace: :delete) diff --git a/lib/groupher_server/cms/cms.ex b/lib/groupher_server/cms/cms.ex index ac8782015..78a7f87b6 100644 --- a/lib/groupher_server/cms/cms.ex +++ b/lib/groupher_server/cms/cms.ex @@ -163,7 +163,6 @@ defmodule GroupherServer.CMS do defdelegate create_report(type, content_id, reason, attr, user), to: AbuseReport defdelegate report_article(thread, article_id, reason, attr, user), to: AbuseReport defdelegate undo_report_article(thread, article_id, user), to: AbuseReport - defdelegate list_reports(type, content_id, filter), to: AbuseReport defdelegate list_reports(filter), to: AbuseReport defdelegate report_article_comment(comment_id, reason, attr, user), to: ArticleCommentAction defdelegate undo_report_article_comment(comment_id, user), to: AbuseReport diff --git a/lib/groupher_server/cms/delegates/abuse_report.ex b/lib/groupher_server/cms/delegates/abuse_report.ex index e14dde2b1..262f17e29 100644 --- a/lib/groupher_server/cms/delegates/abuse_report.ex +++ b/lib/groupher_server/cms/delegates/abuse_report.ex @@ -13,12 +13,12 @@ defmodule GroupherServer.CMS.Delegate.AbuseReport do alias GroupherServer.{Accounts, CMS, Repo} alias Accounts.User - alias CMS.{AbuseReport, Embeds} + alias CMS.{AbuseReport, ArticleComment, Embeds} alias Ecto.Multi # filter = %{ - # contentType: account | post | job | repo | article_comment + # contentType: account | post | job | repo | article_comment | community # contentId: ... # operate_user_id, # min_case_count, @@ -28,9 +28,6 @@ defmodule GroupherServer.CMS.Delegate.AbuseReport do # size # } - # def list_all_reports(thread, filter) - # def list_all_reports(community, filter) - # def list_all_reports(filter) @article_threads [:post, :job, :repo] @export_report_keys [ :id, @@ -43,6 +40,34 @@ defmodule GroupherServer.CMS.Delegate.AbuseReport do :updated_at ] + @export_author_keys [:id, :login, :nickname, :avatar] + @export_article_keys [:id, :title, :digest, :upvotes_count, :views] + + @doc """ + list paged reports for article comemnts + """ + def list_reports(%{content_type: :article_comment, content_id: content_id} = filter) do + %{page: page, size: size} = filter + + with {:ok, info} <- match(:article_comment) do + query = + from(r in AbuseReport, + where: field(r, ^info.foreign_key) == ^content_id, + preload: [article_comment: ^@article_threads], + preload: [article_comment: :author] + ) + + query + |> QueryBuilder.filter_pack(filter) + |> ORM.paginater(~m(page size)a) + |> reports_formater(:article_comment) + |> done() + end + end + + @doc """ + list paged reports for article + """ def list_reports(%{content_type: thread, content_id: content_id} = filter) when thread in @article_threads do %{page: page, size: size} = filter @@ -62,6 +87,17 @@ defmodule GroupherServer.CMS.Delegate.AbuseReport do end end + defp reports_formater(%{entries: entries} = paged_reports, :article_comment) do + paged_reports + |> Map.put( + :entries, + Enum.map(entries, fn report -> + basic_report = report |> Map.take(@export_report_keys) + basic_report |> Map.put(:article_comment, extract_article_comment_info(report)) + end) + ) + end + defp reports_formater(%{entries: entries} = paged_reports, thread) when thread in @article_threads do paged_reports @@ -74,36 +110,18 @@ defmodule GroupherServer.CMS.Delegate.AbuseReport do ) end + # TODO: original community and communities info defp extract_article_info(thread, %AbuseReport{} = report) do article = Map.get(report, thread) - %{ - thread: thread, - id: article.id, - title: article.title, - digest: article.digest, - upvotes_count: article.upvotes_count, - views: article.views - } + article + |> Map.take(@export_article_keys) + |> Map.merge(%{thread: thread}) end - @doc """ - list paged reports for both comment and article - """ - def list_reports(thread, content_id, %{page: page, size: size} = filter) do - with {:ok, info} <- match(thread) do - query = - from(r in AbuseReport, - where: field(r, ^info.foreign_key) == ^content_id, - preload: [^thread, :operate_user] - ) - - query - |> QueryBuilder.filter_pack(filter) - |> ORM.paginater(~m(page size)a) - |> done() - end - end + # def report_account(user_id) do + # # TODO* + # end @doc """ report article content @@ -123,10 +141,6 @@ defmodule GroupherServer.CMS.Delegate.AbuseReport do end end - def undo_report_article_comment(comment_id, %User{} = user) do - undo_report_article(:article_comment, comment_id, user) - end - @doc """ undo report article content """ @@ -145,6 +159,10 @@ defmodule GroupherServer.CMS.Delegate.AbuseReport do end end + def undo_report_article_comment(comment_id, %User{} = user) do + undo_report_article(:article_comment, comment_id, user) + end + def create_report(type, content_id, reason, attr, %User{} = user) do with {:ok, info} <- match(type), {:ok, report} <- not_reported_before(info, content_id, user) do @@ -243,6 +261,30 @@ defmodule GroupherServer.CMS.Delegate.AbuseReport do end end + def extract_article_comment_info(%AbuseReport{} = report) do + keys = [:id, :upvotes_count, :body_html] + author = Map.take(report.article_comment.author, @export_author_keys) + + comment = Map.take(report.article_comment, keys) + comment = Map.merge(comment, %{author: author}) + + article = extract_article_in_comment(report.article_comment) + Map.merge(comment, %{article: article}) + end + + defp extract_article_in_comment(%ArticleComment{} = article_comment) do + article_thread = + Enum.filter(@article_threads, fn thread -> + not is_nil(Map.get(article_comment, :"#{thread}_id")) + end) + |> List.first() + + article_comment + |> Map.get(article_thread) + |> Map.take(@export_article_keys) + |> Map.merge(%{thread: article_thread}) + end + defp result({:ok, %{update_report_flag: result}}), do: result |> done() defp result({:error, _, result, _steps}) do diff --git a/priv/repo/migrations/20210512041939_add_repo_to_article_comment.exs b/priv/repo/migrations/20210512041939_add_repo_to_article_comment.exs new file mode 100644 index 000000000..26a7a2635 --- /dev/null +++ b/priv/repo/migrations/20210512041939_add_repo_to_article_comment.exs @@ -0,0 +1,11 @@ +defmodule GroupherServer.Repo.Migrations.AddRepoToArticleComment do + use Ecto.Migration + + def change do + alter table(:articles_comments) do + add(:repo_id, references(:cms_repos, on_delete: :delete_all)) + end + + create(index(:articles_comments, [:repo_id])) + end +end 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 a3c7a7594..16d2eb0fc 100644 --- a/test/groupher_server/cms/abuse_reports/comment_report_test.exs +++ b/test/groupher_server/cms/abuse_reports/comment_report_test.exs @@ -15,29 +15,32 @@ defmodule GroupherServer.Test.CMS.AbuseReports.CommentReport do end describe "[article comment report/unreport]" do - @tag :wip3 + @tag :wip2 test "report a comment should have a abuse report record", ~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) - {:ok, all_reports} = CMS.list_reports(:article_comment, comment.id, %{page: 1, size: 20}) + filter = %{content_type: :article_comment, content_id: comment.id, page: 1, size: 20} + {:ok, all_reports} = CMS.list_reports(filter) report = List.first(all_reports.entries) report_cases = report.report_cases + assert report.article_comment.id == comment.id assert all_reports.total_count == 1 assert report.report_cases_count == 1 assert List.first(report_cases).user.login == user.login end - @tag :wip3 + @tag :wip2 test "different user report a comment should have same report with different report cases", ~m(user user2 post)a do {:ok, comment} = CMS.create_article_comment(:post, post.id, "commment", user) {:ok, _} = CMS.report_article_comment(comment.id, "reason", "attr", user) {:ok, _} = CMS.report_article_comment(comment.id, "reason", "attr", user2) - {:ok, all_reports} = CMS.list_reports(:article_comment, comment.id, %{page: 1, size: 20}) + filter = %{content_type: :article_comment, content_id: comment.id, page: 1, size: 20} + {:ok, all_reports} = CMS.list_reports(filter) report = List.first(all_reports.entries) report_cases = report.report_cases diff --git a/test/groupher_server/cms/abuse_reports/job_report_test.exs b/test/groupher_server/cms/abuse_reports/job_report_test.exs index fb9d938e3..8d8d524b9 100644 --- a/test/groupher_server/cms/abuse_reports/job_report_test.exs +++ b/test/groupher_server/cms/abuse_reports/job_report_test.exs @@ -17,17 +17,32 @@ defmodule GroupherServer.Test.CMS.AbuseReports.JobReport do end describe "[article job report/unreport]" do + @tag :wip3 + test "list article reports should work", ~m(community user user2 job_attrs)a do + {:ok, job} = CMS.create_content(community, :job, job_attrs, user) + {:ok, _report} = CMS.report_article(:job, job.id, "reason", "attr_info", user) + {:ok, _report} = CMS.report_article(:job, job.id, "reason", "attr_info", user2) + + filter = %{content_type: :job, content_id: job.id, page: 1, size: 20} + {:ok, all_reports} = CMS.list_reports(filter) + + report = all_reports.entries |> List.first() + assert report.article.id == job.id + assert report.article.thread == :job + end + @tag :wip3 test "report a job should have a abuse report record", ~m(community user job_attrs)a do {:ok, job} = CMS.create_content(community, :job, job_attrs, user) {:ok, _report} = CMS.report_article(:job, job.id, "reason", "attr_info", user) - {:ok, all_reports} = CMS.list_reports(:job, job.id, %{page: 1, size: 20}) + filter = %{content_type: :job, content_id: job.id, page: 1, size: 20} + {:ok, all_reports} = CMS.list_reports(filter) report = List.first(all_reports.entries) report_cases = report.report_cases - assert report.job_id == job.id + assert report.article.id == job.id assert all_reports.total_count == 1 assert report.report_cases_count == 1 assert List.first(report_cases).user.login == user.login @@ -43,7 +58,8 @@ defmodule GroupherServer.Test.CMS.AbuseReports.JobReport do {:ok, _report} = CMS.report_article(:job, job.id, "reason", "attr_info", user) {:ok, _report} = CMS.undo_report_article(:job, job.id, user) - {:ok, all_reports} = CMS.list_reports(:job, job.id, %{page: 1, size: 20}) + filter = %{content_type: :job, content_id: job.id, page: 1, size: 20} + {:ok, all_reports} = CMS.list_reports(filter) assert all_reports.total_count == 0 end @@ -54,7 +70,8 @@ defmodule GroupherServer.Test.CMS.AbuseReports.JobReport do {:ok, _report} = CMS.report_article(:job, job.id, "reason", "attr_info", user) {:ok, _report} = CMS.report_article(:job, job.id, "reason", "attr_info", user2) - {:ok, all_reports} = CMS.list_reports(:job, job.id, %{page: 1, size: 20}) + filter = %{content_type: :job, content_id: job.id, page: 1, size: 20} + {:ok, all_reports} = CMS.list_reports(filter) assert all_reports.total_count == 1 report = all_reports.entries |> List.first() @@ -64,7 +81,8 @@ defmodule GroupherServer.Test.CMS.AbuseReports.JobReport do {:ok, _report} = CMS.undo_report_article(:job, job.id, user) - {:ok, all_reports} = CMS.list_reports(:job, job.id, %{page: 1, size: 20}) + filter = %{content_type: :job, content_id: job.id, page: 1, size: 20} + {:ok, all_reports} = CMS.list_reports(filter) assert all_reports.total_count == 1 report = all_reports.entries |> List.first() @@ -80,7 +98,8 @@ defmodule GroupherServer.Test.CMS.AbuseReports.JobReport do {:ok, _report} = CMS.report_article(:job, job.id, "reason", "attr_info", user) {:ok, _report} = CMS.report_article(:job, job.id, "reason2", "attr_info 2", user2) - {:ok, all_reports} = CMS.list_reports(:job, job.id, %{page: 1, size: 20}) + filter = %{content_type: :job, content_id: job.id, page: 1, size: 20} + {:ok, all_reports} = CMS.list_reports(filter) report = List.first(all_reports.entries) report_cases = report.report_cases diff --git a/test/groupher_server/cms/abuse_reports/post_report_test.exs b/test/groupher_server/cms/abuse_reports/post_report_test.exs index ff2d70ba9..f54ad6d31 100644 --- a/test/groupher_server/cms/abuse_reports/post_report_test.exs +++ b/test/groupher_server/cms/abuse_reports/post_report_test.exs @@ -17,7 +17,7 @@ defmodule GroupherServer.Test.CMS.AbuseReports.PostReport do end describe "[article post report/unreport]" do - @tag :wip2 + @tag :wip3 test "list article reports should work", ~m(community user user2 post_attrs)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) {:ok, _report} = CMS.report_article(:post, post.id, "reason", "attr_info", user) @@ -25,14 +25,10 @@ defmodule GroupherServer.Test.CMS.AbuseReports.PostReport do filter = %{content_type: :post, content_id: post.id, page: 1, size: 20} {:ok, all_reports} = CMS.list_reports(filter) - IO.inspect(all_reports, label: "all_reports -- ") - - # report = all_reports.entries |> List.first() - # IO.inspect(Map.keys(report), label: "report keys") - # # [:deal_with, :id, :inserted_at, :is_closed, :operate_user, :post, :report_cases, - # # :report_cases_count, :updated_at] - # assert report |> Map.get(:post) |> Map.get(:id) == post.id - # assert report |> Map.get(:report_cases) |> length == 2 + + report = all_reports.entries |> List.first() + assert report.article.id == post.id + assert report.article.thread == :post end @tag :wip3 @@ -40,12 +36,13 @@ defmodule GroupherServer.Test.CMS.AbuseReports.PostReport do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) {:ok, _report} = CMS.report_article(:post, post.id, "reason", "attr_info", user) - {:ok, all_reports} = CMS.list_reports(:post, post.id, %{page: 1, size: 20}) + filter = %{content_type: :post, content_id: post.id, page: 1, size: 20} + {:ok, all_reports} = CMS.list_reports(filter) report = List.first(all_reports.entries) report_cases = report.report_cases - assert report.post_id == post.id + assert report.article.id == post.id assert all_reports.total_count == 1 assert report.report_cases_count == 1 assert List.first(report_cases).user.login == user.login @@ -61,7 +58,8 @@ defmodule GroupherServer.Test.CMS.AbuseReports.PostReport do {:ok, _report} = CMS.report_article(:post, post.id, "reason", "attr_info", user) {:ok, _report} = CMS.undo_report_article(:post, post.id, user) - {:ok, all_reports} = CMS.list_reports(:post, post.id, %{page: 1, size: 20}) + filter = %{content_type: :post, content_id: post.id, page: 1, size: 20} + {:ok, all_reports} = CMS.list_reports(filter) assert all_reports.total_count == 0 end @@ -72,7 +70,8 @@ defmodule GroupherServer.Test.CMS.AbuseReports.PostReport do {:ok, _report} = CMS.report_article(:post, post.id, "reason", "attr_info", user) {:ok, _report} = CMS.report_article(:post, post.id, "reason", "attr_info", user2) - {:ok, all_reports} = CMS.list_reports(:post, post.id, %{page: 1, size: 20}) + filter = %{content_type: :post, content_id: post.id, page: 1, size: 20} + {:ok, all_reports} = CMS.list_reports(filter) assert all_reports.total_count == 1 report = all_reports.entries |> List.first() @@ -82,7 +81,8 @@ defmodule GroupherServer.Test.CMS.AbuseReports.PostReport do {:ok, _report} = CMS.undo_report_article(:post, post.id, user) - {:ok, all_reports} = CMS.list_reports(:post, post.id, %{page: 1, size: 20}) + filter = %{content_type: :post, content_id: post.id, page: 1, size: 20} + {:ok, all_reports} = CMS.list_reports(filter) assert all_reports.total_count == 1 report = all_reports.entries |> List.first() @@ -98,7 +98,8 @@ defmodule GroupherServer.Test.CMS.AbuseReports.PostReport do {:ok, _report} = CMS.report_article(:post, post.id, "reason", "attr_info", user) {:ok, _report} = CMS.report_article(:post, post.id, "reason2", "attr_info 2", user2) - {:ok, all_reports} = CMS.list_reports(:post, post.id, %{page: 1, size: 20}) + filter = %{content_type: :post, content_id: post.id, page: 1, size: 20} + {:ok, all_reports} = CMS.list_reports(filter) report = List.first(all_reports.entries) report_cases = report.report_cases diff --git a/test/groupher_server/cms/comments/job_comment_test.exs b/test/groupher_server/cms/comments/job_comment_test.exs index fe2980a3b..35a795f86 100644 --- a/test/groupher_server/cms/comments/job_comment_test.exs +++ b/test/groupher_server/cms/comments/job_comment_test.exs @@ -295,7 +295,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do assert not comment.is_reported end - @tag :wip3 + @tag :wip2 test "can undo a report with other user report it too", ~m(user user2 job)a do {:ok, comment} = CMS.create_article_comment(:job, job.id, "commment", user) @@ -303,7 +303,8 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do {:ok, _comment} = CMS.report_article_comment(comment.id, "reason", "attr", user) {:ok, _comment} = CMS.report_article_comment(comment.id, "reason", "attr", user2) - {:ok, all_reports} = CMS.list_reports(:article_comment, comment.id, %{page: 1, size: 20}) + filter = %{content_type: :article_comment, content_id: comment.id, page: 1, size: 20} + {:ok, all_reports} = CMS.list_reports(filter) assert all_reports.total_count == 1 report = all_reports.entries |> List.first() @@ -313,7 +314,8 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do {:ok, _report} = CMS.undo_report_article(:article_comment, comment.id, user) - {:ok, all_reports} = CMS.list_reports(:article_comment, comment.id, %{page: 1, size: 20}) + filter = %{content_type: :article_comment, content_id: comment.id, page: 1, size: 20} + {:ok, all_reports} = CMS.list_reports(filter) assert all_reports.total_count == 1 report = all_reports.entries |> List.first() @@ -321,7 +323,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do assert Enum.any?(report.report_cases, &(&1.user.login == user2.login)) end - @tag :wip3 + @tag :wip2 test "report user < @report_threshold_for_fold will not fold comment", ~m(user job)a do {:ok, comment} = CMS.create_article_comment(:job, job.id, "commment", user) diff --git a/test/groupher_server/cms/comments/post_comment_test.exs b/test/groupher_server/cms/comments/post_comment_test.exs index 8a87401d1..520cfa7ac 100644 --- a/test/groupher_server/cms/comments/post_comment_test.exs +++ b/test/groupher_server/cms/comments/post_comment_test.exs @@ -295,7 +295,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do assert not comment.is_reported end - @tag :wip3 + @tag :wip2 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) @@ -303,7 +303,8 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do {:ok, _comment} = CMS.report_article_comment(comment.id, "reason", "attr", user) {:ok, _comment} = CMS.report_article_comment(comment.id, "reason", "attr", user2) - {:ok, all_reports} = CMS.list_reports(:article_comment, comment.id, %{page: 1, size: 20}) + filter = %{content_type: :article_comment, content_id: comment.id, page: 1, size: 20} + {:ok, all_reports} = CMS.list_reports(filter) assert all_reports.total_count == 1 report = all_reports.entries |> List.first() @@ -313,7 +314,8 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do {:ok, _report} = CMS.undo_report_article(:article_comment, comment.id, user) - {:ok, all_reports} = CMS.list_reports(:article_comment, comment.id, %{page: 1, size: 20}) + filter = %{content_type: :article_comment, content_id: comment.id, page: 1, size: 20} + {:ok, all_reports} = CMS.list_reports(filter) assert all_reports.total_count == 1 report = all_reports.entries |> List.first() From e7c587651261e9656ceea7d677f1ed6b4f415c8a Mon Sep 17 00:00:00 2001 From: mydearxym Date: Wed, 12 May 2021 17:55:46 +0800 Subject: [PATCH 04/13] refactor(abuse-report): wip --- .../accounts/embeds/collect_folder_meta.ex | 4 +- .../accounts/embeds/user_meta.ex | 26 +++ lib/groupher_server/accounts/user.ex | 6 + lib/groupher_server/cms/cms.ex | 4 +- .../cms/delegates/abuse_report.ex | 150 +++++++++++++----- lib/groupher_server/cms/helper/matcher2.ex | 28 +++- lib/helper/utils/utils.ex | 2 + ...20210512072528_add_report_meta_to_user.exs | 10 ++ .../cms/abuse_reports/account_report_test.exs | 121 ++++++++++++++ .../cms/abuse_reports/job_report_test.exs | 14 +- .../cms/abuse_reports/post_report_test.exs | 14 +- .../comments/job_comment_emotions_test.exs | 12 +- .../cms/comments/job_comment_replies_test.exs | 8 +- .../cms/comments/job_comment_test.exs | 14 +- .../comments/post_comment_emotions_test.exs | 12 +- .../comments/post_comment_replies_test.exs | 10 +- .../cms/comments/post_comment_test.exs | 16 +- .../cms/emotions/job_emotions_test.exs | 16 +- .../cms/emotions/post_emotions_test.exs | 16 +- test/groupher_server/cms/job_test.exs | 2 +- test/groupher_server/cms/post_test.exs | 4 +- test/groupher_server/cms/repo_test.exs | 4 +- .../cms/upvotes/job_upvote_test.exs | 10 +- .../cms/upvotes/post_upvote_test.exs | 10 +- .../mutation/accounts/customization_test.exs | 2 +- .../cms/articles/job_emotion_test.exs | 4 +- .../mutation/cms/articles/job_report_test.exs | 4 +- .../mutation/cms/articles/job_test.exs | 2 +- .../cms/articles/post_emotion_test.exs | 4 +- .../cms/articles/post_report_test.exs | 4 +- .../mutation/cms/articles/post_test.exs | 2 +- .../cms/articles/repo_report_test.exs | 4 +- .../mutation/cms/articles/repo_test.exs | 6 +- .../mutation/cms/cms_test.exs | 4 +- .../cms/comments/job_comment_test.exs | 12 +- .../cms/comments/post_comment_test.exs | 12 +- .../mutation/cms/flags/job_flag_test.exs | 14 +- .../mutation/cms/flags/post_flag_test.exs | 16 +- .../mutation/cms/flags/repo_flag_test.exs | 16 +- .../mutation/cms/upvotes/job_upvote_test.exs | 8 +- .../mutation/cms/upvotes/post_upvote_test.exs | 8 +- .../query/cms/collects/job_collect_test.exs | 2 +- .../query/cms/collects/post_collect_test.exs | 2 +- .../query/cms/comments/job_comment_test.exs | 12 +- .../query/cms/comments/post_comment_test.exs | 10 +- .../query/cms/job_test.exs | 4 +- .../query/cms/jobs_flags_test.exs | 2 +- .../query/cms/paged_jobs_test.exs | 2 +- .../query/cms/paged_posts_test.exs | 2 +- .../query/cms/paged_repos_test.exs | 2 +- .../query/cms/post_test.exs | 4 +- .../query/cms/posts_flags_test.exs | 2 +- .../query/cms/repo_test.exs | 4 +- .../query/cms/repos_flags_test.exs | 2 +- .../query/cms/upvotes/post_upvote_test.exs | 2 +- 55 files changed, 469 insertions(+), 218 deletions(-) create mode 100644 lib/groupher_server/accounts/embeds/user_meta.ex create mode 100644 priv/repo/migrations/20210512072528_add_report_meta_to_user.exs create mode 100644 test/groupher_server/cms/abuse_reports/account_report_test.exs diff --git a/lib/groupher_server/accounts/embeds/collect_folder_meta.ex b/lib/groupher_server/accounts/embeds/collect_folder_meta.ex index 76ca25b11..e90416143 100644 --- a/lib/groupher_server/accounts/embeds/collect_folder_meta.ex +++ b/lib/groupher_server/accounts/embeds/collect_folder_meta.ex @@ -1,4 +1,4 @@ -defmodule GroupherServer.CMS.Embeds.CollectFolderMeta.Macros do +defmodule GroupherServer.Accounts.Embeds.CollectFolderMeta.Macros do @moduledoc """ general fields for each folder meta @@ -31,7 +31,7 @@ defmodule GroupherServer.Accounts.Embeds.CollectFolderMeta do """ use Ecto.Schema import Ecto.Changeset - import GroupherServer.CMS.Embeds.CollectFolderMeta.Macros + import GroupherServer.Accounts.Embeds.CollectFolderMeta.Macros alias GroupherServer.Accounts.CollectFolder diff --git a/lib/groupher_server/accounts/embeds/user_meta.ex b/lib/groupher_server/accounts/embeds/user_meta.ex new file mode 100644 index 000000000..115982ba4 --- /dev/null +++ b/lib/groupher_server/accounts/embeds/user_meta.ex @@ -0,0 +1,26 @@ +defmodule GroupherServer.Accounts.Embeds.UserMeta do + @moduledoc """ + general article meta info for article-like content, like post, job, works ... + """ + use Ecto.Schema + use Accessible + import Ecto.Changeset + + @optional_fields ~w(reported_count)a + + @default_meta %{ + reported_count: 0 + } + + @doc "for test usage" + def default_meta(), do: @default_meta + + embedded_schema do + field(:reported_count, :integer, default: 0) + end + + def changeset(struct, params) do + struct + |> cast(params, @optional_fields) + end +end diff --git a/lib/groupher_server/accounts/user.ex b/lib/groupher_server/accounts/user.ex index f665f9642..07b0fc1fa 100644 --- a/lib/groupher_server/accounts/user.ex +++ b/lib/groupher_server/accounts/user.ex @@ -9,6 +9,7 @@ defmodule GroupherServer.Accounts.User do alias GroupherServer.Accounts.{ Achievement, + Embeds, Customization, EducationBackground, CollectFolder, @@ -60,6 +61,9 @@ defmodule GroupherServer.Accounts.User do # field(:paid_member, :boolean) # field(:platinum_member, :boolean) + field(:is_reported, :boolean, default: false) + embeds_one(:meta, Embeds.UserMeta, on_replace: :update) + has_one(:customization, Customization) has_one(:purchase, Purchase) @@ -70,6 +74,7 @@ defmodule GroupherServer.Accounts.User do def changeset(%User{} = user, attrs) do user |> update_changeset(attrs) + |> cast_embed(:meta, required: false, with: &Embeds.UserMeta.changeset/2) |> validate_required(@required_fields) # |> unique_constraint(:username) @@ -80,6 +85,7 @@ defmodule GroupherServer.Accounts.User do |> cast(attrs, @optional_fields ++ @required_fields) |> cast_embed(:education_backgrounds, with: &EducationBackground.changeset/2) |> cast_embed(:work_backgrounds, with: &WorkBackground.changeset/2) + |> cast_embed(:meta, required: false, with: &Embeds.UserMeta.changeset/2) |> validate_length(:nickname, min: 3, max: 30) |> validate_length(:bio, min: 3, max: 100) |> validate_inclusion(:sex, ["dude", "girl"]) diff --git a/lib/groupher_server/cms/cms.ex b/lib/groupher_server/cms/cms.ex index 78a7f87b6..00b61a65e 100644 --- a/lib/groupher_server/cms/cms.ex +++ b/lib/groupher_server/cms/cms.ex @@ -162,9 +162,11 @@ defmodule GroupherServer.CMS do # TODO: move report to abuse report module defdelegate create_report(type, content_id, reason, attr, user), to: AbuseReport defdelegate report_article(thread, article_id, reason, attr, user), to: AbuseReport + defdelegate report_article_comment(comment_id, reason, attr, user), to: ArticleCommentAction + defdelegate report_account(account_id, reason, attr, user), to: AbuseReport + defdelegate undo_report_account(account_id, user), to: AbuseReport defdelegate undo_report_article(thread, article_id, user), to: AbuseReport defdelegate list_reports(filter), to: AbuseReport - defdelegate report_article_comment(comment_id, reason, attr, user), to: ArticleCommentAction defdelegate undo_report_article_comment(comment_id, user), to: AbuseReport # Passport CURD diff --git a/lib/groupher_server/cms/delegates/abuse_report.ex b/lib/groupher_server/cms/delegates/abuse_report.ex index 262f17e29..2a089b2bc 100644 --- a/lib/groupher_server/cms/delegates/abuse_report.ex +++ b/lib/groupher_server/cms/delegates/abuse_report.ex @@ -29,6 +29,8 @@ defmodule GroupherServer.CMS.Delegate.AbuseReport do # } @article_threads [:post, :job, :repo] + @export_author_keys [:id, :login, :nickname, :avatar] + @export_article_keys [:id, :title, :digest, :upvotes_count, :views] @export_report_keys [ :id, :deal_with, @@ -40,8 +42,26 @@ defmodule GroupherServer.CMS.Delegate.AbuseReport do :updated_at ] - @export_author_keys [:id, :login, :nickname, :avatar] - @export_article_keys [:id, :title, :digest, :upvotes_count, :views] + @doc """ + list paged reports for article comemnts + """ + def list_reports(%{content_type: :user, content_id: content_id} = filter) do + %{page: page, size: size} = filter + + with {:ok, info} <- match(:account_user) do + query = + from(r in AbuseReport, + where: field(r, ^info.foreign_key) == ^content_id, + preload: :account + ) + + query + |> QueryBuilder.filter_pack(filter) + |> ORM.paginater(~m(page size)a) + |> reports_formater(:account_user) + |> done() + end + end @doc """ list paged reports for article comemnts @@ -87,42 +107,39 @@ defmodule GroupherServer.CMS.Delegate.AbuseReport do end end - defp reports_formater(%{entries: entries} = paged_reports, :article_comment) do - paged_reports - |> Map.put( - :entries, - Enum.map(entries, fn report -> - basic_report = report |> Map.take(@export_report_keys) - basic_report |> Map.put(:article_comment, extract_article_comment_info(report)) + def report_account(account_id, reason, attr, user) do + with {:ok, info} <- match(:account_user), + {:ok, account} <- ORM.find(info.model, account_id) do + Multi.new() + |> Multi.run(:create_abuse_report, fn _, _ -> + create_report(:account_user, account.id, reason, attr, user) end) - ) - end - - defp reports_formater(%{entries: entries} = paged_reports, thread) - when thread in @article_threads do - paged_reports - |> Map.put( - :entries, - Enum.map(entries, fn report -> - basic_report = report |> Map.take(@export_report_keys) - basic_report |> Map.put(:article, extract_article_info(thread, report)) + |> Multi.run(:update_report_flag, fn _, _ -> + update_report_meta(info, account) end) - ) + |> Repo.transaction() + |> result() + end end - # TODO: original community and communities info - defp extract_article_info(thread, %AbuseReport{} = report) do - article = Map.get(report, thread) - - article - |> Map.take(@export_article_keys) - |> Map.merge(%{thread: thread}) + @doc """ + undo report article content + """ + def undo_report_account(account_id, %User{} = user) do + with {:ok, info} <- match(:account_user), + {:ok, account} <- ORM.find(info.model, account_id) do + Multi.new() + |> Multi.run(:delete_abuse_report, fn _, _ -> + delete_report(:account_user, account.id, user) + end) + |> Multi.run(:update_report_flag, fn _, _ -> + update_report_meta(info, account) + end) + |> Repo.transaction() + |> result() + end end - # def report_account(user_id) do - # # TODO* - # end - @doc """ report article content """ @@ -131,10 +148,10 @@ defmodule GroupherServer.CMS.Delegate.AbuseReport do {:ok, article} <- ORM.find(info.model, article_id) do Multi.new() |> Multi.run(:create_abuse_report, fn _, _ -> - create_report(thread, article_id, reason, attr, user) + create_report(thread, article.id, reason, attr, user) end) |> Multi.run(:update_report_flag, fn _, _ -> - update_report_meta(info, article, true) + update_report_meta(info, article) end) |> Repo.transaction() |> result() @@ -149,10 +166,10 @@ defmodule GroupherServer.CMS.Delegate.AbuseReport do {:ok, article} <- ORM.find(info.model, article_id) do Multi.new() |> Multi.run(:delete_abuse_report, fn _, _ -> - delete_report(thread, article_id, user) + delete_report(thread, article.id, user) end) |> Multi.run(:update_report_flag, fn _, _ -> - update_report_meta(info, article, false) + update_report_meta(info, article) end) |> Repo.transaction() |> result() @@ -219,23 +236,26 @@ defmodule GroupherServer.CMS.Delegate.AbuseReport do end end - # update is_reported flag and reported_count in mete for article or comment - defp update_report_meta(info, content, is_reported) do + # update reported_count in mete for article or comment + defp update_report_meta(info, content) do case ORM.find_by(AbuseReport, Map.put(%{}, info.foreign_key, content.id)) do {:ok, record} -> reported_count = record.report_cases |> length - meta = content.meta |> Map.merge(%{reported_count: reported_count}) |> strip_struct + + safe_meta = if is_nil(content.meta), do: info.default_meta, else: content.meta + meta = safe_meta |> Map.merge(%{reported_count: reported_count}) |> strip_struct content - |> Ecto.Changeset.change(%{is_reported: is_reported}) + |> Ecto.Changeset.change() |> Ecto.Changeset.put_embed(:meta, meta) |> Repo.update() {:error, _} -> - meta = content.meta |> Map.merge(%{reported_count: 0}) |> strip_struct + safe_meta = if is_nil(content.meta), do: info.default_meta, else: content.meta + meta = safe_meta |> Map.merge(%{reported_count: 0}) |> strip_struct content - |> Ecto.Changeset.change(%{is_reported: false}) + |> Ecto.Changeset.change() |> Ecto.Changeset.put_embed(:meta, meta) |> Repo.update() end @@ -261,6 +281,52 @@ defmodule GroupherServer.CMS.Delegate.AbuseReport do end end + defp reports_formater(%{entries: entries} = paged_reports, :account_user) do + paged_reports + |> Map.put( + :entries, + Enum.map(entries, fn report -> + basic_report = report |> Map.take(@export_report_keys) + basic_report |> Map.put(:account, extract_account_info(report)) + end) + ) + end + + defp reports_formater(%{entries: entries} = paged_reports, :article_comment) do + paged_reports + |> Map.put( + :entries, + Enum.map(entries, fn report -> + basic_report = report |> Map.take(@export_report_keys) + basic_report |> Map.put(:article_comment, extract_article_comment_info(report)) + end) + ) + end + + defp reports_formater(%{entries: entries} = paged_reports, thread) + when thread in @article_threads do + paged_reports + |> Map.put( + :entries, + Enum.map(entries, fn report -> + basic_report = report |> Map.take(@export_report_keys) + basic_report |> Map.put(:article, extract_article_info(thread, report)) + end) + ) + end + + defp extract_account_info(%AbuseReport{} = report) do + account = report |> Map.get(:account) |> Map.take(@export_author_keys) + end + + # TODO: original community and communities info + defp extract_article_info(thread, %AbuseReport{} = report) do + report + |> Map.get(thread) + |> Map.take(@export_article_keys) + |> Map.merge(%{thread: thread}) + end + def extract_article_comment_info(%AbuseReport{} = report) do keys = [:id, :upvotes_count, :body_html] author = Map.take(report.article_comment.author, @export_author_keys) diff --git a/lib/groupher_server/cms/helper/matcher2.ex b/lib/groupher_server/cms/helper/matcher2.ex index f583dbdd1..6c986fa2f 100644 --- a/lib/groupher_server/cms/helper/matcher2.ex +++ b/lib/groupher_server/cms/helper/matcher2.ex @@ -5,12 +5,18 @@ defmodule GroupherServer.CMS.Helper.Matcher2 do import Ecto.Query, warn: false - alias GroupherServer.CMS + alias GroupherServer.{Accounts, CMS} + alias Accounts.User alias CMS.{ArticleComment, Post, Job, Repo} def match(:article_comment) do - {:ok, %{model: ArticleComment, foreign_key: :article_comment_id}} + {:ok, + %{ + model: ArticleComment, + foreign_key: :article_comment_id, + default_meta: CMS.Embeds.ArticleCommentMeta.default_meta() + }} end def match(:comment_article, %ArticleComment{post_id: post_id}) when not is_nil(post_id) do @@ -25,13 +31,23 @@ defmodule GroupherServer.CMS.Helper.Matcher2 do {:error, "not supported"} end + def match(:account_user) do + {:ok, + %{ + model: User, + foreign_key: :account_id, + default_meta: Accounts.Embeds.UserMeta.default_meta() + }} + end + # used for paged pin articles def match(Post) do {:ok, %{thread: :post}} end def match(:post) do - {:ok, %{model: Post, foreign_key: :post_id}} + {:ok, + %{model: Post, foreign_key: :post_id, default_meta: CMS.Embeds.ArticleMeta.default_meta()}} end def match(Job) do @@ -39,7 +55,8 @@ defmodule GroupherServer.CMS.Helper.Matcher2 do end def match(:job) do - {:ok, %{model: Job, foreign_key: :job_id}} + {:ok, + %{model: Job, foreign_key: :job_id, default_meta: CMS.Embeds.ArticleMeta.default_meta()}} end def match(Repo) do @@ -47,7 +64,8 @@ defmodule GroupherServer.CMS.Helper.Matcher2 do end def match(:repo) do - {:ok, %{model: Repo, foreign_key: :repo_id}} + {:ok, + %{model: Repo, foreign_key: :repo_id, default_meta: CMS.Embeds.ArticleMeta.default_meta()}} end def match(:post, :query, id), do: {:ok, dynamic([c], c.post_id == ^id)} diff --git a/lib/helper/utils/utils.ex b/lib/helper/utils/utils.ex index 633385c42..1ea595ff9 100644 --- a/lib/helper/utils/utils.ex +++ b/lib/helper/utils/utils.ex @@ -173,6 +173,8 @@ defmodule Helper.Utils do struct |> Map.from_struct() |> Map.delete(:id) end + def strip_struct(map) when is_map(map), do: map + @doc "html uniq id generator for editorjs" @spec uid(:html, map) :: String.t() def uid(:html, %{"id" => id}) when g_none_empty_str(id), do: id diff --git a/priv/repo/migrations/20210512072528_add_report_meta_to_user.exs b/priv/repo/migrations/20210512072528_add_report_meta_to_user.exs new file mode 100644 index 000000000..214c58039 --- /dev/null +++ b/priv/repo/migrations/20210512072528_add_report_meta_to_user.exs @@ -0,0 +1,10 @@ +defmodule GroupherServer.Repo.Migrations.AddReportMetaToUser do + use Ecto.Migration + + def change do + alter table(:users) do + add(:is_reported, :boolean, default: false) + add(:meta, :map) + end + end +end diff --git a/test/groupher_server/cms/abuse_reports/account_report_test.exs b/test/groupher_server/cms/abuse_reports/account_report_test.exs new file mode 100644 index 000000000..31c03883f --- /dev/null +++ b/test/groupher_server/cms/abuse_reports/account_report_test.exs @@ -0,0 +1,121 @@ +# report_account + +defmodule GroupherServer.Test.CMS.AbuseReports.AccountReport do + @moduledoc false + + use GroupherServer.TestTools + + alias Helper.ORM + alias GroupherServer.CMS + alias GroupherServer.Accounts + + alias Accounts.User + + setup do + {:ok, user} = db_insert(:user) + {:ok, user2} = db_insert(:user) + {:ok, user3} = db_insert(:user) + + {:ok, community} = db_insert(:community) + post_attrs = mock_attrs(:post, %{community_id: community.id}) + + {:ok, ~m(user user2 user3 community post_attrs)a} + end + + describe "[account report/unreport]" do + @tag :wip2 + # test "list article reports should work", ~m(community user user2 post_attrs)a do + # {:ok, post} = CMS.create_content(community, :post, post_attrs, user) + # {:ok, _report} = CMS.report_article(:post, post.id, "reason", "attr_info", user) + # {:ok, _report} = CMS.report_article(:post, post.id, "reason", "attr_info", user2) + + # filter = %{content_type: :post, content_id: post.id, page: 1, size: 20} + # {:ok, all_reports} = CMS.list_reports(filter) + + # report = all_reports.entries |> List.first() + # assert report.article.id == post.id + # assert report.article.thread == :post + # end + + @tag :wip2 + test "report an account should have a abuse report record", ~m(user user2)a do + {:ok, report} = CMS.report_account(user.id, "reason", "attr_info", user2) + + filter = %{content_type: :user, content_id: user.id, page: 1, size: 20} + {:ok, all_reports} = CMS.list_reports(filter) + + report = List.first(all_reports.entries) + report_cases = report.report_cases + + assert report.account.id == user.id + assert all_reports.total_count == 1 + assert report.report_cases_count == 1 + assert List.first(report_cases).user.login == user2.login + + {:ok, user} = ORM.find(User, user.id) + assert not user.is_reported + assert user.meta.reported_count == 1 + end + + @tag :wip2 + test "can undo a report", ~m(user user2)a do + {:ok, report} = CMS.report_account(user.id, "reason", "attr_info", user2) + {:ok, _report} = CMS.undo_report_account(user.id, user2) + + filter = %{content_type: :user, content_id: user.id, page: 1, size: 20} + {:ok, all_reports} = CMS.list_reports(filter) + assert all_reports.total_count == 0 + end + + @tag :wip2 + test "can undo a report with other user report it too", ~m(user user2 user3)a do + {:ok, _report} = CMS.report_account(user.id, "reason", "attr_info", user2) + {:ok, _report} = CMS.report_account(user.id, "reason", "attr_info", user3) + + filter = %{content_type: :user, content_id: user.id, page: 1, size: 20} + {:ok, all_reports} = CMS.list_reports(filter) + assert all_reports.total_count == 1 + + report = all_reports.entries |> List.first() + assert report.report_cases |> length == 2 + assert Enum.any?(report.report_cases, &(&1.user.login == user2.login)) + assert Enum.any?(report.report_cases, &(&1.user.login == user3.login)) + + {:ok, _report} = CMS.undo_report_account(user.id, user2) + + filter = %{content_type: :user, content_id: user.id, page: 1, size: 20} + {:ok, all_reports} = CMS.list_reports(filter) + assert all_reports.total_count == 1 + + report = all_reports.entries |> List.first() + assert report.report_cases |> length == 1 + assert Enum.any?(report.report_cases, &(&1.user.login == user3.login)) + end + + @tag :wip2 + test "different user report a account should have same report with different report cases", + ~m(user user2 user3)a do + {:ok, _report} = CMS.report_account(user.id, "reason", "attr_info", user2) + {:ok, _report} = CMS.report_account(user.id, "reason", "attr_info", user3) + + filter = %{content_type: :user, content_id: user.id, page: 1, size: 20} + {:ok, all_reports} = CMS.list_reports(filter) + + report = List.first(all_reports.entries) + report_cases = report.report_cases + + assert all_reports.total_count == 1 + assert length(report_cases) == 2 + assert report.report_cases_count == 2 + + assert List.first(report_cases).user.login == user2.login + assert List.last(report_cases).user.login == user3.login + end + + @tag :wip2 + test "same user can not report a account twice", ~m(user user2)a do + {:ok, _report} = CMS.report_account(user.id, "reason", "attr_info", user2) + assert {:error, _report} = CMS.report_account(user.id, "reason", "attr_info", user2) + end + end +end diff --git a/test/groupher_server/cms/abuse_reports/job_report_test.exs b/test/groupher_server/cms/abuse_reports/job_report_test.exs index 8d8d524b9..566cb0da1 100644 --- a/test/groupher_server/cms/abuse_reports/job_report_test.exs +++ b/test/groupher_server/cms/abuse_reports/job_report_test.exs @@ -17,7 +17,7 @@ defmodule GroupherServer.Test.CMS.AbuseReports.JobReport do end describe "[article job report/unreport]" do - @tag :wip3 + @tag :wip2 test "list article reports should work", ~m(community user user2 job_attrs)a do {:ok, job} = CMS.create_content(community, :job, job_attrs, user) {:ok, _report} = CMS.report_article(:job, job.id, "reason", "attr_info", user) @@ -31,7 +31,7 @@ defmodule GroupherServer.Test.CMS.AbuseReports.JobReport do assert report.article.thread == :job end - @tag :wip3 + @tag :wip2 test "report a job should have a abuse report record", ~m(community user job_attrs)a do {:ok, job} = CMS.create_content(community, :job, job_attrs, user) {:ok, _report} = CMS.report_article(:job, job.id, "reason", "attr_info", user) @@ -48,11 +48,11 @@ defmodule GroupherServer.Test.CMS.AbuseReports.JobReport do assert List.first(report_cases).user.login == user.login {:ok, job} = ORM.find(CMS.Job, job.id) - assert job.is_reported + assert not job.is_reported assert job.meta.reported_count == 1 end - @tag :wip3 + @tag :wip2 test "can undo a report", ~m(community user job_attrs)a do {:ok, job} = CMS.create_content(community, :job, job_attrs, user) {:ok, _report} = CMS.report_article(:job, job.id, "reason", "attr_info", user) @@ -63,7 +63,7 @@ defmodule GroupherServer.Test.CMS.AbuseReports.JobReport do assert all_reports.total_count == 0 end - @tag :wip3 + @tag :wip2 test "can undo a report with other user report it too", ~m(community user user2 job_attrs)a do {:ok, job} = CMS.create_content(community, :job, job_attrs, user) @@ -90,7 +90,7 @@ defmodule GroupherServer.Test.CMS.AbuseReports.JobReport do assert Enum.any?(report.report_cases, &(&1.user.login == user2.login)) end - @tag :wip3 + @tag :wip2 test "different user report a comment should have same report with different report cases", ~m(community user user2 job_attrs)a do {:ok, job} = CMS.create_content(community, :job, job_attrs, user) @@ -112,7 +112,7 @@ defmodule GroupherServer.Test.CMS.AbuseReports.JobReport do assert List.last(report_cases).user.login == user2.login end - @tag :wip3 + @tag :wip2 test "same user can not report a comment twice", ~m(community job_attrs user)a do {:ok, job} = CMS.create_content(community, :job, job_attrs, user) diff --git a/test/groupher_server/cms/abuse_reports/post_report_test.exs b/test/groupher_server/cms/abuse_reports/post_report_test.exs index f54ad6d31..9d487634d 100644 --- a/test/groupher_server/cms/abuse_reports/post_report_test.exs +++ b/test/groupher_server/cms/abuse_reports/post_report_test.exs @@ -17,7 +17,7 @@ defmodule GroupherServer.Test.CMS.AbuseReports.PostReport do end describe "[article post report/unreport]" do - @tag :wip3 + @tag :wip2 test "list article reports should work", ~m(community user user2 post_attrs)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) {:ok, _report} = CMS.report_article(:post, post.id, "reason", "attr_info", user) @@ -31,7 +31,7 @@ defmodule GroupherServer.Test.CMS.AbuseReports.PostReport do assert report.article.thread == :post end - @tag :wip3 + @tag :wip2 test "report a post should have a abuse report record", ~m(community user post_attrs)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) {:ok, _report} = CMS.report_article(:post, post.id, "reason", "attr_info", user) @@ -48,11 +48,11 @@ defmodule GroupherServer.Test.CMS.AbuseReports.PostReport do assert List.first(report_cases).user.login == user.login {:ok, post} = ORM.find(CMS.Post, post.id) - assert post.is_reported + assert not post.is_reported assert post.meta.reported_count == 1 end - @tag :wip3 + @tag :wip2 test "can undo a report", ~m(community user post_attrs)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) {:ok, _report} = CMS.report_article(:post, post.id, "reason", "attr_info", user) @@ -63,7 +63,7 @@ defmodule GroupherServer.Test.CMS.AbuseReports.PostReport do assert all_reports.total_count == 0 end - @tag :wip3 + @tag :wip2 test "can undo a report with other user report it too", ~m(community user user2 post_attrs)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) @@ -90,7 +90,7 @@ defmodule GroupherServer.Test.CMS.AbuseReports.PostReport do assert Enum.any?(report.report_cases, &(&1.user.login == user2.login)) end - @tag :wip3 + @tag :wip2 test "different user report a comment should have same report with different report cases", ~m(community user user2 post_attrs)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) @@ -112,7 +112,7 @@ defmodule GroupherServer.Test.CMS.AbuseReports.PostReport do assert List.last(report_cases).user.login == user2.login end - @tag :wip3 + @tag :wip2 test "same user can not report a comment twice", ~m(community post_attrs user)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) 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 7c3cc5369..3cc538cc6 100644 --- a/test/groupher_server/cms/comments/job_comment_emotions_test.exs +++ b/test/groupher_server/cms/comments/job_comment_emotions_test.exs @@ -21,7 +21,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentEmotions do end describe "[emotion in paged article comment]" do - @tag :wip3 + @tag :wip2 test "login user should got viewer has emotioned status", ~m(job user)a do total_count = 0 page_number = 10 @@ -76,7 +76,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentEmotions do assert @default_emotions == emotions end - @tag :wip3 + @tag :wip2 test "can make emotion to comment", ~m(job user user2)a do parent_content = "parent comment" {:ok, parent_comment} = CMS.create_article_comment(:job, job.id, parent_content, user) @@ -91,7 +91,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentEmotions do assert user_exist_in?(user2, emotions.latest_downvote_users) end - @tag :wip3 + @tag :wip2 test "can undo emotion to comment", ~m(job user user2)a do parent_content = "parent comment" {:ok, parent_comment} = CMS.create_article_comment(:job, job.id, parent_content, user) @@ -114,7 +114,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentEmotions do assert not user_exist_in?(user2, emotions.latest_downvote_users) end - @tag :wip3 + @tag :wip2 test "same user make same emotion to same comment.", ~m(job user)a do parent_content = "parent comment" {:ok, parent_comment} = CMS.create_article_comment(:job, job.id, parent_content, user) @@ -128,7 +128,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentEmotions do assert user_exist_in?(user, parent_comment.emotions.latest_downvote_users) end - @tag :wip3 + @tag :wip2 test "same user same emotion to same comment only have one user_emotion record", ~m(job user)a do parent_content = "parent comment" @@ -152,7 +152,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentEmotions do assert record.heart end - @tag :wip3 + @tag :wip2 test "different user can make same emotions on same comment", ~m(job user user2 user3)a do {:ok, parent_comment} = CMS.create_article_comment(:job, job.id, "parent comment", 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 6a127ca62..67081286f 100644 --- a/test/groupher_server/cms/comments/job_comment_replies_test.exs +++ b/test/groupher_server/cms/comments/job_comment_replies_test.exs @@ -33,7 +33,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentReplies do assert exist_in?(replyed_comment, parent_comment.replies) end - @tag :wip3 + @tag :wip2 test "deleted comment can not be reply", ~m(job user user2)a do parent_content = "parent comment" reply_content = "reply comment" @@ -64,7 +64,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentReplies do assert exist_in?(replyed_comment_2, parent_comment.replies) end - @tag :wip3 + @tag :wip2 test "reply to reply inside a comment should belong same parent comment", ~m(job user user2)a do {:ok, parent_comment} = CMS.create_article_comment(:job, job.id, "parent comment", user) @@ -90,7 +90,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentReplies do assert replyed_comment_3.reply_to_id == replyed_comment_2.id end - @tag :wip3 + @tag :wip2 test "reply to reply inside a comment should have is_reply_to_others flag in meta", ~m(job user user2)a do {:ok, parent_comment} = CMS.create_article_comment(:job, job.id, "parent comment", user) @@ -110,7 +110,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentReplies do assert replyed_comment_3.meta.is_reply_to_others end - @tag :wip3 + @tag :wip2 test "comment replies only contains @max_parent_replies_count replies", ~m(job user)a do total_reply_count = @max_parent_replies_count + 1 diff --git a/test/groupher_server/cms/comments/job_comment_test.exs b/test/groupher_server/cms/comments/job_comment_test.exs index 35a795f86..e934d1255 100644 --- a/test/groupher_server/cms/comments/job_comment_test.exs +++ b/test/groupher_server/cms/comments/job_comment_test.exs @@ -39,7 +39,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do assert comment.meta |> Map.from_struct() |> Map.delete(:id) == @default_comment_meta end - @tag :wip3 + @tag :wip2 test "comment can be updated", ~m(job user)a do {:ok, comment} = CMS.create_article_comment(:job, job.id, "job comment", user) @@ -130,7 +130,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do assert comment.meta.is_article_author_upvoted end - @tag :wip3 + @tag :wip2 test "user upvote job comment will add id to upvoted_user_ids", ~m(job user)a do comment = "job_comment" {:ok, comment} = CMS.create_article_comment(:job, job.id, comment, user) @@ -139,7 +139,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do assert user.id in comment.meta.upvoted_user_ids end - @tag :wip3 + @tag :wip2 test "user undo upvote job comment will remove id from upvoted_user_ids", ~m(job user user2)a do comment = "job_comment" @@ -463,7 +463,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do assert paged_comments.total_count == total_count end - @tag :wip3 + @tag :wip2 test "paged article comments should not contains folded and repoted comments", ~m(user job)a do total_count = 15 @@ -571,7 +571,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do end describe "[article comment delete]" do - @tag :wip3 + @tag :wip2 test "delete comment still exsit in paged list and content is gone", ~m(user job)a do total_count = 10 page_number = 1 @@ -596,7 +596,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do assert deleted_comment.body_html == @delete_hint end - @tag :wip3 + @tag :wip2 test "delete comment still update article's comments_count field", ~m(user job)a do {:ok, _comment} = CMS.create_article_comment(:job, job.id, "commment", user) {:ok, _comment} = CMS.create_article_comment(:job, job.id, "commment", user) @@ -614,7 +614,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do assert job.article_comments_count == 4 end - @tag :wip3 + @tag :wip2 test "delete comment still delete pined record if needed", ~m(user job)a do total_count = 10 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 0e55ecfd3..02665c31c 100644 --- a/test/groupher_server/cms/comments/post_comment_emotions_test.exs +++ b/test/groupher_server/cms/comments/post_comment_emotions_test.exs @@ -21,7 +21,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostCommentEmotions do end describe "[emotion in paged article comment]" do - @tag :wip3 + @tag :wip2 test "login user should got viewer has emotioned status", ~m(post user)a do total_count = 0 page_number = 10 @@ -76,7 +76,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostCommentEmotions do assert @default_emotions == emotions end - @tag :wip3 + @tag :wip2 test "can make emotion to comment", ~m(post user user2)a do parent_content = "parent comment" {:ok, parent_comment} = CMS.create_article_comment(:post, post.id, parent_content, user) @@ -91,7 +91,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostCommentEmotions do assert user_exist_in?(user2, emotions.latest_downvote_users) end - @tag :wip3 + @tag :wip2 test "can undo emotion to comment", ~m(post user user2)a do parent_content = "parent comment" {:ok, parent_comment} = CMS.create_article_comment(:post, post.id, parent_content, user) @@ -114,7 +114,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostCommentEmotions do assert not user_exist_in?(user2, emotions.latest_downvote_users) end - @tag :wip3 + @tag :wip2 test "same user make same emotion to same comment.", ~m(post user)a do parent_content = "parent comment" {:ok, parent_comment} = CMS.create_article_comment(:post, post.id, parent_content, user) @@ -128,7 +128,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostCommentEmotions do assert user_exist_in?(user, parent_comment.emotions.latest_downvote_users) end - @tag :wip3 + @tag :wip2 test "same user same emotion to same comment only have one user_emotion record", ~m(post user)a do parent_content = "parent comment" @@ -152,7 +152,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostCommentEmotions do assert record.heart end - @tag :wip3 + @tag :wip2 test "different user can make same emotions on same comment", ~m(post user user2 user3)a do {:ok, parent_comment} = CMS.create_article_comment(:post, post.id, "parent comment", 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 d7508fa62..fc968d208 100644 --- a/test/groupher_server/cms/comments/post_comment_replies_test.exs +++ b/test/groupher_server/cms/comments/post_comment_replies_test.exs @@ -33,7 +33,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostCommentReplies do assert exist_in?(replyed_comment, parent_comment.replies) end - @tag :wip3 + @tag :wip2 test "deleted comment can not be reply", ~m(post user user2)a do parent_content = "parent comment" reply_content = "reply comment" @@ -64,7 +64,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostCommentReplies do assert exist_in?(replyed_comment_2, parent_comment.replies) end - @tag :wip3 + @tag :wip2 test "reply to reply inside a comment should belong same parent comment", ~m(post user user2)a do {:ok, parent_comment} = CMS.create_article_comment(:post, post.id, "parent comment", user) @@ -90,7 +90,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostCommentReplies do assert replyed_comment_3.reply_to_id == replyed_comment_2.id end - @tag :wip3 + @tag :wip2 test "reply to reply inside a comment should have is_reply_to_others flag in meta", ~m(post user user2)a do {:ok, parent_comment} = CMS.create_article_comment(:post, post.id, "parent comment", user) @@ -110,7 +110,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostCommentReplies do assert replyed_comment_3.meta.is_reply_to_others end - @tag :wip3 + @tag :wip2 test "comment replies only contains @max_parent_replies_count replies", ~m(post user)a do total_reply_count = @max_parent_replies_count + 1 @@ -160,7 +160,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostCommentReplies do end describe "[paged article comment replies]" do - @tag :wip3 + @tag :wip2 test "can get paged replies of a parent comment", ~m(post user)a do {:ok, parent_comment} = CMS.create_article_comment(:post, post.id, "parent_conent", user) {:ok, paged_replies} = CMS.list_comment_replies(parent_comment.id, %{page: 1, size: 20}) diff --git a/test/groupher_server/cms/comments/post_comment_test.exs b/test/groupher_server/cms/comments/post_comment_test.exs index 520cfa7ac..d01cb5813 100644 --- a/test/groupher_server/cms/comments/post_comment_test.exs +++ b/test/groupher_server/cms/comments/post_comment_test.exs @@ -39,7 +39,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do assert comment.meta |> Map.from_struct() |> Map.delete(:id) == @default_comment_meta end - @tag :wip3 + @tag :wip2 test "comment can be updated", ~m(post user)a do {:ok, comment} = CMS.create_article_comment(:post, post.id, "post comment", user) @@ -130,7 +130,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do assert comment.meta.is_article_author_upvoted end - @tag :wip3 + @tag :wip2 test "user upvote post comment will add id to upvoted_user_ids", ~m(post user)a do comment = "post_comment" {:ok, comment} = CMS.create_article_comment(:post, post.id, comment, user) @@ -139,7 +139,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do assert user.id in comment.meta.upvoted_user_ids end - @tag :wip3 + @tag :wip2 test "user undo upvote post comment will remove id from upvoted_user_ids", ~m(post user user2)a do comment = "post_comment" @@ -282,7 +282,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do assert comment.is_reported end - @tag :wip3 + @tag :wip2 test "user can unreport a comment", ~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) @@ -463,7 +463,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do assert paged_comments.total_count == total_count end - @tag :wip3 + @tag :wip2 test "paged article comments should not contains folded and repoted comments", ~m(user post)a do total_count = 15 @@ -571,7 +571,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do end describe "[article comment delete]" do - @tag :wip3 + @tag :wip2 test "delete comment still exsit in paged list and content is gone", ~m(user post)a do total_count = 10 page_number = 1 @@ -596,7 +596,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do assert deleted_comment.body_html == @delete_hint end - @tag :wip3 + @tag :wip2 test "delete comment still update article's comments_count field", ~m(user post)a do {:ok, _comment} = CMS.create_article_comment(:post, post.id, "commment", user) {:ok, _comment} = CMS.create_article_comment(:post, post.id, "commment", user) @@ -614,7 +614,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do assert post.article_comments_count == 4 end - @tag :wip3 + @tag :wip2 test "delete comment still delete pined record if needed", ~m(user post)a do total_count = 10 diff --git a/test/groupher_server/cms/emotions/job_emotions_test.exs b/test/groupher_server/cms/emotions/job_emotions_test.exs index 699214674..bd822186b 100644 --- a/test/groupher_server/cms/emotions/job_emotions_test.exs +++ b/test/groupher_server/cms/emotions/job_emotions_test.exs @@ -22,7 +22,7 @@ defmodule GroupherServer.Test.CMS.Emotions.JobEmotions do end describe "[emotion in paged jobs]" do - @tag :wip3 + @tag :wip2 test "login user should got viewer has emotioned status", ~m(community job_attrs user)a do total_count = 10 @@ -61,7 +61,7 @@ defmodule GroupherServer.Test.CMS.Emotions.JobEmotions do end describe "[basic article emotion]" do - @tag :wip3 + @tag :wip2 test "job has default emotions after created", ~m(community job_attrs user)a do {:ok, job} = CMS.create_content(community, :job, job_attrs, user) @@ -69,7 +69,7 @@ defmodule GroupherServer.Test.CMS.Emotions.JobEmotions do assert @default_emotions == emotions end - @tag :wip3 + @tag :wip2 test "can make emotion to job", ~m(community job_attrs user user2)a do {:ok, job} = CMS.create_content(community, :job, job_attrs, user) @@ -83,7 +83,7 @@ defmodule GroupherServer.Test.CMS.Emotions.JobEmotions do assert user_exist_in?(user2, emotions.latest_downvote_users) end - @tag :wip3 + @tag :wip2 test "can undo emotion to job", ~m(community job_attrs user user2)a do {:ok, job} = CMS.create_content(community, :job, job_attrs, user) @@ -100,7 +100,7 @@ defmodule GroupherServer.Test.CMS.Emotions.JobEmotions do assert not user_exist_in?(user2, emotions.latest_downvote_users) end - @tag :wip3 + @tag :wip2 test "same user make same emotion to same job.", ~m(community job_attrs user)a do {:ok, job} = CMS.create_content(community, :job, job_attrs, user) @@ -113,7 +113,7 @@ defmodule GroupherServer.Test.CMS.Emotions.JobEmotions do assert user_exist_in?(user, job.emotions.latest_downvote_users) end - @tag :wip3 + @tag :wip2 test "same user same emotion to same job only have one user_emotion record", ~m(community job_attrs user)a do {:ok, job} = CMS.create_content(community, :job, job_attrs, user) @@ -131,7 +131,7 @@ defmodule GroupherServer.Test.CMS.Emotions.JobEmotions do assert record.heart end - @tag :wip3 + @tag :wip2 test "different user can make same emotions on same job", ~m(community job_attrs user user2 user3)a do {:ok, job} = CMS.create_content(community, :job, job_attrs, user) @@ -148,7 +148,7 @@ defmodule GroupherServer.Test.CMS.Emotions.JobEmotions do assert user_exist_in?(user3, emotions.latest_beer_users) end - @tag :wip3 + @tag :wip2 test "same user can make differcent emotions on same job", ~m(community job_attrs user)a do {:ok, job} = CMS.create_content(community, :job, job_attrs, user) diff --git a/test/groupher_server/cms/emotions/post_emotions_test.exs b/test/groupher_server/cms/emotions/post_emotions_test.exs index 24a10fce8..2624b43d3 100644 --- a/test/groupher_server/cms/emotions/post_emotions_test.exs +++ b/test/groupher_server/cms/emotions/post_emotions_test.exs @@ -22,7 +22,7 @@ defmodule GroupherServer.Test.CMS.Emotions.PostEmotions do end describe "[emotion in paged posts]" do - @tag :wip3 + @tag :wip2 test "login user should got viewer has emotioned status", ~m(community post_attrs user)a do total_count = 10 @@ -61,7 +61,7 @@ defmodule GroupherServer.Test.CMS.Emotions.PostEmotions do end describe "[basic article emotion]" do - @tag :wip3 + @tag :wip2 test "post has default emotions after created", ~m(community post_attrs user)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) @@ -69,7 +69,7 @@ defmodule GroupherServer.Test.CMS.Emotions.PostEmotions do assert @default_emotions == emotions end - @tag :wip3 + @tag :wip2 test "can make emotion to post", ~m(community post_attrs user user2)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) @@ -83,7 +83,7 @@ defmodule GroupherServer.Test.CMS.Emotions.PostEmotions do assert user_exist_in?(user2, emotions.latest_downvote_users) end - @tag :wip3 + @tag :wip2 test "can undo emotion to post", ~m(community post_attrs user user2)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) @@ -100,7 +100,7 @@ defmodule GroupherServer.Test.CMS.Emotions.PostEmotions do assert not user_exist_in?(user2, emotions.latest_downvote_users) end - @tag :wip3 + @tag :wip2 test "same user make same emotion to same post.", ~m(community post_attrs user)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) @@ -113,7 +113,7 @@ defmodule GroupherServer.Test.CMS.Emotions.PostEmotions do assert user_exist_in?(user, post.emotions.latest_downvote_users) end - @tag :wip3 + @tag :wip2 test "same user same emotion to same post only have one user_emotion record", ~m(community post_attrs user)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) @@ -131,7 +131,7 @@ defmodule GroupherServer.Test.CMS.Emotions.PostEmotions do assert record.heart end - @tag :wip3 + @tag :wip2 test "different user can make same emotions on same post", ~m(community post_attrs user user2 user3)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) @@ -148,7 +148,7 @@ defmodule GroupherServer.Test.CMS.Emotions.PostEmotions do assert user_exist_in?(user3, emotions.latest_beer_users) end - @tag :wip3 + @tag :wip2 test "same user can make differcent emotions on same post", ~m(community post_attrs user)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) diff --git a/test/groupher_server/cms/job_test.exs b/test/groupher_server/cms/job_test.exs index 6d924a25f..297468cd6 100644 --- a/test/groupher_server/cms/job_test.exs +++ b/test/groupher_server/cms/job_test.exs @@ -25,7 +25,7 @@ defmodule GroupherServer.Test.Job do assert found.title == job.title end - @tag :wip3 + @tag :wip2 test "read job should update views and meta viewed_user_list", ~m(job_attrs community user user2)a do {:ok, job} = CMS.create_content(community, :job, job_attrs, user) diff --git a/test/groupher_server/cms/post_test.exs b/test/groupher_server/cms/post_test.exs index eae07914a..f028aece3 100644 --- a/test/groupher_server/cms/post_test.exs +++ b/test/groupher_server/cms/post_test.exs @@ -18,7 +18,7 @@ defmodule GroupherServer.Test.CMS.Post do describe "[cms post curd]" do alias CMS.{Author, Community} - @tag :wip3 + @tag :wip2 test "can create post with valid attrs", ~m(user community post_attrs)a do assert {:error, _} = ORM.find_by(Author, user_id: user.id) @@ -27,7 +27,7 @@ defmodule GroupherServer.Test.CMS.Post do assert post.title == post_attrs.title end - @tag :wip3 + @tag :wip2 test "read post should update views and meta viewed_user_list", ~m(post_attrs community user user2)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) diff --git a/test/groupher_server/cms/repo_test.exs b/test/groupher_server/cms/repo_test.exs index 0446b00c5..69b65a579 100644 --- a/test/groupher_server/cms/repo_test.exs +++ b/test/groupher_server/cms/repo_test.exs @@ -17,7 +17,7 @@ defmodule GroupherServer.Test.Repo do describe "[cms repo curd]" do alias CMS.{Author, Community} - @tag :wip3 + @tag :wip2 test "can create repo with valid attrs", ~m(user community repo_attrs)a do assert {:error, _} = ORM.find_by(Author, user_id: user.id) @@ -27,7 +27,7 @@ defmodule GroupherServer.Test.Repo do assert repo.contributors |> length !== 0 end - @tag :wip3 + @tag :wip2 test "read repo should update views and meta viewed_user_list", ~m(repo_attrs community user user2)a do {:ok, repo} = CMS.create_content(community, :repo, repo_attrs, user) diff --git a/test/groupher_server/cms/upvotes/job_upvote_test.exs b/test/groupher_server/cms/upvotes/job_upvote_test.exs index 18286922b..daf36dd6c 100644 --- a/test/groupher_server/cms/upvotes/job_upvote_test.exs +++ b/test/groupher_server/cms/upvotes/job_upvote_test.exs @@ -15,7 +15,7 @@ defmodule GroupherServer.Test.Upvotes.JobUpvote do end describe "[cms job upvote]" do - @tag :wip3 + @tag :wip2 test "job can be upvote && upvotes_count should inc by 1", ~m(user user2 community job_attrs)a do {:ok, job} = CMS.create_content(community, :job, job_attrs, user) @@ -28,7 +28,7 @@ defmodule GroupherServer.Test.Upvotes.JobUpvote do assert article.upvotes_count == 2 end - @tag :wip3 + @tag :wip2 test "job can be undo upvote && upvotes_count should dec by 1", ~m(user user2 community job_attrs)a do {:ok, job} = CMS.create_content(community, :job, job_attrs, user) @@ -41,7 +41,7 @@ defmodule GroupherServer.Test.Upvotes.JobUpvote do assert article.upvotes_count == 0 end - @tag :wip3 + @tag :wip2 test "can get upvotes_users", ~m(user user2 community job_attrs)a do {:ok, job} = CMS.create_content(community, :job, job_attrs, user) @@ -55,7 +55,7 @@ defmodule GroupherServer.Test.Upvotes.JobUpvote do assert user_exist_in?(user2, users.entries) end - @tag :wip3 + @tag :wip2 test "job meta history should be updated after upvote", ~m(user user2 community job_attrs)a do {:ok, job} = CMS.create_content(community, :job, job_attrs, user) @@ -67,7 +67,7 @@ defmodule GroupherServer.Test.Upvotes.JobUpvote do assert user2.id in article.meta.upvoted_user_ids end - @tag :wip3 + @tag :wip2 test "job meta history should be updated after undo upvote", ~m(user user2 community job_attrs)a do {:ok, job} = CMS.create_content(community, :job, job_attrs, user) diff --git a/test/groupher_server/cms/upvotes/post_upvote_test.exs b/test/groupher_server/cms/upvotes/post_upvote_test.exs index 5cf2c8ed8..fda68d1d1 100644 --- a/test/groupher_server/cms/upvotes/post_upvote_test.exs +++ b/test/groupher_server/cms/upvotes/post_upvote_test.exs @@ -15,7 +15,7 @@ defmodule GroupherServer.Test.Upvotes.PostUpvote do end describe "[cms post upvote]" do - @tag :wip3 + @tag :wip2 test "post can be upvote && upvotes_count should inc by 1", ~m(user user2 community post_attrs)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) @@ -28,7 +28,7 @@ defmodule GroupherServer.Test.Upvotes.PostUpvote do assert article.upvotes_count == 2 end - @tag :wip3 + @tag :wip2 test "post can be undo upvote && upvotes_count should dec by 1", ~m(user user2 community post_attrs)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) @@ -41,7 +41,7 @@ defmodule GroupherServer.Test.Upvotes.PostUpvote do assert article.upvotes_count == 0 end - @tag :wip3 + @tag :wip2 test "can get upvotes_users", ~m(user user2 community post_attrs)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) @@ -55,7 +55,7 @@ defmodule GroupherServer.Test.Upvotes.PostUpvote do assert user_exist_in?(user2, users.entries) end - @tag :wip3 + @tag :wip2 test "post meta history should be updated after upvote", ~m(user user2 community post_attrs)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) @@ -67,7 +67,7 @@ defmodule GroupherServer.Test.Upvotes.PostUpvote do assert user2.id in article.meta.upvoted_user_ids end - @tag :wip3 + @tag :wip2 test "post meta history should be updated after undo upvote", ~m(user user2 community post_attrs)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) diff --git a/test/groupher_server_web/mutation/accounts/customization_test.exs b/test/groupher_server_web/mutation/accounts/customization_test.exs index 8f42ad231..de3de03cd 100644 --- a/test/groupher_server_web/mutation/accounts/customization_test.exs +++ b/test/groupher_server_web/mutation/accounts/customization_test.exs @@ -72,7 +72,7 @@ defmodule GroupherServer.Test.Mutation.Account.Customization do } } """ - @tag :wip3 + @tag :wip2 test "PageSizeProof middleware should lint c11n displayDensity size", ~m(user)a do user_conn = simu_conn(:user, user) db_insert_multi(:post, 50) diff --git a/test/groupher_server_web/mutation/cms/articles/job_emotion_test.exs b/test/groupher_server_web/mutation/cms/articles/job_emotion_test.exs index b822aff94..428036419 100644 --- a/test/groupher_server_web/mutation/cms/articles/job_emotion_test.exs +++ b/test/groupher_server_web/mutation/cms/articles/job_emotion_test.exs @@ -32,7 +32,7 @@ defmodule GroupherServer.Test.Mutation.Articles.JobEmotion do } } """ - @tag :wip3 + @tag :wip2 test "login user can emotion to a pjob", ~m(community job_attrs user user_conn)a do {:ok, job} = CMS.create_content(community, :job, job_attrs, user) @@ -58,7 +58,7 @@ defmodule GroupherServer.Test.Mutation.Articles.JobEmotion do } } """ - @tag :wip3 + @tag :wip2 test "login user can undo emotion to a job", ~m(community job_attrs user owner_conn)a do {:ok, job} = CMS.create_content(community, :job, job_attrs, user) {:ok, _} = CMS.emotion_to_article(:job, job.id, :beer, user) diff --git a/test/groupher_server_web/mutation/cms/articles/job_report_test.exs b/test/groupher_server_web/mutation/cms/articles/job_report_test.exs index 4e17dd534..310226193 100644 --- a/test/groupher_server_web/mutation/cms/articles/job_report_test.exs +++ b/test/groupher_server_web/mutation/cms/articles/job_report_test.exs @@ -26,7 +26,7 @@ defmodule GroupherServer.Test.Mutation.Articles.JobReport do } } """ - @tag :wip3 + @tag :wip2 test "login user can report a job", ~m(community job_attrs user user_conn)a do {:ok, job} = CMS.create_content(community, :job, job_attrs, user) @@ -46,7 +46,7 @@ defmodule GroupherServer.Test.Mutation.Articles.JobReport do } } """ - @tag :wip3 + @tag :wip2 test "login user can undo report a job", ~m(community job_attrs user user_conn)a do {:ok, job} = CMS.create_content(community, :job, job_attrs, user) diff --git a/test/groupher_server_web/mutation/cms/articles/job_test.exs b/test/groupher_server_web/mutation/cms/articles/job_test.exs index c269abc50..e8875e3be 100644 --- a/test/groupher_server_web/mutation/cms/articles/job_test.exs +++ b/test/groupher_server_web/mutation/cms/articles/job_test.exs @@ -282,7 +282,7 @@ defmodule GroupherServer.Test.Mutation.Articles.Job do } } """ - @tag :wip3 + @tag :wip2 test "can delete a job by job's owner", ~m(owner_conn job)a do deleted = owner_conn |> mutation_result(@query, %{id: job.id}, "deleteJob") diff --git a/test/groupher_server_web/mutation/cms/articles/post_emotion_test.exs b/test/groupher_server_web/mutation/cms/articles/post_emotion_test.exs index 30c37a5e4..0d4196d7d 100644 --- a/test/groupher_server_web/mutation/cms/articles/post_emotion_test.exs +++ b/test/groupher_server_web/mutation/cms/articles/post_emotion_test.exs @@ -32,7 +32,7 @@ defmodule GroupherServer.Test.Mutation.Articles.PostEmotion do } } """ - @tag :wip3 + @tag :wip2 test "login user can emotion to a ppost", ~m(community post_attrs user user_conn)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) @@ -58,7 +58,7 @@ defmodule GroupherServer.Test.Mutation.Articles.PostEmotion do } } """ - @tag :wip3 + @tag :wip2 test "login user can undo emotion to a post", ~m(community post_attrs user owner_conn)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) {:ok, _} = CMS.emotion_to_article(:post, post.id, :beer, user) diff --git a/test/groupher_server_web/mutation/cms/articles/post_report_test.exs b/test/groupher_server_web/mutation/cms/articles/post_report_test.exs index 2596bdbcb..876b38f16 100644 --- a/test/groupher_server_web/mutation/cms/articles/post_report_test.exs +++ b/test/groupher_server_web/mutation/cms/articles/post_report_test.exs @@ -26,7 +26,7 @@ defmodule GroupherServer.Test.Mutation.Articles.PostReport do } } """ - @tag :wip3 + @tag :wip2 test "login user can report a post", ~m(community post_attrs user user_conn)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) @@ -46,7 +46,7 @@ defmodule GroupherServer.Test.Mutation.Articles.PostReport do } } """ - @tag :wip3 + @tag :wip2 test "login user can undo report a post", ~m(community post_attrs user user_conn)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) 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 ac96ddaa2..8def50861 100644 --- a/test/groupher_server_web/mutation/cms/articles/post_test.exs +++ b/test/groupher_server_web/mutation/cms/articles/post_test.exs @@ -142,7 +142,7 @@ defmodule GroupherServer.Test.Mutation.Articles.Post do } } """ - @tag :wip3 + @tag :wip2 test "delete a post by post's owner", ~m(owner_conn post)a do deleted = owner_conn |> mutation_result(@query, %{id: post.id}, "deletePost") diff --git a/test/groupher_server_web/mutation/cms/articles/repo_report_test.exs b/test/groupher_server_web/mutation/cms/articles/repo_report_test.exs index 99a085be1..2802f7a22 100644 --- a/test/groupher_server_web/mutation/cms/articles/repo_report_test.exs +++ b/test/groupher_server_web/mutation/cms/articles/repo_report_test.exs @@ -26,7 +26,7 @@ defmodule GroupherServer.Test.Mutation.Articles.RepoReport do } } """ - @tag :wip3 + @tag :wip2 test "login user can report a repo", ~m(community repo_attrs user user_conn)a do {:ok, repo} = CMS.create_content(community, :repo, repo_attrs, user) @@ -46,7 +46,7 @@ defmodule GroupherServer.Test.Mutation.Articles.RepoReport do } } """ - @tag :wip3 + @tag :wip2 test "login user can undo report a repo", ~m(community repo_attrs user user_conn)a do {:ok, repo} = CMS.create_content(community, :repo, repo_attrs, user) diff --git a/test/groupher_server_web/mutation/cms/articles/repo_test.exs b/test/groupher_server_web/mutation/cms/articles/repo_test.exs index afedc0217..ff70a48e0 100644 --- a/test/groupher_server_web/mutation/cms/articles/repo_test.exs +++ b/test/groupher_server_web/mutation/cms/articles/repo_test.exs @@ -193,7 +193,7 @@ defmodule GroupherServer.Test.Mutation.Articles.Repo do } } """ - @tag :wip3 + @tag :wip2 test "delete a repo by repo's owner", ~m(owner_conn repo)a do deleted = owner_conn |> mutation_result(@query, %{id: repo.id}, "deleteRepo") @@ -201,7 +201,7 @@ defmodule GroupherServer.Test.Mutation.Articles.Repo do assert {:error, _} = ORM.find(CMS.Repo, deleted["id"]) end - @tag :wip3 + @tag :wip2 test "can delete a repo by auth user", ~m(repo)a do belongs_community_title = repo.communities |> List.first() |> Map.get(:title) rule_conn = simu_conn(:user, cms: %{belongs_community_title => %{"repo.delete" => true}}) @@ -212,7 +212,7 @@ defmodule GroupherServer.Test.Mutation.Articles.Repo do assert {:error, _} = ORM.find(CMS.Repo, deleted["id"]) end - @tag :wip3 + @tag :wip2 test "delete a repo without login user fails", ~m(guest_conn repo)a do assert guest_conn |> mutation_get_error?(@query, %{id: repo.id}, ecode(:account_login)) end diff --git a/test/groupher_server_web/mutation/cms/cms_test.exs b/test/groupher_server_web/mutation/cms/cms_test.exs index 158431643..9a2bd8d88 100644 --- a/test/groupher_server_web/mutation/cms/cms_test.exs +++ b/test/groupher_server_web/mutation/cms/cms_test.exs @@ -431,7 +431,7 @@ defmodule GroupherServer.Test.Mutation.CMS.Basic do } } """ - @tag :wip3 + @tag :wip2 test "auth user can create thread", ~m(user)a do title = "post" raw = "POST" @@ -445,7 +445,7 @@ defmodule GroupherServer.Test.Mutation.CMS.Basic do assert result["title"] == title end - @tag :wip3 + @tag :wip2 test "unauth user create thread fails", ~m(user_conn guest_conn)a do title = "psot" raw = "POST" diff --git a/test/groupher_server_web/mutation/cms/comments/job_comment_test.exs b/test/groupher_server_web/mutation/cms/comments/job_comment_test.exs index 3161d7018..aea2e5a99 100644 --- a/test/groupher_server_web/mutation/cms/comments/job_comment_test.exs +++ b/test/groupher_server_web/mutation/cms/comments/job_comment_test.exs @@ -24,7 +24,7 @@ defmodule GroupherServer.Test.Mutation.Comments.JobComment do } } """ - @tag :wip3 + @tag :wip2 test "write article comment to a exsit job", ~m(job user_conn)a do comment = "a test comment" variables = %{thread: "JOB", id: job.id, content: comment} @@ -43,7 +43,7 @@ defmodule GroupherServer.Test.Mutation.Comments.JobComment do } } """ - @tag :wip3 + @tag :wip2 test "login user can reply to a comment", ~m(job user user_conn)a do {:ok, comment} = CMS.create_article_comment(:job, job.id, "commment", user) variables = %{id: comment.id, content: "reply content"} @@ -63,7 +63,7 @@ defmodule GroupherServer.Test.Mutation.Comments.JobComment do } } """ - @tag :wip3 + @tag :wip2 test "only owner can update a exsit comment", ~m(job user guest_conn user_conn owner_conn)a do {:ok, comment} = CMS.create_article_comment(:job, job.id, "job comment", user) @@ -88,7 +88,7 @@ defmodule GroupherServer.Test.Mutation.Comments.JobComment do } } """ - @tag :wip3 + @tag :wip2 test "only owner can delete a exsit comment", ~m(job user guest_conn user_conn owner_conn)a do {:ok, comment} = CMS.create_article_comment(:job, job.id, "job comment", user) @@ -123,7 +123,7 @@ defmodule GroupherServer.Test.Mutation.Comments.JobComment do } } """ - @tag :wip3 + @tag :wip2 test "login user can emotion to a comment", ~m(job user user_conn)a do {:ok, comment} = CMS.create_article_comment(:job, job.id, "job comment", user) variables = %{id: comment.id, emotion: "BEER"} @@ -150,7 +150,7 @@ defmodule GroupherServer.Test.Mutation.Comments.JobComment do } } """ - @tag :wip3 + @tag :wip2 test "login user can undo emotion to a comment", ~m(job user owner_conn)a do {:ok, comment} = CMS.create_article_comment(:job, job.id, "job comment", user) {:ok, _} = CMS.emotion_to_comment(comment.id, :beer, user) diff --git a/test/groupher_server_web/mutation/cms/comments/post_comment_test.exs b/test/groupher_server_web/mutation/cms/comments/post_comment_test.exs index 9a8ec7d86..2e4fad36e 100644 --- a/test/groupher_server_web/mutation/cms/comments/post_comment_test.exs +++ b/test/groupher_server_web/mutation/cms/comments/post_comment_test.exs @@ -24,7 +24,7 @@ defmodule GroupherServer.Test.Mutation.Comments.PostComment do } } """ - @tag :wip3 + @tag :wip2 test "write article comment to a exsit post", ~m(post user_conn)a do comment = "a test comment" variables = %{thread: "POST", id: post.id, content: comment} @@ -43,7 +43,7 @@ defmodule GroupherServer.Test.Mutation.Comments.PostComment do } } """ - @tag :wip3 + @tag :wip2 test "login user can reply to a comment", ~m(post user user_conn)a do {:ok, comment} = CMS.create_article_comment(:post, post.id, "commment", user) variables = %{id: comment.id, content: "reply content"} @@ -63,7 +63,7 @@ defmodule GroupherServer.Test.Mutation.Comments.PostComment do } } """ - @tag :wip3 + @tag :wip2 test "only owner can update a exsit comment", ~m(post user guest_conn user_conn owner_conn)a do {:ok, comment} = CMS.create_article_comment(:post, post.id, "post comment", user) @@ -88,7 +88,7 @@ defmodule GroupherServer.Test.Mutation.Comments.PostComment do } } """ - @tag :wip3 + @tag :wip2 test "only owner can delete a exsit comment", ~m(post user guest_conn user_conn owner_conn)a do {:ok, comment} = CMS.create_article_comment(:post, post.id, "post comment", user) @@ -123,7 +123,7 @@ defmodule GroupherServer.Test.Mutation.Comments.PostComment do } } """ - @tag :wip3 + @tag :wip2 test "login user can emotion to a comment", ~m(post user user_conn)a do {:ok, comment} = CMS.create_article_comment(:post, post.id, "post comment", user) variables = %{id: comment.id, emotion: "BEER"} @@ -150,7 +150,7 @@ defmodule GroupherServer.Test.Mutation.Comments.PostComment do } } """ - @tag :wip3 + @tag :wip2 test "login user can undo emotion to a comment", ~m(post user owner_conn)a do {:ok, comment} = CMS.create_article_comment(:post, post.id, "post comment", user) {:ok, _} = CMS.emotion_to_comment(comment.id, :beer, user) diff --git a/test/groupher_server_web/mutation/cms/flags/job_flag_test.exs b/test/groupher_server_web/mutation/cms/flags/job_flag_test.exs index c9c0fb219..d91b8591e 100644 --- a/test/groupher_server_web/mutation/cms/flags/job_flag_test.exs +++ b/test/groupher_server_web/mutation/cms/flags/job_flag_test.exs @@ -25,7 +25,7 @@ defmodule GroupherServer.Test.Mutation.Flags.JobFlag do } } """ - @tag :wip3 + @tag :wip2 test "auth user can trash job", ~m(community job)a do variables = %{id: job.id, communityId: community.id} @@ -38,7 +38,7 @@ defmodule GroupherServer.Test.Mutation.Flags.JobFlag do assert updated["trash"] == true end - @tag :wip3 + @tag :wip2 test "unauth user trash job fails", ~m(user_conn guest_conn job community)a do variables = %{id: job.id, communityId: community.id} rule_conn = simu_conn(:user, cms: %{"what.ever" => true}) @@ -56,7 +56,7 @@ defmodule GroupherServer.Test.Mutation.Flags.JobFlag do } } """ - @tag :wip3 + @tag :wip2 test "auth user can undo trash job", ~m(community job)a do variables = %{id: job.id, communityId: community.id} @@ -87,7 +87,7 @@ defmodule GroupherServer.Test.Mutation.Flags.JobFlag do } } """ - @tag :wip3 + @tag :wip2 test "auth user can pin job", ~m(community job)a do variables = %{id: job.id, communityId: community.id} @@ -99,7 +99,7 @@ defmodule GroupherServer.Test.Mutation.Flags.JobFlag do assert updated["id"] == to_string(job.id) end - @tag :wip3 + @tag :wip2 test "unauth user pin job fails", ~m(user_conn guest_conn community job)a do variables = %{id: job.id, communityId: community.id} rule_conn = simu_conn(:user, cms: %{"what.ever" => true}) @@ -117,7 +117,7 @@ defmodule GroupherServer.Test.Mutation.Flags.JobFlag do } } """ - @tag :wip3 + @tag :wip2 test "auth user can undo pin job", ~m(community job)a do variables = %{id: job.id, communityId: community.id} @@ -131,7 +131,7 @@ defmodule GroupherServer.Test.Mutation.Flags.JobFlag do assert updated["isPinned"] == false end - @tag :wip3 + @tag :wip2 test "unauth user undo pin job fails", ~m(user_conn guest_conn community job)a do variables = %{id: job.id, communityId: community.id} rule_conn = simu_conn(:user, cms: %{"what.ever" => true}) 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 61d6eacb0..f54f9f9e2 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 } } """ - @tag :wip3 + @tag :wip2 test "auth user can trash post", ~m(community post)a do variables = %{id: post.id, communityId: community.id} @@ -38,7 +38,7 @@ defmodule GroupherServer.Test.Mutation.Flags.PostFlag do assert updated["trash"] == true end - @tag :wip3 + @tag :wip2 test "unauth user trash post fails", ~m(user_conn guest_conn post community)a do variables = %{id: post.id, communityId: community.id} rule_conn = simu_conn(:user, cms: %{"what.ever" => true}) @@ -56,7 +56,7 @@ defmodule GroupherServer.Test.Mutation.Flags.PostFlag do } } """ - @tag :wip3 + @tag :wip2 test "auth user can undo trash post", ~m(community post)a do variables = %{id: post.id, communityId: community.id} @@ -71,7 +71,7 @@ defmodule GroupherServer.Test.Mutation.Flags.PostFlag do assert updated["trash"] == false end - @tag :wip3 + @tag :wip2 test "unauth user undo trash post fails", ~m(user_conn guest_conn community post)a do variables = %{id: post.id, communityId: community.id} rule_conn = simu_conn(:user, cms: %{"what.ever" => true}) @@ -88,7 +88,7 @@ defmodule GroupherServer.Test.Mutation.Flags.PostFlag do } } """ - @tag :wip3 + @tag :wip2 test "auth user can pin post", ~m(community post)a do variables = %{id: post.id, communityId: community.id} @@ -100,7 +100,7 @@ defmodule GroupherServer.Test.Mutation.Flags.PostFlag do assert updated["id"] == to_string(post.id) end - @tag :wip3 + @tag :wip2 test "unauth user pin post fails", ~m(user_conn guest_conn community post)a do variables = %{id: post.id, communityId: community.id} rule_conn = simu_conn(:user, cms: %{"what.ever" => true}) @@ -118,7 +118,7 @@ defmodule GroupherServer.Test.Mutation.Flags.PostFlag do } } """ - @tag :wip3 + @tag :wip2 test "auth user can undo pin post", ~m(community post)a do variables = %{id: post.id, communityId: community.id} @@ -131,7 +131,7 @@ defmodule GroupherServer.Test.Mutation.Flags.PostFlag do assert updated["id"] == to_string(post.id) end - @tag :wip3 + @tag :wip2 test "unauth user undo pin post fails", ~m(user_conn guest_conn community post)a do variables = %{id: post.id, communityId: community.id} rule_conn = simu_conn(:user, cms: %{"what.ever" => true}) diff --git a/test/groupher_server_web/mutation/cms/flags/repo_flag_test.exs b/test/groupher_server_web/mutation/cms/flags/repo_flag_test.exs index 6a3c5270c..2243a0125 100644 --- a/test/groupher_server_web/mutation/cms/flags/repo_flag_test.exs +++ b/test/groupher_server_web/mutation/cms/flags/repo_flag_test.exs @@ -25,7 +25,7 @@ defmodule GroupherServer.Test.Mutation.Flags.RepoFlag do } } """ - @tag :wip3 + @tag :wip2 test "auth user can trash repo", ~m(community repo)a do variables = %{id: repo.id, communityId: community.id} @@ -38,7 +38,7 @@ defmodule GroupherServer.Test.Mutation.Flags.RepoFlag do assert updated["trash"] == true end - @tag :wip3 + @tag :wip2 test "unauth user trash repo fails", ~m(user_conn guest_conn repo community)a do variables = %{id: repo.id, communityId: community.id} rule_conn = simu_conn(:user, cms: %{"what.ever" => true}) @@ -56,7 +56,7 @@ defmodule GroupherServer.Test.Mutation.Flags.RepoFlag do } } """ - @tag :wip3 + @tag :wip2 test "auth user can undo trash repo", ~m(community repo)a do variables = %{id: repo.id, communityId: community.id} @@ -71,7 +71,7 @@ defmodule GroupherServer.Test.Mutation.Flags.RepoFlag do assert updated["trash"] == false end - @tag :wip3 + @tag :wip2 test "unauth user undo trash repo fails", ~m(user_conn guest_conn community repo)a do variables = %{id: repo.id, communityId: community.id} rule_conn = simu_conn(:user, cms: %{"what.ever" => true}) @@ -88,7 +88,7 @@ defmodule GroupherServer.Test.Mutation.Flags.RepoFlag do } } """ - @tag :wip3 + @tag :wip2 test "auth user can pin repo", ~m(community repo)a do variables = %{id: repo.id, communityId: community.id} @@ -100,7 +100,7 @@ defmodule GroupherServer.Test.Mutation.Flags.RepoFlag do assert updated["id"] == to_string(repo.id) end - @tag :wip3 + @tag :wip2 test "unauth user pin repo fails", ~m(user_conn guest_conn community repo)a do variables = %{id: repo.id, communityId: community.id} rule_conn = simu_conn(:user, cms: %{"what.ever" => true}) @@ -118,7 +118,7 @@ defmodule GroupherServer.Test.Mutation.Flags.RepoFlag do } } """ - @tag :wip3 + @tag :wip2 test "auth user can undo pin repo", ~m(community repo)a do variables = %{id: repo.id, communityId: community.id} @@ -131,7 +131,7 @@ defmodule GroupherServer.Test.Mutation.Flags.RepoFlag do assert updated["id"] == to_string(repo.id) end - @tag :wip3 + @tag :wip2 test "unauth user undo pin repo fails", ~m(user_conn guest_conn community repo)a do variables = %{id: repo.id, communityId: community.id} rule_conn = simu_conn(:user, cms: %{"what.ever" => true}) diff --git a/test/groupher_server_web/mutation/cms/upvotes/job_upvote_test.exs b/test/groupher_server_web/mutation/cms/upvotes/job_upvote_test.exs index 7c1f8869c..ff32d1cc7 100644 --- a/test/groupher_server_web/mutation/cms/upvotes/job_upvote_test.exs +++ b/test/groupher_server_web/mutation/cms/upvotes/job_upvote_test.exs @@ -22,7 +22,7 @@ defmodule GroupherServer.Test.Mutation.Upvotes.JobUpvote do } } """ - @tag :wip3 + @tag :wip2 test "login user can upvote a job", ~m(user_conn job)a do variables = %{id: job.id} created = user_conn |> mutation_result(@query, variables, "upvoteJob") @@ -30,7 +30,7 @@ defmodule GroupherServer.Test.Mutation.Upvotes.JobUpvote do assert created["id"] == to_string(job.id) end - @tag :wip3 + @tag :wip2 test "unauth user upvote a job fails", ~m(guest_conn job)a do variables = %{id: job.id} @@ -45,7 +45,7 @@ defmodule GroupherServer.Test.Mutation.Upvotes.JobUpvote do } } """ - @tag :wip3 + @tag :wip2 test "login user can undo upvote to a job", ~m(user_conn job user)a do {:ok, _} = CMS.upvote_article(:job, job.id, user) @@ -55,7 +55,7 @@ defmodule GroupherServer.Test.Mutation.Upvotes.JobUpvote do assert updated["id"] == to_string(job.id) end - @tag :wip3 + @tag :wip2 test "unauth user undo upvote a job fails", ~m(guest_conn job)a do variables = %{id: job.id} diff --git a/test/groupher_server_web/mutation/cms/upvotes/post_upvote_test.exs b/test/groupher_server_web/mutation/cms/upvotes/post_upvote_test.exs index 7d85684c1..002ff0e2f 100644 --- a/test/groupher_server_web/mutation/cms/upvotes/post_upvote_test.exs +++ b/test/groupher_server_web/mutation/cms/upvotes/post_upvote_test.exs @@ -22,7 +22,7 @@ defmodule GroupherServer.Test.Mutation.Upvotes.PostUpvote do } } """ - @tag :wip3 + @tag :wip2 test "login user can upvote a post", ~m(user_conn post)a do variables = %{id: post.id} created = user_conn |> mutation_result(@query, variables, "upvotePost") @@ -30,7 +30,7 @@ defmodule GroupherServer.Test.Mutation.Upvotes.PostUpvote do assert created["id"] == to_string(post.id) end - @tag :wip3 + @tag :wip2 test "unauth user upvote a post fails", ~m(guest_conn post)a do variables = %{id: post.id} @@ -44,7 +44,7 @@ defmodule GroupherServer.Test.Mutation.Upvotes.PostUpvote do } } """ - @tag :wip3 + @tag :wip2 test "login user can undo upvote to a post", ~m(user_conn post user)a do {:ok, _} = CMS.upvote_article(:post, post.id, user) @@ -54,7 +54,7 @@ defmodule GroupherServer.Test.Mutation.Upvotes.PostUpvote do assert updated["id"] == to_string(post.id) end - @tag :wip3 + @tag :wip2 test "unauth user undo upvote a post fails", ~m(guest_conn post)a do variables = %{id: post.id} diff --git a/test/groupher_server_web/query/cms/collects/job_collect_test.exs b/test/groupher_server_web/query/cms/collects/job_collect_test.exs index 3e889f3a7..8ad1a03b1 100644 --- a/test/groupher_server_web/query/cms/collects/job_collect_test.exs +++ b/test/groupher_server_web/query/cms/collects/job_collect_test.exs @@ -35,7 +35,7 @@ defmodule GroupherServer.Test.Query.Collects.JobCollect do } } """ - @tag :wip3 + @tag :wip2 test "guest can get collected users list after collect a job", ~m(guest_conn job user user2)a do {:ok, _} = CMS.collect_article(:job, job.id, user) diff --git a/test/groupher_server_web/query/cms/collects/post_collect_test.exs b/test/groupher_server_web/query/cms/collects/post_collect_test.exs index bbad70c01..b1f9d7199 100644 --- a/test/groupher_server_web/query/cms/collects/post_collect_test.exs +++ b/test/groupher_server_web/query/cms/collects/post_collect_test.exs @@ -35,7 +35,7 @@ defmodule GroupherServer.Test.Query.Collects.PostCollect do } } """ - @tag :wip3 + @tag :wip2 test "guest can get collected users list after collect a post", ~m(guest_conn post user user2)a do {:ok, _} = CMS.collect_article(:post, post.id, 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 d8a925471..548e2e12f 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 @@ -288,7 +288,7 @@ defmodule GroupherServer.Test.Query.Comments.JobComment do assert results["entries"] |> List.last() |> Map.get("floor") == 5 end - @tag :wip3 + @tag :wip2 test "the comments is loaded in default asc order", ~m(guest_conn job user)a do page_size = 10 thread = :job @@ -312,7 +312,7 @@ defmodule GroupherServer.Test.Query.Comments.JobComment do assert List.last(results["entries"]) |> Map.get("id") == to_string(comment3.id) end - @tag :wip3 + @tag :wip2 test "the comments can be loaded in desc order in timeline-mode", ~m(guest_conn job user)a do page_size = 10 thread = :job @@ -336,7 +336,7 @@ defmodule GroupherServer.Test.Query.Comments.JobComment do assert List.last(results["entries"]) |> Map.get("id") == to_string(comment.id) end - @tag :wip3 + @tag :wip2 test "the comments can be loaded in desc order in replies-mode", ~m(guest_conn job user user2)a do page_size = 10 @@ -433,7 +433,7 @@ defmodule GroupherServer.Test.Query.Comments.JobComment do assert the_random_comment |> get_in(["meta", "isArticleAuthorUpvoted"]) end - @tag :wip3 + @tag :wip2 test "guest user can get paged comment with emotions info", ~m(guest_conn job user user2)a do total_count = 2 @@ -511,7 +511,7 @@ defmodule GroupherServer.Test.Query.Comments.JobComment do |> get_in(["emotions", "viewerHasDownvoteed"]) end - @tag :wip3 + @tag :wip2 test "comment should have viewer has upvoted flag", ~m(user_conn job user)a do total_count = 10 page_size = 12 @@ -551,7 +551,7 @@ defmodule GroupherServer.Test.Query.Comments.JobComment do } } """ - @tag :wip3 + @tag :wip2 test "guest user can get paged participators", ~m(guest_conn job user)a do total_count = 30 page_size = 10 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 8fc646754..5a7e69eb6 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 @@ -288,7 +288,7 @@ defmodule GroupherServer.Test.Query.Comments.PostComment do assert results["entries"] |> List.last() |> Map.get("floor") == 5 end - @tag :wip3 + @tag :wip2 test "the comments is loaded in default asc order", ~m(guest_conn post user)a do page_size = 10 thread = :post @@ -312,7 +312,7 @@ defmodule GroupherServer.Test.Query.Comments.PostComment do assert List.last(results["entries"]) |> Map.get("id") == to_string(comment3.id) end - @tag :wip3 + @tag :wip2 test "the comments can be loaded in desc order in timeline-mode", ~m(guest_conn post user)a do page_size = 10 thread = :post @@ -336,7 +336,7 @@ defmodule GroupherServer.Test.Query.Comments.PostComment do assert List.last(results["entries"]) |> Map.get("id") == to_string(comment.id) end - @tag :wip3 + @tag :wip2 test "the comments can be loaded in desc order in replies-mode", ~m(guest_conn post user user2)a do page_size = 10 @@ -433,7 +433,7 @@ defmodule GroupherServer.Test.Query.Comments.PostComment do assert the_random_comment |> get_in(["meta", "isArticleAuthorUpvoted"]) end - @tag :wip3 + @tag :wip2 test "guest user can get paged comment with emotions info", ~m(guest_conn post user user2)a do total_count = 2 @@ -511,7 +511,7 @@ defmodule GroupherServer.Test.Query.Comments.PostComment do |> get_in(["emotions", "viewerHasDownvoteed"]) end - @tag :wip3 + @tag :wip2 test "comment should have viewer has upvoted flag", ~m(user_conn post user)a do total_count = 10 page_size = 12 diff --git a/test/groupher_server_web/query/cms/job_test.exs b/test/groupher_server_web/query/cms/job_test.exs index 417d8e867..eebf90599 100644 --- a/test/groupher_server_web/query/cms/job_test.exs +++ b/test/groupher_server_web/query/cms/job_test.exs @@ -19,7 +19,7 @@ defmodule GroupherServer.Test.Query.Job do } } """ - @tag :wip3 + @tag :wip2 test "basic graphql query on job with logined user", ~m(user_conn job)a do variables = %{id: job.id} results = user_conn |> query_result(@query, variables, "job") @@ -30,7 +30,7 @@ defmodule GroupherServer.Test.Query.Job do assert length(Map.keys(results)) == 3 end - @tag :wip3 + @tag :wip2 test "basic graphql query on job with stranger(unloged user)", ~m(guest_conn job)a do variables = %{id: job.id} results = guest_conn |> query_result(@query, variables, "job") diff --git a/test/groupher_server_web/query/cms/jobs_flags_test.exs b/test/groupher_server_web/query/cms/jobs_flags_test.exs index e977f1a87..de9eb4adf 100644 --- a/test/groupher_server_web/query/cms/jobs_flags_test.exs +++ b/test/groupher_server_web/query/cms/jobs_flags_test.exs @@ -51,7 +51,7 @@ defmodule GroupherServer.Test.Query.JobsFlags do } } """ - @tag :wip3 + @tag :wip2 test "if have pined jobs, the pined jobs should at the top of entries", ~m(guest_conn community job_m)a do variables = %{filter: %{community: community.raw}} diff --git a/test/groupher_server_web/query/cms/paged_jobs_test.exs b/test/groupher_server_web/query/cms/paged_jobs_test.exs index b1254dde5..c68f415bd 100644 --- a/test/groupher_server_web/query/cms/paged_jobs_test.exs +++ b/test/groupher_server_web/query/cms/paged_jobs_test.exs @@ -97,7 +97,7 @@ defmodule GroupherServer.Test.Query.PagedJobs do } } """ - @tag :wip3 + @tag :wip2 test "has_xxx state should work", ~m(user)a do user_conn = simu_conn(:user, user) {:ok, community} = db_insert(:community) diff --git a/test/groupher_server_web/query/cms/paged_posts_test.exs b/test/groupher_server_web/query/cms/paged_posts_test.exs index bde4c3b74..b09740e57 100644 --- a/test/groupher_server_web/query/cms/paged_posts_test.exs +++ b/test/groupher_server_web/query/cms/paged_posts_test.exs @@ -170,7 +170,7 @@ defmodule GroupherServer.Test.Query.PagedPosts do } } """ - @tag :wip3 + @tag :wip2 test "has_xxx state should work", ~m(user)a do user_conn = simu_conn(:user, user) {:ok, community} = db_insert(:community) diff --git a/test/groupher_server_web/query/cms/paged_repos_test.exs b/test/groupher_server_web/query/cms/paged_repos_test.exs index e725b7a0f..c50aa0e6f 100644 --- a/test/groupher_server_web/query/cms/paged_repos_test.exs +++ b/test/groupher_server_web/query/cms/paged_repos_test.exs @@ -93,7 +93,7 @@ defmodule GroupherServer.Test.Query.PagedRepos do } } """ - @tag :wip3 + @tag :wip2 test "has_xxx state should work", ~m(user)a do user_conn = simu_conn(:user, user) {:ok, community} = db_insert(:community) diff --git a/test/groupher_server_web/query/cms/post_test.exs b/test/groupher_server_web/query/cms/post_test.exs index 3c53e9c6e..5e92fbb0e 100644 --- a/test/groupher_server_web/query/cms/post_test.exs +++ b/test/groupher_server_web/query/cms/post_test.exs @@ -28,7 +28,7 @@ defmodule GroupherServer.Test.Query.Post do } } """ - @tag :wip3 + @tag :wip2 test "basic graphql query on post with logined user", ~m(user_conn community user post_attrs)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) @@ -43,7 +43,7 @@ defmodule GroupherServer.Test.Query.Post do assert length(Map.keys(results)) == 4 end - @tag :wip3 + @tag :wip2 test "basic graphql query on post with stranger(unloged user)", ~m(guest_conn post)a do variables = %{id: post.id} results = guest_conn |> query_result(@query, variables, "post") diff --git a/test/groupher_server_web/query/cms/posts_flags_test.exs b/test/groupher_server_web/query/cms/posts_flags_test.exs index a63fa5d41..0cd6f01ec 100644 --- a/test/groupher_server_web/query/cms/posts_flags_test.exs +++ b/test/groupher_server_web/query/cms/posts_flags_test.exs @@ -51,7 +51,7 @@ defmodule GroupherServer.Test.Query.PostsFlags do } } """ - @tag :wip3 + @tag :wip2 test "if have pined posts, the pined posts should at the top of entries", ~m(guest_conn community post_m)a do variables = %{filter: %{community: community.raw}} diff --git a/test/groupher_server_web/query/cms/repo_test.exs b/test/groupher_server_web/query/cms/repo_test.exs index a4c82f63a..dc982deb0 100644 --- a/test/groupher_server_web/query/cms/repo_test.exs +++ b/test/groupher_server_web/query/cms/repo_test.exs @@ -19,7 +19,7 @@ defmodule GroupherServer.Test.Query.Repo do } } """ - @tag :wip3 + @tag :wip2 test "basic graphql query on repo with logined user", ~m(user_conn repo)a do variables = %{id: repo.id} results = user_conn |> query_result(@query, variables, "repo") @@ -30,7 +30,7 @@ defmodule GroupherServer.Test.Query.Repo do assert length(Map.keys(results)) == 3 end - @tag :wip3 + @tag :wip2 test "basic graphql query on repo with stranger(unloged user)", ~m(guest_conn repo)a do variables = %{id: repo.id} results = guest_conn |> query_result(@query, variables, "repo") diff --git a/test/groupher_server_web/query/cms/repos_flags_test.exs b/test/groupher_server_web/query/cms/repos_flags_test.exs index c0cf8707a..c013d9b29 100644 --- a/test/groupher_server_web/query/cms/repos_flags_test.exs +++ b/test/groupher_server_web/query/cms/repos_flags_test.exs @@ -50,7 +50,7 @@ defmodule GroupherServer.Test.Query.ReposFlags do } } """ - @tag :wip3 + @tag :wip2 test "if have pined repos, the pined repos should at the top of entries", ~m(guest_conn community repo_m)a do variables = %{filter: %{community: community.raw}} diff --git a/test/groupher_server_web/query/cms/upvotes/post_upvote_test.exs b/test/groupher_server_web/query/cms/upvotes/post_upvote_test.exs index 47b311cde..5a62315ee 100644 --- a/test/groupher_server_web/query/cms/upvotes/post_upvote_test.exs +++ b/test/groupher_server_web/query/cms/upvotes/post_upvote_test.exs @@ -35,7 +35,7 @@ defmodule GroupherServer.Test.Query.Upvotes.PostUpvote do } } """ - @tag :wip3 + @tag :wip2 test "guest can get upvoted users list after upvote to a post", ~m(guest_conn post user user2)a do {:ok, _} = CMS.upvote_article(:post, post.id, user) From c53d7c7846ae0c5983662221d8592c438dda9cde Mon Sep 17 00:00:00 2001 From: mydearxym Date: Wed, 12 May 2021 18:02:26 +0800 Subject: [PATCH 05/13] refactor(abuse-report): wip --- test/groupher_server/cms/comments/job_comment_test.exs | 6 +++--- test/groupher_server/cms/comments/post_comment_test.exs | 2 +- .../mutation/cms/articles/job_report_test.exs | 4 ++-- .../mutation/cms/articles/post_report_test.exs | 4 ++-- .../mutation/cms/articles/repo_report_test.exs | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/test/groupher_server/cms/comments/job_comment_test.exs b/test/groupher_server/cms/comments/job_comment_test.exs index e934d1255..aa6ee5ac5 100644 --- a/test/groupher_server/cms/comments/job_comment_test.exs +++ b/test/groupher_server/cms/comments/job_comment_test.exs @@ -279,7 +279,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do {:ok, comment} = CMS.report_article_comment(comment.id, "reason", "attr", user) {:ok, comment} = ORM.find(ArticleComment, comment.id) - assert comment.is_reported + assert not comment.is_reported end @tag :wip @@ -288,7 +288,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do {:ok, _comment} = CMS.report_article_comment(comment.id, "reason", "attr", user) {:ok, comment} = ORM.find(ArticleComment, comment.id) - assert comment.is_reported + assert not comment.is_reported {:ok, _comment} = CMS.undo_report_article_comment(comment.id, user) {:ok, comment} = ORM.find(ArticleComment, comment.id) @@ -353,7 +353,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do end) {:ok, comment} = ORM.find(ArticleComment, comment.id) - assert comment.is_reported + assert not comment.is_reported assert comment.is_folded 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 d01cb5813..6d337f5ce 100644 --- a/test/groupher_server/cms/comments/post_comment_test.exs +++ b/test/groupher_server/cms/comments/post_comment_test.exs @@ -288,7 +288,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do {:ok, _comment} = CMS.report_article_comment(comment.id, "reason", "attr", user) {:ok, comment} = ORM.find(ArticleComment, comment.id) - assert comment.is_reported + assert not comment.is_reported {:ok, _comment} = CMS.undo_report_article_comment(comment.id, user) {:ok, comment} = ORM.find(ArticleComment, comment.id) diff --git a/test/groupher_server_web/mutation/cms/articles/job_report_test.exs b/test/groupher_server_web/mutation/cms/articles/job_report_test.exs index 310226193..248946c7c 100644 --- a/test/groupher_server_web/mutation/cms/articles/job_report_test.exs +++ b/test/groupher_server_web/mutation/cms/articles/job_report_test.exs @@ -33,7 +33,7 @@ defmodule GroupherServer.Test.Mutation.Articles.JobReport do variables = %{id: job.id, reason: "reason"} article = user_conn |> mutation_result(@report_query, variables, "reportJob") - assert article["isReported"] + assert not article["isReported"] assert article["id"] == to_string(job.id) end @@ -53,7 +53,7 @@ defmodule GroupherServer.Test.Mutation.Articles.JobReport do variables = %{id: job.id, reason: "reason"} article = user_conn |> mutation_result(@report_query, variables, "reportJob") - assert article["isReported"] + assert not article["isReported"] assert article["id"] == to_string(job.id) variables = %{id: job.id} diff --git a/test/groupher_server_web/mutation/cms/articles/post_report_test.exs b/test/groupher_server_web/mutation/cms/articles/post_report_test.exs index 876b38f16..99ffbf6e9 100644 --- a/test/groupher_server_web/mutation/cms/articles/post_report_test.exs +++ b/test/groupher_server_web/mutation/cms/articles/post_report_test.exs @@ -33,7 +33,7 @@ defmodule GroupherServer.Test.Mutation.Articles.PostReport do variables = %{id: post.id, reason: "reason"} article = user_conn |> mutation_result(@report_query, variables, "reportPost") - assert article["isReported"] + assert not article["isReported"] assert article["id"] == to_string(post.id) end @@ -53,7 +53,7 @@ defmodule GroupherServer.Test.Mutation.Articles.PostReport do variables = %{id: post.id, reason: "reason"} article = user_conn |> mutation_result(@report_query, variables, "reportPost") - assert article["isReported"] + assert not article["isReported"] assert article["id"] == to_string(post.id) variables = %{id: post.id} diff --git a/test/groupher_server_web/mutation/cms/articles/repo_report_test.exs b/test/groupher_server_web/mutation/cms/articles/repo_report_test.exs index 2802f7a22..c6bcbf0c6 100644 --- a/test/groupher_server_web/mutation/cms/articles/repo_report_test.exs +++ b/test/groupher_server_web/mutation/cms/articles/repo_report_test.exs @@ -33,7 +33,7 @@ defmodule GroupherServer.Test.Mutation.Articles.RepoReport do variables = %{id: repo.id, reason: "reason"} article = user_conn |> mutation_result(@report_query, variables, "reportRepo") - assert article["isReported"] + assert not article["isReported"] assert article["id"] == to_string(repo.id) end @@ -53,7 +53,7 @@ defmodule GroupherServer.Test.Mutation.Articles.RepoReport do variables = %{id: repo.id, reason: "reason"} article = user_conn |> mutation_result(@report_query, variables, "reportRepo") - assert article["isReported"] + assert not article["isReported"] assert article["id"] == to_string(repo.id) variables = %{id: repo.id} From 7e55780455f1880b07c15a515b6fad978733d966 Mon Sep 17 00:00:00 2001 From: mydearxym Date: Wed, 12 May 2021 20:23:03 +0800 Subject: [PATCH 06/13] refactor(abuse-report): remove is_reported field --- lib/groupher_server/accounts/user.ex | 1 - lib/groupher_server/cms/abuse_report.ex | 6 +- lib/groupher_server/cms/article_comment.ex | 6 +- .../cms/delegates/abuse_report.ex | 6 +- .../cms/delegates/article_comment.ex | 18 ++--- .../cms/delegates/article_comment_action.ex | 6 +- lib/groupher_server/cms/helper/matcher2.ex | 23 +++++- lib/groupher_server/cms/job.ex | 3 +- lib/groupher_server/cms/post.ex | 3 +- lib/groupher_server/cms/repo.ex | 3 +- .../schema/cms/cms_types.ex | 5 -- ...name_is_close_to_is_confirm_in_reports.exs | 10 +++ .../cms/abuse_reports/account_report_test.exs | 13 ++-- .../cms/abuse_reports/comment_report_test.exs | 4 +- .../cms/abuse_reports/job_report_test.exs | 13 ++-- .../cms/abuse_reports/post_report_test.exs | 13 ++-- .../comments/job_comment_emotions_test.exs | 12 ++-- .../cms/comments/job_comment_replies_test.exs | 8 +-- .../cms/comments/job_comment_test.exs | 66 ++++++++--------- .../comments/post_comment_emotions_test.exs | 12 ++-- .../comments/post_comment_replies_test.exs | 10 +-- .../cms/comments/post_comment_test.exs | 72 +++++++------------ .../cms/emotions/job_emotions_test.exs | 16 ++--- .../cms/emotions/post_emotions_test.exs | 16 ++--- test/groupher_server/cms/job_test.exs | 2 +- test/groupher_server/cms/post_test.exs | 4 +- test/groupher_server/cms/repo_test.exs | 4 +- .../cms/upvotes/job_upvote_test.exs | 10 +-- .../cms/upvotes/post_upvote_test.exs | 10 +-- .../mutation/accounts/customization_test.exs | 2 +- .../cms/articles/job_emotion_test.exs | 4 +- .../mutation/cms/articles/job_report_test.exs | 9 +-- .../mutation/cms/articles/job_test.exs | 2 +- .../cms/articles/post_emotion_test.exs | 4 +- .../cms/articles/post_report_test.exs | 6 -- .../mutation/cms/articles/post_test.exs | 2 +- .../cms/articles/repo_report_test.exs | 9 +-- .../mutation/cms/articles/repo_test.exs | 6 +- .../mutation/cms/cms_test.exs | 4 +- .../cms/comments/job_comment_test.exs | 12 ++-- .../cms/comments/post_comment_test.exs | 12 ++-- .../mutation/cms/flags/job_flag_test.exs | 14 ++-- .../mutation/cms/flags/post_flag_test.exs | 16 ++--- .../mutation/cms/flags/repo_flag_test.exs | 16 ++--- .../mutation/cms/upvotes/job_upvote_test.exs | 8 +-- .../mutation/cms/upvotes/post_upvote_test.exs | 8 +-- .../query/cms/collects/job_collect_test.exs | 2 +- .../query/cms/collects/post_collect_test.exs | 2 +- .../query/cms/comments/job_comment_test.exs | 12 ++-- .../query/cms/comments/post_comment_test.exs | 10 +-- .../query/cms/job_test.exs | 4 +- .../query/cms/jobs_flags_test.exs | 2 +- .../query/cms/paged_jobs_test.exs | 2 +- .../query/cms/paged_posts_test.exs | 2 +- .../query/cms/paged_repos_test.exs | 2 +- .../query/cms/post_test.exs | 4 +- .../query/cms/posts_flags_test.exs | 2 +- .../query/cms/repo_test.exs | 4 +- .../query/cms/repos_flags_test.exs | 2 +- .../query/cms/upvotes/post_upvote_test.exs | 2 +- 60 files changed, 260 insertions(+), 301 deletions(-) create mode 100644 priv/repo/migrations/20210512110812_rename_is_close_to_is_confirm_in_reports.exs diff --git a/lib/groupher_server/accounts/user.ex b/lib/groupher_server/accounts/user.ex index 07b0fc1fa..323fcfd56 100644 --- a/lib/groupher_server/accounts/user.ex +++ b/lib/groupher_server/accounts/user.ex @@ -61,7 +61,6 @@ defmodule GroupherServer.Accounts.User do # field(:paid_member, :boolean) # field(:platinum_member, :boolean) - field(:is_reported, :boolean, default: false) embeds_one(:meta, Embeds.UserMeta, on_replace: :update) has_one(:customization, Customization) diff --git a/lib/groupher_server/cms/abuse_report.ex b/lib/groupher_server/cms/abuse_report.ex index c99b6fe36..ddbae3ada 100644 --- a/lib/groupher_server/cms/abuse_report.ex +++ b/lib/groupher_server/cms/abuse_report.ex @@ -9,8 +9,8 @@ defmodule GroupherServer.CMS.AbuseReport do alias CMS.{ArticleComment, Embeds, Post, Job, Repo} # @required_fields ~w(article_comment_id user_id recived_user_id)a - @optional_fields ~w(article_comment_id post_id job_id repo_id account_id operate_user_id deal_with is_closed report_cases_count)a - @update_fields ~w(operate_user_id deal_with is_closed report_cases_count)a + @optional_fields ~w(article_comment_id post_id job_id repo_id account_id operate_user_id deal_with is_confirmed report_cases_count)a + @update_fields ~w(operate_user_id deal_with is_confirmed report_cases_count)a @type t :: %AbuseReport{} schema "abuse_reports" do @@ -26,7 +26,7 @@ defmodule GroupherServer.CMS.AbuseReport do belongs_to(:operate_user, Accounts.User, foreign_key: :operate_user_id) field(:deal_with, :string) - field(:is_closed, :boolean, default: false) + field(:is_confirmed, :boolean, default: false) timestamps(type: :utc_datetime) end diff --git a/lib/groupher_server/cms/article_comment.ex b/lib/groupher_server/cms/article_comment.ex index 53d58702b..f4af65240 100644 --- a/lib/groupher_server/cms/article_comment.ex +++ b/lib/groupher_server/cms/article_comment.ex @@ -20,8 +20,8 @@ defmodule GroupherServer.CMS.ArticleComment do # alias Helper.HTML @required_fields ~w(body_html author_id)a - @optional_fields ~w(post_id job_id repo_id reply_to_id replies_count is_folded is_reported is_deleted floor is_article_author)a - @updatable_fields ~w(is_folded is_reported is_deleted floor upvotes_count is_pinned)a + @optional_fields ~w(post_id job_id repo_id reply_to_id replies_count is_folded is_deleted floor is_article_author)a + @updatable_fields ~w(is_folded is_deleted floor upvotes_count is_pinned)a @max_participator_count 5 @max_parent_replies_count 3 @@ -56,8 +56,6 @@ defmodule GroupherServer.CMS.ArticleComment do field(:body_html, :string) # 是否被折叠 field(:is_folded, :boolean, default: false) - # 是否被举报 - field(:is_reported, :boolean, default: false) # 是否被删除 field(:is_deleted, :boolean, default: false) # 楼层 diff --git a/lib/groupher_server/cms/delegates/abuse_report.ex b/lib/groupher_server/cms/delegates/abuse_report.ex index 2a089b2bc..eafb149ac 100644 --- a/lib/groupher_server/cms/delegates/abuse_report.ex +++ b/lib/groupher_server/cms/delegates/abuse_report.ex @@ -23,7 +23,6 @@ defmodule GroupherServer.CMS.Delegate.AbuseReport do # operate_user_id, # min_case_count, # max_case_count, - # is_closed # page # size # } @@ -34,7 +33,6 @@ defmodule GroupherServer.CMS.Delegate.AbuseReport do @export_report_keys [ :id, :deal_with, - :is_closed, :operate_user, :report_cases, :report_cases_count, @@ -107,6 +105,9 @@ defmodule GroupherServer.CMS.Delegate.AbuseReport do end end + @doc """ + report an account + """ def report_account(account_id, reason, attr, user) do with {:ok, info} <- match(:account_user), {:ok, account} <- ORM.find(info.model, account_id) do @@ -352,6 +353,7 @@ defmodule GroupherServer.CMS.Delegate.AbuseReport do end defp result({:ok, %{update_report_flag: result}}), do: result |> done() + defp result({:ok, %{update_content_reported_flag: result}}), do: result |> done() defp result({:error, _, result, _steps}) do {:error, result} diff --git a/lib/groupher_server/cms/delegates/article_comment.ex b/lib/groupher_server/cms/delegates/article_comment.ex index dbd72b160..8fbf44db8 100644 --- a/lib/groupher_server/cms/delegates/article_comment.ex +++ b/lib/groupher_server/cms/delegates/article_comment.ex @@ -33,7 +33,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleComment do def list_article_comments(thread, article_id, filters, mode, user \\ nil) def list_article_comments(thread, article_id, filters, :timeline, user) do - where_query = dynamic([c], not c.is_folded and not c.is_reported and not c.is_pinned) + where_query = dynamic([c], not c.is_folded and not c.is_pinned) do_list_article_comment(thread, article_id, filters, where_query, user) end @@ -44,26 +44,19 @@ defmodule GroupherServer.CMS.Delegate.ArticleComment do where_query = dynamic( [c], - is_nil(c.reply_to_id) and not c.is_folded and not c.is_reported and not c.is_pinned + is_nil(c.reply_to_id) and not c.is_folded and not c.is_pinned ) do_list_article_comment(thread, article_id, filters, where_query, user) end def list_folded_article_comments(thread, article_id, filters) do - where_query = dynamic([c], c.is_folded and not c.is_reported and not c.is_pinned) + where_query = dynamic([c], c.is_folded and not c.is_pinned) do_list_article_comment(thread, article_id, filters, where_query, nil) end def list_folded_article_comments(thread, article_id, filters, user) do - where_query = dynamic([c], c.is_folded and not c.is_reported and not c.is_pinned) - do_list_article_comment(thread, article_id, filters, where_query, user) - end - - def list_reported_article_comments(thread, article_id, filters, user \\ nil) - - def list_reported_article_comments(thread, article_id, filters, user) do - where_query = dynamic([c], c.is_reported) + where_query = dynamic([c], c.is_folded and not c.is_pinned) do_list_article_comment(thread, article_id, filters, where_query, user) end @@ -227,8 +220,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleComment do %{page: page, size: size} = filters query = from(c in ArticleComment, preload: [reply_to: :author]) - where_query = - dynamic([c], not c.is_reported and not c.is_folded and c.reply_to_id == ^comment_id) + where_query = dynamic([c], not c.is_folded and c.reply_to_id == ^comment_id) query |> where(^where_query) diff --git a/lib/groupher_server/cms/delegates/article_comment_action.ex b/lib/groupher_server/cms/delegates/article_comment_action.ex index f99236103..82f23de5e 100644 --- a/lib/groupher_server/cms/delegates/article_comment_action.ex +++ b/lib/groupher_server/cms/delegates/article_comment_action.ex @@ -108,10 +108,6 @@ defmodule GroupherServer.CMS.Delegate.ArticleCommentAction do |> Multi.run(:create_abuse_report, fn _, _ -> CMS.create_report(:article_comment, comment_id, reason, attr, user) end) - |> Multi.run(:update_report_flag, fn _, _ -> - # TODO: update report count in meta - ORM.update(comment, %{is_reported: true}) - end) |> Multi.run(:fold_comment_report_too_many, fn _, %{create_abuse_report: abuse_report} -> if abuse_report.report_cases_count >= @report_threshold_for_fold, do: fold_article_comment(comment, user), @@ -349,7 +345,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleCommentAction do defp upsert_comment_result({:ok, %{create_article_comment: result}}), do: {:ok, result} defp upsert_comment_result({:ok, %{add_reply_to: result}}), do: {:ok, result} defp upsert_comment_result({:ok, %{check_article_author_upvoted: result}}), do: {:ok, result} - defp upsert_comment_result({:ok, %{update_report_flag: result}}), do: {:ok, result} + defp upsert_comment_result({:ok, %{fold_comment_report_too_many: result}}), do: {:ok, result} defp upsert_comment_result({:ok, %{update_comment_flag: result}}), do: {:ok, result} defp upsert_comment_result({:ok, %{delete_article_comment: result}}), do: {:ok, result} diff --git a/lib/groupher_server/cms/helper/matcher2.ex b/lib/groupher_server/cms/helper/matcher2.ex index 6c986fa2f..ad72f8e29 100644 --- a/lib/groupher_server/cms/helper/matcher2.ex +++ b/lib/groupher_server/cms/helper/matcher2.ex @@ -15,6 +15,7 @@ defmodule GroupherServer.CMS.Helper.Matcher2 do %{ model: ArticleComment, foreign_key: :article_comment_id, + preload: :article_comment, default_meta: CMS.Embeds.ArticleCommentMeta.default_meta() }} end @@ -36,6 +37,7 @@ defmodule GroupherServer.CMS.Helper.Matcher2 do %{ model: User, foreign_key: :account_id, + preload: :account, default_meta: Accounts.Embeds.UserMeta.default_meta() }} end @@ -47,7 +49,12 @@ defmodule GroupherServer.CMS.Helper.Matcher2 do def match(:post) do {:ok, - %{model: Post, foreign_key: :post_id, default_meta: CMS.Embeds.ArticleMeta.default_meta()}} + %{ + model: Post, + foreign_key: :post_id, + preload: :post, + default_meta: CMS.Embeds.ArticleMeta.default_meta() + }} end def match(Job) do @@ -56,7 +63,12 @@ defmodule GroupherServer.CMS.Helper.Matcher2 do def match(:job) do {:ok, - %{model: Job, foreign_key: :job_id, default_meta: CMS.Embeds.ArticleMeta.default_meta()}} + %{ + model: Job, + foreign_key: :job_id, + preload: :job, + default_meta: CMS.Embeds.ArticleMeta.default_meta() + }} end def match(Repo) do @@ -65,7 +77,12 @@ defmodule GroupherServer.CMS.Helper.Matcher2 do def match(:repo) do {:ok, - %{model: Repo, foreign_key: :repo_id, default_meta: CMS.Embeds.ArticleMeta.default_meta()}} + %{ + model: Repo, + foreign_key: :repo_id, + preload: :repo, + default_meta: CMS.Embeds.ArticleMeta.default_meta() + }} end def match(:post, :query, id), do: {:ok, dynamic([c], c.post_id == ^id)} diff --git a/lib/groupher_server/cms/job.ex b/lib/groupher_server/cms/job.ex index b39a89dbe..51f62046a 100644 --- a/lib/groupher_server/cms/job.ex +++ b/lib/groupher_server/cms/job.ex @@ -24,7 +24,7 @@ defmodule GroupherServer.CMS.Job do @timestamps_opts [type: :utc_datetime_usec] @required_fields ~w(title company company_logo body digest length)a - @optional_fields ~w(origial_community_id desc company_link link_addr copy_right salary exp education field finance scale article_comments_count article_comments_participators_count upvotes_count collects_count is_reported)a + @optional_fields ~w(origial_community_id desc company_link link_addr copy_right salary exp education field finance scale article_comments_count article_comments_participators_count upvotes_count collects_count)a @type t :: %Job{} schema "cms_jobs" do @@ -57,7 +57,6 @@ defmodule GroupherServer.CMS.Job do # NOTE: this one is tricky, pin is dynamic changed when return by func: add_pin_contents_ifneed field(:is_pinned, :boolean, default: false, virtual: true) field(:trash, :boolean, default_value: false, virtual: true) - field(:is_reported, :boolean, default: false) has_many(:upvotes, {"article_upvotes", ArticleUpvote}) field(:upvotes_count, :integer, default: 0) diff --git a/lib/groupher_server/cms/post.ex b/lib/groupher_server/cms/post.ex index cf601882d..336d15fbf 100644 --- a/lib/groupher_server/cms/post.ex +++ b/lib/groupher_server/cms/post.ex @@ -26,7 +26,7 @@ defmodule GroupherServer.CMS.Post do @timestamps_opts [type: :utc_datetime_usec] @required_fields ~w(title body digest length)a - @optional_fields ~w(origial_community_id link_addr copy_right link_addr link_icon article_comments_count article_comments_participators_count upvotes_count collects_count is_reported)a + @optional_fields ~w(origial_community_id link_addr copy_right link_addr link_icon article_comments_count article_comments_participators_count upvotes_count collects_count)a @type t :: %Post{} schema "cms_posts" do @@ -48,7 +48,6 @@ defmodule GroupherServer.CMS.Post do # field(:pin, :boolean, default_value: false, virtual: true) field(:is_pinned, :boolean, default: false, virtual: true) field(:trash, :boolean, default_value: false, virtual: true) - field(:is_reported, :boolean, default: false) field(:viewer_has_viewed, :boolean, default: false, virtual: true) field(:viewer_has_upvoted, :boolean, default: false, virtual: true) diff --git a/lib/groupher_server/cms/repo.ex b/lib/groupher_server/cms/repo.ex index 9bd840a79..c24c879c6 100644 --- a/lib/groupher_server/cms/repo.ex +++ b/lib/groupher_server/cms/repo.ex @@ -25,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 upvotes_count collects_count)a - @optional_fields ~w(origial_community_id last_sync homepage_url release_tag license is_reported)a + @optional_fields ~w(origial_community_id last_sync homepage_url release_tag license)a @type t :: %Repo{} schema "cms_repos" do @@ -61,7 +61,6 @@ defmodule GroupherServer.CMS.Repo do # NOTE: this one is tricky, pin is dynamic changed when return by func: add_pin_contents_ifneed field(:is_pinned, :boolean, default: false, virtual: true) field(:trash, :boolean, default_value: false) - field(:is_reported, :boolean, default: false) has_many(:upvotes, {"article_upvotes", ArticleUpvote}) field(:upvotes_count, :integer, default: 0) diff --git a/lib/groupher_server_web/schema/cms/cms_types.ex b/lib/groupher_server_web/schema/cms/cms_types.ex index be0de5a78..dff7764e3 100644 --- a/lib/groupher_server_web/schema/cms/cms_types.ex +++ b/lib/groupher_server_web/schema/cms/cms_types.ex @@ -68,8 +68,6 @@ defmodule GroupherServerWeb.Schema.CMS.Types do end) end - field(:is_reported, :boolean) - article_comments_fields() viewer_has_state_fields() # upvoted_count @@ -111,7 +109,6 @@ defmodule GroupherServerWeb.Schema.CMS.Types do field(:finance, :string) field(:scale, :string) - field(:is_reported, :boolean) # comments_count # comments_participators article_comments_fields() @@ -156,7 +153,6 @@ defmodule GroupherServerWeb.Schema.CMS.Types do field(:origial_community, :community, resolve: dataloader(CMS, :origial_community)) field(:communities, list_of(:community), resolve: dataloader(CMS, :communities)) - field(:is_reported, :boolean) viewer_has_state_fields() # comments_count # comments_participators @@ -460,7 +456,6 @@ defmodule GroupherServerWeb.Schema.CMS.Types do object :article_meta do field(:is_edited, :boolean) field(:is_comment_locked, :boolean) - # field(:isReported, :boolean) # field(:linked_posts_count, :integer) # field(:linked_jobs_count, :integer) # field(:linked_works_count, :integer) diff --git a/priv/repo/migrations/20210512110812_rename_is_close_to_is_confirm_in_reports.exs b/priv/repo/migrations/20210512110812_rename_is_close_to_is_confirm_in_reports.exs new file mode 100644 index 000000000..6e5f94823 --- /dev/null +++ b/priv/repo/migrations/20210512110812_rename_is_close_to_is_confirm_in_reports.exs @@ -0,0 +1,10 @@ +defmodule GroupherServer.Repo.Migrations.RenameIsCloseToIsConfirmInReports do + use Ecto.Migration + + def change do + alter(table(:abuse_reports), do: remove(:is_closed)) + alter(table(:cms_posts), do: remove(:is_reported)) + alter(table(:cms_jobs), do: remove(:is_reported)) + alter(table(:cms_repos), do: remove(:is_reported)) + end +end diff --git a/test/groupher_server/cms/abuse_reports/account_report_test.exs b/test/groupher_server/cms/abuse_reports/account_report_test.exs index 31c03883f..fe0295f92 100644 --- a/test/groupher_server/cms/abuse_reports/account_report_test.exs +++ b/test/groupher_server/cms/abuse_reports/account_report_test.exs @@ -23,7 +23,7 @@ defmodule GroupherServer.Test.CMS.AbuseReports.AccountReport do end describe "[account report/unreport]" do - @tag :wip2 + @tag :wip3 # test "list article reports should work", ~m(community user user2 post_attrs)a do # {:ok, post} = CMS.create_content(community, :post, post_attrs, user) # {:ok, _report} = CMS.report_article(:post, post.id, "reason", "attr_info", user) @@ -37,7 +37,7 @@ defmodule GroupherServer.Test.CMS.AbuseReports.AccountReport do # assert report.article.thread == :post # end - @tag :wip2 + @tag :wip3 test "report an account should have a abuse report record", ~m(user user2)a do {:ok, report} = CMS.report_account(user.id, "reason", "attr_info", user2) @@ -53,11 +53,10 @@ defmodule GroupherServer.Test.CMS.AbuseReports.AccountReport do assert List.first(report_cases).user.login == user2.login {:ok, user} = ORM.find(User, user.id) - assert not user.is_reported assert user.meta.reported_count == 1 end - @tag :wip2 + @tag :wip3 test "can undo a report", ~m(user user2)a do {:ok, report} = CMS.report_account(user.id, "reason", "attr_info", user2) {:ok, _report} = CMS.undo_report_account(user.id, user2) @@ -67,7 +66,7 @@ defmodule GroupherServer.Test.CMS.AbuseReports.AccountReport do assert all_reports.total_count == 0 end - @tag :wip2 + @tag :wip3 test "can undo a report with other user report it too", ~m(user user2 user3)a do {:ok, _report} = CMS.report_account(user.id, "reason", "attr_info", user2) {:ok, _report} = CMS.report_account(user.id, "reason", "attr_info", user3) @@ -92,7 +91,7 @@ defmodule GroupherServer.Test.CMS.AbuseReports.AccountReport do assert Enum.any?(report.report_cases, &(&1.user.login == user3.login)) end - @tag :wip2 + @tag :wip3 test "different user report a account should have same report with different report cases", ~m(user user2 user3)a do {:ok, _report} = CMS.report_account(user.id, "reason", "attr_info", user2) @@ -112,7 +111,7 @@ defmodule GroupherServer.Test.CMS.AbuseReports.AccountReport do assert List.last(report_cases).user.login == user3.login end - @tag :wip2 + @tag :wip3 test "same user can not report a account twice", ~m(user user2)a do {:ok, _report} = CMS.report_account(user.id, "reason", "attr_info", user2) assert {:error, _report} = CMS.report_account(user.id, "reason", "attr_info", user2) 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 16d2eb0fc..631243dc2 100644 --- a/test/groupher_server/cms/abuse_reports/comment_report_test.exs +++ b/test/groupher_server/cms/abuse_reports/comment_report_test.exs @@ -15,7 +15,7 @@ defmodule GroupherServer.Test.CMS.AbuseReports.CommentReport do end describe "[article comment report/unreport]" do - @tag :wip2 + @tag :wip3 test "report a comment should have a abuse report record", ~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) @@ -32,7 +32,7 @@ defmodule GroupherServer.Test.CMS.AbuseReports.CommentReport do assert List.first(report_cases).user.login == user.login end - @tag :wip2 + @tag :wip3 test "different user report a comment should have same report with different report cases", ~m(user user2 post)a do {:ok, comment} = CMS.create_article_comment(:post, post.id, "commment", user) diff --git a/test/groupher_server/cms/abuse_reports/job_report_test.exs b/test/groupher_server/cms/abuse_reports/job_report_test.exs index 566cb0da1..44e5b0c8e 100644 --- a/test/groupher_server/cms/abuse_reports/job_report_test.exs +++ b/test/groupher_server/cms/abuse_reports/job_report_test.exs @@ -17,7 +17,7 @@ defmodule GroupherServer.Test.CMS.AbuseReports.JobReport do end describe "[article job report/unreport]" do - @tag :wip2 + @tag :wip3 test "list article reports should work", ~m(community user user2 job_attrs)a do {:ok, job} = CMS.create_content(community, :job, job_attrs, user) {:ok, _report} = CMS.report_article(:job, job.id, "reason", "attr_info", user) @@ -31,7 +31,7 @@ defmodule GroupherServer.Test.CMS.AbuseReports.JobReport do assert report.article.thread == :job end - @tag :wip2 + @tag :wip3 test "report a job should have a abuse report record", ~m(community user job_attrs)a do {:ok, job} = CMS.create_content(community, :job, job_attrs, user) {:ok, _report} = CMS.report_article(:job, job.id, "reason", "attr_info", user) @@ -48,11 +48,10 @@ defmodule GroupherServer.Test.CMS.AbuseReports.JobReport do assert List.first(report_cases).user.login == user.login {:ok, job} = ORM.find(CMS.Job, job.id) - assert not job.is_reported assert job.meta.reported_count == 1 end - @tag :wip2 + @tag :wip3 test "can undo a report", ~m(community user job_attrs)a do {:ok, job} = CMS.create_content(community, :job, job_attrs, user) {:ok, _report} = CMS.report_article(:job, job.id, "reason", "attr_info", user) @@ -63,7 +62,7 @@ defmodule GroupherServer.Test.CMS.AbuseReports.JobReport do assert all_reports.total_count == 0 end - @tag :wip2 + @tag :wip3 test "can undo a report with other user report it too", ~m(community user user2 job_attrs)a do {:ok, job} = CMS.create_content(community, :job, job_attrs, user) @@ -90,7 +89,7 @@ defmodule GroupherServer.Test.CMS.AbuseReports.JobReport do assert Enum.any?(report.report_cases, &(&1.user.login == user2.login)) end - @tag :wip2 + @tag :wip3 test "different user report a comment should have same report with different report cases", ~m(community user user2 job_attrs)a do {:ok, job} = CMS.create_content(community, :job, job_attrs, user) @@ -112,7 +111,7 @@ defmodule GroupherServer.Test.CMS.AbuseReports.JobReport do assert List.last(report_cases).user.login == user2.login end - @tag :wip2 + @tag :wip3 test "same user can not report a comment twice", ~m(community job_attrs user)a do {:ok, job} = CMS.create_content(community, :job, job_attrs, user) diff --git a/test/groupher_server/cms/abuse_reports/post_report_test.exs b/test/groupher_server/cms/abuse_reports/post_report_test.exs index 9d487634d..1c427bf83 100644 --- a/test/groupher_server/cms/abuse_reports/post_report_test.exs +++ b/test/groupher_server/cms/abuse_reports/post_report_test.exs @@ -17,7 +17,7 @@ defmodule GroupherServer.Test.CMS.AbuseReports.PostReport do end describe "[article post report/unreport]" do - @tag :wip2 + @tag :wip3 test "list article reports should work", ~m(community user user2 post_attrs)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) {:ok, _report} = CMS.report_article(:post, post.id, "reason", "attr_info", user) @@ -31,7 +31,7 @@ defmodule GroupherServer.Test.CMS.AbuseReports.PostReport do assert report.article.thread == :post end - @tag :wip2 + @tag :wip3 test "report a post should have a abuse report record", ~m(community user post_attrs)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) {:ok, _report} = CMS.report_article(:post, post.id, "reason", "attr_info", user) @@ -48,11 +48,10 @@ defmodule GroupherServer.Test.CMS.AbuseReports.PostReport do assert List.first(report_cases).user.login == user.login {:ok, post} = ORM.find(CMS.Post, post.id) - assert not post.is_reported assert post.meta.reported_count == 1 end - @tag :wip2 + @tag :wip3 test "can undo a report", ~m(community user post_attrs)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) {:ok, _report} = CMS.report_article(:post, post.id, "reason", "attr_info", user) @@ -63,7 +62,7 @@ defmodule GroupherServer.Test.CMS.AbuseReports.PostReport do assert all_reports.total_count == 0 end - @tag :wip2 + @tag :wip3 test "can undo a report with other user report it too", ~m(community user user2 post_attrs)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) @@ -90,7 +89,7 @@ defmodule GroupherServer.Test.CMS.AbuseReports.PostReport do assert Enum.any?(report.report_cases, &(&1.user.login == user2.login)) end - @tag :wip2 + @tag :wip3 test "different user report a comment should have same report with different report cases", ~m(community user user2 post_attrs)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) @@ -112,7 +111,7 @@ defmodule GroupherServer.Test.CMS.AbuseReports.PostReport do assert List.last(report_cases).user.login == user2.login end - @tag :wip2 + @tag :wip3 test "same user can not report a comment twice", ~m(community post_attrs user)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) 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 3cc538cc6..7c3cc5369 100644 --- a/test/groupher_server/cms/comments/job_comment_emotions_test.exs +++ b/test/groupher_server/cms/comments/job_comment_emotions_test.exs @@ -21,7 +21,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentEmotions do end describe "[emotion in paged article comment]" do - @tag :wip2 + @tag :wip3 test "login user should got viewer has emotioned status", ~m(job user)a do total_count = 0 page_number = 10 @@ -76,7 +76,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentEmotions do assert @default_emotions == emotions end - @tag :wip2 + @tag :wip3 test "can make emotion to comment", ~m(job user user2)a do parent_content = "parent comment" {:ok, parent_comment} = CMS.create_article_comment(:job, job.id, parent_content, user) @@ -91,7 +91,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentEmotions do assert user_exist_in?(user2, emotions.latest_downvote_users) end - @tag :wip2 + @tag :wip3 test "can undo emotion to comment", ~m(job user user2)a do parent_content = "parent comment" {:ok, parent_comment} = CMS.create_article_comment(:job, job.id, parent_content, user) @@ -114,7 +114,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentEmotions do assert not user_exist_in?(user2, emotions.latest_downvote_users) end - @tag :wip2 + @tag :wip3 test "same user make same emotion to same comment.", ~m(job user)a do parent_content = "parent comment" {:ok, parent_comment} = CMS.create_article_comment(:job, job.id, parent_content, user) @@ -128,7 +128,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentEmotions do assert user_exist_in?(user, parent_comment.emotions.latest_downvote_users) end - @tag :wip2 + @tag :wip3 test "same user same emotion to same comment only have one user_emotion record", ~m(job user)a do parent_content = "parent comment" @@ -152,7 +152,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentEmotions do assert record.heart end - @tag :wip2 + @tag :wip3 test "different user can make same emotions on same comment", ~m(job user user2 user3)a do {:ok, parent_comment} = CMS.create_article_comment(:job, job.id, "parent comment", 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 67081286f..6a127ca62 100644 --- a/test/groupher_server/cms/comments/job_comment_replies_test.exs +++ b/test/groupher_server/cms/comments/job_comment_replies_test.exs @@ -33,7 +33,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentReplies do assert exist_in?(replyed_comment, parent_comment.replies) end - @tag :wip2 + @tag :wip3 test "deleted comment can not be reply", ~m(job user user2)a do parent_content = "parent comment" reply_content = "reply comment" @@ -64,7 +64,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentReplies do assert exist_in?(replyed_comment_2, parent_comment.replies) end - @tag :wip2 + @tag :wip3 test "reply to reply inside a comment should belong same parent comment", ~m(job user user2)a do {:ok, parent_comment} = CMS.create_article_comment(:job, job.id, "parent comment", user) @@ -90,7 +90,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentReplies do assert replyed_comment_3.reply_to_id == replyed_comment_2.id end - @tag :wip2 + @tag :wip3 test "reply to reply inside a comment should have is_reply_to_others flag in meta", ~m(job user user2)a do {:ok, parent_comment} = CMS.create_article_comment(:job, job.id, "parent comment", user) @@ -110,7 +110,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentReplies do assert replyed_comment_3.meta.is_reply_to_others end - @tag :wip2 + @tag :wip3 test "comment replies only contains @max_parent_replies_count replies", ~m(job user)a do total_reply_count = @max_parent_replies_count + 1 diff --git a/test/groupher_server/cms/comments/job_comment_test.exs b/test/groupher_server/cms/comments/job_comment_test.exs index aa6ee5ac5..7c34d0d6c 100644 --- a/test/groupher_server/cms/comments/job_comment_test.exs +++ b/test/groupher_server/cms/comments/job_comment_test.exs @@ -39,7 +39,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do assert comment.meta |> Map.from_struct() |> Map.delete(:id) == @default_comment_meta end - @tag :wip2 + @tag :wip3 test "comment can be updated", ~m(job user)a do {:ok, comment} = CMS.create_article_comment(:job, job.id, "job comment", user) @@ -130,7 +130,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do assert comment.meta.is_article_author_upvoted end - @tag :wip2 + @tag :wip3 test "user upvote job comment will add id to upvoted_user_ids", ~m(job user)a do comment = "job_comment" {:ok, comment} = CMS.create_article_comment(:job, job.id, comment, user) @@ -139,7 +139,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do assert user.id in comment.meta.upvoted_user_ids end - @tag :wip2 + @tag :wip3 test "user undo upvote job comment will remove id from upvoted_user_ids", ~m(job user user2)a do comment = "job_comment" @@ -270,32 +270,26 @@ 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) - - assert not comment.is_reported - - {:ok, comment} = CMS.report_article_comment(comment.id, "reason", "attr", user) - {:ok, comment} = ORM.find(ArticleComment, comment.id) - assert not comment.is_reported - 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) - {:ok, comment} = ORM.find(ArticleComment, comment.id) - - assert not comment.is_reported - - {:ok, _comment} = CMS.undo_report_article_comment(comment.id, user) - {:ok, comment} = ORM.find(ArticleComment, comment.id) - assert not comment.is_reported - end - - @tag :wip2 + # @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) + + # {:ok, comment} = CMS.report_article_comment(comment.id, "reason", "attr", user) + # {: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) + # {:ok, comment} = ORM.find(ArticleComment, comment.id) + + # {:ok, _comment} = CMS.undo_report_article_comment(comment.id, user) + # {:ok, comment} = ORM.find(ArticleComment, comment.id) + # end + + @tag :wip3 test "can undo a report with other user report it too", ~m(user user2 job)a do {:ok, comment} = CMS.create_article_comment(:job, job.id, "commment", user) @@ -323,11 +317,10 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do assert Enum.any?(report.report_cases, &(&1.user.login == user2.login)) end - @tag :wip2 + @tag :wip3 test "report user < @report_threshold_for_fold will not fold comment", ~m(user job)a do {:ok, comment} = CMS.create_article_comment(:job, job.id, "commment", user) - assert not comment.is_reported assert not comment.is_folded Enum.reduce(1..(@report_threshold_for_fold - 1), [], fn _, _acc -> @@ -336,7 +329,6 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do end) {:ok, comment} = ORM.find(ArticleComment, comment.id) - assert comment.is_reported assert not comment.is_folded end @@ -344,7 +336,6 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do 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) - assert not comment.is_reported assert not comment.is_folded Enum.reduce(1..(@report_threshold_for_fold + 1), [], fn _, _acc -> @@ -353,7 +344,6 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do end) {:ok, comment} = ORM.find(ArticleComment, comment.id) - assert not comment.is_reported assert comment.is_folded end end @@ -463,7 +453,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do assert paged_comments.total_count == total_count end - @tag :wip2 + @tag :wip3 test "paged article comments should not contains folded and repoted comments", ~m(user job)a do total_count = 15 @@ -571,7 +561,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do end describe "[article comment delete]" do - @tag :wip2 + @tag :wip3 test "delete comment still exsit in paged list and content is gone", ~m(user job)a do total_count = 10 page_number = 1 @@ -596,7 +586,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do assert deleted_comment.body_html == @delete_hint end - @tag :wip2 + @tag :wip3 test "delete comment still update article's comments_count field", ~m(user job)a do {:ok, _comment} = CMS.create_article_comment(:job, job.id, "commment", user) {:ok, _comment} = CMS.create_article_comment(:job, job.id, "commment", user) @@ -614,7 +604,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do assert job.article_comments_count == 4 end - @tag :wip2 + @tag :wip3 test "delete comment still delete pined record if needed", ~m(user job)a do total_count = 10 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 02665c31c..0e55ecfd3 100644 --- a/test/groupher_server/cms/comments/post_comment_emotions_test.exs +++ b/test/groupher_server/cms/comments/post_comment_emotions_test.exs @@ -21,7 +21,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostCommentEmotions do end describe "[emotion in paged article comment]" do - @tag :wip2 + @tag :wip3 test "login user should got viewer has emotioned status", ~m(post user)a do total_count = 0 page_number = 10 @@ -76,7 +76,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostCommentEmotions do assert @default_emotions == emotions end - @tag :wip2 + @tag :wip3 test "can make emotion to comment", ~m(post user user2)a do parent_content = "parent comment" {:ok, parent_comment} = CMS.create_article_comment(:post, post.id, parent_content, user) @@ -91,7 +91,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostCommentEmotions do assert user_exist_in?(user2, emotions.latest_downvote_users) end - @tag :wip2 + @tag :wip3 test "can undo emotion to comment", ~m(post user user2)a do parent_content = "parent comment" {:ok, parent_comment} = CMS.create_article_comment(:post, post.id, parent_content, user) @@ -114,7 +114,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostCommentEmotions do assert not user_exist_in?(user2, emotions.latest_downvote_users) end - @tag :wip2 + @tag :wip3 test "same user make same emotion to same comment.", ~m(post user)a do parent_content = "parent comment" {:ok, parent_comment} = CMS.create_article_comment(:post, post.id, parent_content, user) @@ -128,7 +128,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostCommentEmotions do assert user_exist_in?(user, parent_comment.emotions.latest_downvote_users) end - @tag :wip2 + @tag :wip3 test "same user same emotion to same comment only have one user_emotion record", ~m(post user)a do parent_content = "parent comment" @@ -152,7 +152,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostCommentEmotions do assert record.heart end - @tag :wip2 + @tag :wip3 test "different user can make same emotions on same comment", ~m(post user user2 user3)a do {:ok, parent_comment} = CMS.create_article_comment(:post, post.id, "parent comment", 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 fc968d208..d7508fa62 100644 --- a/test/groupher_server/cms/comments/post_comment_replies_test.exs +++ b/test/groupher_server/cms/comments/post_comment_replies_test.exs @@ -33,7 +33,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostCommentReplies do assert exist_in?(replyed_comment, parent_comment.replies) end - @tag :wip2 + @tag :wip3 test "deleted comment can not be reply", ~m(post user user2)a do parent_content = "parent comment" reply_content = "reply comment" @@ -64,7 +64,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostCommentReplies do assert exist_in?(replyed_comment_2, parent_comment.replies) end - @tag :wip2 + @tag :wip3 test "reply to reply inside a comment should belong same parent comment", ~m(post user user2)a do {:ok, parent_comment} = CMS.create_article_comment(:post, post.id, "parent comment", user) @@ -90,7 +90,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostCommentReplies do assert replyed_comment_3.reply_to_id == replyed_comment_2.id end - @tag :wip2 + @tag :wip3 test "reply to reply inside a comment should have is_reply_to_others flag in meta", ~m(post user user2)a do {:ok, parent_comment} = CMS.create_article_comment(:post, post.id, "parent comment", user) @@ -110,7 +110,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostCommentReplies do assert replyed_comment_3.meta.is_reply_to_others end - @tag :wip2 + @tag :wip3 test "comment replies only contains @max_parent_replies_count replies", ~m(post user)a do total_reply_count = @max_parent_replies_count + 1 @@ -160,7 +160,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostCommentReplies do end describe "[paged article comment replies]" do - @tag :wip2 + @tag :wip3 test "can get paged replies of a parent comment", ~m(post user)a do {:ok, parent_comment} = CMS.create_article_comment(:post, post.id, "parent_conent", user) {:ok, paged_replies} = CMS.list_comment_replies(parent_comment.id, %{page: 1, size: 20}) diff --git a/test/groupher_server/cms/comments/post_comment_test.exs b/test/groupher_server/cms/comments/post_comment_test.exs index 6d337f5ce..dc0ee21e9 100644 --- a/test/groupher_server/cms/comments/post_comment_test.exs +++ b/test/groupher_server/cms/comments/post_comment_test.exs @@ -39,7 +39,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do assert comment.meta |> Map.from_struct() |> Map.delete(:id) == @default_comment_meta end - @tag :wip2 + @tag :wip3 test "comment can be updated", ~m(post user)a do {:ok, comment} = CMS.create_article_comment(:post, post.id, "post comment", user) @@ -130,7 +130,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do assert comment.meta.is_article_author_upvoted end - @tag :wip2 + @tag :wip3 test "user upvote post comment will add id to upvoted_user_ids", ~m(post user)a do comment = "post_comment" {:ok, comment} = CMS.create_article_comment(:post, post.id, comment, user) @@ -139,7 +139,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do assert user.id in comment.meta.upvoted_user_ids end - @tag :wip2 + @tag :wip3 test "user undo upvote post comment will remove id from upvoted_user_ids", ~m(post user user2)a do comment = "post_comment" @@ -270,32 +270,26 @@ 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) - - assert not comment.is_reported - - {:ok, comment} = CMS.report_article_comment(comment.id, "reason", "attr", user) - {:ok, comment} = ORM.find(ArticleComment, comment.id) - assert comment.is_reported - end - - @tag :wip2 - test "user can unreport a comment", ~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) - {:ok, comment} = ORM.find(ArticleComment, comment.id) - - assert not comment.is_reported - - {:ok, _comment} = CMS.undo_report_article_comment(comment.id, user) - {:ok, comment} = ORM.find(ArticleComment, comment.id) - assert not comment.is_reported - end - - @tag :wip2 + # @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) + + # {:ok, comment} = CMS.report_article_comment(comment.id, "reason", "attr", user) + # {:ok, comment} = ORM.find(ArticleComment, comment.id) + # end + + # @tag :wip3 + # test "user can unreport a comment", ~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) + # {:ok, comment} = ORM.find(ArticleComment, comment.id) + + # {:ok, _comment} = CMS.undo_report_article_comment(comment.id, user) + # {:ok, comment} = ORM.find(ArticleComment, comment.id) + # end + + @tag :wip3 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) @@ -327,7 +321,6 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do 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) - assert not comment.is_reported assert not comment.is_folded Enum.reduce(1..(@report_threshold_for_fold - 1), [], fn _, _acc -> @@ -336,7 +329,6 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do end) {:ok, comment} = ORM.find(ArticleComment, comment.id) - assert comment.is_reported assert not comment.is_folded end @@ -344,7 +336,6 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do 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) - assert not comment.is_reported assert not comment.is_folded Enum.reduce(1..(@report_threshold_for_fold + 1), [], fn _, _acc -> @@ -353,7 +344,6 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do end) {:ok, comment} = ORM.find(ArticleComment, comment.id) - assert comment.is_reported assert comment.is_folded end end @@ -489,10 +479,6 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do {:ok, _comment} = CMS.fold_article_comment(random_comment_2.id, user) {:ok, _comment} = CMS.fold_article_comment(random_comment_3.id, user) - {:ok, _comment} = CMS.report_article_comment(random_comment_4.id, "reason", "attr", user) - {:ok, _comment} = CMS.report_article_comment(random_comment_5.id, "reason", "attr", user) - {:ok, _comment} = CMS.report_article_comment(random_comment_6.id, "reason", "attr", user) - {:ok, paged_comments} = CMS.list_article_comments(:post, post.id, %{page: page_number, size: page_size}, :replies) @@ -500,13 +486,9 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do assert not exist_in?(random_comment_2, paged_comments.entries) assert not exist_in?(random_comment_3, paged_comments.entries) - assert not exist_in?(random_comment_4, paged_comments.entries) - assert not exist_in?(random_comment_5, paged_comments.entries) - assert not exist_in?(random_comment_6, paged_comments.entries) - assert page_number == paged_comments.page_number assert page_size == paged_comments.page_size - assert total_count - 6 == paged_comments.total_count + assert total_count - 3 == paged_comments.total_count end @tag :wip @@ -571,7 +553,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do end describe "[article comment delete]" do - @tag :wip2 + @tag :wip3 test "delete comment still exsit in paged list and content is gone", ~m(user post)a do total_count = 10 page_number = 1 @@ -596,7 +578,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do assert deleted_comment.body_html == @delete_hint end - @tag :wip2 + @tag :wip3 test "delete comment still update article's comments_count field", ~m(user post)a do {:ok, _comment} = CMS.create_article_comment(:post, post.id, "commment", user) {:ok, _comment} = CMS.create_article_comment(:post, post.id, "commment", user) @@ -614,7 +596,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do assert post.article_comments_count == 4 end - @tag :wip2 + @tag :wip3 test "delete comment still delete pined record if needed", ~m(user post)a do total_count = 10 diff --git a/test/groupher_server/cms/emotions/job_emotions_test.exs b/test/groupher_server/cms/emotions/job_emotions_test.exs index bd822186b..699214674 100644 --- a/test/groupher_server/cms/emotions/job_emotions_test.exs +++ b/test/groupher_server/cms/emotions/job_emotions_test.exs @@ -22,7 +22,7 @@ defmodule GroupherServer.Test.CMS.Emotions.JobEmotions do end describe "[emotion in paged jobs]" do - @tag :wip2 + @tag :wip3 test "login user should got viewer has emotioned status", ~m(community job_attrs user)a do total_count = 10 @@ -61,7 +61,7 @@ defmodule GroupherServer.Test.CMS.Emotions.JobEmotions do end describe "[basic article emotion]" do - @tag :wip2 + @tag :wip3 test "job has default emotions after created", ~m(community job_attrs user)a do {:ok, job} = CMS.create_content(community, :job, job_attrs, user) @@ -69,7 +69,7 @@ defmodule GroupherServer.Test.CMS.Emotions.JobEmotions do assert @default_emotions == emotions end - @tag :wip2 + @tag :wip3 test "can make emotion to job", ~m(community job_attrs user user2)a do {:ok, job} = CMS.create_content(community, :job, job_attrs, user) @@ -83,7 +83,7 @@ defmodule GroupherServer.Test.CMS.Emotions.JobEmotions do assert user_exist_in?(user2, emotions.latest_downvote_users) end - @tag :wip2 + @tag :wip3 test "can undo emotion to job", ~m(community job_attrs user user2)a do {:ok, job} = CMS.create_content(community, :job, job_attrs, user) @@ -100,7 +100,7 @@ defmodule GroupherServer.Test.CMS.Emotions.JobEmotions do assert not user_exist_in?(user2, emotions.latest_downvote_users) end - @tag :wip2 + @tag :wip3 test "same user make same emotion to same job.", ~m(community job_attrs user)a do {:ok, job} = CMS.create_content(community, :job, job_attrs, user) @@ -113,7 +113,7 @@ defmodule GroupherServer.Test.CMS.Emotions.JobEmotions do assert user_exist_in?(user, job.emotions.latest_downvote_users) end - @tag :wip2 + @tag :wip3 test "same user same emotion to same job only have one user_emotion record", ~m(community job_attrs user)a do {:ok, job} = CMS.create_content(community, :job, job_attrs, user) @@ -131,7 +131,7 @@ defmodule GroupherServer.Test.CMS.Emotions.JobEmotions do assert record.heart end - @tag :wip2 + @tag :wip3 test "different user can make same emotions on same job", ~m(community job_attrs user user2 user3)a do {:ok, job} = CMS.create_content(community, :job, job_attrs, user) @@ -148,7 +148,7 @@ defmodule GroupherServer.Test.CMS.Emotions.JobEmotions do assert user_exist_in?(user3, emotions.latest_beer_users) end - @tag :wip2 + @tag :wip3 test "same user can make differcent emotions on same job", ~m(community job_attrs user)a do {:ok, job} = CMS.create_content(community, :job, job_attrs, user) diff --git a/test/groupher_server/cms/emotions/post_emotions_test.exs b/test/groupher_server/cms/emotions/post_emotions_test.exs index 2624b43d3..24a10fce8 100644 --- a/test/groupher_server/cms/emotions/post_emotions_test.exs +++ b/test/groupher_server/cms/emotions/post_emotions_test.exs @@ -22,7 +22,7 @@ defmodule GroupherServer.Test.CMS.Emotions.PostEmotions do end describe "[emotion in paged posts]" do - @tag :wip2 + @tag :wip3 test "login user should got viewer has emotioned status", ~m(community post_attrs user)a do total_count = 10 @@ -61,7 +61,7 @@ defmodule GroupherServer.Test.CMS.Emotions.PostEmotions do end describe "[basic article emotion]" do - @tag :wip2 + @tag :wip3 test "post has default emotions after created", ~m(community post_attrs user)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) @@ -69,7 +69,7 @@ defmodule GroupherServer.Test.CMS.Emotions.PostEmotions do assert @default_emotions == emotions end - @tag :wip2 + @tag :wip3 test "can make emotion to post", ~m(community post_attrs user user2)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) @@ -83,7 +83,7 @@ defmodule GroupherServer.Test.CMS.Emotions.PostEmotions do assert user_exist_in?(user2, emotions.latest_downvote_users) end - @tag :wip2 + @tag :wip3 test "can undo emotion to post", ~m(community post_attrs user user2)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) @@ -100,7 +100,7 @@ defmodule GroupherServer.Test.CMS.Emotions.PostEmotions do assert not user_exist_in?(user2, emotions.latest_downvote_users) end - @tag :wip2 + @tag :wip3 test "same user make same emotion to same post.", ~m(community post_attrs user)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) @@ -113,7 +113,7 @@ defmodule GroupherServer.Test.CMS.Emotions.PostEmotions do assert user_exist_in?(user, post.emotions.latest_downvote_users) end - @tag :wip2 + @tag :wip3 test "same user same emotion to same post only have one user_emotion record", ~m(community post_attrs user)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) @@ -131,7 +131,7 @@ defmodule GroupherServer.Test.CMS.Emotions.PostEmotions do assert record.heart end - @tag :wip2 + @tag :wip3 test "different user can make same emotions on same post", ~m(community post_attrs user user2 user3)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) @@ -148,7 +148,7 @@ defmodule GroupherServer.Test.CMS.Emotions.PostEmotions do assert user_exist_in?(user3, emotions.latest_beer_users) end - @tag :wip2 + @tag :wip3 test "same user can make differcent emotions on same post", ~m(community post_attrs user)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) diff --git a/test/groupher_server/cms/job_test.exs b/test/groupher_server/cms/job_test.exs index 297468cd6..6d924a25f 100644 --- a/test/groupher_server/cms/job_test.exs +++ b/test/groupher_server/cms/job_test.exs @@ -25,7 +25,7 @@ defmodule GroupherServer.Test.Job do assert found.title == job.title end - @tag :wip2 + @tag :wip3 test "read job should update views and meta viewed_user_list", ~m(job_attrs community user user2)a do {:ok, job} = CMS.create_content(community, :job, job_attrs, user) diff --git a/test/groupher_server/cms/post_test.exs b/test/groupher_server/cms/post_test.exs index f028aece3..eae07914a 100644 --- a/test/groupher_server/cms/post_test.exs +++ b/test/groupher_server/cms/post_test.exs @@ -18,7 +18,7 @@ defmodule GroupherServer.Test.CMS.Post do describe "[cms post curd]" do alias CMS.{Author, Community} - @tag :wip2 + @tag :wip3 test "can create post with valid attrs", ~m(user community post_attrs)a do assert {:error, _} = ORM.find_by(Author, user_id: user.id) @@ -27,7 +27,7 @@ defmodule GroupherServer.Test.CMS.Post do assert post.title == post_attrs.title end - @tag :wip2 + @tag :wip3 test "read post should update views and meta viewed_user_list", ~m(post_attrs community user user2)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) diff --git a/test/groupher_server/cms/repo_test.exs b/test/groupher_server/cms/repo_test.exs index 69b65a579..0446b00c5 100644 --- a/test/groupher_server/cms/repo_test.exs +++ b/test/groupher_server/cms/repo_test.exs @@ -17,7 +17,7 @@ defmodule GroupherServer.Test.Repo do describe "[cms repo curd]" do alias CMS.{Author, Community} - @tag :wip2 + @tag :wip3 test "can create repo with valid attrs", ~m(user community repo_attrs)a do assert {:error, _} = ORM.find_by(Author, user_id: user.id) @@ -27,7 +27,7 @@ defmodule GroupherServer.Test.Repo do assert repo.contributors |> length !== 0 end - @tag :wip2 + @tag :wip3 test "read repo should update views and meta viewed_user_list", ~m(repo_attrs community user user2)a do {:ok, repo} = CMS.create_content(community, :repo, repo_attrs, user) diff --git a/test/groupher_server/cms/upvotes/job_upvote_test.exs b/test/groupher_server/cms/upvotes/job_upvote_test.exs index daf36dd6c..18286922b 100644 --- a/test/groupher_server/cms/upvotes/job_upvote_test.exs +++ b/test/groupher_server/cms/upvotes/job_upvote_test.exs @@ -15,7 +15,7 @@ defmodule GroupherServer.Test.Upvotes.JobUpvote do end describe "[cms job upvote]" do - @tag :wip2 + @tag :wip3 test "job can be upvote && upvotes_count should inc by 1", ~m(user user2 community job_attrs)a do {:ok, job} = CMS.create_content(community, :job, job_attrs, user) @@ -28,7 +28,7 @@ defmodule GroupherServer.Test.Upvotes.JobUpvote do assert article.upvotes_count == 2 end - @tag :wip2 + @tag :wip3 test "job can be undo upvote && upvotes_count should dec by 1", ~m(user user2 community job_attrs)a do {:ok, job} = CMS.create_content(community, :job, job_attrs, user) @@ -41,7 +41,7 @@ defmodule GroupherServer.Test.Upvotes.JobUpvote do assert article.upvotes_count == 0 end - @tag :wip2 + @tag :wip3 test "can get upvotes_users", ~m(user user2 community job_attrs)a do {:ok, job} = CMS.create_content(community, :job, job_attrs, user) @@ -55,7 +55,7 @@ defmodule GroupherServer.Test.Upvotes.JobUpvote do assert user_exist_in?(user2, users.entries) end - @tag :wip2 + @tag :wip3 test "job meta history should be updated after upvote", ~m(user user2 community job_attrs)a do {:ok, job} = CMS.create_content(community, :job, job_attrs, user) @@ -67,7 +67,7 @@ defmodule GroupherServer.Test.Upvotes.JobUpvote do assert user2.id in article.meta.upvoted_user_ids end - @tag :wip2 + @tag :wip3 test "job meta history should be updated after undo upvote", ~m(user user2 community job_attrs)a do {:ok, job} = CMS.create_content(community, :job, job_attrs, user) diff --git a/test/groupher_server/cms/upvotes/post_upvote_test.exs b/test/groupher_server/cms/upvotes/post_upvote_test.exs index fda68d1d1..5cf2c8ed8 100644 --- a/test/groupher_server/cms/upvotes/post_upvote_test.exs +++ b/test/groupher_server/cms/upvotes/post_upvote_test.exs @@ -15,7 +15,7 @@ defmodule GroupherServer.Test.Upvotes.PostUpvote do end describe "[cms post upvote]" do - @tag :wip2 + @tag :wip3 test "post can be upvote && upvotes_count should inc by 1", ~m(user user2 community post_attrs)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) @@ -28,7 +28,7 @@ defmodule GroupherServer.Test.Upvotes.PostUpvote do assert article.upvotes_count == 2 end - @tag :wip2 + @tag :wip3 test "post can be undo upvote && upvotes_count should dec by 1", ~m(user user2 community post_attrs)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) @@ -41,7 +41,7 @@ defmodule GroupherServer.Test.Upvotes.PostUpvote do assert article.upvotes_count == 0 end - @tag :wip2 + @tag :wip3 test "can get upvotes_users", ~m(user user2 community post_attrs)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) @@ -55,7 +55,7 @@ defmodule GroupherServer.Test.Upvotes.PostUpvote do assert user_exist_in?(user2, users.entries) end - @tag :wip2 + @tag :wip3 test "post meta history should be updated after upvote", ~m(user user2 community post_attrs)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) @@ -67,7 +67,7 @@ defmodule GroupherServer.Test.Upvotes.PostUpvote do assert user2.id in article.meta.upvoted_user_ids end - @tag :wip2 + @tag :wip3 test "post meta history should be updated after undo upvote", ~m(user user2 community post_attrs)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) diff --git a/test/groupher_server_web/mutation/accounts/customization_test.exs b/test/groupher_server_web/mutation/accounts/customization_test.exs index de3de03cd..8f42ad231 100644 --- a/test/groupher_server_web/mutation/accounts/customization_test.exs +++ b/test/groupher_server_web/mutation/accounts/customization_test.exs @@ -72,7 +72,7 @@ defmodule GroupherServer.Test.Mutation.Account.Customization do } } """ - @tag :wip2 + @tag :wip3 test "PageSizeProof middleware should lint c11n displayDensity size", ~m(user)a do user_conn = simu_conn(:user, user) db_insert_multi(:post, 50) diff --git a/test/groupher_server_web/mutation/cms/articles/job_emotion_test.exs b/test/groupher_server_web/mutation/cms/articles/job_emotion_test.exs index 428036419..b822aff94 100644 --- a/test/groupher_server_web/mutation/cms/articles/job_emotion_test.exs +++ b/test/groupher_server_web/mutation/cms/articles/job_emotion_test.exs @@ -32,7 +32,7 @@ defmodule GroupherServer.Test.Mutation.Articles.JobEmotion do } } """ - @tag :wip2 + @tag :wip3 test "login user can emotion to a pjob", ~m(community job_attrs user user_conn)a do {:ok, job} = CMS.create_content(community, :job, job_attrs, user) @@ -58,7 +58,7 @@ defmodule GroupherServer.Test.Mutation.Articles.JobEmotion do } } """ - @tag :wip2 + @tag :wip3 test "login user can undo emotion to a job", ~m(community job_attrs user owner_conn)a do {:ok, job} = CMS.create_content(community, :job, job_attrs, user) {:ok, _} = CMS.emotion_to_article(:job, job.id, :beer, user) diff --git a/test/groupher_server_web/mutation/cms/articles/job_report_test.exs b/test/groupher_server_web/mutation/cms/articles/job_report_test.exs index 248946c7c..39acfbbb2 100644 --- a/test/groupher_server_web/mutation/cms/articles/job_report_test.exs +++ b/test/groupher_server_web/mutation/cms/articles/job_report_test.exs @@ -22,18 +22,16 @@ defmodule GroupherServer.Test.Mutation.Articles.JobReport do reportJob(id: $id, reason: $reason, attr: $attr) { id title - isReported } } """ - @tag :wip2 + @tag :wip3 test "login user can report a job", ~m(community job_attrs user user_conn)a do {:ok, job} = CMS.create_content(community, :job, job_attrs, user) variables = %{id: job.id, reason: "reason"} article = user_conn |> mutation_result(@report_query, variables, "reportJob") - assert not article["isReported"] assert article["id"] == to_string(job.id) end @@ -42,25 +40,22 @@ defmodule GroupherServer.Test.Mutation.Articles.JobReport do undoReportJob(id: $id) { id title - isReported } } """ - @tag :wip2 + @tag :wip3 test "login user can undo report a job", ~m(community job_attrs user user_conn)a do {:ok, job} = CMS.create_content(community, :job, job_attrs, user) variables = %{id: job.id, reason: "reason"} article = user_conn |> mutation_result(@report_query, variables, "reportJob") - assert not article["isReported"] assert article["id"] == to_string(job.id) variables = %{id: job.id} article = user_conn |> mutation_result(@undo_report_query, variables, "undoReportJob") - assert not article["isReported"] assert article["id"] == to_string(job.id) end end diff --git a/test/groupher_server_web/mutation/cms/articles/job_test.exs b/test/groupher_server_web/mutation/cms/articles/job_test.exs index e8875e3be..c269abc50 100644 --- a/test/groupher_server_web/mutation/cms/articles/job_test.exs +++ b/test/groupher_server_web/mutation/cms/articles/job_test.exs @@ -282,7 +282,7 @@ defmodule GroupherServer.Test.Mutation.Articles.Job do } } """ - @tag :wip2 + @tag :wip3 test "can delete a job by job's owner", ~m(owner_conn job)a do deleted = owner_conn |> mutation_result(@query, %{id: job.id}, "deleteJob") diff --git a/test/groupher_server_web/mutation/cms/articles/post_emotion_test.exs b/test/groupher_server_web/mutation/cms/articles/post_emotion_test.exs index 0d4196d7d..30c37a5e4 100644 --- a/test/groupher_server_web/mutation/cms/articles/post_emotion_test.exs +++ b/test/groupher_server_web/mutation/cms/articles/post_emotion_test.exs @@ -32,7 +32,7 @@ defmodule GroupherServer.Test.Mutation.Articles.PostEmotion do } } """ - @tag :wip2 + @tag :wip3 test "login user can emotion to a ppost", ~m(community post_attrs user user_conn)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) @@ -58,7 +58,7 @@ defmodule GroupherServer.Test.Mutation.Articles.PostEmotion do } } """ - @tag :wip2 + @tag :wip3 test "login user can undo emotion to a post", ~m(community post_attrs user owner_conn)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) {:ok, _} = CMS.emotion_to_article(:post, post.id, :beer, user) diff --git a/test/groupher_server_web/mutation/cms/articles/post_report_test.exs b/test/groupher_server_web/mutation/cms/articles/post_report_test.exs index 99ffbf6e9..5a53acfca 100644 --- a/test/groupher_server_web/mutation/cms/articles/post_report_test.exs +++ b/test/groupher_server_web/mutation/cms/articles/post_report_test.exs @@ -22,7 +22,6 @@ defmodule GroupherServer.Test.Mutation.Articles.PostReport do reportPost(id: $id, reason: $reason, attr: $attr) { id title - isReported } } """ @@ -33,7 +32,6 @@ defmodule GroupherServer.Test.Mutation.Articles.PostReport do variables = %{id: post.id, reason: "reason"} article = user_conn |> mutation_result(@report_query, variables, "reportPost") - assert not article["isReported"] assert article["id"] == to_string(post.id) end @@ -42,7 +40,6 @@ defmodule GroupherServer.Test.Mutation.Articles.PostReport do undoReportPost(id: $id) { id title - isReported } } """ @@ -53,14 +50,11 @@ defmodule GroupherServer.Test.Mutation.Articles.PostReport do variables = %{id: post.id, reason: "reason"} article = user_conn |> mutation_result(@report_query, variables, "reportPost") - assert not article["isReported"] assert article["id"] == to_string(post.id) variables = %{id: post.id} article = user_conn |> mutation_result(@undo_report_query, variables, "undoReportPost") - - assert not article["isReported"] assert article["id"] == to_string(post.id) end end 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 8def50861..ac96ddaa2 100644 --- a/test/groupher_server_web/mutation/cms/articles/post_test.exs +++ b/test/groupher_server_web/mutation/cms/articles/post_test.exs @@ -142,7 +142,7 @@ defmodule GroupherServer.Test.Mutation.Articles.Post do } } """ - @tag :wip2 + @tag :wip3 test "delete a post by post's owner", ~m(owner_conn post)a do deleted = owner_conn |> mutation_result(@query, %{id: post.id}, "deletePost") diff --git a/test/groupher_server_web/mutation/cms/articles/repo_report_test.exs b/test/groupher_server_web/mutation/cms/articles/repo_report_test.exs index c6bcbf0c6..c00165f59 100644 --- a/test/groupher_server_web/mutation/cms/articles/repo_report_test.exs +++ b/test/groupher_server_web/mutation/cms/articles/repo_report_test.exs @@ -22,18 +22,16 @@ defmodule GroupherServer.Test.Mutation.Articles.RepoReport do reportRepo(id: $id, reason: $reason, attr: $attr) { id title - isReported } } """ - @tag :wip2 + @tag :wip3 test "login user can report a repo", ~m(community repo_attrs user user_conn)a do {:ok, repo} = CMS.create_content(community, :repo, repo_attrs, user) variables = %{id: repo.id, reason: "reason"} article = user_conn |> mutation_result(@report_query, variables, "reportRepo") - assert not article["isReported"] assert article["id"] == to_string(repo.id) end @@ -42,25 +40,22 @@ defmodule GroupherServer.Test.Mutation.Articles.RepoReport do undoReportRepo(id: $id) { id title - isReported } } """ - @tag :wip2 + @tag :wip3 test "login user can undo report a repo", ~m(community repo_attrs user user_conn)a do {:ok, repo} = CMS.create_content(community, :repo, repo_attrs, user) variables = %{id: repo.id, reason: "reason"} article = user_conn |> mutation_result(@report_query, variables, "reportRepo") - assert not article["isReported"] assert article["id"] == to_string(repo.id) variables = %{id: repo.id} article = user_conn |> mutation_result(@undo_report_query, variables, "undoReportRepo") - assert not article["isReported"] assert article["id"] == to_string(repo.id) end end diff --git a/test/groupher_server_web/mutation/cms/articles/repo_test.exs b/test/groupher_server_web/mutation/cms/articles/repo_test.exs index ff70a48e0..afedc0217 100644 --- a/test/groupher_server_web/mutation/cms/articles/repo_test.exs +++ b/test/groupher_server_web/mutation/cms/articles/repo_test.exs @@ -193,7 +193,7 @@ defmodule GroupherServer.Test.Mutation.Articles.Repo do } } """ - @tag :wip2 + @tag :wip3 test "delete a repo by repo's owner", ~m(owner_conn repo)a do deleted = owner_conn |> mutation_result(@query, %{id: repo.id}, "deleteRepo") @@ -201,7 +201,7 @@ defmodule GroupherServer.Test.Mutation.Articles.Repo do assert {:error, _} = ORM.find(CMS.Repo, deleted["id"]) end - @tag :wip2 + @tag :wip3 test "can delete a repo by auth user", ~m(repo)a do belongs_community_title = repo.communities |> List.first() |> Map.get(:title) rule_conn = simu_conn(:user, cms: %{belongs_community_title => %{"repo.delete" => true}}) @@ -212,7 +212,7 @@ defmodule GroupherServer.Test.Mutation.Articles.Repo do assert {:error, _} = ORM.find(CMS.Repo, deleted["id"]) end - @tag :wip2 + @tag :wip3 test "delete a repo without login user fails", ~m(guest_conn repo)a do assert guest_conn |> mutation_get_error?(@query, %{id: repo.id}, ecode(:account_login)) end diff --git a/test/groupher_server_web/mutation/cms/cms_test.exs b/test/groupher_server_web/mutation/cms/cms_test.exs index 9a2bd8d88..158431643 100644 --- a/test/groupher_server_web/mutation/cms/cms_test.exs +++ b/test/groupher_server_web/mutation/cms/cms_test.exs @@ -431,7 +431,7 @@ defmodule GroupherServer.Test.Mutation.CMS.Basic do } } """ - @tag :wip2 + @tag :wip3 test "auth user can create thread", ~m(user)a do title = "post" raw = "POST" @@ -445,7 +445,7 @@ defmodule GroupherServer.Test.Mutation.CMS.Basic do assert result["title"] == title end - @tag :wip2 + @tag :wip3 test "unauth user create thread fails", ~m(user_conn guest_conn)a do title = "psot" raw = "POST" diff --git a/test/groupher_server_web/mutation/cms/comments/job_comment_test.exs b/test/groupher_server_web/mutation/cms/comments/job_comment_test.exs index aea2e5a99..3161d7018 100644 --- a/test/groupher_server_web/mutation/cms/comments/job_comment_test.exs +++ b/test/groupher_server_web/mutation/cms/comments/job_comment_test.exs @@ -24,7 +24,7 @@ defmodule GroupherServer.Test.Mutation.Comments.JobComment do } } """ - @tag :wip2 + @tag :wip3 test "write article comment to a exsit job", ~m(job user_conn)a do comment = "a test comment" variables = %{thread: "JOB", id: job.id, content: comment} @@ -43,7 +43,7 @@ defmodule GroupherServer.Test.Mutation.Comments.JobComment do } } """ - @tag :wip2 + @tag :wip3 test "login user can reply to a comment", ~m(job user user_conn)a do {:ok, comment} = CMS.create_article_comment(:job, job.id, "commment", user) variables = %{id: comment.id, content: "reply content"} @@ -63,7 +63,7 @@ defmodule GroupherServer.Test.Mutation.Comments.JobComment do } } """ - @tag :wip2 + @tag :wip3 test "only owner can update a exsit comment", ~m(job user guest_conn user_conn owner_conn)a do {:ok, comment} = CMS.create_article_comment(:job, job.id, "job comment", user) @@ -88,7 +88,7 @@ defmodule GroupherServer.Test.Mutation.Comments.JobComment do } } """ - @tag :wip2 + @tag :wip3 test "only owner can delete a exsit comment", ~m(job user guest_conn user_conn owner_conn)a do {:ok, comment} = CMS.create_article_comment(:job, job.id, "job comment", user) @@ -123,7 +123,7 @@ defmodule GroupherServer.Test.Mutation.Comments.JobComment do } } """ - @tag :wip2 + @tag :wip3 test "login user can emotion to a comment", ~m(job user user_conn)a do {:ok, comment} = CMS.create_article_comment(:job, job.id, "job comment", user) variables = %{id: comment.id, emotion: "BEER"} @@ -150,7 +150,7 @@ defmodule GroupherServer.Test.Mutation.Comments.JobComment do } } """ - @tag :wip2 + @tag :wip3 test "login user can undo emotion to a comment", ~m(job user owner_conn)a do {:ok, comment} = CMS.create_article_comment(:job, job.id, "job comment", user) {:ok, _} = CMS.emotion_to_comment(comment.id, :beer, user) diff --git a/test/groupher_server_web/mutation/cms/comments/post_comment_test.exs b/test/groupher_server_web/mutation/cms/comments/post_comment_test.exs index 2e4fad36e..9a8ec7d86 100644 --- a/test/groupher_server_web/mutation/cms/comments/post_comment_test.exs +++ b/test/groupher_server_web/mutation/cms/comments/post_comment_test.exs @@ -24,7 +24,7 @@ defmodule GroupherServer.Test.Mutation.Comments.PostComment do } } """ - @tag :wip2 + @tag :wip3 test "write article comment to a exsit post", ~m(post user_conn)a do comment = "a test comment" variables = %{thread: "POST", id: post.id, content: comment} @@ -43,7 +43,7 @@ defmodule GroupherServer.Test.Mutation.Comments.PostComment do } } """ - @tag :wip2 + @tag :wip3 test "login user can reply to a comment", ~m(post user user_conn)a do {:ok, comment} = CMS.create_article_comment(:post, post.id, "commment", user) variables = %{id: comment.id, content: "reply content"} @@ -63,7 +63,7 @@ defmodule GroupherServer.Test.Mutation.Comments.PostComment do } } """ - @tag :wip2 + @tag :wip3 test "only owner can update a exsit comment", ~m(post user guest_conn user_conn owner_conn)a do {:ok, comment} = CMS.create_article_comment(:post, post.id, "post comment", user) @@ -88,7 +88,7 @@ defmodule GroupherServer.Test.Mutation.Comments.PostComment do } } """ - @tag :wip2 + @tag :wip3 test "only owner can delete a exsit comment", ~m(post user guest_conn user_conn owner_conn)a do {:ok, comment} = CMS.create_article_comment(:post, post.id, "post comment", user) @@ -123,7 +123,7 @@ defmodule GroupherServer.Test.Mutation.Comments.PostComment do } } """ - @tag :wip2 + @tag :wip3 test "login user can emotion to a comment", ~m(post user user_conn)a do {:ok, comment} = CMS.create_article_comment(:post, post.id, "post comment", user) variables = %{id: comment.id, emotion: "BEER"} @@ -150,7 +150,7 @@ defmodule GroupherServer.Test.Mutation.Comments.PostComment do } } """ - @tag :wip2 + @tag :wip3 test "login user can undo emotion to a comment", ~m(post user owner_conn)a do {:ok, comment} = CMS.create_article_comment(:post, post.id, "post comment", user) {:ok, _} = CMS.emotion_to_comment(comment.id, :beer, user) diff --git a/test/groupher_server_web/mutation/cms/flags/job_flag_test.exs b/test/groupher_server_web/mutation/cms/flags/job_flag_test.exs index d91b8591e..c9c0fb219 100644 --- a/test/groupher_server_web/mutation/cms/flags/job_flag_test.exs +++ b/test/groupher_server_web/mutation/cms/flags/job_flag_test.exs @@ -25,7 +25,7 @@ defmodule GroupherServer.Test.Mutation.Flags.JobFlag do } } """ - @tag :wip2 + @tag :wip3 test "auth user can trash job", ~m(community job)a do variables = %{id: job.id, communityId: community.id} @@ -38,7 +38,7 @@ defmodule GroupherServer.Test.Mutation.Flags.JobFlag do assert updated["trash"] == true end - @tag :wip2 + @tag :wip3 test "unauth user trash job fails", ~m(user_conn guest_conn job community)a do variables = %{id: job.id, communityId: community.id} rule_conn = simu_conn(:user, cms: %{"what.ever" => true}) @@ -56,7 +56,7 @@ defmodule GroupherServer.Test.Mutation.Flags.JobFlag do } } """ - @tag :wip2 + @tag :wip3 test "auth user can undo trash job", ~m(community job)a do variables = %{id: job.id, communityId: community.id} @@ -87,7 +87,7 @@ defmodule GroupherServer.Test.Mutation.Flags.JobFlag do } } """ - @tag :wip2 + @tag :wip3 test "auth user can pin job", ~m(community job)a do variables = %{id: job.id, communityId: community.id} @@ -99,7 +99,7 @@ defmodule GroupherServer.Test.Mutation.Flags.JobFlag do assert updated["id"] == to_string(job.id) end - @tag :wip2 + @tag :wip3 test "unauth user pin job fails", ~m(user_conn guest_conn community job)a do variables = %{id: job.id, communityId: community.id} rule_conn = simu_conn(:user, cms: %{"what.ever" => true}) @@ -117,7 +117,7 @@ defmodule GroupherServer.Test.Mutation.Flags.JobFlag do } } """ - @tag :wip2 + @tag :wip3 test "auth user can undo pin job", ~m(community job)a do variables = %{id: job.id, communityId: community.id} @@ -131,7 +131,7 @@ defmodule GroupherServer.Test.Mutation.Flags.JobFlag do assert updated["isPinned"] == false end - @tag :wip2 + @tag :wip3 test "unauth user undo pin job fails", ~m(user_conn guest_conn community job)a do variables = %{id: job.id, communityId: community.id} rule_conn = simu_conn(:user, cms: %{"what.ever" => true}) 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 f54f9f9e2..61d6eacb0 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 } } """ - @tag :wip2 + @tag :wip3 test "auth user can trash post", ~m(community post)a do variables = %{id: post.id, communityId: community.id} @@ -38,7 +38,7 @@ defmodule GroupherServer.Test.Mutation.Flags.PostFlag do assert updated["trash"] == true end - @tag :wip2 + @tag :wip3 test "unauth user trash post fails", ~m(user_conn guest_conn post community)a do variables = %{id: post.id, communityId: community.id} rule_conn = simu_conn(:user, cms: %{"what.ever" => true}) @@ -56,7 +56,7 @@ defmodule GroupherServer.Test.Mutation.Flags.PostFlag do } } """ - @tag :wip2 + @tag :wip3 test "auth user can undo trash post", ~m(community post)a do variables = %{id: post.id, communityId: community.id} @@ -71,7 +71,7 @@ defmodule GroupherServer.Test.Mutation.Flags.PostFlag do assert updated["trash"] == false end - @tag :wip2 + @tag :wip3 test "unauth user undo trash post fails", ~m(user_conn guest_conn community post)a do variables = %{id: post.id, communityId: community.id} rule_conn = simu_conn(:user, cms: %{"what.ever" => true}) @@ -88,7 +88,7 @@ defmodule GroupherServer.Test.Mutation.Flags.PostFlag do } } """ - @tag :wip2 + @tag :wip3 test "auth user can pin post", ~m(community post)a do variables = %{id: post.id, communityId: community.id} @@ -100,7 +100,7 @@ defmodule GroupherServer.Test.Mutation.Flags.PostFlag do assert updated["id"] == to_string(post.id) end - @tag :wip2 + @tag :wip3 test "unauth user pin post fails", ~m(user_conn guest_conn community post)a do variables = %{id: post.id, communityId: community.id} rule_conn = simu_conn(:user, cms: %{"what.ever" => true}) @@ -118,7 +118,7 @@ defmodule GroupherServer.Test.Mutation.Flags.PostFlag do } } """ - @tag :wip2 + @tag :wip3 test "auth user can undo pin post", ~m(community post)a do variables = %{id: post.id, communityId: community.id} @@ -131,7 +131,7 @@ defmodule GroupherServer.Test.Mutation.Flags.PostFlag do assert updated["id"] == to_string(post.id) end - @tag :wip2 + @tag :wip3 test "unauth user undo pin post fails", ~m(user_conn guest_conn community post)a do variables = %{id: post.id, communityId: community.id} rule_conn = simu_conn(:user, cms: %{"what.ever" => true}) diff --git a/test/groupher_server_web/mutation/cms/flags/repo_flag_test.exs b/test/groupher_server_web/mutation/cms/flags/repo_flag_test.exs index 2243a0125..6a3c5270c 100644 --- a/test/groupher_server_web/mutation/cms/flags/repo_flag_test.exs +++ b/test/groupher_server_web/mutation/cms/flags/repo_flag_test.exs @@ -25,7 +25,7 @@ defmodule GroupherServer.Test.Mutation.Flags.RepoFlag do } } """ - @tag :wip2 + @tag :wip3 test "auth user can trash repo", ~m(community repo)a do variables = %{id: repo.id, communityId: community.id} @@ -38,7 +38,7 @@ defmodule GroupherServer.Test.Mutation.Flags.RepoFlag do assert updated["trash"] == true end - @tag :wip2 + @tag :wip3 test "unauth user trash repo fails", ~m(user_conn guest_conn repo community)a do variables = %{id: repo.id, communityId: community.id} rule_conn = simu_conn(:user, cms: %{"what.ever" => true}) @@ -56,7 +56,7 @@ defmodule GroupherServer.Test.Mutation.Flags.RepoFlag do } } """ - @tag :wip2 + @tag :wip3 test "auth user can undo trash repo", ~m(community repo)a do variables = %{id: repo.id, communityId: community.id} @@ -71,7 +71,7 @@ defmodule GroupherServer.Test.Mutation.Flags.RepoFlag do assert updated["trash"] == false end - @tag :wip2 + @tag :wip3 test "unauth user undo trash repo fails", ~m(user_conn guest_conn community repo)a do variables = %{id: repo.id, communityId: community.id} rule_conn = simu_conn(:user, cms: %{"what.ever" => true}) @@ -88,7 +88,7 @@ defmodule GroupherServer.Test.Mutation.Flags.RepoFlag do } } """ - @tag :wip2 + @tag :wip3 test "auth user can pin repo", ~m(community repo)a do variables = %{id: repo.id, communityId: community.id} @@ -100,7 +100,7 @@ defmodule GroupherServer.Test.Mutation.Flags.RepoFlag do assert updated["id"] == to_string(repo.id) end - @tag :wip2 + @tag :wip3 test "unauth user pin repo fails", ~m(user_conn guest_conn community repo)a do variables = %{id: repo.id, communityId: community.id} rule_conn = simu_conn(:user, cms: %{"what.ever" => true}) @@ -118,7 +118,7 @@ defmodule GroupherServer.Test.Mutation.Flags.RepoFlag do } } """ - @tag :wip2 + @tag :wip3 test "auth user can undo pin repo", ~m(community repo)a do variables = %{id: repo.id, communityId: community.id} @@ -131,7 +131,7 @@ defmodule GroupherServer.Test.Mutation.Flags.RepoFlag do assert updated["id"] == to_string(repo.id) end - @tag :wip2 + @tag :wip3 test "unauth user undo pin repo fails", ~m(user_conn guest_conn community repo)a do variables = %{id: repo.id, communityId: community.id} rule_conn = simu_conn(:user, cms: %{"what.ever" => true}) diff --git a/test/groupher_server_web/mutation/cms/upvotes/job_upvote_test.exs b/test/groupher_server_web/mutation/cms/upvotes/job_upvote_test.exs index ff32d1cc7..7c1f8869c 100644 --- a/test/groupher_server_web/mutation/cms/upvotes/job_upvote_test.exs +++ b/test/groupher_server_web/mutation/cms/upvotes/job_upvote_test.exs @@ -22,7 +22,7 @@ defmodule GroupherServer.Test.Mutation.Upvotes.JobUpvote do } } """ - @tag :wip2 + @tag :wip3 test "login user can upvote a job", ~m(user_conn job)a do variables = %{id: job.id} created = user_conn |> mutation_result(@query, variables, "upvoteJob") @@ -30,7 +30,7 @@ defmodule GroupherServer.Test.Mutation.Upvotes.JobUpvote do assert created["id"] == to_string(job.id) end - @tag :wip2 + @tag :wip3 test "unauth user upvote a job fails", ~m(guest_conn job)a do variables = %{id: job.id} @@ -45,7 +45,7 @@ defmodule GroupherServer.Test.Mutation.Upvotes.JobUpvote do } } """ - @tag :wip2 + @tag :wip3 test "login user can undo upvote to a job", ~m(user_conn job user)a do {:ok, _} = CMS.upvote_article(:job, job.id, user) @@ -55,7 +55,7 @@ defmodule GroupherServer.Test.Mutation.Upvotes.JobUpvote do assert updated["id"] == to_string(job.id) end - @tag :wip2 + @tag :wip3 test "unauth user undo upvote a job fails", ~m(guest_conn job)a do variables = %{id: job.id} diff --git a/test/groupher_server_web/mutation/cms/upvotes/post_upvote_test.exs b/test/groupher_server_web/mutation/cms/upvotes/post_upvote_test.exs index 002ff0e2f..7d85684c1 100644 --- a/test/groupher_server_web/mutation/cms/upvotes/post_upvote_test.exs +++ b/test/groupher_server_web/mutation/cms/upvotes/post_upvote_test.exs @@ -22,7 +22,7 @@ defmodule GroupherServer.Test.Mutation.Upvotes.PostUpvote do } } """ - @tag :wip2 + @tag :wip3 test "login user can upvote a post", ~m(user_conn post)a do variables = %{id: post.id} created = user_conn |> mutation_result(@query, variables, "upvotePost") @@ -30,7 +30,7 @@ defmodule GroupherServer.Test.Mutation.Upvotes.PostUpvote do assert created["id"] == to_string(post.id) end - @tag :wip2 + @tag :wip3 test "unauth user upvote a post fails", ~m(guest_conn post)a do variables = %{id: post.id} @@ -44,7 +44,7 @@ defmodule GroupherServer.Test.Mutation.Upvotes.PostUpvote do } } """ - @tag :wip2 + @tag :wip3 test "login user can undo upvote to a post", ~m(user_conn post user)a do {:ok, _} = CMS.upvote_article(:post, post.id, user) @@ -54,7 +54,7 @@ defmodule GroupherServer.Test.Mutation.Upvotes.PostUpvote do assert updated["id"] == to_string(post.id) end - @tag :wip2 + @tag :wip3 test "unauth user undo upvote a post fails", ~m(guest_conn post)a do variables = %{id: post.id} diff --git a/test/groupher_server_web/query/cms/collects/job_collect_test.exs b/test/groupher_server_web/query/cms/collects/job_collect_test.exs index 8ad1a03b1..3e889f3a7 100644 --- a/test/groupher_server_web/query/cms/collects/job_collect_test.exs +++ b/test/groupher_server_web/query/cms/collects/job_collect_test.exs @@ -35,7 +35,7 @@ defmodule GroupherServer.Test.Query.Collects.JobCollect do } } """ - @tag :wip2 + @tag :wip3 test "guest can get collected users list after collect a job", ~m(guest_conn job user user2)a do {:ok, _} = CMS.collect_article(:job, job.id, user) diff --git a/test/groupher_server_web/query/cms/collects/post_collect_test.exs b/test/groupher_server_web/query/cms/collects/post_collect_test.exs index b1f9d7199..bbad70c01 100644 --- a/test/groupher_server_web/query/cms/collects/post_collect_test.exs +++ b/test/groupher_server_web/query/cms/collects/post_collect_test.exs @@ -35,7 +35,7 @@ defmodule GroupherServer.Test.Query.Collects.PostCollect do } } """ - @tag :wip2 + @tag :wip3 test "guest can get collected users list after collect a post", ~m(guest_conn post user user2)a do {:ok, _} = CMS.collect_article(:post, post.id, 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 548e2e12f..d8a925471 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 @@ -288,7 +288,7 @@ defmodule GroupherServer.Test.Query.Comments.JobComment do assert results["entries"] |> List.last() |> Map.get("floor") == 5 end - @tag :wip2 + @tag :wip3 test "the comments is loaded in default asc order", ~m(guest_conn job user)a do page_size = 10 thread = :job @@ -312,7 +312,7 @@ defmodule GroupherServer.Test.Query.Comments.JobComment do assert List.last(results["entries"]) |> Map.get("id") == to_string(comment3.id) end - @tag :wip2 + @tag :wip3 test "the comments can be loaded in desc order in timeline-mode", ~m(guest_conn job user)a do page_size = 10 thread = :job @@ -336,7 +336,7 @@ defmodule GroupherServer.Test.Query.Comments.JobComment do assert List.last(results["entries"]) |> Map.get("id") == to_string(comment.id) end - @tag :wip2 + @tag :wip3 test "the comments can be loaded in desc order in replies-mode", ~m(guest_conn job user user2)a do page_size = 10 @@ -433,7 +433,7 @@ defmodule GroupherServer.Test.Query.Comments.JobComment do assert the_random_comment |> get_in(["meta", "isArticleAuthorUpvoted"]) end - @tag :wip2 + @tag :wip3 test "guest user can get paged comment with emotions info", ~m(guest_conn job user user2)a do total_count = 2 @@ -511,7 +511,7 @@ defmodule GroupherServer.Test.Query.Comments.JobComment do |> get_in(["emotions", "viewerHasDownvoteed"]) end - @tag :wip2 + @tag :wip3 test "comment should have viewer has upvoted flag", ~m(user_conn job user)a do total_count = 10 page_size = 12 @@ -551,7 +551,7 @@ defmodule GroupherServer.Test.Query.Comments.JobComment do } } """ - @tag :wip2 + @tag :wip3 test "guest user can get paged participators", ~m(guest_conn job user)a do total_count = 30 page_size = 10 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 5a7e69eb6..8fc646754 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 @@ -288,7 +288,7 @@ defmodule GroupherServer.Test.Query.Comments.PostComment do assert results["entries"] |> List.last() |> Map.get("floor") == 5 end - @tag :wip2 + @tag :wip3 test "the comments is loaded in default asc order", ~m(guest_conn post user)a do page_size = 10 thread = :post @@ -312,7 +312,7 @@ defmodule GroupherServer.Test.Query.Comments.PostComment do assert List.last(results["entries"]) |> Map.get("id") == to_string(comment3.id) end - @tag :wip2 + @tag :wip3 test "the comments can be loaded in desc order in timeline-mode", ~m(guest_conn post user)a do page_size = 10 thread = :post @@ -336,7 +336,7 @@ defmodule GroupherServer.Test.Query.Comments.PostComment do assert List.last(results["entries"]) |> Map.get("id") == to_string(comment.id) end - @tag :wip2 + @tag :wip3 test "the comments can be loaded in desc order in replies-mode", ~m(guest_conn post user user2)a do page_size = 10 @@ -433,7 +433,7 @@ defmodule GroupherServer.Test.Query.Comments.PostComment do assert the_random_comment |> get_in(["meta", "isArticleAuthorUpvoted"]) end - @tag :wip2 + @tag :wip3 test "guest user can get paged comment with emotions info", ~m(guest_conn post user user2)a do total_count = 2 @@ -511,7 +511,7 @@ defmodule GroupherServer.Test.Query.Comments.PostComment do |> get_in(["emotions", "viewerHasDownvoteed"]) end - @tag :wip2 + @tag :wip3 test "comment should have viewer has upvoted flag", ~m(user_conn post user)a do total_count = 10 page_size = 12 diff --git a/test/groupher_server_web/query/cms/job_test.exs b/test/groupher_server_web/query/cms/job_test.exs index eebf90599..417d8e867 100644 --- a/test/groupher_server_web/query/cms/job_test.exs +++ b/test/groupher_server_web/query/cms/job_test.exs @@ -19,7 +19,7 @@ defmodule GroupherServer.Test.Query.Job do } } """ - @tag :wip2 + @tag :wip3 test "basic graphql query on job with logined user", ~m(user_conn job)a do variables = %{id: job.id} results = user_conn |> query_result(@query, variables, "job") @@ -30,7 +30,7 @@ defmodule GroupherServer.Test.Query.Job do assert length(Map.keys(results)) == 3 end - @tag :wip2 + @tag :wip3 test "basic graphql query on job with stranger(unloged user)", ~m(guest_conn job)a do variables = %{id: job.id} results = guest_conn |> query_result(@query, variables, "job") diff --git a/test/groupher_server_web/query/cms/jobs_flags_test.exs b/test/groupher_server_web/query/cms/jobs_flags_test.exs index de9eb4adf..e977f1a87 100644 --- a/test/groupher_server_web/query/cms/jobs_flags_test.exs +++ b/test/groupher_server_web/query/cms/jobs_flags_test.exs @@ -51,7 +51,7 @@ defmodule GroupherServer.Test.Query.JobsFlags do } } """ - @tag :wip2 + @tag :wip3 test "if have pined jobs, the pined jobs should at the top of entries", ~m(guest_conn community job_m)a do variables = %{filter: %{community: community.raw}} diff --git a/test/groupher_server_web/query/cms/paged_jobs_test.exs b/test/groupher_server_web/query/cms/paged_jobs_test.exs index c68f415bd..b1254dde5 100644 --- a/test/groupher_server_web/query/cms/paged_jobs_test.exs +++ b/test/groupher_server_web/query/cms/paged_jobs_test.exs @@ -97,7 +97,7 @@ defmodule GroupherServer.Test.Query.PagedJobs do } } """ - @tag :wip2 + @tag :wip3 test "has_xxx state should work", ~m(user)a do user_conn = simu_conn(:user, user) {:ok, community} = db_insert(:community) diff --git a/test/groupher_server_web/query/cms/paged_posts_test.exs b/test/groupher_server_web/query/cms/paged_posts_test.exs index b09740e57..bde4c3b74 100644 --- a/test/groupher_server_web/query/cms/paged_posts_test.exs +++ b/test/groupher_server_web/query/cms/paged_posts_test.exs @@ -170,7 +170,7 @@ defmodule GroupherServer.Test.Query.PagedPosts do } } """ - @tag :wip2 + @tag :wip3 test "has_xxx state should work", ~m(user)a do user_conn = simu_conn(:user, user) {:ok, community} = db_insert(:community) diff --git a/test/groupher_server_web/query/cms/paged_repos_test.exs b/test/groupher_server_web/query/cms/paged_repos_test.exs index c50aa0e6f..e725b7a0f 100644 --- a/test/groupher_server_web/query/cms/paged_repos_test.exs +++ b/test/groupher_server_web/query/cms/paged_repos_test.exs @@ -93,7 +93,7 @@ defmodule GroupherServer.Test.Query.PagedRepos do } } """ - @tag :wip2 + @tag :wip3 test "has_xxx state should work", ~m(user)a do user_conn = simu_conn(:user, user) {:ok, community} = db_insert(:community) diff --git a/test/groupher_server_web/query/cms/post_test.exs b/test/groupher_server_web/query/cms/post_test.exs index 5e92fbb0e..3c53e9c6e 100644 --- a/test/groupher_server_web/query/cms/post_test.exs +++ b/test/groupher_server_web/query/cms/post_test.exs @@ -28,7 +28,7 @@ defmodule GroupherServer.Test.Query.Post do } } """ - @tag :wip2 + @tag :wip3 test "basic graphql query on post with logined user", ~m(user_conn community user post_attrs)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) @@ -43,7 +43,7 @@ defmodule GroupherServer.Test.Query.Post do assert length(Map.keys(results)) == 4 end - @tag :wip2 + @tag :wip3 test "basic graphql query on post with stranger(unloged user)", ~m(guest_conn post)a do variables = %{id: post.id} results = guest_conn |> query_result(@query, variables, "post") diff --git a/test/groupher_server_web/query/cms/posts_flags_test.exs b/test/groupher_server_web/query/cms/posts_flags_test.exs index 0cd6f01ec..a63fa5d41 100644 --- a/test/groupher_server_web/query/cms/posts_flags_test.exs +++ b/test/groupher_server_web/query/cms/posts_flags_test.exs @@ -51,7 +51,7 @@ defmodule GroupherServer.Test.Query.PostsFlags do } } """ - @tag :wip2 + @tag :wip3 test "if have pined posts, the pined posts should at the top of entries", ~m(guest_conn community post_m)a do variables = %{filter: %{community: community.raw}} diff --git a/test/groupher_server_web/query/cms/repo_test.exs b/test/groupher_server_web/query/cms/repo_test.exs index dc982deb0..a4c82f63a 100644 --- a/test/groupher_server_web/query/cms/repo_test.exs +++ b/test/groupher_server_web/query/cms/repo_test.exs @@ -19,7 +19,7 @@ defmodule GroupherServer.Test.Query.Repo do } } """ - @tag :wip2 + @tag :wip3 test "basic graphql query on repo with logined user", ~m(user_conn repo)a do variables = %{id: repo.id} results = user_conn |> query_result(@query, variables, "repo") @@ -30,7 +30,7 @@ defmodule GroupherServer.Test.Query.Repo do assert length(Map.keys(results)) == 3 end - @tag :wip2 + @tag :wip3 test "basic graphql query on repo with stranger(unloged user)", ~m(guest_conn repo)a do variables = %{id: repo.id} results = guest_conn |> query_result(@query, variables, "repo") diff --git a/test/groupher_server_web/query/cms/repos_flags_test.exs b/test/groupher_server_web/query/cms/repos_flags_test.exs index c013d9b29..c0cf8707a 100644 --- a/test/groupher_server_web/query/cms/repos_flags_test.exs +++ b/test/groupher_server_web/query/cms/repos_flags_test.exs @@ -50,7 +50,7 @@ defmodule GroupherServer.Test.Query.ReposFlags do } } """ - @tag :wip2 + @tag :wip3 test "if have pined repos, the pined repos should at the top of entries", ~m(guest_conn community repo_m)a do variables = %{filter: %{community: community.raw}} diff --git a/test/groupher_server_web/query/cms/upvotes/post_upvote_test.exs b/test/groupher_server_web/query/cms/upvotes/post_upvote_test.exs index 5a62315ee..47b311cde 100644 --- a/test/groupher_server_web/query/cms/upvotes/post_upvote_test.exs +++ b/test/groupher_server_web/query/cms/upvotes/post_upvote_test.exs @@ -35,7 +35,7 @@ defmodule GroupherServer.Test.Query.Upvotes.PostUpvote do } } """ - @tag :wip2 + @tag :wip3 test "guest can get upvoted users list after upvote to a post", ~m(guest_conn post user user2)a do {:ok, _} = CMS.upvote_article(:post, post.id, user) From 31708ef7a17f3807afd2d255284cd42bd474661b Mon Sep 17 00:00:00 2001 From: mydearxym Date: Wed, 12 May 2021 22:58:26 +0800 Subject: [PATCH 07/13] refactor(abuse-report): add reported_user_ids --- .../accounts/embeds/user_meta.ex | 4 +- lib/groupher_server/cms/abuse_report.ex | 5 +- lib/groupher_server/cms/cms.ex | 6 +- .../cms/delegates/abuse_report.ex | 81 ++++++++++++------- .../cms/delegates/article_comment_action.ex | 18 ----- lib/groupher_server/cms/embeds/user.ex | 3 +- .../cms/abuse_reports/account_report_test.exs | 27 ++++++- .../cms/abuse_reports/job_report_test.exs | 21 +++++ .../cms/abuse_reports/post_report_test.exs | 21 +++++ .../cms/comments/job_comment_test.exs | 30 ------- .../cms/comments/post_comment_test.exs | 32 +------- .../cms/articles/post_report_test.exs | 4 +- 12 files changed, 129 insertions(+), 123 deletions(-) diff --git a/lib/groupher_server/accounts/embeds/user_meta.ex b/lib/groupher_server/accounts/embeds/user_meta.ex index 115982ba4..f604e67bc 100644 --- a/lib/groupher_server/accounts/embeds/user_meta.ex +++ b/lib/groupher_server/accounts/embeds/user_meta.ex @@ -9,7 +9,8 @@ defmodule GroupherServer.Accounts.Embeds.UserMeta do @optional_fields ~w(reported_count)a @default_meta %{ - reported_count: 0 + reported_count: 0, + reported_user_ids: [] } @doc "for test usage" @@ -17,6 +18,7 @@ defmodule GroupherServer.Accounts.Embeds.UserMeta do embedded_schema do field(:reported_count, :integer, default: 0) + field(:reported_user_ids, {:array, :integer}, default: []) end def changeset(struct, params) do diff --git a/lib/groupher_server/cms/abuse_report.ex b/lib/groupher_server/cms/abuse_report.ex index ddbae3ada..9b733c149 100644 --- a/lib/groupher_server/cms/abuse_report.ex +++ b/lib/groupher_server/cms/abuse_report.ex @@ -9,8 +9,8 @@ defmodule GroupherServer.CMS.AbuseReport do alias CMS.{ArticleComment, Embeds, Post, Job, Repo} # @required_fields ~w(article_comment_id user_id recived_user_id)a - @optional_fields ~w(article_comment_id post_id job_id repo_id account_id operate_user_id deal_with is_confirmed report_cases_count)a - @update_fields ~w(operate_user_id deal_with is_confirmed report_cases_count)a + @optional_fields ~w(article_comment_id post_id job_id repo_id account_id operate_user_id deal_with report_cases_count)a + @update_fields ~w(operate_user_id deal_with report_cases_count)a @type t :: %AbuseReport{} schema "abuse_reports" do @@ -26,7 +26,6 @@ defmodule GroupherServer.CMS.AbuseReport do belongs_to(:operate_user, Accounts.User, foreign_key: :operate_user_id) field(:deal_with, :string) - field(:is_confirmed, :boolean, default: false) timestamps(type: :utc_datetime) end diff --git a/lib/groupher_server/cms/cms.ex b/lib/groupher_server/cms/cms.ex index 00b61a65e..8cd5466cd 100644 --- a/lib/groupher_server/cms/cms.ex +++ b/lib/groupher_server/cms/cms.ex @@ -121,10 +121,6 @@ defmodule GroupherServer.CMS do defdelegate list_folded_article_comments(thread, article_id, filters), to: ArticleComment defdelegate list_folded_article_comments(thread, article_id, filters, user), to: ArticleComment - defdelegate list_reported_article_comments(thread, article_id, filters), to: ArticleComment - - defdelegate list_reported_article_comments(thread, article_id, filters, user), - to: ArticleComment defdelegate list_comment_replies(comment_id, filters), to: ArticleComment defdelegate list_comment_replies(comment_id, filters, user), to: ArticleComment @@ -162,7 +158,7 @@ defmodule GroupherServer.CMS do # TODO: move report to abuse report module defdelegate create_report(type, content_id, reason, attr, user), to: AbuseReport defdelegate report_article(thread, article_id, reason, attr, user), to: AbuseReport - defdelegate report_article_comment(comment_id, reason, attr, user), to: ArticleCommentAction + defdelegate report_article_comment(comment_id, reason, attr, user), to: AbuseReport defdelegate report_account(account_id, reason, attr, user), to: AbuseReport defdelegate undo_report_account(account_id, user), to: AbuseReport defdelegate undo_report_article(thread, article_id, user), to: AbuseReport diff --git a/lib/groupher_server/cms/delegates/abuse_report.ex b/lib/groupher_server/cms/delegates/abuse_report.ex index eafb149ac..65b859fa2 100644 --- a/lib/groupher_server/cms/delegates/abuse_report.ex +++ b/lib/groupher_server/cms/delegates/abuse_report.ex @@ -17,6 +17,8 @@ defmodule GroupherServer.CMS.Delegate.AbuseReport do alias Ecto.Multi + @report_threshold_for_fold ArticleComment.report_threshold_for_fold() + # filter = %{ # contentType: account | post | job | repo | article_comment | community # contentId: ... @@ -115,7 +117,7 @@ defmodule GroupherServer.CMS.Delegate.AbuseReport do |> Multi.run(:create_abuse_report, fn _, _ -> create_report(:account_user, account.id, reason, attr, user) end) - |> Multi.run(:update_report_flag, fn _, _ -> + |> Multi.run(:update_report_meta, fn _, _ -> update_report_meta(info, account) end) |> Repo.transaction() @@ -133,7 +135,7 @@ defmodule GroupherServer.CMS.Delegate.AbuseReport do |> Multi.run(:delete_abuse_report, fn _, _ -> delete_report(:account_user, account.id, user) end) - |> Multi.run(:update_report_flag, fn _, _ -> + |> Multi.run(:update_report_meta, fn _, _ -> update_report_meta(info, account) end) |> Repo.transaction() @@ -151,7 +153,7 @@ defmodule GroupherServer.CMS.Delegate.AbuseReport do |> Multi.run(:create_abuse_report, fn _, _ -> create_report(thread, article.id, reason, attr, user) end) - |> Multi.run(:update_report_flag, fn _, _ -> + |> Multi.run(:update_report_meta, fn _, _ -> update_report_meta(info, article) end) |> Repo.transaction() @@ -169,7 +171,7 @@ defmodule GroupherServer.CMS.Delegate.AbuseReport do |> Multi.run(:delete_abuse_report, fn _, _ -> delete_report(thread, article.id, user) end) - |> Multi.run(:update_report_flag, fn _, _ -> + |> Multi.run(:update_report_meta, fn _, _ -> update_report_meta(info, article) end) |> Repo.transaction() @@ -177,6 +179,27 @@ defmodule GroupherServer.CMS.Delegate.AbuseReport do end end + @doc "report a comment" + def report_article_comment(comment_id, reason, attr, %User{} = user) do + with {:ok, comment} <- ORM.find(ArticleComment, comment_id) do + Multi.new() + |> Multi.run(:create_abuse_report, fn _, _ -> + CMS.create_report(:article_comment, comment_id, reason, attr, user) + end) + |> Multi.run(:update_report_meta, fn _, _ -> + {:ok, info} = match(:article_comment) + update_report_meta(info, comment) + end) + |> Multi.run(:fold_comment_report_too_many, fn _, %{create_abuse_report: abuse_report} -> + if abuse_report.report_cases_count >= @report_threshold_for_fold, + do: CMS.fold_article_comment(comment, user), + else: {:ok, comment} + end) + |> Repo.transaction() + |> result() + end + end + def undo_report_article_comment(comment_id, %User{} = user) do undo_report_article(:article_comment, comment_id, user) end @@ -190,7 +213,7 @@ defmodule GroupherServer.CMS.Delegate.AbuseReport do %{ reason: reason, attr: attr, - user: %{login: user.login, nickname: user.nickname} + user: %{user_id: user.id, login: user.login, nickname: user.nickname} } ] @@ -201,7 +224,7 @@ defmodule GroupherServer.CMS.Delegate.AbuseReport do AbuseReport |> ORM.create(args) _ -> - user = %{login: user.login, nickname: user.nickname} + user = %{user_id: user.id, login: user.login, nickname: user.nickname} report_cases = report.report_cases @@ -237,29 +260,29 @@ defmodule GroupherServer.CMS.Delegate.AbuseReport do end end - # update reported_count in mete for article or comment + # update reported_count in mete for article | comment | account defp update_report_meta(info, content) do - case ORM.find_by(AbuseReport, Map.put(%{}, info.foreign_key, content.id)) do - {:ok, record} -> - reported_count = record.report_cases |> length - - safe_meta = if is_nil(content.meta), do: info.default_meta, else: content.meta - meta = safe_meta |> Map.merge(%{reported_count: reported_count}) |> strip_struct - - content - |> Ecto.Changeset.change() - |> Ecto.Changeset.put_embed(:meta, meta) - |> Repo.update() - - {:error, _} -> - safe_meta = if is_nil(content.meta), do: info.default_meta, else: content.meta - meta = safe_meta |> Map.merge(%{reported_count: 0}) |> strip_struct - - content - |> Ecto.Changeset.change() - |> Ecto.Changeset.put_embed(:meta, meta) - |> Repo.update() - end + meta = + case ORM.find_by(AbuseReport, Map.put(%{}, info.foreign_key, content.id)) do + {:ok, record} -> + report_cases = record.report_cases + reported_count = length(report_cases) + safe_meta = if is_nil(content.meta), do: info.default_meta, else: content.meta + reported_user_ids = report_cases |> Enum.map(& &1.user.user_id) + + meta = + safe_meta + |> Map.merge(%{reported_count: reported_count, reported_user_ids: reported_user_ids}) + |> strip_struct + + {:error, _} -> + safe_meta = if is_nil(content.meta), do: info.default_meta, else: content.meta + + meta = + safe_meta |> Map.merge(%{reported_count: 0, reported_user_ids: []}) |> strip_struct + end + + content |> ORM.update_meta(meta) end defp not_reported_before(info, content_id, %User{login: login}) do @@ -352,7 +375,7 @@ defmodule GroupherServer.CMS.Delegate.AbuseReport do |> Map.merge(%{thread: article_thread}) end - defp result({:ok, %{update_report_flag: result}}), do: result |> done() + defp result({:ok, %{update_report_meta: result}}), do: result |> done() defp result({:ok, %{update_content_reported_flag: result}}), do: result |> done() defp result({:error, _, result, _steps}) do diff --git a/lib/groupher_server/cms/delegates/article_comment_action.ex b/lib/groupher_server/cms/delegates/article_comment_action.ex index 82f23de5e..644933c5c 100644 --- a/lib/groupher_server/cms/delegates/article_comment_action.ex +++ b/lib/groupher_server/cms/delegates/article_comment_action.ex @@ -30,7 +30,6 @@ defmodule GroupherServer.CMS.Delegate.ArticleCommentAction do alias Ecto.Multi @max_parent_replies_count ArticleComment.max_parent_replies_count() - @report_threshold_for_fold ArticleComment.report_threshold_for_fold() @pined_comment_limit ArticleComment.pined_comment_limit() @spec pin_article_comment(Integer.t()) :: {:ok, ArticleComment.t()} @@ -101,23 +100,6 @@ defmodule GroupherServer.CMS.Delegate.ArticleCommentAction do end end - @doc "report a comment" - def report_article_comment(comment_id, reason, attr, %User{} = user) do - with {:ok, comment} <- ORM.find(ArticleComment, comment_id) do - Multi.new() - |> Multi.run(:create_abuse_report, fn _, _ -> - CMS.create_report(:article_comment, comment_id, reason, attr, user) - end) - |> Multi.run(:fold_comment_report_too_many, fn _, %{create_abuse_report: abuse_report} -> - if abuse_report.report_cases_count >= @report_threshold_for_fold, - do: fold_article_comment(comment, user), - else: {:ok, comment} - end) - |> Repo.transaction() - |> upsert_comment_result() - end - end - @doc "reply to exsiting comment" def reply_article_comment(comment_id, content, %User{} = user) do with {:ok, target_comment} <- diff --git a/lib/groupher_server/cms/embeds/user.ex b/lib/groupher_server/cms/embeds/user.ex index 8d08f92b6..33e458ecf 100644 --- a/lib/groupher_server/cms/embeds/user.ex +++ b/lib/groupher_server/cms/embeds/user.ex @@ -7,13 +7,14 @@ defmodule GroupherServer.CMS.Embeds.User do import Ecto.Changeset embedded_schema do + field(:user_id, :integer) field(:login, :string) field(:nickname, :string) end def changeset(struct, params) do struct - |> cast(params, [:login, :nickname]) + |> cast(params, [:login, :nickname, :user_id]) |> validate_required([:login, :nickname]) end end diff --git a/test/groupher_server/cms/abuse_reports/account_report_test.exs b/test/groupher_server/cms/abuse_reports/account_report_test.exs index fe0295f92..70fda2b26 100644 --- a/test/groupher_server/cms/abuse_reports/account_report_test.exs +++ b/test/groupher_server/cms/abuse_reports/account_report_test.exs @@ -39,7 +39,7 @@ defmodule GroupherServer.Test.CMS.AbuseReports.AccountReport do @tag :wip3 test "report an account should have a abuse report record", ~m(user user2)a do - {:ok, report} = CMS.report_account(user.id, "reason", "attr_info", user2) + {:ok, _report} = CMS.report_account(user.id, "reason", "attr_info", user2) filter = %{content_type: :user, content_id: user.id, page: 1, size: 20} {:ok, all_reports} = CMS.list_reports(filter) @@ -56,14 +56,35 @@ defmodule GroupherServer.Test.CMS.AbuseReports.AccountReport do assert user.meta.reported_count == 1 end - @tag :wip3 + @tag :wip2 test "can undo a report", ~m(user user2)a do - {:ok, report} = CMS.report_account(user.id, "reason", "attr_info", user2) + {:ok, _report} = CMS.report_account(user.id, "reason", "attr_info", user2) + {:ok, user} = ORM.find(User, user.id) + assert user2.id in user.meta.reported_user_ids + {:ok, _report} = CMS.undo_report_account(user.id, user2) filter = %{content_type: :user, content_id: user.id, page: 1, size: 20} {:ok, all_reports} = CMS.list_reports(filter) assert all_reports.total_count == 0 + + {:ok, user} = ORM.find(User, user.id) + assert user2.id not in user.meta.reported_user_ids + end + + @tag :wip2 + test "can undo a existed report", ~m(user user2 user3)a do + {:ok, _report} = CMS.report_account(user.id, "reason", "attr_info", user2) + {:ok, _report} = CMS.report_account(user.id, "reason", "attr_info", user3) + {:ok, _report} = CMS.undo_report_account(user.id, user2) + + filter = %{content_type: :user, content_id: user.id, page: 1, size: 20} + {:ok, all_reports} = CMS.list_reports(filter) + assert all_reports.total_count == 1 + + {:ok, user} = ORM.find(User, user.id) + assert user2.id not in user.meta.reported_user_ids + assert user3.id in user.meta.reported_user_ids end @tag :wip3 diff --git a/test/groupher_server/cms/abuse_reports/job_report_test.exs b/test/groupher_server/cms/abuse_reports/job_report_test.exs index 44e5b0c8e..644219a55 100644 --- a/test/groupher_server/cms/abuse_reports/job_report_test.exs +++ b/test/groupher_server/cms/abuse_reports/job_report_test.exs @@ -49,6 +49,7 @@ defmodule GroupherServer.Test.CMS.AbuseReports.JobReport do {:ok, job} = ORM.find(CMS.Job, job.id) assert job.meta.reported_count == 1 + assert user.id in job.meta.reported_user_ids end @tag :wip3 @@ -60,6 +61,26 @@ defmodule GroupherServer.Test.CMS.AbuseReports.JobReport do filter = %{content_type: :job, content_id: job.id, page: 1, size: 20} {:ok, all_reports} = CMS.list_reports(filter) assert all_reports.total_count == 0 + + {:ok, job} = ORM.find(CMS.Job, job.id) + assert user.id not in job.meta.reported_user_ids + end + + @tag :wip2 + test "can undo a existed report", ~m(community user user2 job_attrs)a do + {:ok, job} = CMS.create_content(community, :job, job_attrs, user) + {:ok, _report} = CMS.report_article(:job, job.id, "reason", "attr_info", user) + {:ok, _report} = CMS.report_article(:job, job.id, "reason", "attr_info", user2) + {:ok, _report} = CMS.undo_report_article(:job, job.id, user) + + filter = %{content_type: :job, content_id: job.id, page: 1, size: 20} + {:ok, all_reports} = CMS.list_reports(filter) + assert all_reports.total_count == 1 + + {:ok, job} = ORM.find(CMS.Job, job.id) + + assert user2.id in job.meta.reported_user_ids + assert user.id not in job.meta.reported_user_ids end @tag :wip3 diff --git a/test/groupher_server/cms/abuse_reports/post_report_test.exs b/test/groupher_server/cms/abuse_reports/post_report_test.exs index 1c427bf83..d13433513 100644 --- a/test/groupher_server/cms/abuse_reports/post_report_test.exs +++ b/test/groupher_server/cms/abuse_reports/post_report_test.exs @@ -49,6 +49,7 @@ defmodule GroupherServer.Test.CMS.AbuseReports.PostReport do {:ok, post} = ORM.find(CMS.Post, post.id) assert post.meta.reported_count == 1 + assert user.id in post.meta.reported_user_ids end @tag :wip3 @@ -60,6 +61,26 @@ defmodule GroupherServer.Test.CMS.AbuseReports.PostReport do filter = %{content_type: :post, content_id: post.id, page: 1, size: 20} {:ok, all_reports} = CMS.list_reports(filter) assert all_reports.total_count == 0 + + {:ok, post} = ORM.find(CMS.Post, post.id) + assert user.id not in post.meta.reported_user_ids + end + + @tag :wip2 + test "can undo a existed report", ~m(community user user2 post_attrs)a do + {:ok, post} = CMS.create_content(community, :post, post_attrs, user) + {:ok, _report} = CMS.report_article(:post, post.id, "reason", "attr_info", user) + {:ok, _report} = CMS.report_article(:post, post.id, "reason", "attr_info", user2) + {:ok, _report} = CMS.undo_report_article(:post, post.id, user) + + filter = %{content_type: :post, content_id: post.id, page: 1, size: 20} + {:ok, all_reports} = CMS.list_reports(filter) + assert all_reports.total_count == 1 + + {:ok, post} = ORM.find(CMS.Post, post.id) + + assert user2.id in post.meta.reported_user_ids + assert user.id not in post.meta.reported_user_ids end @tag :wip3 diff --git a/test/groupher_server/cms/comments/job_comment_test.exs b/test/groupher_server/cms/comments/job_comment_test.exs index 7c34d0d6c..dc0fbf472 100644 --- a/test/groupher_server/cms/comments/job_comment_test.exs +++ b/test/groupher_server/cms/comments/job_comment_test.exs @@ -528,36 +528,6 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do assert page_size == paged_comments.page_size assert total_count == paged_comments.total_count end - - @tag :wip - test "can loaded paged reported comment", ~m(user job)a do - total_count = 10 - page_number = 1 - page_size = 20 - - all_reported_comments = - Enum.reduce(1..total_count, [], fn _, acc -> - {:ok, comment} = CMS.create_article_comment(:job, job.id, "commment", user) - CMS.report_article_comment(comment.id, "reason", "attr", user) - - acc ++ [comment] - end) - - random_comment_1 = all_reported_comments |> Enum.at(1) - random_comment_2 = all_reported_comments |> Enum.at(3) - random_comment_3 = all_reported_comments |> Enum.at(5) - - {:ok, paged_comments} = - CMS.list_reported_article_comments(:job, job.id, %{page: page_number, size: page_size}) - - assert exist_in?(random_comment_1, paged_comments.entries) - assert exist_in?(random_comment_2, paged_comments.entries) - assert exist_in?(random_comment_3, paged_comments.entries) - - assert page_number == paged_comments.page_number - assert page_size == paged_comments.page_size - assert total_count == paged_comments.total_count - end end describe "[article comment delete]" do diff --git a/test/groupher_server/cms/comments/post_comment_test.exs b/test/groupher_server/cms/comments/post_comment_test.exs index dc0ee21e9..667a5a7a8 100644 --- a/test/groupher_server/cms/comments/post_comment_test.exs +++ b/test/groupher_server/cms/comments/post_comment_test.exs @@ -453,7 +453,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do assert paged_comments.total_count == total_count end - @tag :wip2 + @tag :wip3 test "paged article comments should not contains folded and repoted comments", ~m(user post)a do total_count = 15 @@ -520,36 +520,6 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do assert page_size == paged_comments.page_size assert total_count == paged_comments.total_count end - - @tag :wip - test "can loaded paged reported comment", ~m(user post)a do - total_count = 10 - page_number = 1 - page_size = 20 - - all_reported_comments = - Enum.reduce(1..total_count, [], fn _, acc -> - {:ok, comment} = CMS.create_article_comment(:post, post.id, "commment", user) - CMS.report_article_comment(comment.id, "reason", "attr", user) - - acc ++ [comment] - end) - - random_comment_1 = all_reported_comments |> Enum.at(1) - random_comment_2 = all_reported_comments |> Enum.at(3) - random_comment_3 = all_reported_comments |> Enum.at(5) - - {:ok, paged_comments} = - CMS.list_reported_article_comments(:post, post.id, %{page: page_number, size: page_size}) - - assert exist_in?(random_comment_1, paged_comments.entries) - assert exist_in?(random_comment_2, paged_comments.entries) - assert exist_in?(random_comment_3, paged_comments.entries) - - assert page_number == paged_comments.page_number - assert page_size == paged_comments.page_size - assert total_count == paged_comments.total_count - end end describe "[article comment delete]" do diff --git a/test/groupher_server_web/mutation/cms/articles/post_report_test.exs b/test/groupher_server_web/mutation/cms/articles/post_report_test.exs index 5a53acfca..5bf9cfc90 100644 --- a/test/groupher_server_web/mutation/cms/articles/post_report_test.exs +++ b/test/groupher_server_web/mutation/cms/articles/post_report_test.exs @@ -25,7 +25,7 @@ defmodule GroupherServer.Test.Mutation.Articles.PostReport do } } """ - @tag :wip2 + @tag :wip3 test "login user can report a post", ~m(community post_attrs user user_conn)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) @@ -43,7 +43,7 @@ defmodule GroupherServer.Test.Mutation.Articles.PostReport do } } """ - @tag :wip2 + @tag :wip3 test "login user can undo report a post", ~m(community post_attrs user user_conn)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) From 3b31554ae69fede24a53be6778fd7d4985b2e2a7 Mon Sep 17 00:00:00 2001 From: mydearxym Date: Wed, 12 May 2021 23:15:02 +0800 Subject: [PATCH 08/13] refactor(abuse-report): debug viewer_has_reported --- lib/groupher_server/accounts/user.ex | 1 + lib/groupher_server/cms/job.ex | 5 +++++ lib/groupher_server/cms/repo.ex | 5 +++++ test/groupher_server/cms/comments/post_comment_test.exs | 4 ---- test/groupher_server_web/query/cms/paged_jobs_test.exs | 6 +++++- test/groupher_server_web/query/cms/paged_posts_test.exs | 6 +++++- test/groupher_server_web/query/cms/paged_repos_test.exs | 6 +++++- 7 files changed, 26 insertions(+), 7 deletions(-) diff --git a/lib/groupher_server/accounts/user.ex b/lib/groupher_server/accounts/user.ex index 323fcfd56..4e6fee509 100644 --- a/lib/groupher_server/accounts/user.ex +++ b/lib/groupher_server/accounts/user.ex @@ -60,6 +60,7 @@ defmodule GroupherServer.Accounts.User do # field(:sponsor_member, :boolean) # field(:paid_member, :boolean) # field(:platinum_member, :boolean) + field(:viewer_has_reported, :boolean, default: false, virtual: true) embeds_one(:meta, Embeds.UserMeta, on_replace: :update) diff --git a/lib/groupher_server/cms/job.ex b/lib/groupher_server/cms/job.ex index 51f62046a..bfecbb93a 100644 --- a/lib/groupher_server/cms/job.ex +++ b/lib/groupher_server/cms/job.ex @@ -61,6 +61,11 @@ defmodule GroupherServer.CMS.Job do has_many(:upvotes, {"article_upvotes", ArticleUpvote}) field(:upvotes_count, :integer, default: 0) + field(:viewer_has_viewed, :boolean, default: false, virtual: true) + field(:viewer_has_upvoted, :boolean, default: false, virtual: true) + field(:viewer_has_collected, :boolean, default: false, virtual: true) + field(:viewer_has_reported, :boolean, default: false, virtual: true) + has_many(:collects, {"article_collects", ArticleCollect}) field(:collects_count, :integer, default: 0) diff --git a/lib/groupher_server/cms/repo.ex b/lib/groupher_server/cms/repo.ex index c24c879c6..cc8b9133d 100644 --- a/lib/groupher_server/cms/repo.ex +++ b/lib/groupher_server/cms/repo.ex @@ -62,6 +62,11 @@ defmodule GroupherServer.CMS.Repo do field(:is_pinned, :boolean, default: false, virtual: true) field(:trash, :boolean, default_value: false) + field(:viewer_has_viewed, :boolean, default: false, virtual: true) + field(:viewer_has_upvoted, :boolean, default: false, virtual: true) + field(:viewer_has_collected, :boolean, default: false, virtual: true) + field(:viewer_has_reported, :boolean, default: false, virtual: true) + has_many(:upvotes, {"article_upvotes", ArticleUpvote}) field(:upvotes_count, :integer, default: 0) diff --git a/test/groupher_server/cms/comments/post_comment_test.exs b/test/groupher_server/cms/comments/post_comment_test.exs index 667a5a7a8..8c8a95f19 100644 --- a/test/groupher_server/cms/comments/post_comment_test.exs +++ b/test/groupher_server/cms/comments/post_comment_test.exs @@ -471,10 +471,6 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do random_comment_2 = all_comments |> Enum.at(1) random_comment_3 = all_comments |> Enum.at(3) - random_comment_4 = all_comments |> Enum.at(2) - random_comment_5 = all_comments |> Enum.at(4) - random_comment_6 = all_comments |> Enum.at(8) - {:ok, _comment} = CMS.fold_article_comment(random_comment_1.id, user) {:ok, _comment} = CMS.fold_article_comment(random_comment_2.id, user) {:ok, _comment} = CMS.fold_article_comment(random_comment_3.id, user) diff --git a/test/groupher_server_web/query/cms/paged_jobs_test.exs b/test/groupher_server_web/query/cms/paged_jobs_test.exs index b1254dde5..7110e89c7 100644 --- a/test/groupher_server_web/query/cms/paged_jobs_test.exs +++ b/test/groupher_server_web/query/cms/paged_jobs_test.exs @@ -92,12 +92,13 @@ defmodule GroupherServer.Test.Query.PagedJobs do viewerHasCollected viewerHasUpvoted viewerHasViewed + viewerHasReported } totalCount } } """ - @tag :wip3 + @tag :wip2 test "has_xxx state should work", ~m(user)a do user_conn = simu_conn(:user, user) {:ok, community} = db_insert(:community) @@ -114,16 +115,19 @@ defmodule GroupherServer.Test.Query.PagedJobs do assert not the_job["viewerHasViewed"] assert not the_job["viewerHasUpvoted"] assert not the_job["viewerHasCollected"] + assert not the_job["viewerHasReported"] {:ok, _} = CMS.read_article(:job, job.id, user) {:ok, _} = CMS.upvote_article(:job, job.id, user) {:ok, _} = CMS.collect_article(:job, job.id, user) + {:ok, _} = CMS.report_article(:job, job.id, "reason", "attr_info", user) results = user_conn |> query_result(@query, variables, "pagedJobs") the_job = Enum.find(results["entries"], &(&1["id"] == to_string(job.id))) assert the_job["viewerHasViewed"] assert the_job["viewerHasUpvoted"] assert the_job["viewerHasCollected"] + assert the_job["viewerHasReported"] end end diff --git a/test/groupher_server_web/query/cms/paged_posts_test.exs b/test/groupher_server_web/query/cms/paged_posts_test.exs index bde4c3b74..49e9db151 100644 --- a/test/groupher_server_web/query/cms/paged_posts_test.exs +++ b/test/groupher_server_web/query/cms/paged_posts_test.exs @@ -165,12 +165,13 @@ defmodule GroupherServer.Test.Query.PagedPosts do viewerHasCollected viewerHasUpvoted viewerHasViewed + viewerHasReported } totalCount } } """ - @tag :wip3 + @tag :wip2 test "has_xxx state should work", ~m(user)a do user_conn = simu_conn(:user, user) {:ok, community} = db_insert(:community) @@ -187,16 +188,19 @@ defmodule GroupherServer.Test.Query.PagedPosts do assert not the_post["viewerHasViewed"] assert not the_post["viewerHasUpvoted"] assert not the_post["viewerHasCollected"] + assert not the_post["viewerHasReported"] {:ok, _} = CMS.read_article(:post, post.id, user) {:ok, _} = CMS.upvote_article(:post, post.id, user) {:ok, _} = CMS.collect_article(:post, post.id, user) + {:ok, _} = CMS.report_article(:post, post.id, "reason", "attr_info", user) results = user_conn |> query_result(@query, variables, "pagedPosts") the_post = Enum.find(results["entries"], &(&1["id"] == to_string(post.id))) assert the_post["viewerHasViewed"] assert the_post["viewerHasUpvoted"] assert the_post["viewerHasCollected"] + assert the_post["viewerHasReported"] end end diff --git a/test/groupher_server_web/query/cms/paged_repos_test.exs b/test/groupher_server_web/query/cms/paged_repos_test.exs index e725b7a0f..e9fd2e271 100644 --- a/test/groupher_server_web/query/cms/paged_repos_test.exs +++ b/test/groupher_server_web/query/cms/paged_repos_test.exs @@ -88,12 +88,13 @@ defmodule GroupherServer.Test.Query.PagedRepos do viewerHasCollected viewerHasUpvoted viewerHasViewed + viewerHasReported } totalCount } } """ - @tag :wip3 + @tag :wip2 test "has_xxx state should work", ~m(user)a do user_conn = simu_conn(:user, user) {:ok, community} = db_insert(:community) @@ -110,16 +111,19 @@ defmodule GroupherServer.Test.Query.PagedRepos do assert not the_repo["viewerHasViewed"] assert not the_repo["viewerHasUpvoted"] assert not the_repo["viewerHasCollected"] + assert not the_repo["viewerHasReported"] {:ok, _} = CMS.read_article(:repo, repo.id, user) {:ok, _} = CMS.upvote_article(:repo, repo.id, user) {:ok, _} = CMS.collect_article(:repo, repo.id, user) + {:ok, _} = CMS.report_article(:repo, repo.id, "reason", "attr_info", user) results = user_conn |> query_result(@query, variables, "pagedRepos") the_repo = Enum.find(results["entries"], &(&1["id"] == to_string(repo.id))) assert the_repo["viewerHasViewed"] assert the_repo["viewerHasUpvoted"] assert the_repo["viewerHasCollected"] + assert the_repo["viewerHasReported"] end end From b35d121b9aee072b91e783249b25c1cd0c4b8dcd Mon Sep 17 00:00:00 2001 From: mydearxym Date: Thu, 13 May 2021 10:00:24 +0800 Subject: [PATCH 09/13] refactor(abuse-report): clean up --- .../cms/embeds/article_comment_meta.ex | 4 +++- .../cms/abuse_reports/account_report_test.exs | 7 ------ .../cms/abuse_reports/comment_report_test.exs | 2 -- .../cms/abuse_reports/job_report_test.exs | 7 ------ .../cms/abuse_reports/post_report_test.exs | 7 ------ .../comments/job_comment_emotions_test.exs | 6 ----- .../cms/comments/job_comment_replies_test.exs | 4 ---- .../cms/comments/job_comment_test.exs | 24 ++----------------- .../comments/post_comment_emotions_test.exs | 6 ----- .../comments/post_comment_replies_test.exs | 5 ---- .../cms/comments/post_comment_test.exs | 10 +------- .../cms/emotions/job_emotions_test.exs | 8 ------- .../cms/emotions/post_emotions_test.exs | 8 ------- test/groupher_server/cms/job_test.exs | 1 - test/groupher_server/cms/post_test.exs | 2 -- test/groupher_server/cms/repo_test.exs | 3 +-- .../cms/upvotes/job_upvote_test.exs | 5 ---- .../cms/upvotes/post_upvote_test.exs | 5 ---- .../mutation/accounts/customization_test.exs | 2 +- .../cms/articles/job_emotion_test.exs | 4 ++-- .../mutation/cms/articles/job_report_test.exs | 4 ++-- .../mutation/cms/articles/job_test.exs | 2 +- .../cms/articles/post_emotion_test.exs | 4 ++-- .../cms/articles/post_report_test.exs | 4 ++-- .../mutation/cms/articles/post_test.exs | 2 +- .../cms/articles/repo_report_test.exs | 4 ++-- .../mutation/cms/articles/repo_test.exs | 4 +--- .../mutation/cms/cms_test.exs | 3 +-- .../cms/comments/job_comment_test.exs | 12 +++++----- .../cms/comments/post_comment_test.exs | 12 +++++----- .../mutation/cms/flags/job_flag_test.exs | 11 ++++----- .../mutation/cms/flags/post_flag_test.exs | 12 ++++------ .../mutation/cms/flags/repo_flag_test.exs | 12 ++++------ .../mutation/cms/upvotes/job_upvote_test.exs | 6 ++--- .../mutation/cms/upvotes/post_upvote_test.exs | 6 ++--- .../query/cms/collects/job_collect_test.exs | 2 +- .../query/cms/collects/post_collect_test.exs | 2 +- .../query/cms/comments/job_comment_test.exs | 7 +----- .../query/cms/comments/post_comment_test.exs | 5 ---- .../query/cms/job_test.exs | 3 +-- .../query/cms/jobs_flags_test.exs | 2 +- .../query/cms/paged_jobs_test.exs | 2 +- .../query/cms/paged_posts_test.exs | 2 +- .../query/cms/paged_repos_test.exs | 2 +- .../query/cms/post_test.exs | 3 +-- .../query/cms/posts_flags_test.exs | 2 +- .../query/cms/repo_test.exs | 3 +-- .../query/cms/repos_flags_test.exs | 2 +- .../query/cms/upvotes/post_upvote_test.exs | 2 +- 49 files changed, 63 insertions(+), 194 deletions(-) diff --git a/lib/groupher_server/cms/embeds/article_comment_meta.ex b/lib/groupher_server/cms/embeds/article_comment_meta.ex index 982345a0c..3670d38d3 100644 --- a/lib/groupher_server/cms/embeds/article_comment_meta.ex +++ b/lib/groupher_server/cms/embeds/article_comment_meta.ex @@ -7,7 +7,7 @@ defmodule GroupherServer.CMS.Embeds.ArticleCommentMeta do import Ecto.Changeset - @optional_fields ~w(is_article_author_upvoted is_solution report_count is_reply_to_others reported_count)a + @optional_fields ~w(is_article_author_upvoted is_solution report_count is_reply_to_others reported_count reported_user_ids)a @default_meta %{ is_article_author_upvoted: false, @@ -15,6 +15,7 @@ defmodule GroupherServer.CMS.Embeds.ArticleCommentMeta do is_reply_to_others: false, report_count: 0, upvoted_user_ids: [], + reported_user_ids: [], reported_count: 0 } @@ -30,6 +31,7 @@ defmodule GroupherServer.CMS.Embeds.ArticleCommentMeta do field(:report_count, :integer, default: 0) field(:upvoted_user_ids, {:array, :integer}, default: []) + field(:reported_user_ids, {:array, :integer}, default: []) field(:reported_count, :integer, default: 0) end diff --git a/test/groupher_server/cms/abuse_reports/account_report_test.exs b/test/groupher_server/cms/abuse_reports/account_report_test.exs index 70fda2b26..1ec88ef10 100644 --- a/test/groupher_server/cms/abuse_reports/account_report_test.exs +++ b/test/groupher_server/cms/abuse_reports/account_report_test.exs @@ -23,7 +23,6 @@ defmodule GroupherServer.Test.CMS.AbuseReports.AccountReport do end describe "[account report/unreport]" do - @tag :wip3 # test "list article reports should work", ~m(community user user2 post_attrs)a do # {:ok, post} = CMS.create_content(community, :post, post_attrs, user) # {:ok, _report} = CMS.report_article(:post, post.id, "reason", "attr_info", user) @@ -37,7 +36,6 @@ defmodule GroupherServer.Test.CMS.AbuseReports.AccountReport do # assert report.article.thread == :post # end - @tag :wip3 test "report an account should have a abuse report record", ~m(user user2)a do {:ok, _report} = CMS.report_account(user.id, "reason", "attr_info", user2) @@ -56,7 +54,6 @@ defmodule GroupherServer.Test.CMS.AbuseReports.AccountReport do assert user.meta.reported_count == 1 end - @tag :wip2 test "can undo a report", ~m(user user2)a do {:ok, _report} = CMS.report_account(user.id, "reason", "attr_info", user2) {:ok, user} = ORM.find(User, user.id) @@ -72,7 +69,6 @@ defmodule GroupherServer.Test.CMS.AbuseReports.AccountReport do assert user2.id not in user.meta.reported_user_ids end - @tag :wip2 test "can undo a existed report", ~m(user user2 user3)a do {:ok, _report} = CMS.report_account(user.id, "reason", "attr_info", user2) {:ok, _report} = CMS.report_account(user.id, "reason", "attr_info", user3) @@ -87,7 +83,6 @@ defmodule GroupherServer.Test.CMS.AbuseReports.AccountReport do assert user3.id in user.meta.reported_user_ids end - @tag :wip3 test "can undo a report with other user report it too", ~m(user user2 user3)a do {:ok, _report} = CMS.report_account(user.id, "reason", "attr_info", user2) {:ok, _report} = CMS.report_account(user.id, "reason", "attr_info", user3) @@ -112,7 +107,6 @@ defmodule GroupherServer.Test.CMS.AbuseReports.AccountReport do assert Enum.any?(report.report_cases, &(&1.user.login == user3.login)) end - @tag :wip3 test "different user report a account should have same report with different report cases", ~m(user user2 user3)a do {:ok, _report} = CMS.report_account(user.id, "reason", "attr_info", user2) @@ -132,7 +126,6 @@ defmodule GroupherServer.Test.CMS.AbuseReports.AccountReport do assert List.last(report_cases).user.login == user3.login end - @tag :wip3 test "same user can not report a account twice", ~m(user user2)a do {:ok, _report} = CMS.report_account(user.id, "reason", "attr_info", user2) assert {:error, _report} = CMS.report_account(user.id, "reason", "attr_info", user2) 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 631243dc2..7071490dc 100644 --- a/test/groupher_server/cms/abuse_reports/comment_report_test.exs +++ b/test/groupher_server/cms/abuse_reports/comment_report_test.exs @@ -15,7 +15,6 @@ defmodule GroupherServer.Test.CMS.AbuseReports.CommentReport do end describe "[article comment report/unreport]" do - @tag :wip3 test "report a comment should have a abuse report record", ~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) @@ -32,7 +31,6 @@ defmodule GroupherServer.Test.CMS.AbuseReports.CommentReport do assert List.first(report_cases).user.login == user.login end - @tag :wip3 test "different user report a comment should have same report with different report cases", ~m(user user2 post)a do {:ok, comment} = CMS.create_article_comment(:post, post.id, "commment", user) diff --git a/test/groupher_server/cms/abuse_reports/job_report_test.exs b/test/groupher_server/cms/abuse_reports/job_report_test.exs index 644219a55..8e9019729 100644 --- a/test/groupher_server/cms/abuse_reports/job_report_test.exs +++ b/test/groupher_server/cms/abuse_reports/job_report_test.exs @@ -17,7 +17,6 @@ defmodule GroupherServer.Test.CMS.AbuseReports.JobReport do end describe "[article job report/unreport]" do - @tag :wip3 test "list article reports should work", ~m(community user user2 job_attrs)a do {:ok, job} = CMS.create_content(community, :job, job_attrs, user) {:ok, _report} = CMS.report_article(:job, job.id, "reason", "attr_info", user) @@ -31,7 +30,6 @@ defmodule GroupherServer.Test.CMS.AbuseReports.JobReport do assert report.article.thread == :job end - @tag :wip3 test "report a job should have a abuse report record", ~m(community user job_attrs)a do {:ok, job} = CMS.create_content(community, :job, job_attrs, user) {:ok, _report} = CMS.report_article(:job, job.id, "reason", "attr_info", user) @@ -52,7 +50,6 @@ defmodule GroupherServer.Test.CMS.AbuseReports.JobReport do assert user.id in job.meta.reported_user_ids end - @tag :wip3 test "can undo a report", ~m(community user job_attrs)a do {:ok, job} = CMS.create_content(community, :job, job_attrs, user) {:ok, _report} = CMS.report_article(:job, job.id, "reason", "attr_info", user) @@ -66,7 +63,6 @@ defmodule GroupherServer.Test.CMS.AbuseReports.JobReport do assert user.id not in job.meta.reported_user_ids end - @tag :wip2 test "can undo a existed report", ~m(community user user2 job_attrs)a do {:ok, job} = CMS.create_content(community, :job, job_attrs, user) {:ok, _report} = CMS.report_article(:job, job.id, "reason", "attr_info", user) @@ -83,7 +79,6 @@ defmodule GroupherServer.Test.CMS.AbuseReports.JobReport do assert user.id not in job.meta.reported_user_ids end - @tag :wip3 test "can undo a report with other user report it too", ~m(community user user2 job_attrs)a do {:ok, job} = CMS.create_content(community, :job, job_attrs, user) @@ -110,7 +105,6 @@ defmodule GroupherServer.Test.CMS.AbuseReports.JobReport do assert Enum.any?(report.report_cases, &(&1.user.login == user2.login)) end - @tag :wip3 test "different user report a comment should have same report with different report cases", ~m(community user user2 job_attrs)a do {:ok, job} = CMS.create_content(community, :job, job_attrs, user) @@ -132,7 +126,6 @@ defmodule GroupherServer.Test.CMS.AbuseReports.JobReport do assert List.last(report_cases).user.login == user2.login end - @tag :wip3 test "same user can not report a comment twice", ~m(community job_attrs user)a do {:ok, job} = CMS.create_content(community, :job, job_attrs, user) diff --git a/test/groupher_server/cms/abuse_reports/post_report_test.exs b/test/groupher_server/cms/abuse_reports/post_report_test.exs index d13433513..050817404 100644 --- a/test/groupher_server/cms/abuse_reports/post_report_test.exs +++ b/test/groupher_server/cms/abuse_reports/post_report_test.exs @@ -17,7 +17,6 @@ defmodule GroupherServer.Test.CMS.AbuseReports.PostReport do end describe "[article post report/unreport]" do - @tag :wip3 test "list article reports should work", ~m(community user user2 post_attrs)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) {:ok, _report} = CMS.report_article(:post, post.id, "reason", "attr_info", user) @@ -31,7 +30,6 @@ defmodule GroupherServer.Test.CMS.AbuseReports.PostReport do assert report.article.thread == :post end - @tag :wip3 test "report a post should have a abuse report record", ~m(community user post_attrs)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) {:ok, _report} = CMS.report_article(:post, post.id, "reason", "attr_info", user) @@ -52,7 +50,6 @@ defmodule GroupherServer.Test.CMS.AbuseReports.PostReport do assert user.id in post.meta.reported_user_ids end - @tag :wip3 test "can undo a report", ~m(community user post_attrs)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) {:ok, _report} = CMS.report_article(:post, post.id, "reason", "attr_info", user) @@ -66,7 +63,6 @@ defmodule GroupherServer.Test.CMS.AbuseReports.PostReport do assert user.id not in post.meta.reported_user_ids end - @tag :wip2 test "can undo a existed report", ~m(community user user2 post_attrs)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) {:ok, _report} = CMS.report_article(:post, post.id, "reason", "attr_info", user) @@ -83,7 +79,6 @@ defmodule GroupherServer.Test.CMS.AbuseReports.PostReport do assert user.id not in post.meta.reported_user_ids end - @tag :wip3 test "can undo a report with other user report it too", ~m(community user user2 post_attrs)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) @@ -110,7 +105,6 @@ defmodule GroupherServer.Test.CMS.AbuseReports.PostReport do assert Enum.any?(report.report_cases, &(&1.user.login == user2.login)) end - @tag :wip3 test "different user report a comment should have same report with different report cases", ~m(community user user2 post_attrs)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) @@ -132,7 +126,6 @@ defmodule GroupherServer.Test.CMS.AbuseReports.PostReport do assert List.last(report_cases).user.login == user2.login end - @tag :wip3 test "same user can not report a comment twice", ~m(community post_attrs user)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) 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 7c3cc5369..02bcf5e60 100644 --- a/test/groupher_server/cms/comments/job_comment_emotions_test.exs +++ b/test/groupher_server/cms/comments/job_comment_emotions_test.exs @@ -21,7 +21,6 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentEmotions do end describe "[emotion in paged article comment]" do - @tag :wip3 test "login user should got viewer has emotioned status", ~m(job user)a do total_count = 0 page_number = 10 @@ -76,7 +75,6 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentEmotions do assert @default_emotions == emotions end - @tag :wip3 test "can make emotion to comment", ~m(job user user2)a do parent_content = "parent comment" {:ok, parent_comment} = CMS.create_article_comment(:job, job.id, parent_content, user) @@ -91,7 +89,6 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentEmotions do assert user_exist_in?(user2, emotions.latest_downvote_users) end - @tag :wip3 test "can undo emotion to comment", ~m(job user user2)a do parent_content = "parent comment" {:ok, parent_comment} = CMS.create_article_comment(:job, job.id, parent_content, user) @@ -114,7 +111,6 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentEmotions do assert not user_exist_in?(user2, emotions.latest_downvote_users) end - @tag :wip3 test "same user make same emotion to same comment.", ~m(job user)a do parent_content = "parent comment" {:ok, parent_comment} = CMS.create_article_comment(:job, job.id, parent_content, user) @@ -128,7 +124,6 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentEmotions do assert user_exist_in?(user, parent_comment.emotions.latest_downvote_users) end - @tag :wip3 test "same user same emotion to same comment only have one user_emotion record", ~m(job user)a do parent_content = "parent comment" @@ -152,7 +147,6 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentEmotions do assert record.heart end - @tag :wip3 test "different user can make same emotions on same comment", ~m(job user user2 user3)a do {:ok, parent_comment} = CMS.create_article_comment(:job, job.id, "parent comment", 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 6a127ca62..d1fd18560 100644 --- a/test/groupher_server/cms/comments/job_comment_replies_test.exs +++ b/test/groupher_server/cms/comments/job_comment_replies_test.exs @@ -33,7 +33,6 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentReplies do assert exist_in?(replyed_comment, parent_comment.replies) end - @tag :wip3 test "deleted comment can not be reply", ~m(job user user2)a do parent_content = "parent comment" reply_content = "reply comment" @@ -64,7 +63,6 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentReplies do assert exist_in?(replyed_comment_2, parent_comment.replies) end - @tag :wip3 test "reply to reply inside a comment should belong same parent comment", ~m(job user user2)a do {:ok, parent_comment} = CMS.create_article_comment(:job, job.id, "parent comment", user) @@ -90,7 +88,6 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentReplies do assert replyed_comment_3.reply_to_id == replyed_comment_2.id end - @tag :wip3 test "reply to reply inside a comment should have is_reply_to_others flag in meta", ~m(job user user2)a do {:ok, parent_comment} = CMS.create_article_comment(:job, job.id, "parent comment", user) @@ -110,7 +107,6 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentReplies do assert replyed_comment_3.meta.is_reply_to_others end - @tag :wip3 test "comment replies only contains @max_parent_replies_count replies", ~m(job user)a do total_reply_count = @max_parent_replies_count + 1 diff --git a/test/groupher_server/cms/comments/job_comment_test.exs b/test/groupher_server/cms/comments/job_comment_test.exs index dc0fbf472..c67124e8f 100644 --- a/test/groupher_server/cms/comments/job_comment_test.exs +++ b/test/groupher_server/cms/comments/job_comment_test.exs @@ -39,7 +39,6 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do assert comment.meta |> Map.from_struct() |> Map.delete(:id) == @default_comment_meta end - @tag :wip3 test "comment can be updated", ~m(job user)a do {:ok, comment} = CMS.create_article_comment(:job, job.id, "job comment", user) @@ -130,7 +129,6 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do assert comment.meta.is_article_author_upvoted end - @tag :wip3 test "user upvote job comment will add id to upvoted_user_ids", ~m(job user)a do comment = "job_comment" {:ok, comment} = CMS.create_article_comment(:job, job.id, comment, user) @@ -139,7 +137,6 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do assert user.id in comment.meta.upvoted_user_ids end - @tag :wip3 test "user undo upvote job comment will remove id from upvoted_user_ids", ~m(job user user2)a do comment = "job_comment" @@ -289,7 +286,6 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do # {:ok, comment} = ORM.find(ArticleComment, comment.id) # end - @tag :wip3 test "can undo a report with other user report it too", ~m(user user2 job)a do {:ok, comment} = CMS.create_article_comment(:job, job.id, "commment", user) @@ -317,7 +313,6 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do assert Enum.any?(report.report_cases, &(&1.user.login == user2.login)) end - @tag :wip3 test "report user < @report_threshold_for_fold will not fold comment", ~m(user job)a do {:ok, comment} = CMS.create_article_comment(:job, job.id, "commment", user) @@ -453,7 +448,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do assert paged_comments.total_count == total_count end - @tag :wip3 + @tag :wip2 test "paged article comments should not contains folded and repoted comments", ~m(user job)a do total_count = 15 @@ -471,18 +466,10 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do random_comment_2 = all_comments |> Enum.at(1) random_comment_3 = all_comments |> Enum.at(3) - random_comment_4 = all_comments |> Enum.at(2) - random_comment_5 = all_comments |> Enum.at(4) - random_comment_6 = all_comments |> Enum.at(8) - {:ok, _comment} = CMS.fold_article_comment(random_comment_1.id, user) {:ok, _comment} = CMS.fold_article_comment(random_comment_2.id, user) {:ok, _comment} = CMS.fold_article_comment(random_comment_3.id, user) - {:ok, _comment} = CMS.report_article_comment(random_comment_4.id, "reason", "attr", user) - {:ok, _comment} = CMS.report_article_comment(random_comment_5.id, "reason", "attr", user) - {:ok, _comment} = CMS.report_article_comment(random_comment_6.id, "reason", "attr", user) - {:ok, paged_comments} = CMS.list_article_comments(:job, job.id, %{page: page_number, size: page_size}, :replies) @@ -490,13 +477,9 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do assert not exist_in?(random_comment_2, paged_comments.entries) assert not exist_in?(random_comment_3, paged_comments.entries) - assert not exist_in?(random_comment_4, paged_comments.entries) - assert not exist_in?(random_comment_5, paged_comments.entries) - assert not exist_in?(random_comment_6, paged_comments.entries) - assert page_number == paged_comments.page_number assert page_size == paged_comments.page_size - assert total_count - 6 == paged_comments.total_count + assert total_count - 3 == paged_comments.total_count end @tag :wip @@ -531,7 +514,6 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do end describe "[article comment delete]" do - @tag :wip3 test "delete comment still exsit in paged list and content is gone", ~m(user job)a do total_count = 10 page_number = 1 @@ -556,7 +538,6 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do assert deleted_comment.body_html == @delete_hint end - @tag :wip3 test "delete comment still update article's comments_count field", ~m(user job)a do {:ok, _comment} = CMS.create_article_comment(:job, job.id, "commment", user) {:ok, _comment} = CMS.create_article_comment(:job, job.id, "commment", user) @@ -574,7 +555,6 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do assert job.article_comments_count == 4 end - @tag :wip3 test "delete comment still delete pined record if needed", ~m(user job)a do total_count = 10 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 0e55ecfd3..0d0bb0a2e 100644 --- a/test/groupher_server/cms/comments/post_comment_emotions_test.exs +++ b/test/groupher_server/cms/comments/post_comment_emotions_test.exs @@ -21,7 +21,6 @@ defmodule GroupherServer.Test.CMS.Comments.PostCommentEmotions do end describe "[emotion in paged article comment]" do - @tag :wip3 test "login user should got viewer has emotioned status", ~m(post user)a do total_count = 0 page_number = 10 @@ -76,7 +75,6 @@ defmodule GroupherServer.Test.CMS.Comments.PostCommentEmotions do assert @default_emotions == emotions end - @tag :wip3 test "can make emotion to comment", ~m(post user user2)a do parent_content = "parent comment" {:ok, parent_comment} = CMS.create_article_comment(:post, post.id, parent_content, user) @@ -91,7 +89,6 @@ defmodule GroupherServer.Test.CMS.Comments.PostCommentEmotions do assert user_exist_in?(user2, emotions.latest_downvote_users) end - @tag :wip3 test "can undo emotion to comment", ~m(post user user2)a do parent_content = "parent comment" {:ok, parent_comment} = CMS.create_article_comment(:post, post.id, parent_content, user) @@ -114,7 +111,6 @@ defmodule GroupherServer.Test.CMS.Comments.PostCommentEmotions do assert not user_exist_in?(user2, emotions.latest_downvote_users) end - @tag :wip3 test "same user make same emotion to same comment.", ~m(post user)a do parent_content = "parent comment" {:ok, parent_comment} = CMS.create_article_comment(:post, post.id, parent_content, user) @@ -128,7 +124,6 @@ defmodule GroupherServer.Test.CMS.Comments.PostCommentEmotions do assert user_exist_in?(user, parent_comment.emotions.latest_downvote_users) end - @tag :wip3 test "same user same emotion to same comment only have one user_emotion record", ~m(post user)a do parent_content = "parent comment" @@ -152,7 +147,6 @@ defmodule GroupherServer.Test.CMS.Comments.PostCommentEmotions do assert record.heart end - @tag :wip3 test "different user can make same emotions on same comment", ~m(post user user2 user3)a do {:ok, parent_comment} = CMS.create_article_comment(:post, post.id, "parent comment", 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 d7508fa62..0327a44e2 100644 --- a/test/groupher_server/cms/comments/post_comment_replies_test.exs +++ b/test/groupher_server/cms/comments/post_comment_replies_test.exs @@ -33,7 +33,6 @@ defmodule GroupherServer.Test.CMS.Comments.PostCommentReplies do assert exist_in?(replyed_comment, parent_comment.replies) end - @tag :wip3 test "deleted comment can not be reply", ~m(post user user2)a do parent_content = "parent comment" reply_content = "reply comment" @@ -64,7 +63,6 @@ defmodule GroupherServer.Test.CMS.Comments.PostCommentReplies do assert exist_in?(replyed_comment_2, parent_comment.replies) end - @tag :wip3 test "reply to reply inside a comment should belong same parent comment", ~m(post user user2)a do {:ok, parent_comment} = CMS.create_article_comment(:post, post.id, "parent comment", user) @@ -90,7 +88,6 @@ defmodule GroupherServer.Test.CMS.Comments.PostCommentReplies do assert replyed_comment_3.reply_to_id == replyed_comment_2.id end - @tag :wip3 test "reply to reply inside a comment should have is_reply_to_others flag in meta", ~m(post user user2)a do {:ok, parent_comment} = CMS.create_article_comment(:post, post.id, "parent comment", user) @@ -110,7 +107,6 @@ defmodule GroupherServer.Test.CMS.Comments.PostCommentReplies do assert replyed_comment_3.meta.is_reply_to_others end - @tag :wip3 test "comment replies only contains @max_parent_replies_count replies", ~m(post user)a do total_reply_count = @max_parent_replies_count + 1 @@ -160,7 +156,6 @@ defmodule GroupherServer.Test.CMS.Comments.PostCommentReplies do end describe "[paged article comment replies]" do - @tag :wip3 test "can get paged replies of a parent comment", ~m(post user)a do {:ok, parent_comment} = CMS.create_article_comment(:post, post.id, "parent_conent", user) {:ok, paged_replies} = CMS.list_comment_replies(parent_comment.id, %{page: 1, size: 20}) diff --git a/test/groupher_server/cms/comments/post_comment_test.exs b/test/groupher_server/cms/comments/post_comment_test.exs index 8c8a95f19..9e63255ab 100644 --- a/test/groupher_server/cms/comments/post_comment_test.exs +++ b/test/groupher_server/cms/comments/post_comment_test.exs @@ -39,7 +39,6 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do assert comment.meta |> Map.from_struct() |> Map.delete(:id) == @default_comment_meta end - @tag :wip3 test "comment can be updated", ~m(post user)a do {:ok, comment} = CMS.create_article_comment(:post, post.id, "post comment", user) @@ -130,7 +129,6 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do assert comment.meta.is_article_author_upvoted end - @tag :wip3 test "user upvote post comment will add id to upvoted_user_ids", ~m(post user)a do comment = "post_comment" {:ok, comment} = CMS.create_article_comment(:post, post.id, comment, user) @@ -139,7 +137,6 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do assert user.id in comment.meta.upvoted_user_ids end - @tag :wip3 test "user undo upvote post comment will remove id from upvoted_user_ids", ~m(post user user2)a do comment = "post_comment" @@ -279,7 +276,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do # {:ok, comment} = ORM.find(ArticleComment, comment.id) # end - # @tag :wip3 + # # test "user can unreport a comment", ~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) @@ -289,7 +286,6 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do # {:ok, comment} = ORM.find(ArticleComment, comment.id) # end - @tag :wip3 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) @@ -453,7 +449,6 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do assert paged_comments.total_count == total_count end - @tag :wip3 test "paged article comments should not contains folded and repoted comments", ~m(user post)a do total_count = 15 @@ -519,7 +514,6 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do end describe "[article comment delete]" do - @tag :wip3 test "delete comment still exsit in paged list and content is gone", ~m(user post)a do total_count = 10 page_number = 1 @@ -544,7 +538,6 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do assert deleted_comment.body_html == @delete_hint end - @tag :wip3 test "delete comment still update article's comments_count field", ~m(user post)a do {:ok, _comment} = CMS.create_article_comment(:post, post.id, "commment", user) {:ok, _comment} = CMS.create_article_comment(:post, post.id, "commment", user) @@ -562,7 +555,6 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do assert post.article_comments_count == 4 end - @tag :wip3 test "delete comment still delete pined record if needed", ~m(user post)a do total_count = 10 diff --git a/test/groupher_server/cms/emotions/job_emotions_test.exs b/test/groupher_server/cms/emotions/job_emotions_test.exs index 699214674..dac90c76b 100644 --- a/test/groupher_server/cms/emotions/job_emotions_test.exs +++ b/test/groupher_server/cms/emotions/job_emotions_test.exs @@ -22,7 +22,6 @@ defmodule GroupherServer.Test.CMS.Emotions.JobEmotions do end describe "[emotion in paged jobs]" do - @tag :wip3 test "login user should got viewer has emotioned status", ~m(community job_attrs user)a do total_count = 10 @@ -61,7 +60,6 @@ defmodule GroupherServer.Test.CMS.Emotions.JobEmotions do end describe "[basic article emotion]" do - @tag :wip3 test "job has default emotions after created", ~m(community job_attrs user)a do {:ok, job} = CMS.create_content(community, :job, job_attrs, user) @@ -69,7 +67,6 @@ defmodule GroupherServer.Test.CMS.Emotions.JobEmotions do assert @default_emotions == emotions end - @tag :wip3 test "can make emotion to job", ~m(community job_attrs user user2)a do {:ok, job} = CMS.create_content(community, :job, job_attrs, user) @@ -83,7 +80,6 @@ defmodule GroupherServer.Test.CMS.Emotions.JobEmotions do assert user_exist_in?(user2, emotions.latest_downvote_users) end - @tag :wip3 test "can undo emotion to job", ~m(community job_attrs user user2)a do {:ok, job} = CMS.create_content(community, :job, job_attrs, user) @@ -100,7 +96,6 @@ defmodule GroupherServer.Test.CMS.Emotions.JobEmotions do assert not user_exist_in?(user2, emotions.latest_downvote_users) end - @tag :wip3 test "same user make same emotion to same job.", ~m(community job_attrs user)a do {:ok, job} = CMS.create_content(community, :job, job_attrs, user) @@ -113,7 +108,6 @@ defmodule GroupherServer.Test.CMS.Emotions.JobEmotions do assert user_exist_in?(user, job.emotions.latest_downvote_users) end - @tag :wip3 test "same user same emotion to same job only have one user_emotion record", ~m(community job_attrs user)a do {:ok, job} = CMS.create_content(community, :job, job_attrs, user) @@ -131,7 +125,6 @@ defmodule GroupherServer.Test.CMS.Emotions.JobEmotions do assert record.heart end - @tag :wip3 test "different user can make same emotions on same job", ~m(community job_attrs user user2 user3)a do {:ok, job} = CMS.create_content(community, :job, job_attrs, user) @@ -148,7 +141,6 @@ defmodule GroupherServer.Test.CMS.Emotions.JobEmotions do assert user_exist_in?(user3, emotions.latest_beer_users) end - @tag :wip3 test "same user can make differcent emotions on same job", ~m(community job_attrs user)a do {:ok, job} = CMS.create_content(community, :job, job_attrs, user) diff --git a/test/groupher_server/cms/emotions/post_emotions_test.exs b/test/groupher_server/cms/emotions/post_emotions_test.exs index 24a10fce8..0e332bbfa 100644 --- a/test/groupher_server/cms/emotions/post_emotions_test.exs +++ b/test/groupher_server/cms/emotions/post_emotions_test.exs @@ -22,7 +22,6 @@ defmodule GroupherServer.Test.CMS.Emotions.PostEmotions do end describe "[emotion in paged posts]" do - @tag :wip3 test "login user should got viewer has emotioned status", ~m(community post_attrs user)a do total_count = 10 @@ -61,7 +60,6 @@ defmodule GroupherServer.Test.CMS.Emotions.PostEmotions do end describe "[basic article emotion]" do - @tag :wip3 test "post has default emotions after created", ~m(community post_attrs user)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) @@ -69,7 +67,6 @@ defmodule GroupherServer.Test.CMS.Emotions.PostEmotions do assert @default_emotions == emotions end - @tag :wip3 test "can make emotion to post", ~m(community post_attrs user user2)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) @@ -83,7 +80,6 @@ defmodule GroupherServer.Test.CMS.Emotions.PostEmotions do assert user_exist_in?(user2, emotions.latest_downvote_users) end - @tag :wip3 test "can undo emotion to post", ~m(community post_attrs user user2)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) @@ -100,7 +96,6 @@ defmodule GroupherServer.Test.CMS.Emotions.PostEmotions do assert not user_exist_in?(user2, emotions.latest_downvote_users) end - @tag :wip3 test "same user make same emotion to same post.", ~m(community post_attrs user)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) @@ -113,7 +108,6 @@ defmodule GroupherServer.Test.CMS.Emotions.PostEmotions do assert user_exist_in?(user, post.emotions.latest_downvote_users) end - @tag :wip3 test "same user same emotion to same post only have one user_emotion record", ~m(community post_attrs user)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) @@ -131,7 +125,6 @@ defmodule GroupherServer.Test.CMS.Emotions.PostEmotions do assert record.heart end - @tag :wip3 test "different user can make same emotions on same post", ~m(community post_attrs user user2 user3)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) @@ -148,7 +141,6 @@ defmodule GroupherServer.Test.CMS.Emotions.PostEmotions do assert user_exist_in?(user3, emotions.latest_beer_users) end - @tag :wip3 test "same user can make differcent emotions on same post", ~m(community post_attrs user)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) diff --git a/test/groupher_server/cms/job_test.exs b/test/groupher_server/cms/job_test.exs index 6d924a25f..39cdd6275 100644 --- a/test/groupher_server/cms/job_test.exs +++ b/test/groupher_server/cms/job_test.exs @@ -25,7 +25,6 @@ defmodule GroupherServer.Test.Job do assert found.title == job.title end - @tag :wip3 test "read job should update views and meta viewed_user_list", ~m(job_attrs community user user2)a do {:ok, job} = CMS.create_content(community, :job, job_attrs, user) diff --git a/test/groupher_server/cms/post_test.exs b/test/groupher_server/cms/post_test.exs index eae07914a..50e836dbf 100644 --- a/test/groupher_server/cms/post_test.exs +++ b/test/groupher_server/cms/post_test.exs @@ -18,7 +18,6 @@ defmodule GroupherServer.Test.CMS.Post do describe "[cms post curd]" do alias CMS.{Author, Community} - @tag :wip3 test "can create post with valid attrs", ~m(user community post_attrs)a do assert {:error, _} = ORM.find_by(Author, user_id: user.id) @@ -27,7 +26,6 @@ defmodule GroupherServer.Test.CMS.Post do assert post.title == post_attrs.title end - @tag :wip3 test "read post should update views and meta viewed_user_list", ~m(post_attrs community user user2)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) diff --git a/test/groupher_server/cms/repo_test.exs b/test/groupher_server/cms/repo_test.exs index 0446b00c5..dab873ce3 100644 --- a/test/groupher_server/cms/repo_test.exs +++ b/test/groupher_server/cms/repo_test.exs @@ -17,7 +17,7 @@ defmodule GroupherServer.Test.Repo do describe "[cms repo curd]" do alias CMS.{Author, Community} - @tag :wip3 + test "can create repo with valid attrs", ~m(user community repo_attrs)a do assert {:error, _} = ORM.find_by(Author, user_id: user.id) @@ -27,7 +27,6 @@ defmodule GroupherServer.Test.Repo do assert repo.contributors |> length !== 0 end - @tag :wip3 test "read repo should update views and meta viewed_user_list", ~m(repo_attrs community user user2)a do {:ok, repo} = CMS.create_content(community, :repo, repo_attrs, user) diff --git a/test/groupher_server/cms/upvotes/job_upvote_test.exs b/test/groupher_server/cms/upvotes/job_upvote_test.exs index 18286922b..8320df575 100644 --- a/test/groupher_server/cms/upvotes/job_upvote_test.exs +++ b/test/groupher_server/cms/upvotes/job_upvote_test.exs @@ -15,7 +15,6 @@ defmodule GroupherServer.Test.Upvotes.JobUpvote do end describe "[cms job upvote]" do - @tag :wip3 test "job can be upvote && upvotes_count should inc by 1", ~m(user user2 community job_attrs)a do {:ok, job} = CMS.create_content(community, :job, job_attrs, user) @@ -28,7 +27,6 @@ defmodule GroupherServer.Test.Upvotes.JobUpvote do assert article.upvotes_count == 2 end - @tag :wip3 test "job can be undo upvote && upvotes_count should dec by 1", ~m(user user2 community job_attrs)a do {:ok, job} = CMS.create_content(community, :job, job_attrs, user) @@ -41,7 +39,6 @@ defmodule GroupherServer.Test.Upvotes.JobUpvote do assert article.upvotes_count == 0 end - @tag :wip3 test "can get upvotes_users", ~m(user user2 community job_attrs)a do {:ok, job} = CMS.create_content(community, :job, job_attrs, user) @@ -55,7 +52,6 @@ defmodule GroupherServer.Test.Upvotes.JobUpvote do assert user_exist_in?(user2, users.entries) end - @tag :wip3 test "job meta history should be updated after upvote", ~m(user user2 community job_attrs)a do {:ok, job} = CMS.create_content(community, :job, job_attrs, user) @@ -67,7 +63,6 @@ defmodule GroupherServer.Test.Upvotes.JobUpvote do assert user2.id in article.meta.upvoted_user_ids end - @tag :wip3 test "job meta history should be updated after undo upvote", ~m(user user2 community job_attrs)a do {:ok, job} = CMS.create_content(community, :job, job_attrs, user) diff --git a/test/groupher_server/cms/upvotes/post_upvote_test.exs b/test/groupher_server/cms/upvotes/post_upvote_test.exs index 5cf2c8ed8..00df06794 100644 --- a/test/groupher_server/cms/upvotes/post_upvote_test.exs +++ b/test/groupher_server/cms/upvotes/post_upvote_test.exs @@ -15,7 +15,6 @@ defmodule GroupherServer.Test.Upvotes.PostUpvote do end describe "[cms post upvote]" do - @tag :wip3 test "post can be upvote && upvotes_count should inc by 1", ~m(user user2 community post_attrs)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) @@ -28,7 +27,6 @@ defmodule GroupherServer.Test.Upvotes.PostUpvote do assert article.upvotes_count == 2 end - @tag :wip3 test "post can be undo upvote && upvotes_count should dec by 1", ~m(user user2 community post_attrs)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) @@ -41,7 +39,6 @@ defmodule GroupherServer.Test.Upvotes.PostUpvote do assert article.upvotes_count == 0 end - @tag :wip3 test "can get upvotes_users", ~m(user user2 community post_attrs)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) @@ -55,7 +52,6 @@ defmodule GroupherServer.Test.Upvotes.PostUpvote do assert user_exist_in?(user2, users.entries) end - @tag :wip3 test "post meta history should be updated after upvote", ~m(user user2 community post_attrs)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) @@ -67,7 +63,6 @@ defmodule GroupherServer.Test.Upvotes.PostUpvote do assert user2.id in article.meta.upvoted_user_ids end - @tag :wip3 test "post meta history should be updated after undo upvote", ~m(user user2 community post_attrs)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) diff --git a/test/groupher_server_web/mutation/accounts/customization_test.exs b/test/groupher_server_web/mutation/accounts/customization_test.exs index 8f42ad231..290d90122 100644 --- a/test/groupher_server_web/mutation/accounts/customization_test.exs +++ b/test/groupher_server_web/mutation/accounts/customization_test.exs @@ -72,7 +72,7 @@ defmodule GroupherServer.Test.Mutation.Account.Customization do } } """ - @tag :wip3 + test "PageSizeProof middleware should lint c11n displayDensity size", ~m(user)a do user_conn = simu_conn(:user, user) db_insert_multi(:post, 50) diff --git a/test/groupher_server_web/mutation/cms/articles/job_emotion_test.exs b/test/groupher_server_web/mutation/cms/articles/job_emotion_test.exs index b822aff94..8a8201e94 100644 --- a/test/groupher_server_web/mutation/cms/articles/job_emotion_test.exs +++ b/test/groupher_server_web/mutation/cms/articles/job_emotion_test.exs @@ -32,7 +32,7 @@ defmodule GroupherServer.Test.Mutation.Articles.JobEmotion do } } """ - @tag :wip3 + test "login user can emotion to a pjob", ~m(community job_attrs user user_conn)a do {:ok, job} = CMS.create_content(community, :job, job_attrs, user) @@ -58,7 +58,7 @@ defmodule GroupherServer.Test.Mutation.Articles.JobEmotion do } } """ - @tag :wip3 + test "login user can undo emotion to a job", ~m(community job_attrs user owner_conn)a do {:ok, job} = CMS.create_content(community, :job, job_attrs, user) {:ok, _} = CMS.emotion_to_article(:job, job.id, :beer, user) diff --git a/test/groupher_server_web/mutation/cms/articles/job_report_test.exs b/test/groupher_server_web/mutation/cms/articles/job_report_test.exs index 39acfbbb2..ec80a3791 100644 --- a/test/groupher_server_web/mutation/cms/articles/job_report_test.exs +++ b/test/groupher_server_web/mutation/cms/articles/job_report_test.exs @@ -25,7 +25,7 @@ defmodule GroupherServer.Test.Mutation.Articles.JobReport do } } """ - @tag :wip3 + test "login user can report a job", ~m(community job_attrs user user_conn)a do {:ok, job} = CMS.create_content(community, :job, job_attrs, user) @@ -43,7 +43,7 @@ defmodule GroupherServer.Test.Mutation.Articles.JobReport do } } """ - @tag :wip3 + test "login user can undo report a job", ~m(community job_attrs user user_conn)a do {:ok, job} = CMS.create_content(community, :job, job_attrs, user) diff --git a/test/groupher_server_web/mutation/cms/articles/job_test.exs b/test/groupher_server_web/mutation/cms/articles/job_test.exs index c269abc50..3a8fb022e 100644 --- a/test/groupher_server_web/mutation/cms/articles/job_test.exs +++ b/test/groupher_server_web/mutation/cms/articles/job_test.exs @@ -282,7 +282,7 @@ defmodule GroupherServer.Test.Mutation.Articles.Job do } } """ - @tag :wip3 + test "can delete a job by job's owner", ~m(owner_conn job)a do deleted = owner_conn |> mutation_result(@query, %{id: job.id}, "deleteJob") diff --git a/test/groupher_server_web/mutation/cms/articles/post_emotion_test.exs b/test/groupher_server_web/mutation/cms/articles/post_emotion_test.exs index 30c37a5e4..e67efad1e 100644 --- a/test/groupher_server_web/mutation/cms/articles/post_emotion_test.exs +++ b/test/groupher_server_web/mutation/cms/articles/post_emotion_test.exs @@ -32,7 +32,7 @@ defmodule GroupherServer.Test.Mutation.Articles.PostEmotion do } } """ - @tag :wip3 + test "login user can emotion to a ppost", ~m(community post_attrs user user_conn)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) @@ -58,7 +58,7 @@ defmodule GroupherServer.Test.Mutation.Articles.PostEmotion do } } """ - @tag :wip3 + test "login user can undo emotion to a post", ~m(community post_attrs user owner_conn)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) {:ok, _} = CMS.emotion_to_article(:post, post.id, :beer, user) diff --git a/test/groupher_server_web/mutation/cms/articles/post_report_test.exs b/test/groupher_server_web/mutation/cms/articles/post_report_test.exs index 5bf9cfc90..4cd20e925 100644 --- a/test/groupher_server_web/mutation/cms/articles/post_report_test.exs +++ b/test/groupher_server_web/mutation/cms/articles/post_report_test.exs @@ -25,7 +25,7 @@ defmodule GroupherServer.Test.Mutation.Articles.PostReport do } } """ - @tag :wip3 + test "login user can report a post", ~m(community post_attrs user user_conn)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) @@ -43,7 +43,7 @@ defmodule GroupherServer.Test.Mutation.Articles.PostReport do } } """ - @tag :wip3 + test "login user can undo report a post", ~m(community post_attrs user user_conn)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) 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 ac96ddaa2..76393d533 100644 --- a/test/groupher_server_web/mutation/cms/articles/post_test.exs +++ b/test/groupher_server_web/mutation/cms/articles/post_test.exs @@ -142,7 +142,7 @@ defmodule GroupherServer.Test.Mutation.Articles.Post do } } """ - @tag :wip3 + test "delete a post by post's owner", ~m(owner_conn post)a do deleted = owner_conn |> mutation_result(@query, %{id: post.id}, "deletePost") diff --git a/test/groupher_server_web/mutation/cms/articles/repo_report_test.exs b/test/groupher_server_web/mutation/cms/articles/repo_report_test.exs index c00165f59..3ba92707a 100644 --- a/test/groupher_server_web/mutation/cms/articles/repo_report_test.exs +++ b/test/groupher_server_web/mutation/cms/articles/repo_report_test.exs @@ -25,7 +25,7 @@ defmodule GroupherServer.Test.Mutation.Articles.RepoReport do } } """ - @tag :wip3 + test "login user can report a repo", ~m(community repo_attrs user user_conn)a do {:ok, repo} = CMS.create_content(community, :repo, repo_attrs, user) @@ -43,7 +43,7 @@ defmodule GroupherServer.Test.Mutation.Articles.RepoReport do } } """ - @tag :wip3 + test "login user can undo report a repo", ~m(community repo_attrs user user_conn)a do {:ok, repo} = CMS.create_content(community, :repo, repo_attrs, user) diff --git a/test/groupher_server_web/mutation/cms/articles/repo_test.exs b/test/groupher_server_web/mutation/cms/articles/repo_test.exs index afedc0217..f84881ce8 100644 --- a/test/groupher_server_web/mutation/cms/articles/repo_test.exs +++ b/test/groupher_server_web/mutation/cms/articles/repo_test.exs @@ -193,7 +193,7 @@ defmodule GroupherServer.Test.Mutation.Articles.Repo do } } """ - @tag :wip3 + test "delete a repo by repo's owner", ~m(owner_conn repo)a do deleted = owner_conn |> mutation_result(@query, %{id: repo.id}, "deleteRepo") @@ -201,7 +201,6 @@ defmodule GroupherServer.Test.Mutation.Articles.Repo do assert {:error, _} = ORM.find(CMS.Repo, deleted["id"]) end - @tag :wip3 test "can delete a repo by auth user", ~m(repo)a do belongs_community_title = repo.communities |> List.first() |> Map.get(:title) rule_conn = simu_conn(:user, cms: %{belongs_community_title => %{"repo.delete" => true}}) @@ -212,7 +211,6 @@ defmodule GroupherServer.Test.Mutation.Articles.Repo do assert {:error, _} = ORM.find(CMS.Repo, deleted["id"]) end - @tag :wip3 test "delete a repo without login user fails", ~m(guest_conn repo)a do assert guest_conn |> mutation_get_error?(@query, %{id: repo.id}, ecode(:account_login)) end diff --git a/test/groupher_server_web/mutation/cms/cms_test.exs b/test/groupher_server_web/mutation/cms/cms_test.exs index 158431643..d3ee8d27d 100644 --- a/test/groupher_server_web/mutation/cms/cms_test.exs +++ b/test/groupher_server_web/mutation/cms/cms_test.exs @@ -431,7 +431,7 @@ defmodule GroupherServer.Test.Mutation.CMS.Basic do } } """ - @tag :wip3 + test "auth user can create thread", ~m(user)a do title = "post" raw = "POST" @@ -445,7 +445,6 @@ defmodule GroupherServer.Test.Mutation.CMS.Basic do assert result["title"] == title end - @tag :wip3 test "unauth user create thread fails", ~m(user_conn guest_conn)a do title = "psot" raw = "POST" diff --git a/test/groupher_server_web/mutation/cms/comments/job_comment_test.exs b/test/groupher_server_web/mutation/cms/comments/job_comment_test.exs index 3161d7018..86eba207e 100644 --- a/test/groupher_server_web/mutation/cms/comments/job_comment_test.exs +++ b/test/groupher_server_web/mutation/cms/comments/job_comment_test.exs @@ -24,7 +24,7 @@ defmodule GroupherServer.Test.Mutation.Comments.JobComment do } } """ - @tag :wip3 + test "write article comment to a exsit job", ~m(job user_conn)a do comment = "a test comment" variables = %{thread: "JOB", id: job.id, content: comment} @@ -43,7 +43,7 @@ defmodule GroupherServer.Test.Mutation.Comments.JobComment do } } """ - @tag :wip3 + test "login user can reply to a comment", ~m(job user user_conn)a do {:ok, comment} = CMS.create_article_comment(:job, job.id, "commment", user) variables = %{id: comment.id, content: "reply content"} @@ -63,7 +63,7 @@ defmodule GroupherServer.Test.Mutation.Comments.JobComment do } } """ - @tag :wip3 + test "only owner can update a exsit comment", ~m(job user guest_conn user_conn owner_conn)a do {:ok, comment} = CMS.create_article_comment(:job, job.id, "job comment", user) @@ -88,7 +88,7 @@ defmodule GroupherServer.Test.Mutation.Comments.JobComment do } } """ - @tag :wip3 + test "only owner can delete a exsit comment", ~m(job user guest_conn user_conn owner_conn)a do {:ok, comment} = CMS.create_article_comment(:job, job.id, "job comment", user) @@ -123,7 +123,7 @@ defmodule GroupherServer.Test.Mutation.Comments.JobComment do } } """ - @tag :wip3 + test "login user can emotion to a comment", ~m(job user user_conn)a do {:ok, comment} = CMS.create_article_comment(:job, job.id, "job comment", user) variables = %{id: comment.id, emotion: "BEER"} @@ -150,7 +150,7 @@ defmodule GroupherServer.Test.Mutation.Comments.JobComment do } } """ - @tag :wip3 + test "login user can undo emotion to a comment", ~m(job user owner_conn)a do {:ok, comment} = CMS.create_article_comment(:job, job.id, "job comment", user) {:ok, _} = CMS.emotion_to_comment(comment.id, :beer, user) diff --git a/test/groupher_server_web/mutation/cms/comments/post_comment_test.exs b/test/groupher_server_web/mutation/cms/comments/post_comment_test.exs index 9a8ec7d86..52d43f49c 100644 --- a/test/groupher_server_web/mutation/cms/comments/post_comment_test.exs +++ b/test/groupher_server_web/mutation/cms/comments/post_comment_test.exs @@ -24,7 +24,7 @@ defmodule GroupherServer.Test.Mutation.Comments.PostComment do } } """ - @tag :wip3 + test "write article comment to a exsit post", ~m(post user_conn)a do comment = "a test comment" variables = %{thread: "POST", id: post.id, content: comment} @@ -43,7 +43,7 @@ defmodule GroupherServer.Test.Mutation.Comments.PostComment do } } """ - @tag :wip3 + test "login user can reply to a comment", ~m(post user user_conn)a do {:ok, comment} = CMS.create_article_comment(:post, post.id, "commment", user) variables = %{id: comment.id, content: "reply content"} @@ -63,7 +63,7 @@ defmodule GroupherServer.Test.Mutation.Comments.PostComment do } } """ - @tag :wip3 + test "only owner can update a exsit comment", ~m(post user guest_conn user_conn owner_conn)a do {:ok, comment} = CMS.create_article_comment(:post, post.id, "post comment", user) @@ -88,7 +88,7 @@ defmodule GroupherServer.Test.Mutation.Comments.PostComment do } } """ - @tag :wip3 + test "only owner can delete a exsit comment", ~m(post user guest_conn user_conn owner_conn)a do {:ok, comment} = CMS.create_article_comment(:post, post.id, "post comment", user) @@ -123,7 +123,7 @@ defmodule GroupherServer.Test.Mutation.Comments.PostComment do } } """ - @tag :wip3 + test "login user can emotion to a comment", ~m(post user user_conn)a do {:ok, comment} = CMS.create_article_comment(:post, post.id, "post comment", user) variables = %{id: comment.id, emotion: "BEER"} @@ -150,7 +150,7 @@ defmodule GroupherServer.Test.Mutation.Comments.PostComment do } } """ - @tag :wip3 + test "login user can undo emotion to a comment", ~m(post user owner_conn)a do {:ok, comment} = CMS.create_article_comment(:post, post.id, "post comment", user) {:ok, _} = CMS.emotion_to_comment(comment.id, :beer, user) diff --git a/test/groupher_server_web/mutation/cms/flags/job_flag_test.exs b/test/groupher_server_web/mutation/cms/flags/job_flag_test.exs index c9c0fb219..659472e6c 100644 --- a/test/groupher_server_web/mutation/cms/flags/job_flag_test.exs +++ b/test/groupher_server_web/mutation/cms/flags/job_flag_test.exs @@ -25,7 +25,7 @@ defmodule GroupherServer.Test.Mutation.Flags.JobFlag do } } """ - @tag :wip3 + test "auth user can trash job", ~m(community job)a do variables = %{id: job.id, communityId: community.id} @@ -38,7 +38,6 @@ defmodule GroupherServer.Test.Mutation.Flags.JobFlag do assert updated["trash"] == true end - @tag :wip3 test "unauth user trash job fails", ~m(user_conn guest_conn job community)a do variables = %{id: job.id, communityId: community.id} rule_conn = simu_conn(:user, cms: %{"what.ever" => true}) @@ -56,7 +55,7 @@ defmodule GroupherServer.Test.Mutation.Flags.JobFlag do } } """ - @tag :wip3 + test "auth user can undo trash job", ~m(community job)a do variables = %{id: job.id, communityId: community.id} @@ -87,7 +86,7 @@ defmodule GroupherServer.Test.Mutation.Flags.JobFlag do } } """ - @tag :wip3 + test "auth user can pin job", ~m(community job)a do variables = %{id: job.id, communityId: community.id} @@ -99,7 +98,6 @@ defmodule GroupherServer.Test.Mutation.Flags.JobFlag do assert updated["id"] == to_string(job.id) end - @tag :wip3 test "unauth user pin job fails", ~m(user_conn guest_conn community job)a do variables = %{id: job.id, communityId: community.id} rule_conn = simu_conn(:user, cms: %{"what.ever" => true}) @@ -117,7 +115,7 @@ defmodule GroupherServer.Test.Mutation.Flags.JobFlag do } } """ - @tag :wip3 + test "auth user can undo pin job", ~m(community job)a do variables = %{id: job.id, communityId: community.id} @@ -131,7 +129,6 @@ defmodule GroupherServer.Test.Mutation.Flags.JobFlag do assert updated["isPinned"] == false end - @tag :wip3 test "unauth user undo pin job fails", ~m(user_conn guest_conn community job)a do variables = %{id: job.id, communityId: community.id} rule_conn = simu_conn(:user, cms: %{"what.ever" => true}) 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 61d6eacb0..61cca8464 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 } } """ - @tag :wip3 + test "auth user can trash post", ~m(community post)a do variables = %{id: post.id, communityId: community.id} @@ -38,7 +38,6 @@ defmodule GroupherServer.Test.Mutation.Flags.PostFlag do assert updated["trash"] == true end - @tag :wip3 test "unauth user trash post fails", ~m(user_conn guest_conn post community)a do variables = %{id: post.id, communityId: community.id} rule_conn = simu_conn(:user, cms: %{"what.ever" => true}) @@ -56,7 +55,7 @@ defmodule GroupherServer.Test.Mutation.Flags.PostFlag do } } """ - @tag :wip3 + test "auth user can undo trash post", ~m(community post)a do variables = %{id: post.id, communityId: community.id} @@ -71,7 +70,6 @@ defmodule GroupherServer.Test.Mutation.Flags.PostFlag do assert updated["trash"] == false end - @tag :wip3 test "unauth user undo trash post fails", ~m(user_conn guest_conn community post)a do variables = %{id: post.id, communityId: community.id} rule_conn = simu_conn(:user, cms: %{"what.ever" => true}) @@ -88,7 +86,7 @@ defmodule GroupherServer.Test.Mutation.Flags.PostFlag do } } """ - @tag :wip3 + test "auth user can pin post", ~m(community post)a do variables = %{id: post.id, communityId: community.id} @@ -100,7 +98,6 @@ defmodule GroupherServer.Test.Mutation.Flags.PostFlag do assert updated["id"] == to_string(post.id) end - @tag :wip3 test "unauth user pin post fails", ~m(user_conn guest_conn community post)a do variables = %{id: post.id, communityId: community.id} rule_conn = simu_conn(:user, cms: %{"what.ever" => true}) @@ -118,7 +115,7 @@ defmodule GroupherServer.Test.Mutation.Flags.PostFlag do } } """ - @tag :wip3 + test "auth user can undo pin post", ~m(community post)a do variables = %{id: post.id, communityId: community.id} @@ -131,7 +128,6 @@ defmodule GroupherServer.Test.Mutation.Flags.PostFlag do assert updated["id"] == to_string(post.id) end - @tag :wip3 test "unauth user undo pin post fails", ~m(user_conn guest_conn community post)a do variables = %{id: post.id, communityId: community.id} rule_conn = simu_conn(:user, cms: %{"what.ever" => true}) diff --git a/test/groupher_server_web/mutation/cms/flags/repo_flag_test.exs b/test/groupher_server_web/mutation/cms/flags/repo_flag_test.exs index 6a3c5270c..09ecc187b 100644 --- a/test/groupher_server_web/mutation/cms/flags/repo_flag_test.exs +++ b/test/groupher_server_web/mutation/cms/flags/repo_flag_test.exs @@ -25,7 +25,7 @@ defmodule GroupherServer.Test.Mutation.Flags.RepoFlag do } } """ - @tag :wip3 + test "auth user can trash repo", ~m(community repo)a do variables = %{id: repo.id, communityId: community.id} @@ -38,7 +38,6 @@ defmodule GroupherServer.Test.Mutation.Flags.RepoFlag do assert updated["trash"] == true end - @tag :wip3 test "unauth user trash repo fails", ~m(user_conn guest_conn repo community)a do variables = %{id: repo.id, communityId: community.id} rule_conn = simu_conn(:user, cms: %{"what.ever" => true}) @@ -56,7 +55,7 @@ defmodule GroupherServer.Test.Mutation.Flags.RepoFlag do } } """ - @tag :wip3 + test "auth user can undo trash repo", ~m(community repo)a do variables = %{id: repo.id, communityId: community.id} @@ -71,7 +70,6 @@ defmodule GroupherServer.Test.Mutation.Flags.RepoFlag do assert updated["trash"] == false end - @tag :wip3 test "unauth user undo trash repo fails", ~m(user_conn guest_conn community repo)a do variables = %{id: repo.id, communityId: community.id} rule_conn = simu_conn(:user, cms: %{"what.ever" => true}) @@ -88,7 +86,7 @@ defmodule GroupherServer.Test.Mutation.Flags.RepoFlag do } } """ - @tag :wip3 + test "auth user can pin repo", ~m(community repo)a do variables = %{id: repo.id, communityId: community.id} @@ -100,7 +98,6 @@ defmodule GroupherServer.Test.Mutation.Flags.RepoFlag do assert updated["id"] == to_string(repo.id) end - @tag :wip3 test "unauth user pin repo fails", ~m(user_conn guest_conn community repo)a do variables = %{id: repo.id, communityId: community.id} rule_conn = simu_conn(:user, cms: %{"what.ever" => true}) @@ -118,7 +115,7 @@ defmodule GroupherServer.Test.Mutation.Flags.RepoFlag do } } """ - @tag :wip3 + test "auth user can undo pin repo", ~m(community repo)a do variables = %{id: repo.id, communityId: community.id} @@ -131,7 +128,6 @@ defmodule GroupherServer.Test.Mutation.Flags.RepoFlag do assert updated["id"] == to_string(repo.id) end - @tag :wip3 test "unauth user undo pin repo fails", ~m(user_conn guest_conn community repo)a do variables = %{id: repo.id, communityId: community.id} rule_conn = simu_conn(:user, cms: %{"what.ever" => true}) diff --git a/test/groupher_server_web/mutation/cms/upvotes/job_upvote_test.exs b/test/groupher_server_web/mutation/cms/upvotes/job_upvote_test.exs index 7c1f8869c..1ae181abd 100644 --- a/test/groupher_server_web/mutation/cms/upvotes/job_upvote_test.exs +++ b/test/groupher_server_web/mutation/cms/upvotes/job_upvote_test.exs @@ -22,7 +22,7 @@ defmodule GroupherServer.Test.Mutation.Upvotes.JobUpvote do } } """ - @tag :wip3 + test "login user can upvote a job", ~m(user_conn job)a do variables = %{id: job.id} created = user_conn |> mutation_result(@query, variables, "upvoteJob") @@ -30,7 +30,6 @@ defmodule GroupherServer.Test.Mutation.Upvotes.JobUpvote do assert created["id"] == to_string(job.id) end - @tag :wip3 test "unauth user upvote a job fails", ~m(guest_conn job)a do variables = %{id: job.id} @@ -45,7 +44,7 @@ defmodule GroupherServer.Test.Mutation.Upvotes.JobUpvote do } } """ - @tag :wip3 + test "login user can undo upvote to a job", ~m(user_conn job user)a do {:ok, _} = CMS.upvote_article(:job, job.id, user) @@ -55,7 +54,6 @@ defmodule GroupherServer.Test.Mutation.Upvotes.JobUpvote do assert updated["id"] == to_string(job.id) end - @tag :wip3 test "unauth user undo upvote a job fails", ~m(guest_conn job)a do variables = %{id: job.id} diff --git a/test/groupher_server_web/mutation/cms/upvotes/post_upvote_test.exs b/test/groupher_server_web/mutation/cms/upvotes/post_upvote_test.exs index 7d85684c1..af2760b93 100644 --- a/test/groupher_server_web/mutation/cms/upvotes/post_upvote_test.exs +++ b/test/groupher_server_web/mutation/cms/upvotes/post_upvote_test.exs @@ -22,7 +22,7 @@ defmodule GroupherServer.Test.Mutation.Upvotes.PostUpvote do } } """ - @tag :wip3 + test "login user can upvote a post", ~m(user_conn post)a do variables = %{id: post.id} created = user_conn |> mutation_result(@query, variables, "upvotePost") @@ -30,7 +30,6 @@ defmodule GroupherServer.Test.Mutation.Upvotes.PostUpvote do assert created["id"] == to_string(post.id) end - @tag :wip3 test "unauth user upvote a post fails", ~m(guest_conn post)a do variables = %{id: post.id} @@ -44,7 +43,7 @@ defmodule GroupherServer.Test.Mutation.Upvotes.PostUpvote do } } """ - @tag :wip3 + test "login user can undo upvote to a post", ~m(user_conn post user)a do {:ok, _} = CMS.upvote_article(:post, post.id, user) @@ -54,7 +53,6 @@ defmodule GroupherServer.Test.Mutation.Upvotes.PostUpvote do assert updated["id"] == to_string(post.id) end - @tag :wip3 test "unauth user undo upvote a post fails", ~m(guest_conn post)a do variables = %{id: post.id} diff --git a/test/groupher_server_web/query/cms/collects/job_collect_test.exs b/test/groupher_server_web/query/cms/collects/job_collect_test.exs index 3e889f3a7..164dbb625 100644 --- a/test/groupher_server_web/query/cms/collects/job_collect_test.exs +++ b/test/groupher_server_web/query/cms/collects/job_collect_test.exs @@ -35,7 +35,7 @@ defmodule GroupherServer.Test.Query.Collects.JobCollect do } } """ - @tag :wip3 + test "guest can get collected users list after collect a job", ~m(guest_conn job user user2)a do {:ok, _} = CMS.collect_article(:job, job.id, user) diff --git a/test/groupher_server_web/query/cms/collects/post_collect_test.exs b/test/groupher_server_web/query/cms/collects/post_collect_test.exs index bbad70c01..f95c89fe8 100644 --- a/test/groupher_server_web/query/cms/collects/post_collect_test.exs +++ b/test/groupher_server_web/query/cms/collects/post_collect_test.exs @@ -35,7 +35,7 @@ defmodule GroupherServer.Test.Query.Collects.PostCollect do } } """ - @tag :wip3 + test "guest can get collected users list after collect a post", ~m(guest_conn post user user2)a do {:ok, _} = CMS.collect_article(:post, post.id, 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 d8a925471..47af664eb 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 @@ -288,7 +288,6 @@ defmodule GroupherServer.Test.Query.Comments.JobComment do assert results["entries"] |> List.last() |> Map.get("floor") == 5 end - @tag :wip3 test "the comments is loaded in default asc order", ~m(guest_conn job user)a do page_size = 10 thread = :job @@ -312,7 +311,6 @@ defmodule GroupherServer.Test.Query.Comments.JobComment do assert List.last(results["entries"]) |> Map.get("id") == to_string(comment3.id) end - @tag :wip3 test "the comments can be loaded in desc order in timeline-mode", ~m(guest_conn job user)a do page_size = 10 thread = :job @@ -336,7 +334,6 @@ defmodule GroupherServer.Test.Query.Comments.JobComment do assert List.last(results["entries"]) |> Map.get("id") == to_string(comment.id) end - @tag :wip3 test "the comments can be loaded in desc order in replies-mode", ~m(guest_conn job user user2)a do page_size = 10 @@ -433,7 +430,6 @@ defmodule GroupherServer.Test.Query.Comments.JobComment do assert the_random_comment |> get_in(["meta", "isArticleAuthorUpvoted"]) end - @tag :wip3 test "guest user can get paged comment with emotions info", ~m(guest_conn job user user2)a do total_count = 2 @@ -511,7 +507,6 @@ defmodule GroupherServer.Test.Query.Comments.JobComment do |> get_in(["emotions", "viewerHasDownvoteed"]) end - @tag :wip3 test "comment should have viewer has upvoted flag", ~m(user_conn job user)a do total_count = 10 page_size = 12 @@ -551,7 +546,7 @@ defmodule GroupherServer.Test.Query.Comments.JobComment do } } """ - @tag :wip3 + test "guest user can get paged participators", ~m(guest_conn job user)a do total_count = 30 page_size = 10 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 8fc646754..e521733b2 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 @@ -288,7 +288,6 @@ defmodule GroupherServer.Test.Query.Comments.PostComment do assert results["entries"] |> List.last() |> Map.get("floor") == 5 end - @tag :wip3 test "the comments is loaded in default asc order", ~m(guest_conn post user)a do page_size = 10 thread = :post @@ -312,7 +311,6 @@ defmodule GroupherServer.Test.Query.Comments.PostComment do assert List.last(results["entries"]) |> Map.get("id") == to_string(comment3.id) end - @tag :wip3 test "the comments can be loaded in desc order in timeline-mode", ~m(guest_conn post user)a do page_size = 10 thread = :post @@ -336,7 +334,6 @@ defmodule GroupherServer.Test.Query.Comments.PostComment do assert List.last(results["entries"]) |> Map.get("id") == to_string(comment.id) end - @tag :wip3 test "the comments can be loaded in desc order in replies-mode", ~m(guest_conn post user user2)a do page_size = 10 @@ -433,7 +430,6 @@ defmodule GroupherServer.Test.Query.Comments.PostComment do assert the_random_comment |> get_in(["meta", "isArticleAuthorUpvoted"]) end - @tag :wip3 test "guest user can get paged comment with emotions info", ~m(guest_conn post user user2)a do total_count = 2 @@ -511,7 +507,6 @@ defmodule GroupherServer.Test.Query.Comments.PostComment do |> get_in(["emotions", "viewerHasDownvoteed"]) end - @tag :wip3 test "comment should have viewer has upvoted flag", ~m(user_conn post user)a do total_count = 10 page_size = 12 diff --git a/test/groupher_server_web/query/cms/job_test.exs b/test/groupher_server_web/query/cms/job_test.exs index 417d8e867..1761009db 100644 --- a/test/groupher_server_web/query/cms/job_test.exs +++ b/test/groupher_server_web/query/cms/job_test.exs @@ -19,7 +19,7 @@ defmodule GroupherServer.Test.Query.Job do } } """ - @tag :wip3 + test "basic graphql query on job with logined user", ~m(user_conn job)a do variables = %{id: job.id} results = user_conn |> query_result(@query, variables, "job") @@ -30,7 +30,6 @@ defmodule GroupherServer.Test.Query.Job do assert length(Map.keys(results)) == 3 end - @tag :wip3 test "basic graphql query on job with stranger(unloged user)", ~m(guest_conn job)a do variables = %{id: job.id} results = guest_conn |> query_result(@query, variables, "job") diff --git a/test/groupher_server_web/query/cms/jobs_flags_test.exs b/test/groupher_server_web/query/cms/jobs_flags_test.exs index e977f1a87..4d021de23 100644 --- a/test/groupher_server_web/query/cms/jobs_flags_test.exs +++ b/test/groupher_server_web/query/cms/jobs_flags_test.exs @@ -51,7 +51,7 @@ defmodule GroupherServer.Test.Query.JobsFlags do } } """ - @tag :wip3 + test "if have pined jobs, the pined jobs should at the top of entries", ~m(guest_conn community job_m)a do variables = %{filter: %{community: community.raw}} diff --git a/test/groupher_server_web/query/cms/paged_jobs_test.exs b/test/groupher_server_web/query/cms/paged_jobs_test.exs index 7110e89c7..d04d481a4 100644 --- a/test/groupher_server_web/query/cms/paged_jobs_test.exs +++ b/test/groupher_server_web/query/cms/paged_jobs_test.exs @@ -98,7 +98,7 @@ defmodule GroupherServer.Test.Query.PagedJobs do } } """ - @tag :wip2 + test "has_xxx state should work", ~m(user)a do user_conn = simu_conn(:user, user) {:ok, community} = db_insert(:community) diff --git a/test/groupher_server_web/query/cms/paged_posts_test.exs b/test/groupher_server_web/query/cms/paged_posts_test.exs index 49e9db151..25b5cd8ca 100644 --- a/test/groupher_server_web/query/cms/paged_posts_test.exs +++ b/test/groupher_server_web/query/cms/paged_posts_test.exs @@ -171,7 +171,7 @@ defmodule GroupherServer.Test.Query.PagedPosts do } } """ - @tag :wip2 + test "has_xxx state should work", ~m(user)a do user_conn = simu_conn(:user, user) {:ok, community} = db_insert(:community) diff --git a/test/groupher_server_web/query/cms/paged_repos_test.exs b/test/groupher_server_web/query/cms/paged_repos_test.exs index e9fd2e271..953bc079e 100644 --- a/test/groupher_server_web/query/cms/paged_repos_test.exs +++ b/test/groupher_server_web/query/cms/paged_repos_test.exs @@ -94,7 +94,7 @@ defmodule GroupherServer.Test.Query.PagedRepos do } } """ - @tag :wip2 + test "has_xxx state should work", ~m(user)a do user_conn = simu_conn(:user, user) {:ok, community} = db_insert(:community) diff --git a/test/groupher_server_web/query/cms/post_test.exs b/test/groupher_server_web/query/cms/post_test.exs index 3c53e9c6e..959efc75e 100644 --- a/test/groupher_server_web/query/cms/post_test.exs +++ b/test/groupher_server_web/query/cms/post_test.exs @@ -28,7 +28,7 @@ defmodule GroupherServer.Test.Query.Post do } } """ - @tag :wip3 + test "basic graphql query on post with logined user", ~m(user_conn community user post_attrs)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) @@ -43,7 +43,6 @@ defmodule GroupherServer.Test.Query.Post do assert length(Map.keys(results)) == 4 end - @tag :wip3 test "basic graphql query on post with stranger(unloged user)", ~m(guest_conn post)a do variables = %{id: post.id} results = guest_conn |> query_result(@query, variables, "post") diff --git a/test/groupher_server_web/query/cms/posts_flags_test.exs b/test/groupher_server_web/query/cms/posts_flags_test.exs index a63fa5d41..b213a540e 100644 --- a/test/groupher_server_web/query/cms/posts_flags_test.exs +++ b/test/groupher_server_web/query/cms/posts_flags_test.exs @@ -51,7 +51,7 @@ defmodule GroupherServer.Test.Query.PostsFlags do } } """ - @tag :wip3 + test "if have pined posts, the pined posts should at the top of entries", ~m(guest_conn community post_m)a do variables = %{filter: %{community: community.raw}} diff --git a/test/groupher_server_web/query/cms/repo_test.exs b/test/groupher_server_web/query/cms/repo_test.exs index a4c82f63a..9722dfa0b 100644 --- a/test/groupher_server_web/query/cms/repo_test.exs +++ b/test/groupher_server_web/query/cms/repo_test.exs @@ -19,7 +19,7 @@ defmodule GroupherServer.Test.Query.Repo do } } """ - @tag :wip3 + test "basic graphql query on repo with logined user", ~m(user_conn repo)a do variables = %{id: repo.id} results = user_conn |> query_result(@query, variables, "repo") @@ -30,7 +30,6 @@ defmodule GroupherServer.Test.Query.Repo do assert length(Map.keys(results)) == 3 end - @tag :wip3 test "basic graphql query on repo with stranger(unloged user)", ~m(guest_conn repo)a do variables = %{id: repo.id} results = guest_conn |> query_result(@query, variables, "repo") diff --git a/test/groupher_server_web/query/cms/repos_flags_test.exs b/test/groupher_server_web/query/cms/repos_flags_test.exs index c0cf8707a..b2bfc6bcc 100644 --- a/test/groupher_server_web/query/cms/repos_flags_test.exs +++ b/test/groupher_server_web/query/cms/repos_flags_test.exs @@ -50,7 +50,7 @@ defmodule GroupherServer.Test.Query.ReposFlags do } } """ - @tag :wip3 + test "if have pined repos, the pined repos should at the top of entries", ~m(guest_conn community repo_m)a do variables = %{filter: %{community: community.raw}} diff --git a/test/groupher_server_web/query/cms/upvotes/post_upvote_test.exs b/test/groupher_server_web/query/cms/upvotes/post_upvote_test.exs index 47b311cde..bafa825db 100644 --- a/test/groupher_server_web/query/cms/upvotes/post_upvote_test.exs +++ b/test/groupher_server_web/query/cms/upvotes/post_upvote_test.exs @@ -35,7 +35,7 @@ defmodule GroupherServer.Test.Query.Upvotes.PostUpvote do } } """ - @tag :wip3 + test "guest can get upvoted users list after upvote to a post", ~m(guest_conn post user user2)a do {:ok, _} = CMS.upvote_article(:post, post.id, user) From d7831aa651e954fefb3de6c7b90fbe78781395a3 Mon Sep 17 00:00:00 2001 From: mydearxym Date: Thu, 13 May 2021 13:03:07 +0800 Subject: [PATCH 10/13] refactor(abuse-report): wip --- .../cms/delegates/abuse_report.ex | 96 ++++++++++--------- lib/groupher_server/cms/helper/matcher2.ex | 2 +- .../resolvers/cms_resolver.ex | 4 + .../schema/cms/cms_misc.ex | 45 ++++----- .../schema/cms/cms_queries.ex | 13 ++- .../schema/cms/cms_types.ex | 61 +++++++++--- .../cms/abuse_reports/account_report_test.exs | 12 +-- .../cms/comments/job_comment_test.exs | 1 - .../cms/comments/post_comment_test.exs | 5 +- .../cms/abuse_reports/post_report_test.exs | 81 ++++++++++++++++ .../query/cms/{ => articles}/job_test.exs | 2 +- .../query/cms/{ => articles}/post_test.exs | 2 +- .../query/cms/{ => articles}/repo_test.exs | 2 +- .../query/cms/{ => flags}/jobs_flags_test.exs | 2 +- .../cms/{ => flags}/posts_flags_test.exs | 2 +- .../cms/{ => flags}/repos_flags_test.exs | 2 +- .../{ => paged_articles}/paged_jobs_test.exs | 2 +- .../{ => paged_articles}/paged_posts_test.exs | 2 +- .../{ => paged_articles}/paged_repos_test.exs | 2 +- 19 files changed, 227 insertions(+), 111 deletions(-) create mode 100644 test/groupher_server_web/query/cms/abuse_reports/post_report_test.exs rename test/groupher_server_web/query/cms/{ => articles}/job_test.exs (95%) rename test/groupher_server_web/query/cms/{ => articles}/post_test.exs (96%) rename test/groupher_server_web/query/cms/{ => articles}/repo_test.exs (95%) rename test/groupher_server_web/query/cms/{ => flags}/jobs_flags_test.exs (98%) rename test/groupher_server_web/query/cms/{ => flags}/posts_flags_test.exs (98%) rename test/groupher_server_web/query/cms/{ => flags}/repos_flags_test.exs (98%) rename test/groupher_server_web/query/cms/{ => paged_articles}/paged_jobs_test.exs (99%) rename test/groupher_server_web/query/cms/{ => paged_articles}/paged_posts_test.exs (99%) rename test/groupher_server_web/query/cms/{ => paged_articles}/paged_repos_test.exs (99%) diff --git a/lib/groupher_server/cms/delegates/abuse_report.ex b/lib/groupher_server/cms/delegates/abuse_report.ex index 65b859fa2..a27297be4 100644 --- a/lib/groupher_server/cms/delegates/abuse_report.ex +++ b/lib/groupher_server/cms/delegates/abuse_report.ex @@ -19,16 +19,6 @@ defmodule GroupherServer.CMS.Delegate.AbuseReport do @report_threshold_for_fold ArticleComment.report_threshold_for_fold() - # filter = %{ - # contentType: account | post | job | repo | article_comment | community - # contentId: ... - # operate_user_id, - # min_case_count, - # max_case_count, - # page - # size - # } - @article_threads [:post, :job, :repo] @export_author_keys [:id, :login, :nickname, :avatar] @export_article_keys [:id, :title, :digest, :upvotes_count, :views] @@ -45,21 +35,15 @@ defmodule GroupherServer.CMS.Delegate.AbuseReport do @doc """ list paged reports for article comemnts """ - def list_reports(%{content_type: :user, content_id: content_id} = filter) do - %{page: page, size: size} = filter - - with {:ok, info} <- match(:account_user) do + def list_reports(%{content_type: :account, content_id: content_id} = filter) do + with {:ok, info} <- match(:account) do query = from(r in AbuseReport, where: field(r, ^info.foreign_key) == ^content_id, preload: :account ) - query - |> QueryBuilder.filter_pack(filter) - |> ORM.paginater(~m(page size)a) - |> reports_formater(:account_user) - |> done() + do_list_reports(query, :account, filter) end end @@ -67,8 +51,6 @@ defmodule GroupherServer.CMS.Delegate.AbuseReport do list paged reports for article comemnts """ def list_reports(%{content_type: :article_comment, content_id: content_id} = filter) do - %{page: page, size: size} = filter - with {:ok, info} <- match(:article_comment) do query = from(r in AbuseReport, @@ -77,11 +59,7 @@ defmodule GroupherServer.CMS.Delegate.AbuseReport do preload: [article_comment: :author] ) - query - |> QueryBuilder.filter_pack(filter) - |> ORM.paginater(~m(page size)a) - |> reports_formater(:article_comment) - |> done() + do_list_reports(query, :article_comment, filter) end end @@ -90,8 +68,6 @@ defmodule GroupherServer.CMS.Delegate.AbuseReport do """ def list_reports(%{content_type: thread, content_id: content_id} = filter) when thread in @article_threads do - %{page: page, size: size} = filter - with {:ok, info} <- match(thread) do query = from(r in AbuseReport, @@ -99,23 +75,55 @@ defmodule GroupherServer.CMS.Delegate.AbuseReport do preload: [^thread, :operate_user] ) - query - |> QueryBuilder.filter_pack(filter) - |> ORM.paginater(~m(page size)a) - |> reports_formater(thread) - |> done() + do_list_reports(query, thread, filter) + end + end + + # def list_reports(%{content_type: thread} = filter) when thread in @article_threads do + def list_reports(%{content_type: thread} = filter) do + IO.inspect(filter, label: "list filter 1-") + + with {:ok, info} <- match(thread) do + query = + from(r in AbuseReport, + where: not is_nil(field(r, ^info.foreign_key)), + preload: [^thread, :operate_user], + preload: [article_comment: :author] + ) + + do_list_reports(query, thread, filter) end end + def list_reports(filter) do + query = from(r in AbuseReport, preload: [:operate_user]) + + do_list_reports(query, filter) + end + + defp do_list_reports(query, thread, filter) do + %{page: page, size: size} = filter + + query + |> QueryBuilder.filter_pack(filter) + |> ORM.paginater(~m(page size)a) + |> reports_formater(thread) + |> done() + end + + defp do_list_reports(query, %{page: page, size: size}) do + query |> ORM.paginater(~m(page size)a) |> done() + end + @doc """ report an account """ def report_account(account_id, reason, attr, user) do - with {:ok, info} <- match(:account_user), + with {:ok, info} <- match(:account), {:ok, account} <- ORM.find(info.model, account_id) do Multi.new() |> Multi.run(:create_abuse_report, fn _, _ -> - create_report(:account_user, account.id, reason, attr, user) + create_report(:account, account.id, reason, attr, user) end) |> Multi.run(:update_report_meta, fn _, _ -> update_report_meta(info, account) @@ -129,11 +137,11 @@ defmodule GroupherServer.CMS.Delegate.AbuseReport do undo report article content """ def undo_report_account(account_id, %User{} = user) do - with {:ok, info} <- match(:account_user), + with {:ok, info} <- match(:account), {:ok, account} <- ORM.find(info.model, account_id) do Multi.new() |> Multi.run(:delete_abuse_report, fn _, _ -> - delete_report(:account_user, account.id, user) + delete_report(:account, account.id, user) end) |> Multi.run(:update_report_meta, fn _, _ -> update_report_meta(info, account) @@ -270,16 +278,14 @@ defmodule GroupherServer.CMS.Delegate.AbuseReport do safe_meta = if is_nil(content.meta), do: info.default_meta, else: content.meta reported_user_ids = report_cases |> Enum.map(& &1.user.user_id) - meta = - safe_meta - |> Map.merge(%{reported_count: reported_count, reported_user_ids: reported_user_ids}) - |> strip_struct + safe_meta + |> Map.merge(%{reported_count: reported_count, reported_user_ids: reported_user_ids}) + |> strip_struct {:error, _} -> safe_meta = if is_nil(content.meta), do: info.default_meta, else: content.meta - meta = - safe_meta |> Map.merge(%{reported_count: 0, reported_user_ids: []}) |> strip_struct + safe_meta |> Map.merge(%{reported_count: 0, reported_user_ids: []}) |> strip_struct end content |> ORM.update_meta(meta) @@ -305,7 +311,7 @@ defmodule GroupherServer.CMS.Delegate.AbuseReport do end end - defp reports_formater(%{entries: entries} = paged_reports, :account_user) do + defp reports_formater(%{entries: entries} = paged_reports, :account) do paged_reports |> Map.put( :entries, @@ -340,7 +346,7 @@ defmodule GroupherServer.CMS.Delegate.AbuseReport do end defp extract_account_info(%AbuseReport{} = report) do - account = report |> Map.get(:account) |> Map.take(@export_author_keys) + report |> Map.get(:account) |> Map.take(@export_author_keys) end # TODO: original community and communities info diff --git a/lib/groupher_server/cms/helper/matcher2.ex b/lib/groupher_server/cms/helper/matcher2.ex index ad72f8e29..995613fbf 100644 --- a/lib/groupher_server/cms/helper/matcher2.ex +++ b/lib/groupher_server/cms/helper/matcher2.ex @@ -32,7 +32,7 @@ defmodule GroupherServer.CMS.Helper.Matcher2 do {:error, "not supported"} end - def match(:account_user) do + def match(:account) do {:ok, %{ model: User, diff --git a/lib/groupher_server_web/resolvers/cms_resolver.ex b/lib/groupher_server_web/resolvers/cms_resolver.ex index 6196363f8..4c077a5fb 100644 --- a/lib/groupher_server_web/resolvers/cms_resolver.ex +++ b/lib/groupher_server_web/resolvers/cms_resolver.ex @@ -62,6 +62,10 @@ defmodule GroupherServerWeb.Resolvers.CMS do CMS.paged_articles(thread, filter) end + def list_reports(_root, ~m(filter)a, _) do + CMS.list_reports(filter) + end + def wiki(_root, ~m(community)a, _info), do: CMS.get_wiki(%Community{raw: community}) def cheatsheet(_root, ~m(community)a, _info), do: CMS.get_cheatsheet(%Community{raw: community}) diff --git a/lib/groupher_server_web/schema/cms/cms_misc.ex b/lib/groupher_server_web/schema/cms/cms_misc.ex index 7b3d771c1..48df148ef 100644 --- a/lib/groupher_server_web/schema/cms/cms_misc.ex +++ b/lib/groupher_server_web/schema/cms/cms_misc.ex @@ -40,32 +40,10 @@ defmodule GroupherServerWeb.Schema.CMS.Misc do # value(:watch) end - enum :react_thread do - value(:post) - value(:job) - value(:repo) - # home community - value(:tech) - value(:city) - value(:share) - value(:radar) - end - enum :cms_comment do value(:post_comment) end - enum :commentable_thread do - value(:post) - value(:job) - value(:repo) - # home community - value(:tech) - value(:city) - value(:share) - value(:radar) - end - enum :thread do value(:post) value(:job) @@ -83,11 +61,6 @@ defmodule GroupherServerWeb.Schema.CMS.Misc do value(:company) end - enum :order_enum do - value(:asc) - value(:desc) - end - enum :when_enum do value(:today) value(:this_week) @@ -297,11 +270,25 @@ defmodule GroupherServerWeb.Schema.CMS.Misc do field(:color, :string) end - enum :search_part do - value(:community) + enum :report_content_type do value(:post) value(:job) value(:repo) + value(:account) + value(:article_comment) + # value(:community) + end + + @desc """ + abuse report filter + """ + input_object :report_filter do + field(:content_type, :report_content_type) + field(:content_id, :id) + pagination_args() + # operate_user_id, + # min_case_count, + # max_case_count, end @doc """ diff --git a/lib/groupher_server_web/schema/cms/cms_queries.ex b/lib/groupher_server_web/schema/cms/cms_queries.ex index cb6d7a8ca..abd4a6870 100644 --- a/lib/groupher_server_web/schema/cms/cms_queries.ex +++ b/lib/groupher_server_web/schema/cms/cms_queries.ex @@ -79,9 +79,6 @@ defmodule GroupherServerWeb.Schema.CMS.Queries do resolve(&R.CMS.cheatsheet/3) end - article_reacted_users_query(:upvot, &R.CMS.upvoted_users/3) - article_reacted_users_query(:collect, &R.CMS.collected_users/3) - # get all tags @desc "get paged tags" field :paged_tags, :paged_tags do @@ -204,6 +201,16 @@ defmodule GroupherServerWeb.Schema.CMS.Queries do resolve(&R.CMS.search_items/3) end + @desc "paged reports list" + field :paged_abuse_reports, :paged_reports do + arg(:filter, non_null(:report_filter)) + + resolve(&R.CMS.list_reports/3) + end + + article_reacted_users_query(:upvot, &R.CMS.upvoted_users/3) + article_reacted_users_query(:collect, &R.CMS.collected_users/3) + article_queries(:post) article_queries(:job) article_queries(:repo) diff --git a/lib/groupher_server_web/schema/cms/cms_types.ex b/lib/groupher_server_web/schema/cms/cms_types.ex index dff7764e3..e107fd34f 100644 --- a/lib/groupher_server_web/schema/cms/cms_types.ex +++ b/lib/groupher_server_web/schema/cms/cms_types.ex @@ -13,6 +13,33 @@ defmodule GroupherServerWeb.Schema.CMS.Types do import_types(Schema.CMS.Misc) + ###### + # common stands for minimal info of the type + # usually used in abuse_report, feeds, etc .. + object :common_user do + field(:login, :string) + field(:nickname, :string) + field(:avatar, :string) + end + + object :common_article do + field(:thread, :string) + field(:id, :id) + # field(:body_html, :string) + field(:title, :string) + field(:author, :user, resolve: dataloader(CMS, :author)) + end + + object :common_article_comment do + field(:id, :id) + field(:body_html, :string) + field(:upvotes_count, :integer) + field(:author, :common_user) + field(:article, :common_article) + end + + ###### + object :idlike do field(:id, :id) end @@ -369,16 +396,25 @@ defmodule GroupherServerWeb.Schema.CMS.Types do timestamp_fields() end - object :comment do - comments_fields() + object :abuse_report do + field(:id, :id) + # field(:article_comment, :article_comment, resolve: dataloader(CMS, :article_comment)) + field(:article_comment, :common_article_comment) + # field(:account, :user) + field(:report_cases_count, :integer) + field(:deal_with, :string) + field(:operate_user, :user) + + timestamp_fields() end - object :common_article do - field(:thread, :string) - field(:id, :id) - # field(:body_html, :string) - field(:title, :string) - field(:author, :user, resolve: dataloader(CMS, :author)) + object :paged_reports do + field(:entries, list_of(:abuse_report)) + pagination_fields() + end + + object :comment do + comments_fields() end object :post_comment do @@ -457,12 +493,7 @@ defmodule GroupherServerWeb.Schema.CMS.Types do field(:is_edited, :boolean) field(:is_comment_locked, :boolean) # field(:linked_posts_count, :integer) - # field(:linked_jobs_count, :integer) - # field(:linked_works_count, :integer) - - # reaction: %{ - # rocketCount: 0, - # heartCount: 0, - # } end + + ####### reports end diff --git a/test/groupher_server/cms/abuse_reports/account_report_test.exs b/test/groupher_server/cms/abuse_reports/account_report_test.exs index 1ec88ef10..fa7b0a437 100644 --- a/test/groupher_server/cms/abuse_reports/account_report_test.exs +++ b/test/groupher_server/cms/abuse_reports/account_report_test.exs @@ -39,7 +39,7 @@ defmodule GroupherServer.Test.CMS.AbuseReports.AccountReport do test "report an account should have a abuse report record", ~m(user user2)a do {:ok, _report} = CMS.report_account(user.id, "reason", "attr_info", user2) - filter = %{content_type: :user, content_id: user.id, page: 1, size: 20} + filter = %{content_type: :account, content_id: user.id, page: 1, size: 20} {:ok, all_reports} = CMS.list_reports(filter) report = List.first(all_reports.entries) @@ -61,7 +61,7 @@ defmodule GroupherServer.Test.CMS.AbuseReports.AccountReport do {:ok, _report} = CMS.undo_report_account(user.id, user2) - filter = %{content_type: :user, content_id: user.id, page: 1, size: 20} + filter = %{content_type: :account, content_id: user.id, page: 1, size: 20} {:ok, all_reports} = CMS.list_reports(filter) assert all_reports.total_count == 0 @@ -74,7 +74,7 @@ defmodule GroupherServer.Test.CMS.AbuseReports.AccountReport do {:ok, _report} = CMS.report_account(user.id, "reason", "attr_info", user3) {:ok, _report} = CMS.undo_report_account(user.id, user2) - filter = %{content_type: :user, content_id: user.id, page: 1, size: 20} + filter = %{content_type: :account, content_id: user.id, page: 1, size: 20} {:ok, all_reports} = CMS.list_reports(filter) assert all_reports.total_count == 1 @@ -87,7 +87,7 @@ defmodule GroupherServer.Test.CMS.AbuseReports.AccountReport do {:ok, _report} = CMS.report_account(user.id, "reason", "attr_info", user2) {:ok, _report} = CMS.report_account(user.id, "reason", "attr_info", user3) - filter = %{content_type: :user, content_id: user.id, page: 1, size: 20} + filter = %{content_type: :account, content_id: user.id, page: 1, size: 20} {:ok, all_reports} = CMS.list_reports(filter) assert all_reports.total_count == 1 @@ -98,7 +98,7 @@ defmodule GroupherServer.Test.CMS.AbuseReports.AccountReport do {:ok, _report} = CMS.undo_report_account(user.id, user2) - filter = %{content_type: :user, content_id: user.id, page: 1, size: 20} + filter = %{content_type: :account, content_id: user.id, page: 1, size: 20} {:ok, all_reports} = CMS.list_reports(filter) assert all_reports.total_count == 1 @@ -112,7 +112,7 @@ defmodule GroupherServer.Test.CMS.AbuseReports.AccountReport do {:ok, _report} = CMS.report_account(user.id, "reason", "attr_info", user2) {:ok, _report} = CMS.report_account(user.id, "reason", "attr_info", user3) - filter = %{content_type: :user, content_id: user.id, page: 1, size: 20} + filter = %{content_type: :account, content_id: user.id, page: 1, size: 20} {:ok, all_reports} = CMS.list_reports(filter) report = List.first(all_reports.entries) diff --git a/test/groupher_server/cms/comments/job_comment_test.exs b/test/groupher_server/cms/comments/job_comment_test.exs index c67124e8f..f822b6dfa 100644 --- a/test/groupher_server/cms/comments/job_comment_test.exs +++ b/test/groupher_server/cms/comments/job_comment_test.exs @@ -448,7 +448,6 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do assert paged_comments.total_count == total_count end - @tag :wip2 test "paged article comments should not contains folded and repoted comments", ~m(user job)a do total_count = 15 diff --git a/test/groupher_server/cms/comments/post_comment_test.exs b/test/groupher_server/cms/comments/post_comment_test.exs index 9e63255ab..13bd33da8 100644 --- a/test/groupher_server/cms/comments/post_comment_test.exs +++ b/test/groupher_server/cms/comments/post_comment_test.exs @@ -286,8 +286,8 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do # {:ok, comment} = ORM.find(ArticleComment, comment.id) # end - test "can undo a report with other user report it too", - ~m(user user2 post)a do + @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) {:ok, _comment} = CMS.report_article_comment(comment.id, "reason", "attr", user) @@ -306,6 +306,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do filter = %{content_type: :article_comment, content_id: comment.id, page: 1, size: 20} {:ok, all_reports} = CMS.list_reports(filter) + assert all_reports.total_count == 1 report = all_reports.entries |> List.first() diff --git a/test/groupher_server_web/query/cms/abuse_reports/post_report_test.exs b/test/groupher_server_web/query/cms/abuse_reports/post_report_test.exs new file mode 100644 index 000000000..f0c15a051 --- /dev/null +++ b/test/groupher_server_web/query/cms/abuse_reports/post_report_test.exs @@ -0,0 +1,81 @@ +defmodule GroupherServer.Test.Query.AbuseReports.PostReport do + @moduledoc false + + use GroupherServer.TestTools + + import Helper.Utils, only: [get_config: 2] + + alias GroupherServer.CMS + alias GroupherServer.Repo + + alias CMS.Post + + setup do + {:ok, post} = db_insert(:post) + {:ok, user} = db_insert(:user) + {:ok, user2} = db_insert(:user) + + {:ok, community} = db_insert(:community) + post_attrs = mock_attrs(:post, %{community_id: community.id}) + + guest_conn = simu_conn(:guest) + + {:ok, ~m(guest_conn community post post_attrs user user2)a} + end + + describe "[query paged_posts filter pagination]" do + # id + @query """ + query($filter: ReportFilter!) { + pagedAbuseReports(filter: $filter) { + entries { + id + dealWith + operateUser { + id + login + } + articleComment { + id + bodyHtml + author { + login + } + } + } + totalPages + totalCount + pageSize + pageNumber + } + } + """ + @tag :wip + test "should get pagination info", ~m(guest_conn community post_attrs user user2)a do + {:ok, post} = CMS.create_content(community, :post, post_attrs, user) + {:ok, _report} = CMS.report_article(:post, post.id, "reason", "attr_info", user) + {:ok, _report} = CMS.report_article(:post, post.id, "reason", "attr_info", user2) + + variables = %{filter: %{content_type: "POST", page: 1, size: 10}} + results = guest_conn |> query_result(@query, variables, "pagedAbuseReports") + + assert results |> is_valid_pagination? + end + + @tag :wip2 + test "support article_comment", ~m(guest_conn post user)a do + {:ok, comment} = CMS.create_article_comment(:post, post.id, "comment", user) + {:ok, _} = CMS.report_article_comment(comment.id, "reason", "attr", user) + + variables = %{filter: %{content_type: "ARTICLE_COMMENT", page: 1, size: 10}} + results = guest_conn |> query_result(@query, variables, "pagedAbuseReports") + + IO.inspect(results, label: "results- -") + + report = results["entries"] |> List.first() + assert get_in(report, ["articleComment", "bodyHtml"]) == "comment" + assert get_in(report, ["articleComment", "id"]) == to_string(comment.id) + assert not is_nil(get_in(report, ["articleComment", "author", "login"])) + end + end +end diff --git a/test/groupher_server_web/query/cms/job_test.exs b/test/groupher_server_web/query/cms/articles/job_test.exs similarity index 95% rename from test/groupher_server_web/query/cms/job_test.exs rename to test/groupher_server_web/query/cms/articles/job_test.exs index 1761009db..3c50f89fa 100644 --- a/test/groupher_server_web/query/cms/job_test.exs +++ b/test/groupher_server_web/query/cms/articles/job_test.exs @@ -1,4 +1,4 @@ -defmodule GroupherServer.Test.Query.Job do +defmodule GroupherServer.Test.Query.Articles.Job do use GroupherServer.TestTools setup do diff --git a/test/groupher_server_web/query/cms/post_test.exs b/test/groupher_server_web/query/cms/articles/post_test.exs similarity index 96% rename from test/groupher_server_web/query/cms/post_test.exs rename to test/groupher_server_web/query/cms/articles/post_test.exs index 959efc75e..c48cfc745 100644 --- a/test/groupher_server_web/query/cms/post_test.exs +++ b/test/groupher_server_web/query/cms/articles/post_test.exs @@ -1,4 +1,4 @@ -defmodule GroupherServer.Test.Query.Post do +defmodule GroupherServer.Test.Query.Articles.Post do use GroupherServer.TestTools alias GroupherServer.CMS diff --git a/test/groupher_server_web/query/cms/repo_test.exs b/test/groupher_server_web/query/cms/articles/repo_test.exs similarity index 95% rename from test/groupher_server_web/query/cms/repo_test.exs rename to test/groupher_server_web/query/cms/articles/repo_test.exs index 9722dfa0b..ed6b4cb07 100644 --- a/test/groupher_server_web/query/cms/repo_test.exs +++ b/test/groupher_server_web/query/cms/articles/repo_test.exs @@ -1,4 +1,4 @@ -defmodule GroupherServer.Test.Query.Repo do +defmodule GroupherServer.Test.Query.Articles.Repo do use GroupherServer.TestTools setup do diff --git a/test/groupher_server_web/query/cms/jobs_flags_test.exs b/test/groupher_server_web/query/cms/flags/jobs_flags_test.exs similarity index 98% rename from test/groupher_server_web/query/cms/jobs_flags_test.exs rename to test/groupher_server_web/query/cms/flags/jobs_flags_test.exs index 4d021de23..aac42b3d7 100644 --- a/test/groupher_server_web/query/cms/jobs_flags_test.exs +++ b/test/groupher_server_web/query/cms/flags/jobs_flags_test.exs @@ -1,4 +1,4 @@ -defmodule GroupherServer.Test.Query.JobsFlags do +defmodule GroupherServer.Test.Query.Flags.JobsFlags do use GroupherServer.TestTools import Helper.Utils, only: [get_config: 2] diff --git a/test/groupher_server_web/query/cms/posts_flags_test.exs b/test/groupher_server_web/query/cms/flags/posts_flags_test.exs similarity index 98% rename from test/groupher_server_web/query/cms/posts_flags_test.exs rename to test/groupher_server_web/query/cms/flags/posts_flags_test.exs index b213a540e..9d71db79f 100644 --- a/test/groupher_server_web/query/cms/posts_flags_test.exs +++ b/test/groupher_server_web/query/cms/flags/posts_flags_test.exs @@ -1,4 +1,4 @@ -defmodule GroupherServer.Test.Query.PostsFlags do +defmodule GroupherServer.Test.Query.Flags.PostsFlags do use GroupherServer.TestTools import Helper.Utils, only: [get_config: 2] diff --git a/test/groupher_server_web/query/cms/repos_flags_test.exs b/test/groupher_server_web/query/cms/flags/repos_flags_test.exs similarity index 98% rename from test/groupher_server_web/query/cms/repos_flags_test.exs rename to test/groupher_server_web/query/cms/flags/repos_flags_test.exs index b2bfc6bcc..83d0f7afb 100644 --- a/test/groupher_server_web/query/cms/repos_flags_test.exs +++ b/test/groupher_server_web/query/cms/flags/repos_flags_test.exs @@ -1,4 +1,4 @@ -defmodule GroupherServer.Test.Query.ReposFlags do +defmodule GroupherServer.Test.Query.Flags.ReposFlags do use GroupherServer.TestTools import Helper.Utils, only: [get_config: 2] diff --git a/test/groupher_server_web/query/cms/paged_jobs_test.exs b/test/groupher_server_web/query/cms/paged_articles/paged_jobs_test.exs similarity index 99% rename from test/groupher_server_web/query/cms/paged_jobs_test.exs rename to test/groupher_server_web/query/cms/paged_articles/paged_jobs_test.exs index d04d481a4..bd4a59d6c 100644 --- a/test/groupher_server_web/query/cms/paged_jobs_test.exs +++ b/test/groupher_server_web/query/cms/paged_articles/paged_jobs_test.exs @@ -1,4 +1,4 @@ -defmodule GroupherServer.Test.Query.PagedJobs do +defmodule GroupherServer.Test.Query.PagedArticles.PagedJobs do @moduledoc false use GroupherServer.TestTools diff --git a/test/groupher_server_web/query/cms/paged_posts_test.exs b/test/groupher_server_web/query/cms/paged_articles/paged_posts_test.exs similarity index 99% rename from test/groupher_server_web/query/cms/paged_posts_test.exs rename to test/groupher_server_web/query/cms/paged_articles/paged_posts_test.exs index 25b5cd8ca..75b1b755a 100644 --- a/test/groupher_server_web/query/cms/paged_posts_test.exs +++ b/test/groupher_server_web/query/cms/paged_articles/paged_posts_test.exs @@ -1,4 +1,4 @@ -defmodule GroupherServer.Test.Query.PagedPosts do +defmodule GroupherServer.Test.Query.PagedArticles.PagedPosts do @moduledoc false use GroupherServer.TestTools diff --git a/test/groupher_server_web/query/cms/paged_repos_test.exs b/test/groupher_server_web/query/cms/paged_articles/paged_repos_test.exs similarity index 99% rename from test/groupher_server_web/query/cms/paged_repos_test.exs rename to test/groupher_server_web/query/cms/paged_articles/paged_repos_test.exs index 953bc079e..43d64e2cb 100644 --- a/test/groupher_server_web/query/cms/paged_repos_test.exs +++ b/test/groupher_server_web/query/cms/paged_articles/paged_repos_test.exs @@ -1,4 +1,4 @@ -defmodule GroupherServer.Test.Query.PagedRepos do +defmodule GroupherServer.Test.Query.PagedArticles.PagedRepos do use GroupherServer.TestTools import Helper.Utils, only: [get_config: 2] From af7ec638c3e88afff2997652bf01ee6bb4c819a3 Mon Sep 17 00:00:00 2001 From: mydearxym Date: Thu, 13 May 2021 14:20:44 +0800 Subject: [PATCH 11/13] refactor(abuse-report): wip --- lib/groupher_server/accounts/user.ex | 1 + lib/groupher_server/cms/abuse_report.ex | 1 + .../cms/delegates/abuse_report.ex | 4 +- .../schema/cms/cms_types.ex | 13 +- .../job_report_test.exs | 2 +- .../post_report_test.exs | 2 +- .../repo_report_test.exs | 2 +- .../cms/abuse_reports/account_report_test.exs | 67 +++++++++++ .../cms/abuse_reports/job_report_test.exs | 112 ++++++++++++++++++ .../cms/abuse_reports/post_report_test.exs | 49 ++++++-- .../cms/abuse_reports/repo_report_test.exs | 112 ++++++++++++++++++ 11 files changed, 347 insertions(+), 18 deletions(-) rename test/groupher_server_web/mutation/cms/{articles => abuse_reports}/job_report_test.exs (96%) rename test/groupher_server_web/mutation/cms/{articles => abuse_reports}/post_report_test.exs (96%) rename test/groupher_server_web/mutation/cms/{articles => abuse_reports}/repo_report_test.exs (96%) create mode 100644 test/groupher_server_web/query/cms/abuse_reports/account_report_test.exs create mode 100644 test/groupher_server_web/query/cms/abuse_reports/job_report_test.exs create mode 100644 test/groupher_server_web/query/cms/abuse_reports/repo_report_test.exs diff --git a/lib/groupher_server/accounts/user.ex b/lib/groupher_server/accounts/user.ex index 4e6fee509..8c6438f6e 100644 --- a/lib/groupher_server/accounts/user.ex +++ b/lib/groupher_server/accounts/user.ex @@ -3,6 +3,7 @@ defmodule GroupherServer.Accounts.User do alias __MODULE__ use Ecto.Schema + use Accessible # import GroupherServerWeb.Schema.Helper.Fields import Ecto.Changeset diff --git a/lib/groupher_server/cms/abuse_report.ex b/lib/groupher_server/cms/abuse_report.ex index 9b733c149..ef44a5719 100644 --- a/lib/groupher_server/cms/abuse_report.ex +++ b/lib/groupher_server/cms/abuse_report.ex @@ -3,6 +3,7 @@ defmodule GroupherServer.CMS.AbuseReport do alias __MODULE__ use Ecto.Schema + use Accessible import Ecto.Changeset alias GroupherServer.{Accounts, CMS} diff --git a/lib/groupher_server/cms/delegates/abuse_report.ex b/lib/groupher_server/cms/delegates/abuse_report.ex index a27297be4..dd997bc29 100644 --- a/lib/groupher_server/cms/delegates/abuse_report.ex +++ b/lib/groupher_server/cms/delegates/abuse_report.ex @@ -81,8 +81,6 @@ defmodule GroupherServer.CMS.Delegate.AbuseReport do # def list_reports(%{content_type: thread} = filter) when thread in @article_threads do def list_reports(%{content_type: thread} = filter) do - IO.inspect(filter, label: "list filter 1-") - with {:ok, info} <- match(thread) do query = from(r in AbuseReport, @@ -354,7 +352,7 @@ defmodule GroupherServer.CMS.Delegate.AbuseReport do report |> Map.get(thread) |> Map.take(@export_article_keys) - |> Map.merge(%{thread: thread}) + |> Map.merge(%{thread: thread |> to_string |> String.upcase()}) end def extract_article_comment_info(%AbuseReport{} = report) do diff --git a/lib/groupher_server_web/schema/cms/cms_types.ex b/lib/groupher_server_web/schema/cms/cms_types.ex index e107fd34f..9c01ba98c 100644 --- a/lib/groupher_server_web/schema/cms/cms_types.ex +++ b/lib/groupher_server_web/schema/cms/cms_types.ex @@ -396,14 +396,23 @@ defmodule GroupherServerWeb.Schema.CMS.Types do timestamp_fields() end + ####### reports + object :abuse_report_case do + field(:reason, :string) + field(:attr, :string) + field(:user, :common_user) + end + object :abuse_report do field(:id, :id) + field(:article, :common_article) # field(:article_comment, :article_comment, resolve: dataloader(CMS, :article_comment)) field(:article_comment, :common_article_comment) - # field(:account, :user) + field(:account, :common_user) field(:report_cases_count, :integer) field(:deal_with, :string) field(:operate_user, :user) + field(:report_cases, list_of(:abuse_report_case)) timestamp_fields() end @@ -494,6 +503,4 @@ defmodule GroupherServerWeb.Schema.CMS.Types do field(:is_comment_locked, :boolean) # field(:linked_posts_count, :integer) end - - ####### reports end diff --git a/test/groupher_server_web/mutation/cms/articles/job_report_test.exs b/test/groupher_server_web/mutation/cms/abuse_reports/job_report_test.exs similarity index 96% rename from test/groupher_server_web/mutation/cms/articles/job_report_test.exs rename to test/groupher_server_web/mutation/cms/abuse_reports/job_report_test.exs index ec80a3791..75090f7cf 100644 --- a/test/groupher_server_web/mutation/cms/articles/job_report_test.exs +++ b/test/groupher_server_web/mutation/cms/abuse_reports/job_report_test.exs @@ -1,4 +1,4 @@ -defmodule GroupherServer.Test.Mutation.Articles.JobReport do +defmodule GroupherServer.Test.Mutation.AbuseReports.JobReport do use GroupherServer.TestTools alias GroupherServer.CMS diff --git a/test/groupher_server_web/mutation/cms/articles/post_report_test.exs b/test/groupher_server_web/mutation/cms/abuse_reports/post_report_test.exs similarity index 96% rename from test/groupher_server_web/mutation/cms/articles/post_report_test.exs rename to test/groupher_server_web/mutation/cms/abuse_reports/post_report_test.exs index 4cd20e925..6e5fb4ea1 100644 --- a/test/groupher_server_web/mutation/cms/articles/post_report_test.exs +++ b/test/groupher_server_web/mutation/cms/abuse_reports/post_report_test.exs @@ -1,4 +1,4 @@ -defmodule GroupherServer.Test.Mutation.Articles.PostReport do +defmodule GroupherServer.Test.Mutation.AbuseReports.PostReport do use GroupherServer.TestTools alias GroupherServer.CMS diff --git a/test/groupher_server_web/mutation/cms/articles/repo_report_test.exs b/test/groupher_server_web/mutation/cms/abuse_reports/repo_report_test.exs similarity index 96% rename from test/groupher_server_web/mutation/cms/articles/repo_report_test.exs rename to test/groupher_server_web/mutation/cms/abuse_reports/repo_report_test.exs index 3ba92707a..e0f91e37a 100644 --- a/test/groupher_server_web/mutation/cms/articles/repo_report_test.exs +++ b/test/groupher_server_web/mutation/cms/abuse_reports/repo_report_test.exs @@ -1,4 +1,4 @@ -defmodule GroupherServer.Test.Mutation.Articles.RepoReport do +defmodule GroupherServer.Test.Mutation.AbuseReports.RepoReport do use GroupherServer.TestTools alias GroupherServer.CMS diff --git a/test/groupher_server_web/query/cms/abuse_reports/account_report_test.exs b/test/groupher_server_web/query/cms/abuse_reports/account_report_test.exs new file mode 100644 index 000000000..345f18284 --- /dev/null +++ b/test/groupher_server_web/query/cms/abuse_reports/account_report_test.exs @@ -0,0 +1,67 @@ +defmodule GroupherServer.Test.Query.AbuseReports.AccountReport do + @moduledoc false + + use GroupherServer.TestTools + + alias GroupherServer.CMS + + setup do + {:ok, user} = db_insert(:user) + {:ok, user2} = db_insert(:user) + + {:ok, community} = db_insert(:community) + guest_conn = simu_conn(:guest) + + {:ok, ~m(guest_conn community user user2)a} + end + + describe "[query paged_posts filter pagination]" do + # id + @query """ + query($filter: ReportFilter!) { + pagedAbuseReports(filter: $filter) { + entries { + id + dealWith + operateUser { + id + login + } + articleComment { + id + bodyHtml + author { + login + } + } + account { + login + } + reportCases { + reason + attr + user { + login + } + } + } + totalPages + totalCount + pageSize + pageNumber + } + } + """ + @tag :wip2 + test "should get pagination info", ~m(guest_conn user user2)a do + {:ok, _report} = CMS.report_article(:account, user.id, "reason", "attr_info", user2) + + variables = %{filter: %{content_type: "ACCOUNT", page: 1, size: 10}} + results = guest_conn |> query_result(@query, variables, "pagedAbuseReports") + + report = results["entries"] |> List.first() + assert results |> is_valid_pagination? + assert get_in(report, ["account", "login"]) == user.login + end + end +end diff --git a/test/groupher_server_web/query/cms/abuse_reports/job_report_test.exs b/test/groupher_server_web/query/cms/abuse_reports/job_report_test.exs new file mode 100644 index 000000000..adfbde224 --- /dev/null +++ b/test/groupher_server_web/query/cms/abuse_reports/job_report_test.exs @@ -0,0 +1,112 @@ +defmodule GroupherServer.Test.Query.AbuseReports.JobReport do + @moduledoc false + + use GroupherServer.TestTools + + alias GroupherServer.CMS + + setup do + {:ok, job} = db_insert(:job) + {:ok, user} = db_insert(:user) + {:ok, user2} = db_insert(:user) + + {:ok, community} = db_insert(:community) + job_attrs = mock_attrs(:job, %{community_id: community.id}) + + guest_conn = simu_conn(:guest) + + {:ok, ~m(guest_conn community job job_attrs user user2)a} + end + + describe "[query paged_jobs filter pagination]" do + # id + @query """ + query($filter: ReportFilter!) { + pagedAbuseReports(filter: $filter) { + entries { + id + dealWith + article { + id + thread + title + } + operateUser { + id + login + } + articleComment { + id + bodyHtml + author { + login + } + } + reportCases { + reason + attr + user { + login + } + } + } + totalPages + totalCount + pageSize + pageNumber + } + } + """ + @tag :wip2 + test "should get pagination info", ~m(guest_conn community job_attrs user user2)a do + {:ok, job} = CMS.create_content(community, :job, job_attrs, user) + {:ok, job2} = CMS.create_content(community, :job, job_attrs, user) + + {:ok, _report} = CMS.report_article(:job, job.id, "reason", "attr_info", user) + {:ok, _report} = CMS.report_article(:job, job2.id, "reason", "attr_info", user2) + + variables = %{filter: %{content_type: "JOB", page: 1, size: 10}} + results = guest_conn |> query_result(@query, variables, "pagedAbuseReports") + + assert results |> is_valid_pagination? + assert results["totalCount"] == 2 + end + + @tag :wip2 + test "support search with id", ~m(guest_conn user user2)a do + {:ok, job} = db_insert(:job) + {:ok, job2} = db_insert(:job) + + {:ok, _report} = CMS.report_article(:job, job.id, "reason", "attr_info", user) + {:ok, _report} = CMS.report_article(:job, job2.id, "reason", "attr_info", user2) + + variables = %{filter: %{content_type: "JOB", content_id: job.id, page: 1, size: 10}} + results = guest_conn |> query_result(@query, variables, "pagedAbuseReports") + + report = results["entries"] |> List.first() + + assert get_in(report, ["article", "thread"]) == "JOB" + assert get_in(report, ["article", "id"]) == to_string(job.id) + + assert results |> is_valid_pagination? + assert results["totalCount"] == 1 + end + + @tag :wip3 + test "support article_comment", ~m(guest_conn job user)a do + {:ok, comment} = CMS.create_article_comment(:job, job.id, "comment", user) + {:ok, _} = CMS.report_article_comment(comment.id, "reason", "attr", user) + + variables = %{filter: %{content_type: "ARTICLE_COMMENT", page: 1, size: 10}} + results = guest_conn |> query_result(@query, variables, "pagedAbuseReports") + + report = results["entries"] |> List.first() + report_case = get_in(report, ["reportCases"]) + assert is_list(report_case) + + assert get_in(report, ["articleComment", "bodyHtml"]) == "comment" + assert get_in(report, ["articleComment", "id"]) == to_string(comment.id) + assert not is_nil(get_in(report, ["articleComment", "author", "login"])) + end + end +end diff --git a/test/groupher_server_web/query/cms/abuse_reports/post_report_test.exs b/test/groupher_server_web/query/cms/abuse_reports/post_report_test.exs index f0c15a051..da4e42c83 100644 --- a/test/groupher_server_web/query/cms/abuse_reports/post_report_test.exs +++ b/test/groupher_server_web/query/cms/abuse_reports/post_report_test.exs @@ -3,12 +3,7 @@ defmodule GroupherServer.Test.Query.AbuseReports.PostReport do use GroupherServer.TestTools - import Helper.Utils, only: [get_config: 2] - alias GroupherServer.CMS - alias GroupherServer.Repo - - alias CMS.Post setup do {:ok, post} = db_insert(:post) @@ -31,6 +26,11 @@ defmodule GroupherServer.Test.Query.AbuseReports.PostReport do entries { id dealWith + article { + id + thread + title + } operateUser { id login @@ -42,6 +42,13 @@ defmodule GroupherServer.Test.Query.AbuseReports.PostReport do login } } + reportCases { + reason + attr + user { + login + } + } } totalPages totalCount @@ -50,19 +57,42 @@ defmodule GroupherServer.Test.Query.AbuseReports.PostReport do } } """ - @tag :wip + @tag :wip2 test "should get pagination info", ~m(guest_conn community post_attrs user user2)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) + {:ok, post2} = CMS.create_content(community, :post, post_attrs, user) + {:ok, _report} = CMS.report_article(:post, post.id, "reason", "attr_info", user) - {:ok, _report} = CMS.report_article(:post, post.id, "reason", "attr_info", user2) + {:ok, _report} = CMS.report_article(:post, post2.id, "reason", "attr_info", user2) variables = %{filter: %{content_type: "POST", page: 1, size: 10}} results = guest_conn |> query_result(@query, variables, "pagedAbuseReports") assert results |> is_valid_pagination? + assert results["totalCount"] == 2 end @tag :wip2 + test "support search with id", ~m(guest_conn user user2)a do + {:ok, post} = db_insert(:post) + {:ok, post2} = db_insert(:post) + + {:ok, _report} = CMS.report_article(:post, post.id, "reason", "attr_info", user) + {:ok, _report} = CMS.report_article(:post, post2.id, "reason", "attr_info", user2) + + variables = %{filter: %{content_type: "POST", content_id: post.id, page: 1, size: 10}} + results = guest_conn |> query_result(@query, variables, "pagedAbuseReports") + + report = results["entries"] |> List.first() + + assert get_in(report, ["article", "thread"]) == "POST" + assert get_in(report, ["article", "id"]) == to_string(post.id) + + assert results |> is_valid_pagination? + assert results["totalCount"] == 1 + end + + @tag :wip3 test "support article_comment", ~m(guest_conn post user)a do {:ok, comment} = CMS.create_article_comment(:post, post.id, "comment", user) {:ok, _} = CMS.report_article_comment(comment.id, "reason", "attr", user) @@ -70,9 +100,10 @@ defmodule GroupherServer.Test.Query.AbuseReports.PostReport do variables = %{filter: %{content_type: "ARTICLE_COMMENT", page: 1, size: 10}} results = guest_conn |> query_result(@query, variables, "pagedAbuseReports") - IO.inspect(results, label: "results- -") - report = results["entries"] |> List.first() + report_case = get_in(report, ["reportCases"]) + assert is_list(report_case) + assert get_in(report, ["articleComment", "bodyHtml"]) == "comment" assert get_in(report, ["articleComment", "id"]) == to_string(comment.id) assert not is_nil(get_in(report, ["articleComment", "author", "login"])) diff --git a/test/groupher_server_web/query/cms/abuse_reports/repo_report_test.exs b/test/groupher_server_web/query/cms/abuse_reports/repo_report_test.exs new file mode 100644 index 000000000..03315b60a --- /dev/null +++ b/test/groupher_server_web/query/cms/abuse_reports/repo_report_test.exs @@ -0,0 +1,112 @@ +defmodule GroupherServer.Test.Query.AbuseReports.RepoReport 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) + + {:ok, community} = db_insert(:community) + repo_attrs = mock_attrs(:repo, %{community_id: community.id}) + + guest_conn = simu_conn(:guest) + + {:ok, ~m(guest_conn community repo repo_attrs user user2)a} + end + + describe "[query paged_repos filter pagination]" do + # id + @query """ + query($filter: ReportFilter!) { + pagedAbuseReports(filter: $filter) { + entries { + id + dealWith + article { + id + thread + title + } + operateUser { + id + login + } + articleComment { + id + bodyHtml + author { + login + } + } + reportCases { + reason + attr + user { + login + } + } + } + totalPages + totalCount + pageSize + pageNumber + } + } + """ + @tag :wip2 + test "should get pagination info", ~m(guest_conn community repo_attrs user user2)a do + {:ok, repo} = CMS.create_content(community, :repo, repo_attrs, user) + {:ok, repo2} = CMS.create_content(community, :repo, repo_attrs, user) + + {:ok, _report} = CMS.report_article(:repo, repo.id, "reason", "attr_info", user) + {:ok, _report} = CMS.report_article(:repo, repo2.id, "reason", "attr_info", user2) + + variables = %{filter: %{content_type: "REPO", page: 1, size: 10}} + results = guest_conn |> query_result(@query, variables, "pagedAbuseReports") + + assert results |> is_valid_pagination? + assert results["totalCount"] == 2 + end + + @tag :wip2 + test "support search with id", ~m(guest_conn user user2)a do + {:ok, repo} = db_insert(:repo) + {:ok, repo2} = db_insert(:repo) + + {:ok, _report} = CMS.report_article(:repo, repo.id, "reason", "attr_info", user) + {:ok, _report} = CMS.report_article(:repo, repo2.id, "reason", "attr_info", user2) + + variables = %{filter: %{content_type: "REPO", content_id: repo.id, page: 1, size: 10}} + results = guest_conn |> query_result(@query, variables, "pagedAbuseReports") + + report = results["entries"] |> List.first() + + assert get_in(report, ["article", "thread"]) == "REPO" + assert get_in(report, ["article", "id"]) == to_string(repo.id) + + assert results |> is_valid_pagination? + assert results["totalCount"] == 1 + end + + @tag :wip3 + test "support article_comment", ~m(guest_conn repo user)a do + {:ok, comment} = CMS.create_article_comment(:repo, repo.id, "comment", user) + {:ok, _} = CMS.report_article_comment(comment.id, "reason", "attr", user) + + variables = %{filter: %{content_type: "ARTICLE_COMMENT", page: 1, size: 10}} + results = guest_conn |> query_result(@query, variables, "pagedAbuseReports") + + report = results["entries"] |> List.first() + report_case = get_in(report, ["reportCases"]) + assert is_list(report_case) + + assert get_in(report, ["articleComment", "bodyHtml"]) == "comment" + assert get_in(report, ["articleComment", "id"]) == to_string(comment.id) + assert not is_nil(get_in(report, ["articleComment", "author", "login"])) + end + end +end From ab568c1a52fa28571cf55701fc1a6a17c7103a32 Mon Sep 17 00:00:00 2001 From: mydearxym Date: Thu, 13 May 2021 14:23:01 +0800 Subject: [PATCH 12/13] refactor(abuse-report): wip --- lib/groupher_server/cms/cms.ex | 1 - .../cms/delegates/abuse_report.ex | 32 +++++++++---------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/lib/groupher_server/cms/cms.ex b/lib/groupher_server/cms/cms.ex index 8cd5466cd..43ead789f 100644 --- a/lib/groupher_server/cms/cms.ex +++ b/lib/groupher_server/cms/cms.ex @@ -156,7 +156,6 @@ defmodule GroupherServer.CMS do defdelegate list_comments_participators(thread, content_id, filters), to: CommentCURD # TODO: move report to abuse report module - defdelegate create_report(type, content_id, reason, attr, user), to: AbuseReport defdelegate report_article(thread, article_id, reason, attr, user), to: AbuseReport defdelegate report_article_comment(comment_id, reason, attr, user), to: AbuseReport defdelegate report_account(account_id, reason, attr, user), to: AbuseReport diff --git a/lib/groupher_server/cms/delegates/abuse_report.ex b/lib/groupher_server/cms/delegates/abuse_report.ex index dd997bc29..5d5f265be 100644 --- a/lib/groupher_server/cms/delegates/abuse_report.ex +++ b/lib/groupher_server/cms/delegates/abuse_report.ex @@ -99,20 +99,6 @@ defmodule GroupherServer.CMS.Delegate.AbuseReport do do_list_reports(query, filter) end - defp do_list_reports(query, thread, filter) do - %{page: page, size: size} = filter - - query - |> QueryBuilder.filter_pack(filter) - |> ORM.paginater(~m(page size)a) - |> reports_formater(thread) - |> done() - end - - defp do_list_reports(query, %{page: page, size: size}) do - query |> ORM.paginater(~m(page size)a) |> done() - end - @doc """ report an account """ @@ -190,7 +176,7 @@ defmodule GroupherServer.CMS.Delegate.AbuseReport do with {:ok, comment} <- ORM.find(ArticleComment, comment_id) do Multi.new() |> Multi.run(:create_abuse_report, fn _, _ -> - CMS.create_report(:article_comment, comment_id, reason, attr, user) + create_report(:article_comment, comment_id, reason, attr, user) end) |> Multi.run(:update_report_meta, fn _, _ -> {:ok, info} = match(:article_comment) @@ -210,7 +196,21 @@ defmodule GroupherServer.CMS.Delegate.AbuseReport do undo_report_article(:article_comment, comment_id, user) end - def create_report(type, content_id, reason, attr, %User{} = user) do + defp do_list_reports(query, thread, filter) do + %{page: page, size: size} = filter + + query + |> QueryBuilder.filter_pack(filter) + |> ORM.paginater(~m(page size)a) + |> reports_formater(thread) + |> done() + end + + defp do_list_reports(query, %{page: page, size: size}) do + query |> ORM.paginater(~m(page size)a) |> done() + end + + defp create_report(type, content_id, reason, attr, %User{} = user) do with {:ok, info} <- match(type), {:ok, report} <- not_reported_before(info, content_id, user) do case report do From 247579f90d69b7cf48e35d64a20b439c51957b80 Mon Sep 17 00:00:00 2001 From: mydearxym Date: Thu, 13 May 2021 14:46:56 +0800 Subject: [PATCH 13/13] refactor(abuse-report): fix error --- .../cms/delegates/article_comment.ex | 7 +- lib/groupher_server/cms/helper/matcher2.ex | 6 +- .../cms/abuse_reports/job_report_test.exs | 2 +- .../cms/abuse_reports/post_report_test.exs | 2 +- .../cms/abuse_reports/repo_report_test.exs | 136 ++++++++++++++++++ .../cms/abuse_reports/account_report_test.exs | 2 +- .../cms/abuse_reports/job_report_test.exs | 3 +- .../cms/abuse_reports/post_report_test.exs | 3 +- .../cms/abuse_reports/repo_report_test.exs | 5 +- 9 files changed, 154 insertions(+), 12 deletions(-) create mode 100644 test/groupher_server/cms/abuse_reports/repo_report_test.exs diff --git a/lib/groupher_server/cms/delegates/article_comment.ex b/lib/groupher_server/cms/delegates/article_comment.ex index 8fbf44db8..9050ba9de 100644 --- a/lib/groupher_server/cms/delegates/article_comment.ex +++ b/lib/groupher_server/cms/delegates/article_comment.ex @@ -96,14 +96,19 @@ defmodule GroupherServer.CMS.Delegate.ArticleComment do # make sure the article exsit # author is passed by middleware, it's exsit for sure {:ok, article} <- ORM.find(info.model, article_id, preload: [author: :user]) do + IO.inspect(info, label: "bb") + Multi.new() |> Multi.run(:create_article_comment, fn _, _ -> + IO.inspect("11") do_create_comment(content, info.foreign_key, article, user) end) |> Multi.run(:update_article_comments_count, fn _, %{create_article_comment: comment} -> - update_article_comments_count(comment, :inc) + IO.inspect("22") + update_article_comments_count(comment, :inc) |> IO.inspect(label: "22 after") end) |> Multi.run(:add_participator, fn _, _ -> + IO.inspect("33") add_participator_to_article(article, user) end) |> Repo.transaction() diff --git a/lib/groupher_server/cms/helper/matcher2.ex b/lib/groupher_server/cms/helper/matcher2.ex index 995613fbf..badd57048 100644 --- a/lib/groupher_server/cms/helper/matcher2.ex +++ b/lib/groupher_server/cms/helper/matcher2.ex @@ -28,8 +28,12 @@ defmodule GroupherServer.CMS.Helper.Matcher2 do {:ok, %{model: Job, id: job_id, foreign_key: :job_id}} end + def match(:comment_article, %ArticleComment{repo_id: repo_id}) when not is_nil(repo_id) do + {:ok, %{model: Repo, id: repo_id, foreign_key: :repo_id}} + end + def match(:comment_article, %ArticleComment{}) do - {:error, "not supported"} + {:error, "match error, not supported"} end def match(:account) do diff --git a/test/groupher_server/cms/abuse_reports/job_report_test.exs b/test/groupher_server/cms/abuse_reports/job_report_test.exs index 8e9019729..7d19a743f 100644 --- a/test/groupher_server/cms/abuse_reports/job_report_test.exs +++ b/test/groupher_server/cms/abuse_reports/job_report_test.exs @@ -27,7 +27,7 @@ defmodule GroupherServer.Test.CMS.AbuseReports.JobReport do report = all_reports.entries |> List.first() assert report.article.id == job.id - assert report.article.thread == :job + assert report.article.thread == "JOB" end test "report a job should have a abuse report record", ~m(community user job_attrs)a do diff --git a/test/groupher_server/cms/abuse_reports/post_report_test.exs b/test/groupher_server/cms/abuse_reports/post_report_test.exs index 050817404..743fd1b0d 100644 --- a/test/groupher_server/cms/abuse_reports/post_report_test.exs +++ b/test/groupher_server/cms/abuse_reports/post_report_test.exs @@ -27,7 +27,7 @@ defmodule GroupherServer.Test.CMS.AbuseReports.PostReport do report = all_reports.entries |> List.first() assert report.article.id == post.id - assert report.article.thread == :post + assert report.article.thread == "POST" end test "report a post should have a abuse report record", ~m(community user post_attrs)a do diff --git a/test/groupher_server/cms/abuse_reports/repo_report_test.exs b/test/groupher_server/cms/abuse_reports/repo_report_test.exs new file mode 100644 index 000000000..17b14186b --- /dev/null +++ b/test/groupher_server/cms/abuse_reports/repo_report_test.exs @@ -0,0 +1,136 @@ +defmodule GroupherServer.Test.CMS.AbuseReports.RepoReport do + @moduledoc false + + use GroupherServer.TestTools + + alias Helper.ORM + alias GroupherServer.CMS + + setup do + {:ok, user} = db_insert(:user) + {:ok, user2} = db_insert(:user) + + {:ok, community} = db_insert(:community) + repo_attrs = mock_attrs(:repo, %{community_id: community.id}) + + {:ok, ~m(user user2 community repo_attrs)a} + end + + describe "[article repo report/unreport]" do + test "list article reports should work", ~m(community user user2 repo_attrs)a do + {:ok, repo} = CMS.create_content(community, :repo, repo_attrs, user) + {:ok, _report} = CMS.report_article(:repo, repo.id, "reason", "attr_info", user) + {:ok, _report} = CMS.report_article(:repo, repo.id, "reason", "attr_info", user2) + + filter = %{content_type: :repo, content_id: repo.id, page: 1, size: 20} + {:ok, all_reports} = CMS.list_reports(filter) + + report = all_reports.entries |> List.first() + assert report.article.id == repo.id + assert report.article.thread == "REPO" + end + + test "report a repo should have a abuse report record", ~m(community user repo_attrs)a do + {:ok, repo} = CMS.create_content(community, :repo, repo_attrs, user) + {:ok, _report} = CMS.report_article(:repo, repo.id, "reason", "attr_info", user) + + filter = %{content_type: :repo, content_id: repo.id, page: 1, size: 20} + {:ok, all_reports} = CMS.list_reports(filter) + + report = List.first(all_reports.entries) + report_cases = report.report_cases + + assert report.article.id == repo.id + assert all_reports.total_count == 1 + assert report.report_cases_count == 1 + assert List.first(report_cases).user.login == user.login + + {:ok, repo} = ORM.find(CMS.Repo, repo.id) + assert repo.meta.reported_count == 1 + assert user.id in repo.meta.reported_user_ids + end + + test "can undo a report", ~m(community user repo_attrs)a do + {:ok, repo} = CMS.create_content(community, :repo, repo_attrs, user) + {:ok, _report} = CMS.report_article(:repo, repo.id, "reason", "attr_info", user) + {:ok, _report} = CMS.undo_report_article(:repo, repo.id, user) + + filter = %{content_type: :repo, content_id: repo.id, page: 1, size: 20} + {:ok, all_reports} = CMS.list_reports(filter) + assert all_reports.total_count == 0 + + {:ok, repo} = ORM.find(CMS.Repo, repo.id) + assert user.id not in repo.meta.reported_user_ids + end + + test "can undo a existed report", ~m(community user user2 repo_attrs)a do + {:ok, repo} = CMS.create_content(community, :repo, repo_attrs, user) + {:ok, _report} = CMS.report_article(:repo, repo.id, "reason", "attr_info", user) + {:ok, _report} = CMS.report_article(:repo, repo.id, "reason", "attr_info", user2) + {:ok, _report} = CMS.undo_report_article(:repo, repo.id, user) + + filter = %{content_type: :repo, content_id: repo.id, page: 1, size: 20} + {:ok, all_reports} = CMS.list_reports(filter) + assert all_reports.total_count == 1 + + {:ok, repo} = ORM.find(CMS.Repo, repo.id) + + assert user2.id in repo.meta.reported_user_ids + assert user.id not in repo.meta.reported_user_ids + end + + test "can undo a report with other user report it too", + ~m(community user user2 repo_attrs)a do + {:ok, repo} = CMS.create_content(community, :repo, repo_attrs, user) + {:ok, _report} = CMS.report_article(:repo, repo.id, "reason", "attr_info", user) + {:ok, _report} = CMS.report_article(:repo, repo.id, "reason", "attr_info", user2) + + filter = %{content_type: :repo, content_id: repo.id, page: 1, size: 20} + {:ok, all_reports} = CMS.list_reports(filter) + assert all_reports.total_count == 1 + + report = all_reports.entries |> List.first() + assert report.report_cases |> length == 2 + assert Enum.any?(report.report_cases, &(&1.user.login == user.login)) + assert Enum.any?(report.report_cases, &(&1.user.login == user2.login)) + + {:ok, _report} = CMS.undo_report_article(:repo, repo.id, user) + + filter = %{content_type: :repo, content_id: repo.id, page: 1, size: 20} + {:ok, all_reports} = CMS.list_reports(filter) + assert all_reports.total_count == 1 + + report = all_reports.entries |> List.first() + assert report.report_cases |> length == 1 + assert Enum.any?(report.report_cases, &(&1.user.login == user2.login)) + end + + test "different user report a comment should have same report with different report cases", + ~m(community user user2 repo_attrs)a do + {:ok, repo} = CMS.create_content(community, :repo, repo_attrs, user) + + {:ok, _report} = CMS.report_article(:repo, repo.id, "reason", "attr_info", user) + {:ok, _report} = CMS.report_article(:repo, repo.id, "reason2", "attr_info 2", user2) + + filter = %{content_type: :repo, content_id: repo.id, page: 1, size: 20} + {:ok, all_reports} = CMS.list_reports(filter) + + report = List.first(all_reports.entries) + report_cases = report.report_cases + + assert all_reports.total_count == 1 + assert length(report_cases) == 2 + assert report.report_cases_count == 2 + + assert List.first(report_cases).user.login == user.login + assert List.last(report_cases).user.login == user2.login + end + + test "same user can not report a comment twice", ~m(community repo_attrs user)a do + {:ok, repo} = CMS.create_content(community, :repo, repo_attrs, user) + + {:ok, _report} = CMS.report_article(:repo, repo.id, "reason", "attr_info", user) + assert {:error, _report} = CMS.report_article(:repo, repo.id, "reason", "attr_info", user) + end + end +end diff --git a/test/groupher_server_web/query/cms/abuse_reports/account_report_test.exs b/test/groupher_server_web/query/cms/abuse_reports/account_report_test.exs index 345f18284..99e00a441 100644 --- a/test/groupher_server_web/query/cms/abuse_reports/account_report_test.exs +++ b/test/groupher_server_web/query/cms/abuse_reports/account_report_test.exs @@ -52,7 +52,7 @@ defmodule GroupherServer.Test.Query.AbuseReports.AccountReport do } } """ - @tag :wip2 + test "should get pagination info", ~m(guest_conn user user2)a do {:ok, _report} = CMS.report_article(:account, user.id, "reason", "attr_info", user2) diff --git a/test/groupher_server_web/query/cms/abuse_reports/job_report_test.exs b/test/groupher_server_web/query/cms/abuse_reports/job_report_test.exs index adfbde224..3ade64c62 100644 --- a/test/groupher_server_web/query/cms/abuse_reports/job_report_test.exs +++ b/test/groupher_server_web/query/cms/abuse_reports/job_report_test.exs @@ -57,7 +57,7 @@ defmodule GroupherServer.Test.Query.AbuseReports.JobReport do } } """ - @tag :wip2 + test "should get pagination info", ~m(guest_conn community job_attrs user user2)a do {:ok, job} = CMS.create_content(community, :job, job_attrs, user) {:ok, job2} = CMS.create_content(community, :job, job_attrs, user) @@ -72,7 +72,6 @@ defmodule GroupherServer.Test.Query.AbuseReports.JobReport do assert results["totalCount"] == 2 end - @tag :wip2 test "support search with id", ~m(guest_conn user user2)a do {:ok, job} = db_insert(:job) {:ok, job2} = db_insert(:job) diff --git a/test/groupher_server_web/query/cms/abuse_reports/post_report_test.exs b/test/groupher_server_web/query/cms/abuse_reports/post_report_test.exs index da4e42c83..5eebf2c46 100644 --- a/test/groupher_server_web/query/cms/abuse_reports/post_report_test.exs +++ b/test/groupher_server_web/query/cms/abuse_reports/post_report_test.exs @@ -57,7 +57,7 @@ defmodule GroupherServer.Test.Query.AbuseReports.PostReport do } } """ - @tag :wip2 + test "should get pagination info", ~m(guest_conn community post_attrs user user2)a do {:ok, post} = CMS.create_content(community, :post, post_attrs, user) {:ok, post2} = CMS.create_content(community, :post, post_attrs, user) @@ -72,7 +72,6 @@ defmodule GroupherServer.Test.Query.AbuseReports.PostReport do assert results["totalCount"] == 2 end - @tag :wip2 test "support search with id", ~m(guest_conn user user2)a do {:ok, post} = db_insert(:post) {:ok, post2} = db_insert(:post) diff --git a/test/groupher_server_web/query/cms/abuse_reports/repo_report_test.exs b/test/groupher_server_web/query/cms/abuse_reports/repo_report_test.exs index 03315b60a..5060e5af2 100644 --- a/test/groupher_server_web/query/cms/abuse_reports/repo_report_test.exs +++ b/test/groupher_server_web/query/cms/abuse_reports/repo_report_test.exs @@ -57,7 +57,7 @@ defmodule GroupherServer.Test.Query.AbuseReports.RepoReport do } } """ - @tag :wip2 + test "should get pagination info", ~m(guest_conn community repo_attrs user user2)a do {:ok, repo} = CMS.create_content(community, :repo, repo_attrs, user) {:ok, repo2} = CMS.create_content(community, :repo, repo_attrs, user) @@ -72,7 +72,6 @@ defmodule GroupherServer.Test.Query.AbuseReports.RepoReport do assert results["totalCount"] == 2 end - @tag :wip2 test "support search with id", ~m(guest_conn user user2)a do {:ok, repo} = db_insert(:repo) {:ok, repo2} = db_insert(:repo) @@ -92,7 +91,7 @@ defmodule GroupherServer.Test.Query.AbuseReports.RepoReport do assert results["totalCount"] == 1 end - @tag :wip3 + @tag :wip2 test "support article_comment", ~m(guest_conn repo user)a do {:ok, comment} = CMS.create_article_comment(:repo, repo.id, "comment", user) {:ok, _} = CMS.report_article_comment(comment.id, "reason", "attr", user)