logo

pleroma

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

timeline_test.exs (2001B)


  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.Web.Preload.Providers.TimelineTest do
  5. use Pleroma.DataCase
  6. import Pleroma.Factory
  7. alias Pleroma.Web.CommonAPI
  8. alias Pleroma.Web.Preload.Providers.Timelines
  9. @public_url "/api/v1/timelines/public"
  10. describe "unauthenticated timeliness when restricted" do
  11. setup do: clear_config([:restrict_unauthenticated, :timelines, :local], true)
  12. setup do: clear_config([:restrict_unauthenticated, :timelines, :federated], true)
  13. test "return nothing" do
  14. tl_data = Timelines.generate_terms(%{})
  15. refute Map.has_key?(tl_data, "/api/v1/timelines/public")
  16. end
  17. end
  18. describe "unauthenticated timeliness when unrestricted" do
  19. setup do: clear_config([:restrict_unauthenticated, :timelines, :local], false)
  20. setup do: clear_config([:restrict_unauthenticated, :timelines, :federated], false)
  21. setup do: {:ok, user: insert(:user)}
  22. test "returns the timeline when not restricted" do
  23. assert Timelines.generate_terms(%{})
  24. |> Map.has_key?(@public_url)
  25. end
  26. test "returns public items", %{user: user} do
  27. {:ok, _} = CommonAPI.post(user, %{status: "it's post 1!"})
  28. {:ok, _} = CommonAPI.post(user, %{status: "it's post 2!"})
  29. {:ok, _} = CommonAPI.post(user, %{status: "it's post 3!"})
  30. assert Timelines.generate_terms(%{})
  31. |> Map.fetch!(@public_url)
  32. |> Enum.count() == 3
  33. end
  34. test "does not return non-public items", %{user: user} do
  35. {:ok, _} = CommonAPI.post(user, %{status: "it's post 1!", visibility: "unlisted"})
  36. {:ok, _} = CommonAPI.post(user, %{status: "it's post 2!", visibility: "direct"})
  37. {:ok, _} = CommonAPI.post(user, %{status: "it's post 3!"})
  38. assert Timelines.generate_terms(%{})
  39. |> Map.fetch!(@public_url)
  40. |> Enum.count() == 1
  41. end
  42. end
  43. end