diff --git a/lib/groupher_server/cms/abuse_report.ex b/lib/groupher_server/cms/abuse_report.ex index 1af03eb7a..c99b6fe36 100644 --- a/lib/groupher_server/cms/abuse_report.ex +++ b/lib/groupher_server/cms/abuse_report.ex @@ -6,10 +6,10 @@ defmodule GroupherServer.CMS.AbuseReport do import Ecto.Changeset alias GroupherServer.{Accounts, CMS} - alias CMS.{ArticleComment, Embeds, Post, Job} + 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 account_id 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_closed report_cases_count)a @update_fields ~w(operate_user_id deal_with is_closed report_cases_count)a @type t :: %AbuseReport{} @@ -17,6 +17,7 @@ defmodule GroupherServer.CMS.AbuseReport do belongs_to(:article_comment, ArticleComment, foreign_key: :article_comment_id) belongs_to(:post, Post, foreign_key: :post_id) belongs_to(:job, Job, foreign_key: :job_id) + belongs_to(:repo, Repo, foreign_key: :repo_id) belongs_to(:account, Accounts.User, foreign_key: :account_id) embeds_many(:report_cases, Embeds.AbuseReportCase, on_replace: :delete) diff --git a/lib/groupher_server/cms/cms.ex b/lib/groupher_server/cms/cms.ex index 0c0577280..284dcd35d 100644 --- a/lib/groupher_server/cms/cms.ex +++ b/lib/groupher_server/cms/cms.ex @@ -143,8 +143,6 @@ defmodule GroupherServer.CMS do defdelegate fold_article_comment(comment_id, user), to: ArticleCommentAction defdelegate unfold_article_comment(comment_id, user), to: ArticleCommentAction - defdelegate report_article_comment(comment_id, user), to: ArticleCommentAction - defdelegate unreport_article_comment(comment_id, user), to: ArticleCommentAction defdelegate emotion_to_comment(comment_id, args, user), to: ArticleCommentEmotion defdelegate undo_emotion_to_comment(comment_id, args, user), to: ArticleCommentEmotion @@ -161,8 +159,13 @@ defmodule GroupherServer.CMS do defdelegate list_comments(thread, content_id, filters), to: CommentCURD defdelegate list_comments_participators(thread, content_id, filters), to: CommentCURD - # report - defdelegate create_report(type, content_id, args, user), to: AbuseReport + # 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 undo_report_article(thread, article_id, user), to: AbuseReport + defdelegate list_reports(type, content_id, 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 defdelegate stamp_passport(rules, user), to: PassportCURD diff --git a/lib/groupher_server/cms/delegates/abuse_report.ex b/lib/groupher_server/cms/delegates/abuse_report.ex index 2efe1142f..0f93ed115 100644 --- a/lib/groupher_server/cms/delegates/abuse_report.ex +++ b/lib/groupher_server/cms/delegates/abuse_report.ex @@ -3,58 +3,152 @@ defmodule GroupherServer.CMS.Delegate.AbuseReport do CURD and operations for article comments """ import Ecto.Query, warn: false - # import Helper.Utils, only: [done: 1] + import Helper.Utils, only: [done: 1, strip_struct: 1] import GroupherServer.CMS.Helper.Matcher2 - # import ShortMaps + import ShortMaps - alias Helper.{ORM} + alias Helper.ORM + alias Helper.QueryBuilder alias GroupherServer.{Accounts, CMS, Repo} alias Accounts.User alias CMS.{AbuseReport, Embeds} - # alias Accounts.User + alias Ecto.Multi - def create_report(type, content_id, %{reason: reason}, %User{} = user) do + @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) + + query + |> QueryBuilder.filter_pack(filter) + |> ORM.paginater(~m(page size)a) + |> done() + end + end + + @doc """ + report article content + """ + def report_article(thread, article_id, reason, attr, %User{} = user) do + with {:ok, info} <- match(thread), + {: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) + end) + |> Multi.run(:update_report_flag, fn _, _ -> + update_report_meta(info, article, true) + 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 + + @doc """ + undo report article content + """ + def undo_report_article(thread, article_id, %User{} = user) do + with {:ok, info} <- match(thread), + {:ok, article} <- ORM.find(info.model, article_id) do + Multi.new() + |> Multi.run(:delete_abuse_report, fn _, _ -> + delete_report(thread, article_id, user) + end) + |> Multi.run(:update_report_flag, fn _, _ -> + update_report_meta(info, article, false) + end) + |> Repo.transaction() + |> result() + end + 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 case report do nil -> - updated_report_cases = [ + report_cases = [ %{ reason: reason, - additional_reason: "additional_reason", + attr: attr, user: %{login: user.login, nickname: user.nickname} } ] args = - %{report_cases_count: 1, report_cases: updated_report_cases} + %{report_cases_count: 1, report_cases: report_cases} |> Map.put(info.foreign_key, content_id) AbuseReport |> ORM.create(args) _ -> - updated_report_cases = + user = %{login: user.login, nickname: user.nickname} + + report_cases = report.report_cases |> List.insert_at( length(report.report_cases), - %Embeds.AbuseReportCase{ - reason: reason, - additional_reason: "additional_reason", - user: %{login: user.login, nickname: user.nickname} - } + %Embeds.AbuseReportCase{reason: reason, attr: attr, user: user} ) report - |> Ecto.Changeset.change(%{report_cases_count: length(updated_report_cases)}) - |> Ecto.Changeset.put_embed(:report_cases, updated_report_cases) + |> Ecto.Changeset.change(%{report_cases_count: length(report_cases)}) + |> Ecto.Changeset.put_embed(:report_cases, report_cases) + |> Repo.update() + end + end + end + + defp delete_report(thread, content_id, %User{} = user) do + with {:ok, info} <- match(thread), + {:error, _} <- not_reported_before(info, content_id, user), + {:ok, report} = ORM.find_by(AbuseReport, Map.put(%{}, info.foreign_key, content_id)) do + case length(report.report_cases) do + 1 -> + ORM.delete(report) + + _ -> + report_cases = report.report_cases |> Enum.reject(&(&1.user.login == user.login)) + + report + |> Ecto.Changeset.change(%{report_cases_count: length(report_cases)}) + |> Ecto.Changeset.put_embed(:report_cases, report_cases) |> Repo.update() end end end + # update is_reported flag and reported_count in mete for article or comment + defp update_report_meta(info, content, is_reported) 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 + + content + |> Ecto.Changeset.change(%{is_reported: is_reported}) + |> Ecto.Changeset.put_embed(:meta, meta) + |> Repo.update() + + {:error, _} -> + meta = content.meta |> Map.merge(%{reported_count: 0}) |> strip_struct + + content + |> Ecto.Changeset.change(%{is_reported: false}) + |> Ecto.Changeset.put_embed(:meta, meta) + |> Repo.update() + end + end + defp not_reported_before(info, content_id, %User{login: login}) do query = from(r in AbuseReport, where: field(r, ^info.foreign_key) == ^content_id) @@ -71,9 +165,13 @@ defmodule GroupherServer.CMS.Delegate.AbuseReport do |> length |> Kernel.>(0) - if not reported_before, - do: {:ok, report}, - else: {:error, "#{login} already reported"} + if not reported_before, do: {:ok, report}, else: {:error, "#{login} already reported"} end end + + defp result({:ok, %{update_report_flag: result}}), do: result |> done() + + defp result({:error, _, result, _steps}) do + {:error, result} + end end diff --git a/lib/groupher_server/cms/delegates/article_comment_action.ex b/lib/groupher_server/cms/delegates/article_comment_action.ex index a0f23e393..f99236103 100644 --- a/lib/groupher_server/cms/delegates/article_comment_action.ex +++ b/lib/groupher_server/cms/delegates/article_comment_action.ex @@ -82,6 +82,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleCommentAction do end end + @doc "fold a comment" def fold_article_comment(%ArticleComment{} = comment, %User{} = _user) do comment |> ORM.update(%{is_folded: true}) end @@ -93,22 +94,22 @@ defmodule GroupherServer.CMS.Delegate.ArticleCommentAction do end end - @doc "fold a comment" + @doc "unfold a comment" def unfold_article_comment(comment_id, %User{} = _user) do with {:ok, comment} <- ORM.find(ArticleComment, comment_id) do comment |> ORM.update(%{is_folded: false}) end end - @doc "fold a comment" - def report_article_comment(comment_id, %User{} = user) do - with {:ok, comment} <- - ORM.find(ArticleComment, comment_id) do + @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: "todo fucked"}, user) + 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} -> @@ -121,14 +122,6 @@ defmodule GroupherServer.CMS.Delegate.ArticleCommentAction do end end - @doc "fold a comment" - def unreport_article_comment(comment_id, %User{} = _user) do - with {:ok, comment} <- - ORM.find(ArticleComment, comment_id) do - comment |> ORM.update(%{is_reported: false}) - 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/delegates/article_operation.ex b/lib/groupher_server/cms/delegates/article_operation.ex index 6dac2d98b..71c9a91df 100644 --- a/lib/groupher_server/cms/delegates/article_operation.ex +++ b/lib/groupher_server/cms/delegates/article_operation.ex @@ -62,6 +62,12 @@ defmodule GroupherServer.CMS.Delegate.ArticleOperation do end end + ######## + ######## + ######## + ######## + ######## + @doc """ trash / untrash articles """ diff --git a/lib/groupher_server/cms/embeds/abuse_report_case.ex b/lib/groupher_server/cms/embeds/abuse_report_case.ex index 124e7900e..481827970 100644 --- a/lib/groupher_server/cms/embeds/abuse_report_case.ex +++ b/lib/groupher_server/cms/embeds/abuse_report_case.ex @@ -8,9 +8,11 @@ defmodule GroupherServer.CMS.Embeds.AbuseReportCase do alias GroupherServer.CMS alias CMS.Embeds + @optional_fields [:reason, :attr] + embedded_schema do field(:reason, :string) - field(:additional_reason, :string) + field(:attr, :string) embeds_one(:user, Embeds.User, on_replace: :delete) timestamps(type: :utc_datetime) @@ -18,7 +20,7 @@ defmodule GroupherServer.CMS.Embeds.AbuseReportCase do def changeset(struct, params) do struct - |> cast(params, [:reason, :additional_reason]) + |> cast(params, @optional_fields) |> cast_embed(:user, required: true, with: &Embeds.User.changeset/2) end end diff --git a/lib/groupher_server/cms/embeds/article_comment_meta.ex b/lib/groupher_server/cms/embeds/article_comment_meta.ex index 9675c2f6c..982345a0c 100644 --- a/lib/groupher_server/cms/embeds/article_comment_meta.ex +++ b/lib/groupher_server/cms/embeds/article_comment_meta.ex @@ -7,14 +7,15 @@ defmodule GroupherServer.CMS.Embeds.ArticleCommentMeta do import Ecto.Changeset - @optional_fields ~w(is_article_author_upvoted is_solution report_count is_reply_to_others)a + @optional_fields ~w(is_article_author_upvoted is_solution report_count is_reply_to_others reported_count)a @default_meta %{ is_article_author_upvoted: false, is_solution: false, is_reply_to_others: false, report_count: 0, - upvoted_user_ids: [] + upvoted_user_ids: [], + reported_count: 0 } @doc "for test usage" @@ -29,6 +30,7 @@ defmodule GroupherServer.CMS.Embeds.ArticleCommentMeta do field(:report_count, :integer, default: 0) field(:upvoted_user_ids, {:array, :integer}, default: []) + field(:reported_count, :integer, default: 0) end def changeset(struct, params) do diff --git a/lib/groupher_server/cms/embeds/article_meta.ex b/lib/groupher_server/cms/embeds/article_meta.ex index ef8c153ac..bddd20745 100644 --- a/lib/groupher_server/cms/embeds/article_meta.ex +++ b/lib/groupher_server/cms/embeds/article_meta.ex @@ -6,16 +6,16 @@ defmodule GroupherServer.CMS.Embeds.ArticleMeta do use Accessible import Ecto.Changeset - @optional_fields ~w(is_edited is_comment_locked is_reported upvoted_user_ids collected_user_ids viewed_user_ids reported_user_ids)a + @optional_fields ~w(is_edited is_comment_locked upvoted_user_ids collected_user_ids viewed_user_ids reported_user_ids reported_count)a @default_meta %{ is_edited: false, is_comment_locked: false, - is_reported: false, upvoted_user_ids: [], collected_user_ids: [], viewed_user_ids: [], - reported_user_ids: [] + reported_user_ids: [], + reported_count: 0 } @doc "for test usage" @@ -24,12 +24,12 @@ defmodule GroupherServer.CMS.Embeds.ArticleMeta do embedded_schema do field(:is_edited, :boolean, default: false) field(:is_comment_locked, :boolean, default: false) - field(:is_reported, :boolean, default: false) # reaction history field(:upvoted_user_ids, {:array, :integer}, default: []) field(:collected_user_ids, {:array, :integer}, default: []) field(:viewed_user_ids, {:array, :integer}, default: []) field(:reported_user_ids, {:array, :integer}, default: []) + field(:reported_count, :integer, default: 0) end def changeset(struct, params) do diff --git a/lib/groupher_server/cms/job.ex b/lib/groupher_server/cms/job.ex index 51f62046a..b39a89dbe 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)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 @type t :: %Job{} schema "cms_jobs" do @@ -57,6 +57,7 @@ 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 336d15fbf..cf601882d 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)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 @type t :: %Post{} schema "cms_posts" do @@ -48,6 +48,7 @@ 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 c24c879c6..9bd840a79 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)a + @optional_fields ~w(origial_community_id last_sync homepage_url release_tag license is_reported)a @type t :: %Repo{} schema "cms_repos" do @@ -61,6 +61,7 @@ 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/resolvers/cms_resolver.ex b/lib/groupher_server_web/resolvers/cms_resolver.ex index cf145f90b..6196363f8 100644 --- a/lib/groupher_server_web/resolvers/cms_resolver.ex +++ b/lib/groupher_server_web/resolvers/cms_resolver.ex @@ -94,11 +94,16 @@ defmodule GroupherServerWeb.Resolvers.CMS do set_community_flags(community_id, thread, id, %{trash: false}) end + def report_article(_root, ~m(thread id reason attr)a, %{context: %{cur_user: user}}) do + CMS.report_article(thread, id, reason, attr, user) + end + + def undo_report_article(_root, ~m(thread id)a, %{context: %{cur_user: user}}) do + CMS.undo_report_article(thread, id, user) + end + # TODO: report contents - # def report_content(_root, ~m(id thread community_id)a, _info), # do: set_community_flags(community_id, thread, id, %{report: true}) - - # def undo_report_content(_root, ~m(id thread community_id)a, _info), # do: set_community_flags(community_id, thread, id, %{report: false}) defp set_community_flags(community_id, thread, id, flag) do diff --git a/lib/groupher_server_web/schema/Helper/mutations.ex b/lib/groupher_server_web/schema/Helper/mutations.ex index 4efeebfd0..e99f2bfcc 100644 --- a/lib/groupher_server_web/schema/Helper/mutations.ex +++ b/lib/groupher_server_web/schema/Helper/mutations.ex @@ -124,4 +124,28 @@ defmodule GroupherServerWeb.Schema.Helper.Mutations do end end end + + defmacro article_report_mutation(thread) do + quote do + @desc unquote("report a #{thread}") + field unquote(:"report_#{thread}"), unquote(thread) do + arg(:id, non_null(:id)) + arg(:reason, non_null(:string)) + arg(:attr, :string, default_value: "") + arg(:thread, unquote(:"#{thread}_thread"), default_value: unquote(thread)) + + middleware(M.Authorize, :login) + resolve(&R.CMS.report_article/3) + end + + @desc unquote("undo report a #{thread}") + field unquote(:"undo_report_#{thread}"), unquote(thread) do + arg(:id, non_null(:id)) + arg(:thread, unquote(:"#{thread}_thread"), default_value: unquote(thread)) + + middleware(M.Authorize, :login) + resolve(&R.CMS.undo_report_article/3) + end + end + end end diff --git a/lib/groupher_server_web/schema/cms/cms_types.ex b/lib/groupher_server_web/schema/cms/cms_types.ex index ede2370ac..be0de5a78 100644 --- a/lib/groupher_server_web/schema/cms/cms_types.ex +++ b/lib/groupher_server_web/schema/cms/cms_types.ex @@ -68,6 +68,8 @@ defmodule GroupherServerWeb.Schema.CMS.Types do end) end + field(:is_reported, :boolean) + article_comments_fields() viewer_has_state_fields() # upvoted_count @@ -109,6 +111,7 @@ defmodule GroupherServerWeb.Schema.CMS.Types do field(:finance, :string) field(:scale, :string) + field(:is_reported, :boolean) # comments_count # comments_participators article_comments_fields() @@ -153,6 +156,7 @@ 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 diff --git a/lib/groupher_server_web/schema/cms/mutations/job.ex b/lib/groupher_server_web/schema/cms/mutations/job.ex index 49a99bcc3..16e7c0ce5 100644 --- a/lib/groupher_server_web/schema/cms/mutations/job.ex +++ b/lib/groupher_server_web/schema/cms/mutations/job.ex @@ -76,6 +76,7 @@ defmodule GroupherServerWeb.Schema.CMS.Mutations.Job do article_trash_mutation(:job) article_delete_mutation(:job) article_emotion_mutation(:job) + article_report_mutation(:job) ############# end end diff --git a/lib/groupher_server_web/schema/cms/mutations/post.ex b/lib/groupher_server_web/schema/cms/mutations/post.ex index 8894d01a6..bc6fb1b5d 100644 --- a/lib/groupher_server_web/schema/cms/mutations/post.ex +++ b/lib/groupher_server_web/schema/cms/mutations/post.ex @@ -50,6 +50,7 @@ defmodule GroupherServerWeb.Schema.CMS.Mutations.Post do article_trash_mutation(:post) article_delete_mutation(:post) article_emotion_mutation(:post) + article_report_mutation(:post) ############# end end diff --git a/lib/groupher_server_web/schema/cms/mutations/repo.ex b/lib/groupher_server_web/schema/cms/mutations/repo.ex index 7324cf3b1..30c25be20 100644 --- a/lib/groupher_server_web/schema/cms/mutations/repo.ex +++ b/lib/groupher_server_web/schema/cms/mutations/repo.ex @@ -74,6 +74,7 @@ defmodule GroupherServerWeb.Schema.CMS.Mutations.Repo do article_pin_mutation(:repo) article_trash_mutation(:repo) article_delete_mutation(:repo) + article_report_mutation(:repo) ############# end end diff --git a/priv/repo/migrations/20210511052156_move_is_reported_to_article.exs b/priv/repo/migrations/20210511052156_move_is_reported_to_article.exs new file mode 100644 index 000000000..3f2f69b09 --- /dev/null +++ b/priv/repo/migrations/20210511052156_move_is_reported_to_article.exs @@ -0,0 +1,9 @@ +defmodule GroupherServer.Repo.Migrations.MoveIsReportedToArticle do + use Ecto.Migration + + def change do + alter(table(:cms_posts), do: add(:is_reported, :boolean, default: false)) + alter(table(:cms_jobs), do: add(:is_reported, :boolean, default: false)) + alter(table(:cms_repos), do: add(:is_reported, :boolean, default: false)) + end +end diff --git a/priv/repo/migrations/20210511134719_add_repo_to_report.exs b/priv/repo/migrations/20210511134719_add_repo_to_report.exs new file mode 100644 index 000000000..915bd0175 --- /dev/null +++ b/priv/repo/migrations/20210511134719_add_repo_to_report.exs @@ -0,0 +1,9 @@ +defmodule GroupherServer.Repo.Migrations.AddRepoToReport do + use Ecto.Migration + + def change do + alter table(:abuse_reports) do + add(:repo_id, references(:cms_repos, on_delete: :delete_all)) + end + end +end diff --git a/test/groupher_server/cms/abuse_report_test.exs b/test/groupher_server/cms/abuse_reports/comment_report_test.exs similarity index 70% rename from test/groupher_server/cms/abuse_report_test.exs rename to test/groupher_server/cms/abuse_reports/comment_report_test.exs index 1a5f64ce1..dd920db44 100644 --- a/test/groupher_server/cms/abuse_report_test.exs +++ b/test/groupher_server/cms/abuse_reports/comment_report_test.exs @@ -1,13 +1,10 @@ -defmodule GroupherServer.Test.CMS.AbuseReport do +defmodule GroupherServer.Test.CMS.AbuseReports.CommentReport do @moduledoc false use GroupherServer.TestTools - alias Helper.ORM alias GroupherServer.CMS - alias CMS.AbuseReport - setup do {:ok, user} = db_insert(:user) {:ok, user2} = db_insert(:user) @@ -18,12 +15,13 @@ defmodule GroupherServer.Test.CMS.AbuseReport do end describe "[article comment report/unreport]" do - @tag :wip + @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, 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}) - {:ok, all_reports} = ORM.find_all(AbuseReport, %{page: 1, size: 10}) report = List.first(all_reports.entries) report_cases = report.report_cases @@ -32,14 +30,14 @@ defmodule GroupherServer.Test.CMS.AbuseReport do assert List.first(report_cases).user.login == user.login end - @tag :wip + @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, user) - {:ok, _} = CMS.report_article_comment(comment.id, user2) + {:ok, _} = CMS.report_article_comment(comment.id, "reason", "attr", user) + {:ok, _} = CMS.report_article_comment(comment.id, "reason", "attr", user2) - {:ok, all_reports} = ORM.find_all(AbuseReport, %{page: 1, size: 10}) + {:ok, all_reports} = CMS.list_reports(:article_comment, comment.id, %{page: 1, size: 20}) report = List.first(all_reports.entries) report_cases = report.report_cases @@ -55,8 +53,8 @@ defmodule GroupherServer.Test.CMS.AbuseReport do @tag :wip test "same user can not report a comment twice", ~m(user post)a do {:ok, comment} = CMS.create_article_comment(:post, post.id, "commment", user) - {:ok, comment} = CMS.report_article_comment(comment.id, user) - assert {:error, _} = CMS.report_article_comment(comment.id, user) + {:ok, comment} = CMS.report_article_comment(comment.id, "reason", "attr", user) + assert {:error, _} = CMS.report_article_comment(comment.id, "reason", "attr", user) 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 new file mode 100644 index 000000000..5034335cd --- /dev/null +++ b/test/groupher_server/cms/abuse_reports/job_report_test.exs @@ -0,0 +1,104 @@ +defmodule GroupherServer.Test.CMS.AbuseReports.JobReport 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) + job_attrs = mock_attrs(:job, %{community_id: community.id}) + + {:ok, ~m(user user2 community job_attrs)a} + end + + describe "[article job report/unreport]" do + @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) + + {:ok, all_reports} = CMS.list_reports(:job, job.id, %{page: 1, size: 20}) + + report = List.first(all_reports.entries) + report_cases = report.report_cases + + assert report.job_id == job.id + assert all_reports.total_count == 1 + assert report.report_cases_count == 1 + assert List.first(report_cases).user.login == user.login + + {:ok, job} = ORM.find(CMS.Job, job.id) + assert job.is_reported + assert job.meta.reported_count == 1 + end + + @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) + {:ok, _report} = CMS.undo_report_article(:job, job.id, user) + + {:ok, all_reports} = CMS.list_reports(:job, job.id, %{page: 1, size: 20}) + assert all_reports.total_count == 0 + end + + @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) + {: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}) + 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(:job, job.id, user) + + {:ok, all_reports} = CMS.list_reports(:job, job.id, %{page: 1, size: 20}) + 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 + + @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) + + {: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}) + + 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 + + @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) + + {:ok, _report} = CMS.report_article(:job, job.id, "reason", "attr_info", user) + assert {:error, _report} = CMS.report_article(:job, job.id, "reason", "attr_info", user) + end + end +end diff --git a/test/groupher_server/cms/abuse_reports/post_report_test.exs b/test/groupher_server/cms/abuse_reports/post_report_test.exs new file mode 100644 index 000000000..c2945b192 --- /dev/null +++ b/test/groupher_server/cms/abuse_reports/post_report_test.exs @@ -0,0 +1,104 @@ +defmodule GroupherServer.Test.CMS.AbuseReports.PostReport 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) + post_attrs = mock_attrs(:post, %{community_id: community.id}) + + {:ok, ~m(user user2 community post_attrs)a} + end + + describe "[article post report/unreport]" do + @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) + + {:ok, all_reports} = CMS.list_reports(:post, post.id, %{page: 1, size: 20}) + + report = List.first(all_reports.entries) + report_cases = report.report_cases + + assert report.post_id == post.id + assert all_reports.total_count == 1 + assert report.report_cases_count == 1 + assert List.first(report_cases).user.login == user.login + + {:ok, post} = ORM.find(CMS.Post, post.id) + assert post.is_reported + assert post.meta.reported_count == 1 + end + + @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) + {:ok, _report} = CMS.undo_report_article(:post, post.id, user) + + {:ok, all_reports} = CMS.list_reports(:post, post.id, %{page: 1, size: 20}) + assert all_reports.total_count == 0 + end + + @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) + {: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}) + 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(:post, post.id, user) + + {:ok, all_reports} = CMS.list_reports(:post, post.id, %{page: 1, size: 20}) + 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 + + @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) + + {: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}) + + 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 + + @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) + + {:ok, _report} = CMS.report_article(:post, post.id, "reason", "attr_info", user) + assert {:error, _report} = CMS.report_article(:post, post.id, "reason", "attr_info", user) + end + end +end 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 01a44dae0..df8b9a941 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" @@ -277,7 +277,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do assert not comment.is_reported - {:ok, comment} = CMS.report_article_comment(comment.id, user) + {:ok, comment} = CMS.report_article_comment(comment.id, "reason", "attr", user) {:ok, comment} = ORM.find(ArticleComment, comment.id) assert comment.is_reported end @@ -285,17 +285,43 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do @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, user) + {:ok, _comment} = CMS.report_article_comment(comment.id, "reason", "attr", user) {:ok, comment} = ORM.find(ArticleComment, comment.id) assert comment.is_reported - {:ok, _comment} = CMS.unreport_article_comment(comment.id, user) + {:ok, _comment} = CMS.undo_report_article_comment(comment.id, user) {:ok, comment} = ORM.find(ArticleComment, comment.id) assert not comment.is_reported end - @tag :wip + @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) + + {: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}) + 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(:article_comment, comment.id, user) + + {:ok, all_reports} = CMS.list_reports(:article_comment, comment.id, %{page: 1, size: 20}) + 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 + + @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) @@ -304,7 +330,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do Enum.reduce(1..(@report_threshold_for_fold - 1), [], fn _, _acc -> {:ok, user} = db_insert(:user) - {:ok, _comment} = CMS.report_article_comment(comment.id, user) + {:ok, _comment} = CMS.report_article_comment(comment.id, "reason", "attr", user) end) {:ok, comment} = ORM.find(ArticleComment, comment.id) @@ -321,7 +347,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do Enum.reduce(1..(@report_threshold_for_fold + 1), [], fn _, _acc -> {:ok, user} = db_insert(:user) - {:ok, _comment} = CMS.report_article_comment(comment.id, user) + {:ok, _comment} = CMS.report_article_comment(comment.id, "reason", "attr", user) end) {:ok, comment} = ORM.find(ArticleComment, comment.id) @@ -435,7 +461,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do assert paged_comments.total_count == total_count end - @tag :wip + @tag :wip2 test "paged article comments should not contains folded and repoted comments", ~m(user job)a do total_count = 15 @@ -461,9 +487,9 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment 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, user) - {:ok, _comment} = CMS.report_article_comment(random_comment_5.id, user) - {:ok, _comment} = CMS.report_article_comment(random_comment_6.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) @@ -520,7 +546,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do 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, user) + CMS.report_article_comment(comment.id, "reason", "attr", user) acc ++ [comment] end) @@ -543,7 +569,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 @@ -568,7 +594,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) @@ -586,7 +612,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 66fed7c8d..7d48c0a64 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" @@ -277,24 +277,50 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do assert not comment.is_reported - {:ok, comment} = CMS.report_article_comment(comment.id, user) + {:ok, comment} = CMS.report_article_comment(comment.id, "reason", "attr", user) {:ok, comment} = ORM.find(ArticleComment, comment.id) assert comment.is_reported end - @tag :wip + @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, user) + {:ok, _comment} = CMS.report_article_comment(comment.id, "reason", "attr", user) {:ok, comment} = ORM.find(ArticleComment, comment.id) assert comment.is_reported - {:ok, _comment} = CMS.unreport_article_comment(comment.id, user) + {: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 + 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) + {: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}) + 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(:article_comment, comment.id, user) + + {:ok, all_reports} = CMS.list_reports(:article_comment, comment.id, %{page: 1, size: 20}) + 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 + @tag :wip test "report user < @report_threshold_for_fold will not fold comment", ~m(user post)a do {:ok, comment} = CMS.create_article_comment(:post, post.id, "commment", user) @@ -304,7 +330,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do Enum.reduce(1..(@report_threshold_for_fold - 1), [], fn _, _acc -> {:ok, user} = db_insert(:user) - {:ok, _comment} = CMS.report_article_comment(comment.id, user) + {:ok, _comment} = CMS.report_article_comment(comment.id, "reason", "attr", user) end) {:ok, comment} = ORM.find(ArticleComment, comment.id) @@ -321,7 +347,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do Enum.reduce(1..(@report_threshold_for_fold + 1), [], fn _, _acc -> {:ok, user} = db_insert(:user) - {:ok, _comment} = CMS.report_article_comment(comment.id, user) + {:ok, _comment} = CMS.report_article_comment(comment.id, "reason", "attr", user) end) {:ok, comment} = ORM.find(ArticleComment, comment.id) @@ -435,7 +461,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 @@ -461,9 +487,9 @@ 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, user) - {:ok, _comment} = CMS.report_article_comment(random_comment_5.id, user) - {:ok, _comment} = CMS.report_article_comment(random_comment_6.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) @@ -520,7 +546,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do 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, user) + CMS.report_article_comment(comment.id, "reason", "attr", user) acc ++ [comment] end) @@ -543,7 +569,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 @@ -568,7 +594,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) @@ -586,7 +612,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 new file mode 100644 index 000000000..310226193 --- /dev/null +++ b/test/groupher_server_web/mutation/cms/articles/job_report_test.exs @@ -0,0 +1,67 @@ +defmodule GroupherServer.Test.Mutation.Articles.JobReport do + use GroupherServer.TestTools + + alias GroupherServer.CMS + + setup do + {:ok, user} = db_insert(:user) + {:ok, community} = db_insert(:community) + + job_attrs = mock_attrs(:job, %{community_id: community.id}) + + guest_conn = simu_conn(:guest) + user_conn = simu_conn(:user) + owner_conn = simu_conn(:user, user) + + {:ok, ~m(user_conn user guest_conn owner_conn community job_attrs)a} + end + + describe "[job report/undo_report]" do + @report_query """ + mutation($id: ID!, $reason: String!, $attr: String) { + reportJob(id: $id, reason: $reason, attr: $attr) { + id + title + isReported + } + } + """ + @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) + + variables = %{id: job.id, reason: "reason"} + article = user_conn |> mutation_result(@report_query, variables, "reportJob") + + assert article["isReported"] + assert article["id"] == to_string(job.id) + end + + @undo_report_query """ + mutation($id: ID!) { + undoReportJob(id: $id) { + id + title + isReported + } + } + """ + @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) + + variables = %{id: job.id, reason: "reason"} + article = user_conn |> mutation_result(@report_query, variables, "reportJob") + + assert 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 +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 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 new file mode 100644 index 000000000..876b38f16 --- /dev/null +++ b/test/groupher_server_web/mutation/cms/articles/post_report_test.exs @@ -0,0 +1,67 @@ +defmodule GroupherServer.Test.Mutation.Articles.PostReport do + use GroupherServer.TestTools + + alias GroupherServer.CMS + + setup do + {:ok, user} = db_insert(:user) + {:ok, community} = db_insert(:community) + + post_attrs = mock_attrs(:post, %{community_id: community.id}) + + guest_conn = simu_conn(:guest) + user_conn = simu_conn(:user) + owner_conn = simu_conn(:user, user) + + {:ok, ~m(user_conn user guest_conn owner_conn community post_attrs)a} + end + + describe "[post report/undo_report]" do + @report_query """ + mutation($id: ID!, $reason: String!, $attr: String) { + reportPost(id: $id, reason: $reason, attr: $attr) { + id + title + isReported + } + } + """ + @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) + + variables = %{id: post.id, reason: "reason"} + article = user_conn |> mutation_result(@report_query, variables, "reportPost") + + assert article["isReported"] + assert article["id"] == to_string(post.id) + end + + @undo_report_query """ + mutation($id: ID!) { + undoReportPost(id: $id) { + id + title + isReported + } + } + """ + @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) + + variables = %{id: post.id, reason: "reason"} + article = user_conn |> mutation_result(@report_query, variables, "reportPost") + + assert 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 +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 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 new file mode 100644 index 000000000..2802f7a22 --- /dev/null +++ b/test/groupher_server_web/mutation/cms/articles/repo_report_test.exs @@ -0,0 +1,67 @@ +defmodule GroupherServer.Test.Mutation.Articles.RepoReport do + use GroupherServer.TestTools + + alias GroupherServer.CMS + + setup do + {:ok, user} = db_insert(:user) + {:ok, community} = db_insert(:community) + + repo_attrs = mock_attrs(:repo, %{community_id: community.id}) + + guest_conn = simu_conn(:guest) + user_conn = simu_conn(:user) + owner_conn = simu_conn(:user, user) + + {:ok, ~m(user_conn user guest_conn owner_conn community repo_attrs)a} + end + + describe "[repo report/undo_report]" do + @report_query """ + mutation($id: ID!, $reason: String!, $attr: String) { + reportRepo(id: $id, reason: $reason, attr: $attr) { + id + title + isReported + } + } + """ + @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) + + variables = %{id: repo.id, reason: "reason"} + article = user_conn |> mutation_result(@report_query, variables, "reportRepo") + + assert article["isReported"] + assert article["id"] == to_string(repo.id) + end + + @undo_report_query """ + mutation($id: ID!) { + undoReportRepo(id: $id) { + id + title + isReported + } + } + """ + @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) + + variables = %{id: repo.id, reason: "reason"} + article = user_conn |> mutation_result(@report_query, variables, "reportRepo") + + assert 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 +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 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/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)