2020-05-12 15:08:00 +00:00
|
|
|
# Pleroma: A lightweight social networking server
|
2021-01-13 06:49:20 +00:00
|
|
|
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
2020-05-12 15:08:00 +00:00
|
|
|
# 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
|
|
|
|
|
2020-06-29 09:41:00 +00:00
|
|
|
@public_url "/api/v1/timelines/public"
|
2020-05-12 15:08:00 +00:00
|
|
|
|
|
|
|
describe "unauthenticated timeliness when restricted" do
|
2020-08-14 17:55:45 +00:00
|
|
|
setup do: clear_config([:restrict_unauthenticated, :timelines, :local], true)
|
|
|
|
setup do: clear_config([:restrict_unauthenticated, :timelines, :federated], true)
|
2020-05-12 15:08:00 +00:00
|
|
|
|
|
|
|
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
|
2020-08-14 17:55:45 +00:00
|
|
|
setup do: clear_config([:restrict_unauthenticated, :timelines, :local], false)
|
|
|
|
setup do: clear_config([:restrict_unauthenticated, :timelines, :federated], false)
|
2020-05-12 15:08:00 +00:00
|
|
|
|
2020-08-14 17:55:45 +00:00
|
|
|
setup do: {:ok, user: insert(:user)}
|
2020-05-12 15:08:00 +00:00
|
|
|
|
|
|
|
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
|
2020-06-02 14:18:06 +00:00
|
|
|
{: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!"})
|
2020-05-12 15:08:00 +00:00
|
|
|
|
|
|
|
assert Timelines.generate_terms(%{})
|
|
|
|
|> Map.fetch!(@public_url)
|
|
|
|
|> Enum.count() == 3
|
|
|
|
end
|
|
|
|
|
|
|
|
test "does not return non-public items", %{user: user} do
|
2020-06-02 14:18:06 +00:00
|
|
|
{: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!"})
|
2020-05-12 15:08:00 +00:00
|
|
|
|
|
|
|
assert Timelines.generate_terms(%{})
|
|
|
|
|> Map.fetch!(@public_url)
|
|
|
|
|> Enum.count() == 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|