Add test for correct AP outbox pagination
authorD Anzorge <d.anzorge@gmail.com>
Thu, 19 Sep 2019 14:09:24 +0000 (16:09 +0200)
committerD Anzorge <d.anzorge@gmail.com>
Thu, 19 Sep 2019 14:49:27 +0000 (16:49 +0200)
test/web/activity_pub/views/user_view_test.exs

index 2b4a04afdf516d16d0edb9e0600123ad8f51f6f8..eda95e3ea66f7ebf86e9ab529b22121daa82f248 100644 (file)
@@ -142,4 +142,27 @@ defmodule Pleroma.Web.ActivityPub.UserViewTest do
       assert %{"totalItems" => 1} = UserView.render("following.json", %{user: user})
     end
   end
+
+  test "outbox paginates correctly" do
+    user = insert(:user)
+
+    posts =
+      for i <- 0..25 do
+        {:ok, activity} = CommonAPI.post(user, %{"status" => "post #{i}"})
+        activity
+      end
+
+    # outbox sorts chronologically, newest first, with ten per page
+    posts = Enum.reverse(posts)
+
+    %{"first" => %{"next" => next_url}} =
+      UserView.render("outbox.json", %{user: user, max_id: nil})
+
+    next_id = Enum.at(posts, 9).id
+    assert next_url =~ next_id
+
+    %{"next" => next_url} = UserView.render("outbox.json", %{user: user, max_id: next_id})
+    next_id = Enum.at(posts, 19).id
+    assert next_url =~ next_id
+  end
 end