From e4791258d4483cd9dad6016ec453e6ca7ea10d73 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Thu, 31 Dec 2020 10:53:18 -0600 Subject: [PATCH] Ensure newest report is returned first in the list --- .../web/admin_api/views/report_view_test.exs | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/test/pleroma/web/admin_api/views/report_view_test.exs b/test/pleroma/web/admin_api/views/report_view_test.exs index ff3453208..3914751b5 100644 --- a/test/pleroma/web/admin_api/views/report_view_test.exs +++ b/test/pleroma/web/admin_api/views/report_view_test.exs @@ -143,4 +143,29 @@ defmodule Pleroma.Web.AdminAPI.ReportViewTest do assert %{} = ReportView.render("show.json", Report.extract_report_info(activity)) end + + test "reports are ordered newest first" do + user = insert(:user) + other_user = insert(:user) + + {:ok, report1} = + CommonAPI.report(user, %{ + account_id: other_user.id, + comment: "first report" + }) + + {:ok, report2} = + CommonAPI.report(user, %{ + account_id: other_user.id, + comment: "second report" + }) + + %{reports: rendered} = + ReportView.render("index.json", + reports: Pleroma.Web.ActivityPub.Utils.get_reports(%{}, 1, 50) + ) + + assert report2.id == rendered |> Enum.at(0) |> Map.get(:id) + assert report1.id == rendered |> Enum.at(1) |> Map.get(:id) + end end