Merge branch 'develop' of https://git.pleroma.social/pleroma/pleroma into develop
[akkoma] / test / web / preload / 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
16 svd_config = Pleroma.Config.get([:restrict_unauthenticated, :timelines])
17 Pleroma.Config.put([:restrict_unauthenticated, :timelines], %{local: true, federated: true})
18
19 on_exit(fn ->
20 Pleroma.Config.put([:restrict_unauthenticated, :timelines], svd_config)
21 end)
22
23 :ok
24 end
25
26 test "return nothing" do
27 tl_data = Timelines.generate_terms(%{})
28
29 refute Map.has_key?(tl_data, "/api/v1/timelines/public")
30 end
31 end
32
33 describe "unauthenticated timeliness when unrestricted" do
34 setup do
35 svd_config = Pleroma.Config.get([:restrict_unauthenticated, :timelines])
36
37 Pleroma.Config.put([:restrict_unauthenticated, :timelines], %{
38 local: false,
39 federated: false
40 })
41
42 on_exit(fn ->
43 Pleroma.Config.put([:restrict_unauthenticated, :timelines], svd_config)
44 end)
45
46 {:ok, user: insert(:user)}
47 end
48
49 test "returns the timeline when not restricted" do
50 assert Timelines.generate_terms(%{})
51 |> Map.has_key?(@public_url)
52 end
53
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!"})
58
59 assert Timelines.generate_terms(%{})
60 |> Map.fetch!(@public_url)
61 |> Enum.count() == 3
62 end
63
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!"})
68
69 assert Timelines.generate_terms(%{})
70 |> Map.fetch!(@public_url)
71 |> Enum.count() == 1
72 end
73 end
74 end