|
| 1 | +defmodule GroupherServer.Test.CMS.AbuseReports.JobReport do |
| 2 | + @moduledoc false |
| 3 | + |
| 4 | + use GroupherServer.TestTools |
| 5 | + |
| 6 | + alias Helper.ORM |
| 7 | + alias GroupherServer.CMS |
| 8 | + |
| 9 | + setup do |
| 10 | + {:ok, user} = db_insert(:user) |
| 11 | + {:ok, user2} = db_insert(:user) |
| 12 | + |
| 13 | + {:ok, community} = db_insert(:community) |
| 14 | + job_attrs = mock_attrs(:job, %{community_id: community.id}) |
| 15 | + |
| 16 | + {:ok, ~m(user user2 community job_attrs)a} |
| 17 | + end |
| 18 | + |
| 19 | + describe "[article job report/unreport]" do |
| 20 | + @tag :wip2 |
| 21 | + test "report a job should have a abuse report record", ~m(community user job_attrs)a do |
| 22 | + {:ok, job} = CMS.create_content(community, :job, job_attrs, user) |
| 23 | + {:ok, _report} = CMS.report_article(:job, job.id, "reason", "attr_info", user) |
| 24 | + |
| 25 | + {:ok, all_reports} = CMS.list_reports(:job, job.id, %{page: 1, size: 20}) |
| 26 | + |
| 27 | + report = List.first(all_reports.entries) |
| 28 | + report_cases = report.report_cases |
| 29 | + |
| 30 | + assert report.job_id == job.id |
| 31 | + assert all_reports.total_count == 1 |
| 32 | + assert report.report_cases_count == 1 |
| 33 | + assert List.first(report_cases).user.login == user.login |
| 34 | + |
| 35 | + {:ok, job} = ORM.find(CMS.Job, job.id) |
| 36 | + assert job.is_reported |
| 37 | + assert job.meta.reported_count == 1 |
| 38 | + end |
| 39 | + |
| 40 | + @tag :wip2 |
| 41 | + test "can undo a report", ~m(community user job_attrs)a do |
| 42 | + {:ok, job} = CMS.create_content(community, :job, job_attrs, user) |
| 43 | + {:ok, _report} = CMS.report_article(:job, job.id, "reason", "attr_info", user) |
| 44 | + {:ok, _report} = CMS.undo_report_article(:job, job.id, user) |
| 45 | + |
| 46 | + {:ok, all_reports} = CMS.list_reports(:job, job.id, %{page: 1, size: 20}) |
| 47 | + assert all_reports.total_count == 0 |
| 48 | + end |
| 49 | + |
| 50 | + @tag :wip2 |
| 51 | + test "can undo a report with other user report it too", |
| 52 | + ~m(community user user2 job_attrs)a do |
| 53 | + {:ok, job} = CMS.create_content(community, :job, job_attrs, user) |
| 54 | + {:ok, _report} = CMS.report_article(:job, job.id, "reason", "attr_info", user) |
| 55 | + {:ok, _report} = CMS.report_article(:job, job.id, "reason", "attr_info", user2) |
| 56 | + |
| 57 | + {:ok, all_reports} = CMS.list_reports(:job, job.id, %{page: 1, size: 20}) |
| 58 | + assert all_reports.total_count == 1 |
| 59 | + |
| 60 | + report = all_reports.entries |> List.first() |
| 61 | + assert report.report_cases |> length == 2 |
| 62 | + assert Enum.any?(report.report_cases, &(&1.user.login == user.login)) |
| 63 | + assert Enum.any?(report.report_cases, &(&1.user.login == user2.login)) |
| 64 | + |
| 65 | + {:ok, _report} = CMS.undo_report_article(:job, job.id, user) |
| 66 | + |
| 67 | + {:ok, all_reports} = CMS.list_reports(:job, job.id, %{page: 1, size: 20}) |
| 68 | + assert all_reports.total_count == 1 |
| 69 | + |
| 70 | + report = all_reports.entries |> List.first() |
| 71 | + assert report.report_cases |> length == 1 |
| 72 | + assert Enum.any?(report.report_cases, &(&1.user.login == user2.login)) |
| 73 | + end |
| 74 | + |
| 75 | + @tag :wip2 |
| 76 | + test "different user report a comment should have same report with different report cases", |
| 77 | + ~m(community user user2 job_attrs)a do |
| 78 | + {:ok, job} = CMS.create_content(community, :job, job_attrs, user) |
| 79 | + |
| 80 | + {:ok, _report} = CMS.report_article(:job, job.id, "reason", "attr_info", user) |
| 81 | + {:ok, _report} = CMS.report_article(:job, job.id, "reason2", "attr_info 2", user2) |
| 82 | + |
| 83 | + {:ok, all_reports} = CMS.list_reports(:job, job.id, %{page: 1, size: 20}) |
| 84 | + |
| 85 | + report = List.first(all_reports.entries) |
| 86 | + report_cases = report.report_cases |
| 87 | + |
| 88 | + assert all_reports.total_count == 1 |
| 89 | + assert length(report_cases) == 2 |
| 90 | + assert report.report_cases_count == 2 |
| 91 | + |
| 92 | + assert List.first(report_cases).user.login == user.login |
| 93 | + assert List.last(report_cases).user.login == user2.login |
| 94 | + end |
| 95 | + |
| 96 | + @tag :wip2 |
| 97 | + test "same user can not report a comment twice", ~m(community job_attrs user)a do |
| 98 | + {:ok, job} = CMS.create_content(community, :job, job_attrs, user) |
| 99 | + |
| 100 | + {:ok, _report} = CMS.report_article(:job, job.id, "reason", "attr_info", user) |
| 101 | + assert {:error, _report} = CMS.report_article(:job, job.id, "reason", "attr_info", user) |
| 102 | + end |
| 103 | + end |
| 104 | +end |
0 commit comments