2020-01-26 20:11:16 +00:00
|
|
|
defmodule Mobilizon.GraphQL.API.ReportTest do
|
2019-07-23 11:49:22 +00:00
|
|
|
use Mobilizon.DataCase
|
|
|
|
|
2019-09-12 23:35:03 +00:00
|
|
|
import Mobilizon.Factory
|
|
|
|
|
2019-07-23 11:49:22 +00:00
|
|
|
alias Mobilizon.Actors.Actor
|
2020-07-09 15:24:28 +00:00
|
|
|
alias Mobilizon.Discussions.Comment
|
2020-02-18 07:57:00 +00:00
|
|
|
alias Mobilizon.Events.Event
|
2019-09-22 14:26:23 +00:00
|
|
|
alias Mobilizon.Reports.{Note, Report}
|
2020-06-24 14:33:59 +00:00
|
|
|
alias Mobilizon.Service.Formatter.HTML
|
2019-07-23 11:49:22 +00:00
|
|
|
alias Mobilizon.Users
|
2019-09-12 23:35:03 +00:00
|
|
|
alias Mobilizon.Users.User
|
2019-07-23 11:49:22 +00:00
|
|
|
|
2020-01-26 20:11:16 +00:00
|
|
|
alias Mobilizon.GraphQL.API.Reports
|
2020-01-22 01:14:42 +00:00
|
|
|
|
2020-01-26 20:11:16 +00:00
|
|
|
alias Mobilizon.Federation.ActivityPub.{Activity, Relay}
|
2019-07-23 11:49:22 +00:00
|
|
|
|
|
|
|
describe "reports" do
|
|
|
|
test "creates a report on a event" do
|
2020-01-22 01:14:42 +00:00
|
|
|
%Actor{url: relay_reporter_url} = Relay.get_actor()
|
2019-12-03 10:29:51 +00:00
|
|
|
%Actor{id: reporter_id} = insert(:actor)
|
2019-07-23 11:49:22 +00:00
|
|
|
%Actor{id: reported_id, url: reported_url} = reported = insert(:actor)
|
|
|
|
|
|
|
|
%Event{id: event_id, url: event_url} = _event = insert(:event, organizer_actor: reported)
|
|
|
|
|
|
|
|
comment = "This is not acceptable"
|
|
|
|
|
|
|
|
assert {:ok, %Activity{} = flag_activity, _} =
|
|
|
|
Reports.report(%{
|
2019-11-15 17:36:47 +00:00
|
|
|
reporter_id: reporter_id,
|
|
|
|
reported_id: reported_id,
|
2019-09-09 07:31:08 +00:00
|
|
|
content: comment,
|
2019-07-23 11:49:22 +00:00
|
|
|
event_id: event_id,
|
2019-11-15 17:36:47 +00:00
|
|
|
comments_ids: [],
|
2019-12-03 10:29:51 +00:00
|
|
|
forward: false
|
2019-07-23 11:49:22 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
assert %Activity{
|
2019-12-03 10:29:51 +00:00
|
|
|
actor: ^relay_reporter_url,
|
2019-07-23 11:49:22 +00:00
|
|
|
data: %{
|
|
|
|
"type" => "Flag",
|
|
|
|
"cc" => [],
|
|
|
|
"content" => ^comment,
|
2019-11-15 17:36:47 +00:00
|
|
|
"object" => [^reported_url, ^event_url]
|
2019-07-23 11:49:22 +00:00
|
|
|
}
|
|
|
|
} = flag_activity
|
|
|
|
end
|
|
|
|
|
|
|
|
test "creates a report on several comments" do
|
2020-01-22 01:14:42 +00:00
|
|
|
%Actor{url: relay_reporter_url} = Relay.get_actor()
|
2019-12-03 10:29:51 +00:00
|
|
|
%Actor{id: reporter_id} = insert(:actor)
|
2019-07-23 11:49:22 +00:00
|
|
|
%Actor{id: reported_id, url: reported_url} = reported = insert(:actor)
|
|
|
|
|
|
|
|
%Comment{id: comment_1_id, url: comment_1_url} =
|
|
|
|
_comment_1 = insert(:comment, actor: reported)
|
|
|
|
|
|
|
|
%Comment{id: comment_2_id, url: comment_2_url} =
|
|
|
|
_comment_2 = insert(:comment, actor: reported)
|
|
|
|
|
|
|
|
comment = "This is really not acceptable"
|
|
|
|
|
|
|
|
assert {:ok, %Activity{} = flag_activity, _} =
|
|
|
|
Reports.report(%{
|
2019-11-15 17:36:47 +00:00
|
|
|
reporter_id: reporter_id,
|
|
|
|
reported_id: reported_id,
|
2019-09-09 07:31:08 +00:00
|
|
|
content: comment,
|
2019-07-23 11:49:22 +00:00
|
|
|
event_id: nil,
|
|
|
|
comments_ids: [comment_1_id, comment_2_id]
|
|
|
|
})
|
|
|
|
|
|
|
|
assert %Activity{
|
2019-12-03 10:29:51 +00:00
|
|
|
actor: ^relay_reporter_url,
|
2019-07-23 11:49:22 +00:00
|
|
|
data: %{
|
|
|
|
"type" => "Flag",
|
|
|
|
"content" => ^comment,
|
|
|
|
"object" => [^reported_url, ^comment_1_url, ^comment_2_url],
|
2019-12-03 10:29:51 +00:00
|
|
|
"to" => [],
|
2019-11-15 17:36:47 +00:00
|
|
|
"cc" => [],
|
2019-12-03 10:29:51 +00:00
|
|
|
"actor" => ^relay_reporter_url
|
2019-07-23 11:49:22 +00:00
|
|
|
}
|
|
|
|
} = flag_activity
|
|
|
|
end
|
|
|
|
|
|
|
|
test "creates a report that gets federated" do
|
2020-01-22 01:14:42 +00:00
|
|
|
%Actor{url: relay_reporter_url} = Relay.get_actor()
|
2019-12-03 10:29:51 +00:00
|
|
|
%Actor{id: reporter_id} = insert(:actor)
|
2019-07-23 11:49:22 +00:00
|
|
|
%Actor{id: reported_id, url: reported_url} = reported = insert(:actor)
|
|
|
|
|
|
|
|
%Comment{id: comment_1_id, url: comment_1_url} =
|
|
|
|
_comment_1 = insert(:comment, actor: reported)
|
|
|
|
|
|
|
|
%Comment{id: comment_2_id, url: comment_2_url} =
|
|
|
|
_comment_2 = insert(:comment, actor: reported)
|
|
|
|
|
|
|
|
comment = "This is really not acceptable, remote admin I don't know"
|
2020-06-24 14:33:59 +00:00
|
|
|
encoded_comment = HTML.strip_tags(comment)
|
2019-07-23 11:49:22 +00:00
|
|
|
|
|
|
|
assert {:ok, %Activity{} = flag_activity, _} =
|
|
|
|
Reports.report(%{
|
2019-11-15 17:36:47 +00:00
|
|
|
reporter_id: reporter_id,
|
|
|
|
reported_id: reported_id,
|
2019-09-09 07:31:08 +00:00
|
|
|
content: comment,
|
2019-07-23 11:49:22 +00:00
|
|
|
event_id: nil,
|
|
|
|
comments_ids: [comment_1_id, comment_2_id],
|
2019-12-03 10:29:51 +00:00
|
|
|
forward: true
|
2019-07-23 11:49:22 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
assert %Activity{
|
2019-12-03 10:29:51 +00:00
|
|
|
actor: ^relay_reporter_url,
|
2019-07-23 11:49:22 +00:00
|
|
|
data: %{
|
|
|
|
"type" => "Flag",
|
2019-12-03 10:29:51 +00:00
|
|
|
"actor" => ^relay_reporter_url,
|
2019-07-23 11:49:22 +00:00
|
|
|
"cc" => [^reported_url],
|
|
|
|
"content" => ^encoded_comment,
|
|
|
|
"object" => [^reported_url, ^comment_1_url, ^comment_2_url],
|
2019-12-03 10:29:51 +00:00
|
|
|
"to" => []
|
2019-11-15 17:36:47 +00:00
|
|
|
},
|
|
|
|
local: true,
|
2019-12-03 10:29:51 +00:00
|
|
|
recipients: [^reported_url]
|
2019-07-23 11:49:22 +00:00
|
|
|
} = flag_activity
|
|
|
|
end
|
|
|
|
|
|
|
|
test "updates report state" do
|
|
|
|
%Actor{id: reporter_id} = insert(:actor)
|
|
|
|
%Actor{id: reported_id} = reported = insert(:actor)
|
|
|
|
|
|
|
|
%Comment{id: comment_1_id} = _comment_1 = insert(:comment, actor: reported)
|
|
|
|
|
|
|
|
assert {:ok, %Activity{} = flag_activity, %Report{id: report_id} = _report} =
|
|
|
|
Reports.report(%{
|
2019-11-15 17:36:47 +00:00
|
|
|
reporter_id: reporter_id,
|
|
|
|
reported_id: reported_id,
|
2019-09-09 07:31:08 +00:00
|
|
|
content: "This is not a nice thing",
|
2019-07-23 11:49:22 +00:00
|
|
|
event_id: nil,
|
|
|
|
comments_ids: [comment_1_id],
|
|
|
|
forward: true
|
|
|
|
})
|
|
|
|
|
|
|
|
%Report{} = report = Mobilizon.Reports.get_report(report_id)
|
|
|
|
|
|
|
|
%User{} = manager_user = insert(:user, role: :moderator)
|
|
|
|
%Actor{} = manager_actor = insert(:actor, user: manager_user)
|
|
|
|
|
|
|
|
{:ok, new_report} = Reports.update_report_status(manager_actor, report, :resolved)
|
|
|
|
|
|
|
|
assert new_report.status == :resolved
|
|
|
|
end
|
|
|
|
|
|
|
|
test "updates report state with not acceptable status" do
|
|
|
|
%Actor{id: reporter_id} = insert(:actor)
|
|
|
|
%Actor{id: reported_id} = reported = insert(:actor)
|
|
|
|
|
|
|
|
%Comment{id: comment_1_id} = _comment_1 = insert(:comment, actor: reported)
|
|
|
|
|
|
|
|
assert {:ok, %Activity{} = flag_activity, %Report{id: report_id} = _report} =
|
|
|
|
Reports.report(%{
|
2019-11-15 17:36:47 +00:00
|
|
|
reporter_id: reporter_id,
|
|
|
|
reported_id: reported_id,
|
2019-09-09 07:31:08 +00:00
|
|
|
content: "This is not a nice thing",
|
2019-07-23 11:49:22 +00:00
|
|
|
event_id: nil,
|
|
|
|
comments_ids: [comment_1_id],
|
|
|
|
forward: true
|
|
|
|
})
|
|
|
|
|
|
|
|
%Report{} = report = Mobilizon.Reports.get_report(report_id)
|
|
|
|
|
|
|
|
%Actor{} = manager_actor = insert(:actor)
|
|
|
|
|
|
|
|
{:error, "Unsupported state"} = Reports.update_report_status(manager_actor, report, :test)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "note reports" do
|
|
|
|
test "creates a note on a report" do
|
|
|
|
%User{} = moderator_user = insert(:user, role: :moderator)
|
|
|
|
%Actor{} = moderator_actor = insert(:actor, user: moderator_user)
|
|
|
|
%Report{} = report = insert(:report)
|
|
|
|
|
|
|
|
assert {:ok, %Note{} = _note} =
|
|
|
|
Reports.create_report_note(
|
|
|
|
report,
|
|
|
|
moderator_actor,
|
|
|
|
"I'll take care of this later today"
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
test "doesn't create a note on a report when not moderator" do
|
|
|
|
%User{} = user = insert(:user)
|
|
|
|
%Actor{} = actor = insert(:actor, user: user)
|
|
|
|
%Report{} = report = insert(:report)
|
|
|
|
|
|
|
|
assert {:error,
|
|
|
|
"You need to be a moderator or an administrator to create a note on a report"} =
|
|
|
|
Reports.create_report_note(report, actor, "I'll take care of this later today")
|
|
|
|
end
|
|
|
|
|
|
|
|
test "deletes a note on a report" do
|
|
|
|
%User{} = moderator_user = insert(:user, role: :moderator)
|
|
|
|
%Actor{} = moderator_actor = insert(:actor, user: moderator_user)
|
|
|
|
%Note{} = note = insert(:report_note, moderator: moderator_actor)
|
|
|
|
assert {:ok, %Note{}} = Reports.delete_report_note(note, moderator_actor)
|
|
|
|
end
|
|
|
|
|
|
|
|
test "deletes a note on a report with a different moderator actor" do
|
|
|
|
%Note{} = note = insert(:report_note)
|
|
|
|
|
|
|
|
%User{} = other_moderator_user = insert(:user, role: :moderator)
|
|
|
|
%Actor{} = other_moderator_actor = insert(:actor, user: other_moderator_user)
|
|
|
|
|
|
|
|
assert {:error, "You can only remove your own notes"} =
|
|
|
|
Reports.delete_report_note(note, other_moderator_actor)
|
|
|
|
end
|
|
|
|
|
|
|
|
test "try deletes a note on a report with a actor not moderator anymore" do
|
|
|
|
%User{} = moderator_user = insert(:user, role: :moderator)
|
|
|
|
%Actor{} = moderator_actor = insert(:actor, user: moderator_user)
|
|
|
|
%Note{} = note = insert(:report_note, moderator: moderator_actor)
|
|
|
|
|
|
|
|
Users.update_user(moderator_user, %{role: :user})
|
|
|
|
|
|
|
|
assert {:error,
|
|
|
|
"You need to be a moderator or an administrator to create a note on a report"} =
|
|
|
|
Reports.delete_report_note(note, moderator_actor)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|