1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.PaginationTest do
11 alias Pleroma.Pagination
15 notes = insert_list(5, :note)
20 test "paginates by min_id", %{notes: notes} do
21 id = Enum.at(notes, 2).id |> Integer.to_string()
23 %{total: total, items: paginated} =
24 Pagination.fetch_paginated(Object, %{min_id: id, total: true})
26 assert length(paginated) == 2
30 test "paginates by since_id", %{notes: notes} do
31 id = Enum.at(notes, 2).id |> Integer.to_string()
33 %{total: total, items: paginated} =
34 Pagination.fetch_paginated(Object, %{since_id: id, total: true})
36 assert length(paginated) == 2
40 test "paginates by max_id", %{notes: notes} do
41 id = Enum.at(notes, 1).id |> Integer.to_string()
43 %{total: total, items: paginated} =
44 Pagination.fetch_paginated(Object, %{max_id: id, total: true})
46 assert length(paginated) == 1
50 test "paginates by min_id & limit", %{notes: notes} do
51 id = Enum.at(notes, 2).id |> Integer.to_string()
53 paginated = Pagination.fetch_paginated(Object, %{min_id: id, limit: 1})
55 assert length(paginated) == 1
58 test "handles id gracefully", %{notes: notes} do
59 id = Enum.at(notes, 1).id |> Integer.to_string()
62 Pagination.fetch_paginated(Object, %{
63 id: "9s99Hq44Cnv8PKBwWG",
69 assert length(paginated) == 1
75 notes = insert_list(5, :note)
80 test "paginates by limit" do
81 paginated = Pagination.fetch_paginated(Object, %{limit: 2}, :offset)
83 assert length(paginated) == 2
86 test "paginates by limit & offset" do
87 paginated = Pagination.fetch_paginated(Object, %{limit: 2, offset: 4}, :offset)
89 assert length(paginated) == 1