nulla/test/nulla_web/controllers/nodeinfo_controller_test.exs

95 lines
3 KiB
Elixir

defmodule NullaWeb.NodeinfoControllerTest do
use NullaWeb.ConnCase
alias Nulla.KeyGen
alias Nulla.Models.User
alias Nulla.Models.Actor
setup do
{publicKeyPem, privateKeyPem} = KeyGen.gen()
{:ok, actor} =
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: publicKeyPem
),
endpoints: Jason.OrderedObject.new(sharedInbox: "http://localhost/inbox")
})
User.create_user(%{
id: actor.id,
email: "test@localhost",
password: "password",
privateKeyPem: privateKeyPem,
last_active_at: DateTime.utc_now()
})
:ok
end
describe "GET /.well-known/nodeinfo" do
test "returns Nodeinfo JSON index", %{conn: conn} do
conn =
conn
|> get(~p"/.well-known/nodeinfo")
assert response = json_response(conn, 200)
assert is_list(response["links"])
Enum.each(response["links"], fn link ->
assert is_map(link)
assert is_binary(link["rel"])
assert is_binary(link["href"])
end)
end
end
describe "GET /nodeinfo/2.0" do
test "returns Nodeinfo JSON show", %{conn: conn} do
conn =
conn
|> get(~p"/nodeinfo/2.0")
assert response = json_response(conn, 200)
assert response["version"] == "2.0"
assert is_map(response["software"])
assert response["software"]["name"] == "nulla"
assert is_binary(response["software"]["version"])
assert "activitypub" in response["protocols"]
assert is_map(response["services"])
assert is_list(response["services"]["outbound"])
assert is_list(response["services"]["inbound"])
assert is_map(response["usage"])
assert is_map(response["usage"]["users"])
assert response["usage"]["users"]["total"] == 1
assert response["usage"]["users"]["activeMonth"] == 1
assert response["usage"]["users"]["activeHalfyear"] == 1
assert is_boolean(response["openRegistrations"])
assert is_map(response["metadata"])
assert is_binary(response["metadata"]["nodeName"])
assert is_binary(response["metadata"]["nodeDescription"])
end
end
end