88 lines
3.2 KiB
Elixir
88 lines
3.2 KiB
Elixir
defmodule NullaWeb.ActorControllerTest do
|
|
use NullaWeb.ConnCase
|
|
alias Nulla.Models.Actor
|
|
|
|
setup do
|
|
Actor.create_actor(%{
|
|
domain: "localhost",
|
|
ap_id: "http://localhost/users/test",
|
|
type: "Person",
|
|
following: "http://localhost/users/test/following",
|
|
followers: "http://localhost/users/test/followers",
|
|
inbox: "http://localhost/users/test/inbox",
|
|
outbox: "http://localhost/users/test/outbox",
|
|
featured: "http://localhost/users/test/collections/featured",
|
|
featuredTags: "http://localhost/users/test/collections/tags",
|
|
preferredUsername: "test",
|
|
name: "Test",
|
|
summary: "Test User",
|
|
url: "http://localhost/@test",
|
|
manuallyApprovesFollowers: false,
|
|
discoverable: true,
|
|
indexable: true,
|
|
published: DateTime.utc_now(),
|
|
memorial: false,
|
|
publicKey:
|
|
Jason.OrderedObject.new(
|
|
id: "http://localhost/users/test#main-key",
|
|
owner: "http://localhost/users/test",
|
|
publicKeyPem: "PUBLIC KEY"
|
|
),
|
|
endpoints: Jason.OrderedObject.new(sharedInbox: "http://localhost/inbox")
|
|
})
|
|
|
|
:ok
|
|
end
|
|
|
|
describe "GET /@username" do
|
|
test "renders ActivityPub JSON if Accept header is activity+json", %{conn: conn} do
|
|
conn =
|
|
conn
|
|
|> put_req_header("accept", "application/activity+json")
|
|
|> get(~p"/@test")
|
|
|
|
assert response = json_response(conn, 200)
|
|
|
|
assert is_list(response["@context"])
|
|
assert is_binary(response["id"])
|
|
assert is_binary(response["type"])
|
|
assert is_binary(response["following"])
|
|
assert is_binary(response["followers"])
|
|
assert is_binary(response["inbox"])
|
|
assert is_binary(response["outbox"])
|
|
assert is_binary(response["featured"])
|
|
assert is_binary(response["featuredTags"])
|
|
assert is_binary(response["preferredUsername"])
|
|
assert is_binary(response["name"]) or is_nil(response["name"])
|
|
assert is_binary(response["summary"]) or is_nil(response["summary"])
|
|
assert is_binary(response["url"])
|
|
assert is_boolean(response["manuallyApprovesFollowers"])
|
|
assert is_boolean(response["discoverable"])
|
|
assert is_boolean(response["indexable"])
|
|
assert {:ok, _dt, _offset} = DateTime.from_iso8601(response["published"])
|
|
assert is_boolean(response["memorial"])
|
|
assert is_map(response["publicKey"])
|
|
assert is_list(response["tag"])
|
|
assert is_list(response["attachment"])
|
|
assert is_map(response["endpoints"])
|
|
assert is_map(response["icon"]) or is_nil(response["icon"])
|
|
assert is_map(response["image"]) or is_nil(response["image"])
|
|
assert is_binary(response["vcard:bday"]) or is_nil(response["vcard:bday"])
|
|
assert is_binary(response["vcard:Address"]) or is_nil(response["vcard:Address"])
|
|
end
|
|
|
|
test "renders HTML if Accept header is regular", %{conn: conn} do
|
|
conn = get(conn, ~p"/@test")
|
|
|
|
assert html_response(conn, 200) =~ "test"
|
|
assert html_response(conn, 200) =~ "Test"
|
|
assert html_response(conn, 200) =~ "test@localhost"
|
|
end
|
|
|
|
test "returns 404 if actor not found", %{conn: conn} do
|
|
conn = get(conn, ~p"/@nonexistent")
|
|
|
|
assert json_response(conn, 404)["error"] == "Not Found"
|
|
end
|
|
end
|
|
end
|