summaryrefslogtreecommitdiff
path: root/test/web/preload/timeline_test.exs
diff options
context:
space:
mode:
authorstwf <steven.fuchs@dockyard.com>2020-05-12 11:08:00 -0400
committerstwf <steven.fuchs@dockyard.com>2020-05-29 14:15:24 -0400
commitd67b302810c53d92ace7c347c77eecc10be6bcd6 (patch)
treed278d3be9def4c5c9492ad20c000188aef2fa3df /test/web/preload/timeline_test.exs
parent219d2b3146ee72abc0bb8bd163c0ddcd986988fc (diff)
downloadpleroma-d67b302810c53d92ace7c347c77eecc10be6bcd6.tar.gz
pleroma-d67b302810c53d92ace7c347c77eecc10be6bcd6.zip
preload data into index.html
Diffstat (limited to 'test/web/preload/timeline_test.exs')
-rw-r--r--test/web/preload/timeline_test.exs74
1 files changed, 74 insertions, 0 deletions
diff --git a/test/web/preload/timeline_test.exs b/test/web/preload/timeline_test.exs
new file mode 100644
index 000000000..00b10d0ab
--- /dev/null
+++ b/test/web/preload/timeline_test.exs
@@ -0,0 +1,74 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2020 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
+ svd_config = Pleroma.Config.get([:restrict_unauthenticated, :timelines])
+ Pleroma.Config.put([:restrict_unauthenticated, :timelines], %{local: true, federated: true})
+
+ on_exit(fn ->
+ Pleroma.Config.put([:restrict_unauthenticated, :timelines], svd_config)
+ end)
+
+ :ok
+ end
+
+ 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
+ svd_config = Pleroma.Config.get([:restrict_unauthenticated, :timelines])
+
+ Pleroma.Config.put([:restrict_unauthenticated, :timelines], %{
+ local: false,
+ federated: false
+ })
+
+ on_exit(fn ->
+ Pleroma.Config.put([:restrict_unauthenticated, :timelines], svd_config)
+ end)
+
+ {:ok, user: insert(:user)}
+ end
+
+ 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