Ensure newest report is returned first in the list
authorMark Felder <feld@feld.me>
Thu, 31 Dec 2020 16:53:18 +0000 (10:53 -0600)
committerMark Felder <feld@feld.me>
Thu, 31 Dec 2020 18:40:42 +0000 (12:40 -0600)
test/pleroma/web/admin_api/views/report_view_test.exs

index ff345320875e4368554e96b60e429cbd5ae4eb13..3914751b5281680868bde5dfc78ccd7c63a42c64 100644 (file)
@@ -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