mirror of
https://akkoma.dev/AkkomaGang/akkoma.git
synced 2024-11-30 09:02:28 +00:00
Add some further test cases.
Including like ... private visibility, cos that's super important.
This commit is contained in:
parent
2bf592f5dc
commit
ef7c3bdc7a
|
@ -9,6 +9,7 @@ defmodule Pleroma.Web.StaticFE.StaticFEController do
|
||||||
alias Pleroma.Object
|
alias Pleroma.Object
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||||
|
alias Pleroma.Web.ActivityPub.Visibility
|
||||||
alias Pleroma.Web.Metadata
|
alias Pleroma.Web.Metadata
|
||||||
alias Pleroma.Web.Router.Helpers
|
alias Pleroma.Web.Router.Helpers
|
||||||
|
|
||||||
|
@ -62,9 +63,10 @@ defmodule Pleroma.Web.StaticFE.StaticFEController do
|
||||||
end
|
end
|
||||||
|
|
||||||
def show(%{assigns: %{notice_id: notice_id}} = conn, _params) do
|
def show(%{assigns: %{notice_id: notice_id}} = conn, _params) do
|
||||||
case Activity.get_by_id_with_object(notice_id) do
|
with %Activity{local: true} = activity <-
|
||||||
%Activity{local: true} = activity ->
|
Activity.get_by_id_with_object(notice_id),
|
||||||
%User{} = user = User.get_by_ap_id(activity.object.data["actor"])
|
true <- Visibility.is_public?(activity.object),
|
||||||
|
%User{} = user <- User.get_by_ap_id(activity.object.data["actor"]) do
|
||||||
meta = Metadata.build_tags(%{activity_id: notice_id, object: activity.object, user: user})
|
meta = Metadata.build_tags(%{activity_id: notice_id, object: activity.object, user: user})
|
||||||
|
|
||||||
timeline =
|
timeline =
|
||||||
|
@ -74,7 +76,7 @@ defmodule Pleroma.Web.StaticFE.StaticFEController do
|
||||||
|> Enum.map(&represent(&1, &1.object.id == activity.object.id))
|
|> Enum.map(&represent(&1, &1.object.id == activity.object.id))
|
||||||
|
|
||||||
render(conn, "conversation.html", %{activities: timeline, meta: meta})
|
render(conn, "conversation.html", %{activities: timeline, meta: meta})
|
||||||
|
else
|
||||||
_ ->
|
_ ->
|
||||||
conn
|
conn
|
||||||
|> put_status(404)
|
|> put_status(404)
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
defmodule Pleroma.Web.StaticFE.StaticFEControllerTest do
|
defmodule Pleroma.Web.StaticFE.StaticFEControllerTest do
|
||||||
use Pleroma.Web.ConnCase
|
use Pleroma.Web.ConnCase
|
||||||
alias Pleroma.Web.CommonAPI
|
alias Pleroma.Web.CommonAPI
|
||||||
|
alias Pleroma.Web.ActivityPub.Transmogrifier
|
||||||
|
|
||||||
import Pleroma.Factory
|
import Pleroma.Factory
|
||||||
|
|
||||||
clear_config_all([:static_fe, :enabled]) do
|
clear_config_all([:static_fe, :enabled]) do
|
||||||
|
@ -10,7 +12,9 @@ defmodule Pleroma.Web.StaticFE.StaticFEControllerTest do
|
||||||
describe "user profile page" do
|
describe "user profile page" do
|
||||||
test "just the profile as HTML", %{conn: conn} do
|
test "just the profile as HTML", %{conn: conn} do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
conn = conn
|
|
||||||
|
conn =
|
||||||
|
conn
|
||||||
|> put_req_header("accept", "text/html")
|
|> put_req_header("accept", "text/html")
|
||||||
|> get("/users/#{user.nickname}")
|
|> get("/users/#{user.nickname}")
|
||||||
|
|
||||||
|
@ -19,7 +23,9 @@ defmodule Pleroma.Web.StaticFE.StaticFEControllerTest do
|
||||||
|
|
||||||
test "renders json unless there's an html accept header", %{conn: conn} do
|
test "renders json unless there's an html accept header", %{conn: conn} do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
conn = conn
|
|
||||||
|
conn =
|
||||||
|
conn
|
||||||
|> put_req_header("accept", "application/json")
|
|> put_req_header("accept", "application/json")
|
||||||
|> get("/users/#{user.nickname}")
|
|> get("/users/#{user.nickname}")
|
||||||
|
|
||||||
|
@ -27,19 +33,39 @@ defmodule Pleroma.Web.StaticFE.StaticFEControllerTest do
|
||||||
end
|
end
|
||||||
|
|
||||||
test "404 when user not found", %{conn: conn} do
|
test "404 when user not found", %{conn: conn} do
|
||||||
conn = conn
|
conn =
|
||||||
|
conn
|
||||||
|> put_req_header("accept", "text/html")
|
|> put_req_header("accept", "text/html")
|
||||||
|> get("/users/limpopo")
|
|> get("/users/limpopo")
|
||||||
|
|
||||||
assert html_response(conn, 404) =~ "not found"
|
assert html_response(conn, 404) =~ "not found"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "profile does not include private messages", %{conn: conn} do
|
||||||
|
user = insert(:user)
|
||||||
|
CommonAPI.post(user, %{"status" => "public"})
|
||||||
|
CommonAPI.post(user, %{"status" => "private", "visibility" => "private"})
|
||||||
|
|
||||||
|
conn =
|
||||||
|
conn
|
||||||
|
|> put_req_header("accept", "text/html")
|
||||||
|
|> get("/users/#{user.nickname}")
|
||||||
|
|
||||||
|
html = html_response(conn, 200)
|
||||||
|
|
||||||
|
assert html =~ ">public<"
|
||||||
|
refute html =~ ">private<"
|
||||||
|
end
|
||||||
|
|
||||||
test "pagination", %{conn: conn} do
|
test "pagination", %{conn: conn} do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
Enum.map(1..30, fn i -> CommonAPI.post(user, %{"status" => "test#{i}"}) end)
|
Enum.map(1..30, fn i -> CommonAPI.post(user, %{"status" => "test#{i}"}) end)
|
||||||
conn = conn
|
|
||||||
|
conn =
|
||||||
|
conn
|
||||||
|> put_req_header("accept", "text/html")
|
|> put_req_header("accept", "text/html")
|
||||||
|> get("/users/#{user.nickname}")
|
|> get("/users/#{user.nickname}")
|
||||||
|
|
||||||
html = html_response(conn, 200)
|
html = html_response(conn, 200)
|
||||||
|
|
||||||
assert html =~ ">test30<"
|
assert html =~ ">test30<"
|
||||||
|
@ -50,12 +76,14 @@ defmodule Pleroma.Web.StaticFE.StaticFEControllerTest do
|
||||||
|
|
||||||
test "pagination, page 2", %{conn: conn} do
|
test "pagination, page 2", %{conn: conn} do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
activities =
|
activities = Enum.map(1..30, fn i -> CommonAPI.post(user, %{"status" => "test#{i}"}) end)
|
||||||
Enum.map(1..30, fn i -> CommonAPI.post(user, %{"status" => "test#{i}"}) end)
|
|
||||||
{:ok, a11} = Enum.at(activities, 11)
|
{:ok, a11} = Enum.at(activities, 11)
|
||||||
conn = conn
|
|
||||||
|
conn =
|
||||||
|
conn
|
||||||
|> put_req_header("accept", "text/html")
|
|> put_req_header("accept", "text/html")
|
||||||
|> get("/users/#{user.nickname}?max_id=#{a11.id}")
|
|> get("/users/#{user.nickname}?max_id=#{a11.id}")
|
||||||
|
|
||||||
html = html_response(conn, 200)
|
html = html_response(conn, 200)
|
||||||
|
|
||||||
assert html =~ ">test1<"
|
assert html =~ ">test1<"
|
||||||
|
@ -70,7 +98,8 @@ defmodule Pleroma.Web.StaticFE.StaticFEControllerTest do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "testing a thing!"})
|
{:ok, activity} = CommonAPI.post(user, %{"status" => "testing a thing!"})
|
||||||
|
|
||||||
conn = conn
|
conn =
|
||||||
|
conn
|
||||||
|> put_req_header("accept", "text/html")
|
|> put_req_header("accept", "text/html")
|
||||||
|> get("/notice/#{activity.id}")
|
|> get("/notice/#{activity.id}")
|
||||||
|
|
||||||
|
@ -80,12 +109,73 @@ defmodule Pleroma.Web.StaticFE.StaticFEControllerTest do
|
||||||
assert html =~ "testing a thing!"
|
assert html =~ "testing a thing!"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "shows the whole thread", %{conn: conn} do
|
||||||
|
user = insert(:user)
|
||||||
|
{:ok, activity} = CommonAPI.post(user, %{"status" => "space: the final frontier"})
|
||||||
|
|
||||||
|
CommonAPI.post(user, %{
|
||||||
|
"status" => "these are the voyages or something",
|
||||||
|
"in_reply_to_status_id" => activity.id
|
||||||
|
})
|
||||||
|
|
||||||
|
conn =
|
||||||
|
conn
|
||||||
|
|> put_req_header("accept", "text/html")
|
||||||
|
|> get("/notice/#{activity.id}")
|
||||||
|
|
||||||
|
html = html_response(conn, 200)
|
||||||
|
assert html =~ "the final frontier"
|
||||||
|
assert html =~ "voyages"
|
||||||
|
end
|
||||||
|
|
||||||
test "404 when notice not found", %{conn: conn} do
|
test "404 when notice not found", %{conn: conn} do
|
||||||
conn = conn
|
conn =
|
||||||
|
conn
|
||||||
|> put_req_header("accept", "text/html")
|
|> put_req_header("accept", "text/html")
|
||||||
|> get("/notice/88c9c317")
|
|> get("/notice/88c9c317")
|
||||||
|
|
||||||
assert html_response(conn, 404) =~ "not found"
|
assert html_response(conn, 404) =~ "not found"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "404 for private status", %{conn: conn} do
|
||||||
|
user = insert(:user)
|
||||||
|
|
||||||
|
{:ok, activity} =
|
||||||
|
CommonAPI.post(user, %{"status" => "don't show me!", "visibility" => "private"})
|
||||||
|
|
||||||
|
conn =
|
||||||
|
conn
|
||||||
|
|> put_req_header("accept", "text/html")
|
||||||
|
|> get("/notice/#{activity.id}")
|
||||||
|
|
||||||
|
assert html_response(conn, 404) =~ "not found"
|
||||||
|
end
|
||||||
|
|
||||||
|
test "404 for remote cached status", %{conn: conn} do
|
||||||
|
user = insert(:user)
|
||||||
|
|
||||||
|
message = %{
|
||||||
|
"@context" => "https://www.w3.org/ns/activitystreams",
|
||||||
|
"to" => user.follower_address,
|
||||||
|
"cc" => "https://www.w3.org/ns/activitystreams#Public",
|
||||||
|
"type" => "Create",
|
||||||
|
"object" => %{
|
||||||
|
"content" => "blah blah blah",
|
||||||
|
"type" => "Note",
|
||||||
|
"attributedTo" => user.ap_id,
|
||||||
|
"inReplyTo" => nil
|
||||||
|
},
|
||||||
|
"actor" => user.ap_id
|
||||||
|
}
|
||||||
|
|
||||||
|
assert {:ok, activity} = Transmogrifier.handle_incoming(message)
|
||||||
|
|
||||||
|
conn =
|
||||||
|
conn
|
||||||
|
|> put_req_header("accept", "text/html")
|
||||||
|
|> get("/notice/#{activity.id}")
|
||||||
|
|
||||||
|
assert html_response(conn, 404) =~ "not found"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue