preload data into index.html

This commit is contained in:
stwf 2020-05-12 11:08:00 -04:00
commit 29ae5bb771
15 changed files with 532 additions and 156 deletions

View file

@ -0,0 +1,37 @@
# 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.InstanceTest do
use Pleroma.DataCase
alias Pleroma.Web.Preload.Providers.Instance
setup do: {:ok, Instance.generate_terms(nil)}
test "it renders the info", %{"/api/v1/instance": info} do
assert %{
description: description,
email: "admin@example.com",
registrations: true
} = info
assert String.equivalent?(description, "A Pleroma instance, an alternative fediverse server")
end
test "it renders the panel", %{"/instance/panel.html": panel} do
assert String.contains?(
panel,
"<p>Welcome to <a href=\"https://pleroma.social\" target=\"_blank\">Pleroma!</a></p>"
)
end
test "it renders the node_info", %{"/nodeinfo/2.0": nodeinfo} do
%{
metadata: metadata,
version: "2.0"
} = nodeinfo
assert metadata.private == false
assert metadata.suggestions == %{enabled: false}
end
end

View file

@ -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

View file

@ -0,0 +1,33 @@
# 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.UserTest do
use Pleroma.DataCase
import Pleroma.Factory
alias Pleroma.Web.Preload.Providers.User
describe "returns empty when user doesn't exist" do
test "nil user specified" do
refute User.generate_terms(%{user: nil})
|> Map.has_key?("/api/v1/accounts")
end
test "missing user specified" do
refute User.generate_terms(%{user: :not_a_user})
|> Map.has_key?("/api/v1/accounts")
end
end
describe "specified user exists" do
setup do
user = insert(:user)
{:ok, User.generate_terms(%{user: user})}
end
test "account is rendered", %{"/api/v1/accounts": accounts} do
assert %{acct: user, username: user} = accounts
end
end
end