Fork of Pleroma with site-specific changes and feature branches https://git.pleroma.social/pleroma/pleroma
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

79 linhas
1.9KB

  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. end
  41. describe "offset" do
  42. setup do
  43. notes = insert_list(5, :note)
  44. %{notes: notes}
  45. end
  46. test "paginates by limit" do
  47. paginated = Pagination.fetch_paginated(Object, %{limit: 2}, :offset)
  48. assert length(paginated) == 2
  49. end
  50. test "paginates by limit & offset" do
  51. paginated = Pagination.fetch_paginated(Object, %{limit: 2, offset: 4}, :offset)
  52. assert length(paginated) == 1
  53. end
  54. end
  55. end