logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma

pagination_test.exs (2289B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.PaginationTest do
  5. use Pleroma.DataCase
  6. import Pleroma.Factory
  7. alias Pleroma.Object
  8. alias Pleroma.Pagination
  9. describe "keyset" do
  10. setup do
  11. notes = insert_list(5, :note)
  12. %{notes: notes}
  13. end
  14. test "paginates by min_id", %{notes: notes} do
  15. id = Enum.at(notes, 2).id |> Integer.to_string()
  16. %{total: total, items: paginated} =
  17. Pagination.fetch_paginated(Object, %{min_id: id, total: true})
  18. assert length(paginated) == 2
  19. assert total == 5
  20. end
  21. test "paginates by since_id", %{notes: notes} do
  22. id = Enum.at(notes, 2).id |> Integer.to_string()
  23. %{total: total, items: paginated} =
  24. Pagination.fetch_paginated(Object, %{since_id: id, total: true})
  25. assert length(paginated) == 2
  26. assert total == 5
  27. end
  28. test "paginates by max_id", %{notes: notes} do
  29. id = Enum.at(notes, 1).id |> Integer.to_string()
  30. %{total: total, items: paginated} =
  31. Pagination.fetch_paginated(Object, %{max_id: id, total: true})
  32. assert length(paginated) == 1
  33. assert total == 5
  34. end
  35. test "paginates by min_id & limit", %{notes: notes} do
  36. id = Enum.at(notes, 2).id |> Integer.to_string()
  37. paginated = Pagination.fetch_paginated(Object, %{min_id: id, limit: 1})
  38. assert length(paginated) == 1
  39. end
  40. test "handles id gracefully", %{notes: notes} do
  41. id = Enum.at(notes, 1).id |> Integer.to_string()
  42. paginated =
  43. Pagination.fetch_paginated(Object, %{
  44. id: "9s99Hq44Cnv8PKBwWG",
  45. max_id: id,
  46. limit: 20,
  47. offset: 0
  48. })
  49. assert length(paginated) == 1
  50. end
  51. end
  52. describe "offset" do
  53. setup do
  54. notes = insert_list(5, :note)
  55. %{notes: notes}
  56. end
  57. test "paginates by limit" do
  58. paginated = Pagination.fetch_paginated(Object, %{limit: 2}, :offset)
  59. assert length(paginated) == 2
  60. end
  61. test "paginates by limit & offset" do
  62. paginated = Pagination.fetch_paginated(Object, %{limit: 2, offset: 4}, :offset)
  63. assert length(paginated) == 1
  64. end
  65. end
  66. end