1 defmodule Pleroma.Web.ActivityPub.UserViewTest do
5 alias Pleroma.Web.ActivityPub.UserView
7 test "Renders a user, including the public key" do
9 {:ok, user} = Pleroma.Web.WebFinger.ensure_keys_present(user)
11 result = UserView.render("user.json", %{user: user})
13 assert result["id"] == user.ap_id
14 assert result["preferredUsername"] == user.nickname
16 assert String.contains?(result["publicKey"]["publicKeyPem"], "BEGIN PUBLIC KEY")
19 test "Does not add an avatar image if the user hasn't set one" do
21 {:ok, user} = Pleroma.Web.WebFinger.ensure_keys_present(user)
23 result = UserView.render("user.json", %{user: user})
25 refute result["image"]
29 avatar: %{"url" => [%{"href" => "https://someurl"}]},
31 banner: %{"url" => [%{"href" => "https://somebanner"}]}
35 {:ok, user} = Pleroma.Web.WebFinger.ensure_keys_present(user)
37 result = UserView.render("user.json", %{user: user})
38 assert result["icon"]["url"] == "https://someurl"
39 assert result["image"]["url"] == "https://somebanner"
42 describe "endpoints" do
43 test "local users have a usable endpoints structure" do
45 {:ok, user} = Pleroma.Web.WebFinger.ensure_keys_present(user)
47 result = UserView.render("user.json", %{user: user})
49 assert result["id"] == user.ap_id
53 "oauthAuthorizationEndpoint" => _,
54 "oauthRegistrationEndpoint" => _,
55 "oauthTokenEndpoint" => _
56 } = result["endpoints"]
59 test "remote users have an empty endpoints structure" do
60 user = insert(:user, local: false)
61 {:ok, user} = Pleroma.Web.WebFinger.ensure_keys_present(user)
63 result = UserView.render("user.json", %{user: user})
65 assert result["id"] == user.ap_id
66 assert result["endpoints"] == %{}
69 test "instance users do not expose oAuth endpoints" do
70 user = insert(:user, nickname: nil, local: true)
71 {:ok, user} = Pleroma.Web.WebFinger.ensure_keys_present(user)
73 result = UserView.render("user.json", %{user: user})
75 refute result["endpoints"]["oauthAuthorizationEndpoint"]
76 refute result["endpoints"]["oauthRegistrationEndpoint"]
77 refute result["endpoints"]["oauthTokenEndpoint"]