add tests
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
parent
c8fc411b77
commit
266ed48d93
3 changed files with 56 additions and 16 deletions
|
@ -56,22 +56,6 @@ def post_chat_message(%User{} = user, %User{} = recipient, content, opts \\ [])
|
|||
end
|
||||
end
|
||||
|
||||
def assign_report_to_account(activity_ids, user) when is_list(activity_ids) do
|
||||
case Utils.assign_report_to_account(activity_ids, user) do
|
||||
:ok -> {:ok, activity_ids}
|
||||
_ -> {:error, dgettext("errors", "Could not assign account")}
|
||||
end
|
||||
end
|
||||
|
||||
def assign_report_to_account(activity_id, user) do
|
||||
with %Activity{} = activity <- Activity.get_by_id(activity_id) do
|
||||
Utils.assign_report_to_account(activity, user)
|
||||
else
|
||||
nil -> {:error, :not_found}
|
||||
_ -> {:error, dgettext("errors", "Could not assign account")}
|
||||
end
|
||||
end
|
||||
|
||||
defp format_chat_content(nil), do: nil
|
||||
|
||||
defp format_chat_content(content) do
|
||||
|
@ -556,6 +540,22 @@ def update_report_state(activity_id, state) do
|
|||
end
|
||||
end
|
||||
|
||||
def assign_report_to_account(activity_ids, user) when is_list(activity_ids) do
|
||||
case Utils.assign_report_to_account(activity_ids, user) do
|
||||
:ok -> {:ok, activity_ids}
|
||||
_ -> {:error, dgettext("errors", "Could not assign account")}
|
||||
end
|
||||
end
|
||||
|
||||
def assign_report_to_account(activity_id, user) do
|
||||
with %Activity{} = activity <- Activity.get_by_id(activity_id) do
|
||||
Utils.assign_report_to_account(activity, user)
|
||||
else
|
||||
nil -> {:error, :not_found}
|
||||
_ -> {:error, dgettext("errors", "Could not assign account")}
|
||||
end
|
||||
end
|
||||
|
||||
def update_activity_scope(activity_id, opts \\ %{}) do
|
||||
with %Activity{} = activity <- Activity.get_by_id_with_object(activity_id),
|
||||
{:ok, activity} <- toggle_sensitive(activity, opts) do
|
||||
|
|
|
@ -559,4 +559,21 @@ test "returns the data or an emtpy list" do
|
|||
assert Utils.get_cached_emoji_reactions(object) == []
|
||||
end
|
||||
end
|
||||
|
||||
describe "assign_report_to_account/2" do
|
||||
test "assigns report to an account" do
|
||||
reporter = insert(:user)
|
||||
target_account = insert(:user)
|
||||
%{id: assigned_id} = assigned = insert(:user)
|
||||
context = Utils.generate_context_id()
|
||||
|
||||
target_ap_id = target_account.ap_id
|
||||
|
||||
{:ok, report} = CommonAPI.report(reporter, %{account_id: target_account.id})
|
||||
|
||||
{:ok, report} = Utils.assign_report_to_account(report, assigned_id)
|
||||
|
||||
assert %{data: %{"assigned_account" => ^assigned_id}} = report
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1226,6 +1226,29 @@ test "updates state of multiple reports" do
|
|||
assert first_report.data["state"] == "resolved"
|
||||
assert second_report.data["state"] == "resolved"
|
||||
end
|
||||
|
||||
test "assigns report to an account" do
|
||||
[reporter, target_user] = insert_pair(:user)
|
||||
%{id: assigned} = insert(:user)
|
||||
|
||||
{:ok, %Activity{id: report_id}} = CommonAPI.report(reporter, %{account_id: target_user.id})
|
||||
|
||||
{:ok, activity} = CommonAPI.assign_report_to_account(report_id, assigned)
|
||||
|
||||
assert %{data: %{"assigned_account" => ^assigned}} = activity
|
||||
end
|
||||
|
||||
test "unassigns report from account" do
|
||||
[reporter, target_user] = insert_pair(:user)
|
||||
%{id: assigned} = insert(:user)
|
||||
|
||||
{:ok, %Activity{id: report_id}} = CommonAPI.report(reporter, %{account_id: target_user.id})
|
||||
|
||||
CommonAPI.assign_report_to_account(report_id, assigned)
|
||||
{:ok, activity} = CommonAPI.assign_report_to_account(report_id, nil)
|
||||
|
||||
refute Map.has_key?(activity.data, "assigned_account")
|
||||
end
|
||||
end
|
||||
|
||||
describe "reblog muting" do
|
||||
|
|
Loading…
Reference in a new issue