2020-01-23 00:55:07 +01:00
|
|
|
defmodule Mobilizon.Service.Admin.ActionLogTest do
|
2019-07-23 13:49:22 +02:00
|
|
|
@moduledoc """
|
2020-01-23 00:55:07 +01:00
|
|
|
Test the ActionLog module.
|
2019-07-23 13:49:22 +02:00
|
|
|
"""
|
2019-09-22 16:26:23 +02:00
|
|
|
|
2019-07-23 13:49:22 +02:00
|
|
|
use Mobilizon.DataCase
|
2019-09-22 16:26:23 +02:00
|
|
|
|
|
|
|
import Mobilizon.Factory
|
|
|
|
|
2020-01-23 21:59:50 +01:00
|
|
|
alias Mobilizon.Admin
|
2019-07-23 13:49:22 +02:00
|
|
|
alias Mobilizon.Admin.ActionLog
|
2019-09-22 16:26:23 +02:00
|
|
|
alias Mobilizon.Reports.{Note, Report}
|
2019-07-23 13:49:22 +02:00
|
|
|
|
|
|
|
setup do
|
|
|
|
moderator_user = insert(:user, role: :moderator)
|
|
|
|
moderator_actor = insert(:actor, user: moderator_user)
|
|
|
|
{:ok, moderator: moderator_actor}
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "action_log_creation" do
|
|
|
|
test "log a report update", %{moderator: moderator} do
|
2021-09-24 16:46:42 +02:00
|
|
|
%Report{id: report_id} = report = insert(:report)
|
2019-07-23 13:49:22 +02:00
|
|
|
|
|
|
|
assert {:ok,
|
|
|
|
%ActionLog{
|
|
|
|
target_type: "Elixir.Mobilizon.Reports.Report",
|
2021-09-24 16:46:42 +02:00
|
|
|
target_id: found_report_id,
|
2019-09-09 09:31:08 +02:00
|
|
|
action: :update,
|
2021-09-24 16:46:42 +02:00
|
|
|
actor: _moderator
|
2020-01-23 21:59:50 +01:00
|
|
|
}} = Admin.log_action(moderator, "update", report)
|
2021-09-24 16:46:42 +02:00
|
|
|
|
|
|
|
assert found_report_id == report_id
|
2019-07-23 13:49:22 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
test "log the creation of a report note", %{moderator: moderator} do
|
|
|
|
%Report{} = report = insert(:report)
|
2021-09-24 16:46:42 +02:00
|
|
|
%Note{id: note_id} = report = insert(:report_note, report: report)
|
2019-07-23 13:49:22 +02:00
|
|
|
|
|
|
|
assert {:ok,
|
|
|
|
%ActionLog{
|
|
|
|
target_type: "Elixir.Mobilizon.Reports.Note",
|
2021-09-24 16:46:42 +02:00
|
|
|
target_id: found_note_id,
|
2019-09-09 09:31:08 +02:00
|
|
|
action: :create,
|
2021-09-24 16:46:42 +02:00
|
|
|
actor: _moderator
|
2020-01-23 21:59:50 +01:00
|
|
|
}} = Admin.log_action(moderator, "create", report)
|
2021-09-24 16:46:42 +02:00
|
|
|
|
|
|
|
assert found_note_id == note_id
|
2019-07-23 13:49:22 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|