preload data into index.html
This commit is contained in:
parent
219d2b3146
commit
d67b302810
15 changed files with 532 additions and 156 deletions
|
|
@ -16,7 +16,7 @@ defmodule Pleroma.Web.RuntimeStaticPlugTest do
|
|||
|
||||
test "overrides index" do
|
||||
bundled_index = get(build_conn(), "/")
|
||||
assert html_response(bundled_index, 200) == File.read!("priv/static/index.html")
|
||||
refute html_response(bundled_index, 200) == "hello world"
|
||||
|
||||
File.write!(@dir <> "/index.html", "hello world")
|
||||
|
||||
|
|
|
|||
|
|
@ -6,22 +6,36 @@ defmodule Pleroma.Web.FallbackTest do
|
|||
use Pleroma.Web.ConnCase
|
||||
import Pleroma.Factory
|
||||
|
||||
test "GET /registration/:token", %{conn: conn} do
|
||||
assert conn
|
||||
|> get("/registration/foo")
|
||||
|> html_response(200) =~ "<!--server-generated-meta-->"
|
||||
describe "neither preloaded data nor metadata attached to" do
|
||||
test "GET /registration/:token", %{conn: conn} do
|
||||
response = get(conn, "/registration/foo")
|
||||
|
||||
assert html_response(response, 200) =~ "<!--server-generated-meta-->"
|
||||
assert html_response(response, 200) =~ "<!--server-generated-initial-data-->"
|
||||
end
|
||||
end
|
||||
|
||||
test "GET /:maybe_nickname_or_id", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
describe "preloaded data and metadata attached to" do
|
||||
test "GET /:maybe_nickname_or_id", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
user_missing = get(conn, "/foo")
|
||||
user_present = get(conn, "/#{user.nickname}")
|
||||
|
||||
assert conn
|
||||
|> get("/foo")
|
||||
|> html_response(200) =~ "<!--server-generated-meta-->"
|
||||
assert html_response(user_missing, 200) =~ "<!--server-generated-meta-->"
|
||||
refute html_response(user_present, 200) =~ "<!--server-generated-meta-->"
|
||||
|
||||
refute conn
|
||||
|> get("/" <> user.nickname)
|
||||
|> html_response(200) =~ "<!--server-generated-meta-->"
|
||||
assert html_response(user_missing, 200) =~ "<!--server-generated-initial-data-->"
|
||||
refute html_response(user_present, 200) =~ "<!--server-generated-initial-data-->"
|
||||
end
|
||||
end
|
||||
|
||||
describe "preloaded data only attached to" do
|
||||
test "GET /*path", %{conn: conn} do
|
||||
public_page = get(conn, "/main/public")
|
||||
|
||||
assert html_response(public_page, 200) =~ "<!--server-generated-meta-->"
|
||||
refute html_response(public_page, 200) =~ "<!--server-generated-initial-data-->"
|
||||
end
|
||||
end
|
||||
|
||||
test "GET /api*path", %{conn: conn} do
|
||||
|
|
|
|||
37
test/web/preload/instance_test.exs
Normal file
37
test/web/preload/instance_test.exs
Normal 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
|
||||
74
test/web/preload/timeline_test.exs
Normal file
74
test/web/preload/timeline_test.exs
Normal 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
|
||||
33
test/web/preload/user_test.exs
Normal file
33
test/web/preload/user_test.exs
Normal 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue