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