X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=test%2Fweb%2Fadmin_api%2Fviews%2Freport_view_test.exs;h=a0c6eab3c546f395af031c611780e5f0ba6f45e0;hb=3ecf131511afc1fc366be6402ca94cf0e6c30e11;hp=52774c88954d0e7fb3725fe629407ddcf7878b58;hpb=e943905bd7e256555a66b54d956013aa499d08d6;p=akkoma diff --git a/test/web/admin_api/views/report_view_test.exs b/test/web/admin_api/views/report_view_test.exs index 52774c889..a0c6eab3c 100644 --- a/test/web/admin_api/views/report_view_test.exs +++ b/test/web/admin_api/views/report_view_test.exs @@ -5,10 +5,11 @@ defmodule Pleroma.Web.AdminAPI.ReportViewTest do use Pleroma.DataCase import Pleroma.Factory + alias Pleroma.Web.AdminAPI.Report alias Pleroma.Web.AdminAPI.ReportView + alias Pleroma.Web.CommonAPI alias Pleroma.Web.MastodonAPI.AccountView alias Pleroma.Web.MastodonAPI.StatusView - alias Pleroma.Web.CommonAPI test "renders a report" do user = insert(:user) @@ -17,16 +18,25 @@ defmodule Pleroma.Web.AdminAPI.ReportViewTest do {:ok, activity} = CommonAPI.report(user, %{"account_id" => other_user.id}) expected = %{ - content: "", - actor: AccountView.render("account.json", %{user: user}), - account: AccountView.render("account.json", %{user: other_user}), + content: nil, + actor: + Map.merge( + AccountView.render("show.json", %{user: user}), + Pleroma.Web.AdminAPI.AccountView.render("show.json", %{user: user}) + ), + account: + Map.merge( + AccountView.render("show.json", %{user: other_user}), + Pleroma.Web.AdminAPI.AccountView.render("show.json", %{user: other_user}) + ), statuses: [], + notes: [], state: "open", id: activity.id } result = - ReportView.render("show.json", %{report: activity}) + ReportView.render("show.json", Report.extract_report_info(activity)) |> Map.delete(:created_at) assert result == expected @@ -40,17 +50,28 @@ defmodule Pleroma.Web.AdminAPI.ReportViewTest do {:ok, report_activity} = CommonAPI.report(user, %{"account_id" => other_user.id, "status_ids" => [activity.id]}) + other_user = Pleroma.User.get_by_id(other_user.id) + expected = %{ - content: "", - actor: AccountView.render("account.json", %{user: user}), - account: AccountView.render("account.json", %{user: other_user}), - statuses: [StatusView.render("status.json", %{activity: activity})], + content: nil, + actor: + Map.merge( + AccountView.render("show.json", %{user: user}), + Pleroma.Web.AdminAPI.AccountView.render("show.json", %{user: user}) + ), + account: + Map.merge( + AccountView.render("show.json", %{user: other_user}), + Pleroma.Web.AdminAPI.AccountView.render("show.json", %{user: other_user}) + ), + statuses: [StatusView.render("show.json", %{activity: activity})], state: "open", + notes: [], id: report_activity.id } result = - ReportView.render("show.json", %{report: report_activity}) + ReportView.render("show.json", Report.extract_report_info(report_activity)) |> Map.delete(:created_at) assert result == expected @@ -62,7 +83,9 @@ defmodule Pleroma.Web.AdminAPI.ReportViewTest do {:ok, activity} = CommonAPI.report(user, %{"account_id" => other_user.id}) {:ok, activity} = CommonAPI.update_report_state(activity.id, "closed") - assert %{state: "closed"} = ReportView.render("show.json", %{report: activity}) + + assert %{state: "closed"} = + ReportView.render("show.json", Report.extract_report_info(activity)) end test "renders report description" do @@ -76,7 +99,7 @@ defmodule Pleroma.Web.AdminAPI.ReportViewTest do }) assert %{content: "posts are too good for this instance"} = - ReportView.render("show.json", %{report: activity}) + ReportView.render("show.json", Report.extract_report_info(activity)) end test "sanitizes report description" do @@ -92,7 +115,23 @@ defmodule Pleroma.Web.AdminAPI.ReportViewTest do data = Map.put(activity.data, "content", "") activity = Map.put(activity, :data, data) - refute %{content: ""} == - ReportView.render("show.json", %{report: activity})[:content] + refute "" == + ReportView.render("show.json", Report.extract_report_info(activity))[:content] + end + + test "doesn't error out when the user doesn't exists" do + user = insert(:user) + other_user = insert(:user) + + {:ok, activity} = + CommonAPI.report(user, %{ + "account_id" => other_user.id, + "comment" => "" + }) + + Pleroma.User.delete(other_user) + Pleroma.User.invalidate_cache(other_user) + + assert %{} = ReportView.render("show.json", Report.extract_report_info(activity)) end end