summaryrefslogtreecommitdiff
path: root/test/pleroma/web/preload/providers/timeline_test.exs
blob: 162aabd4a5fa81b66c00e4091ed8c4af5626f219 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# Pleroma: A lightweight social networking server
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only

defmodule Pleroma.Web.Preload.Providers.TimelineTest do
  use Pleroma.DataCase
  import Pleroma.Factory

  alias Pleroma.Web.CommonAPI
  alias Pleroma.Web.Preload.Providers.Timelines

  @public_url "/api/v1/timelines/public"

  describe "unauthenticated timeliness when restricted" do
    setup do: clear_config([:restrict_unauthenticated, :timelines, :local], true)
    setup do: clear_config([:restrict_unauthenticated, :timelines, :federated], true)

    test "return nothing" do
      tl_data = Timelines.generate_terms(%{})

      refute Map.has_key?(tl_data, "/api/v1/timelines/public")
    end
  end

  describe "unauthenticated timeliness when unrestricted" do
    setup do: clear_config([:restrict_unauthenticated, :timelines, :local], false)
    setup do: clear_config([:restrict_unauthenticated, :timelines, :federated], false)

    setup do: {:ok, user: insert(:user)}

    test "returns the timeline when not restricted" do
      assert Timelines.generate_terms(%{})
             |> Map.has_key?(@public_url)
    end

    test "returns public items", %{user: user} do
      {:ok, _} = CommonAPI.post(user, %{status: "it's post 1!"})
      {:ok, _} = CommonAPI.post(user, %{status: "it's post 2!"})
      {:ok, _} = CommonAPI.post(user, %{status: "it's post 3!"})

      assert Timelines.generate_terms(%{})
             |> Map.fetch!(@public_url)
             |> Enum.count() == 3
    end

    test "does not return non-public items", %{user: user} do
      {:ok, _} = CommonAPI.post(user, %{status: "it's post 1!", visibility: "unlisted"})
      {:ok, _} = CommonAPI.post(user, %{status: "it's post 2!", visibility: "direct"})
      {:ok, _} = CommonAPI.post(user, %{status: "it's post 3!"})

      assert Timelines.generate_terms(%{})
             |> Map.fetch!(@public_url)
             |> Enum.count() == 1
    end
  end
end