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.Web.Preload.Providers.TimelineTest do
9 alias Pleroma.Web.CommonAPI
10 alias Pleroma.Web.Preload.Providers.Timelines
12 @public_url "/api/v1/timelines/public"
14 describe "unauthenticated timeliness when restricted" do
16 svd_config = Pleroma.Config.get([:restrict_unauthenticated, :timelines])
17 Pleroma.Config.put([:restrict_unauthenticated, :timelines], %{local: true, federated: true})
20 Pleroma.Config.put([:restrict_unauthenticated, :timelines], svd_config)
26 test "return nothing" do
27 tl_data = Timelines.generate_terms(%{})
29 refute Map.has_key?(tl_data, "/api/v1/timelines/public")
33 describe "unauthenticated timeliness when unrestricted" do
35 svd_config = Pleroma.Config.get([:restrict_unauthenticated, :timelines])
37 Pleroma.Config.put([:restrict_unauthenticated, :timelines], %{
43 Pleroma.Config.put([:restrict_unauthenticated, :timelines], svd_config)
46 {:ok, user: insert(:user)}
49 test "returns the timeline when not restricted" do
50 assert Timelines.generate_terms(%{})
51 |> Map.has_key?(@public_url)
54 test "returns public items", %{user: user} do
55 {:ok, _} = CommonAPI.post(user, %{status: "it's post 1!"})
56 {:ok, _} = CommonAPI.post(user, %{status: "it's post 2!"})
57 {:ok, _} = CommonAPI.post(user, %{status: "it's post 3!"})
59 assert Timelines.generate_terms(%{})
60 |> Map.fetch!(@public_url)
64 test "does not return non-public items", %{user: user} do
65 {:ok, _} = CommonAPI.post(user, %{status: "it's post 1!", visibility: "unlisted"})
66 {:ok, _} = CommonAPI.post(user, %{status: "it's post 2!", visibility: "direct"})
67 {:ok, _} = CommonAPI.post(user, %{status: "it's post 3!"})
69 assert Timelines.generate_terms(%{})
70 |> Map.fetch!(@public_url)