# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.Preload.Providers.User do
+ alias Pleroma.User
alias Pleroma.Web.MastodonAPI.AccountView
alias Pleroma.Web.Preload.Providers.Provider
@behaviour Provider
- @account_url :"/api/v1/accounts"
+ @account_url_base :"/api/v1/accounts"
@impl Provider
def generate_terms(%{user: user}) do
def generate_terms(_params), do: %{}
- def build_accounts_tag(acc, nil), do: acc
-
- def build_accounts_tag(acc, user) do
+ def build_accounts_tag(acc, %User{} = user) do
account_data = AccountView.render("show.json", %{user: user, for: user})
- Map.put(acc, @account_url, account_data)
+ Map.put(acc, :"#{@account_url_base}/#{user.id}", account_data)
end
+
+ def build_accounts_tag(acc, _), do: acc
end
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")
+ assert User.generate_terms(%{user: nil}) == %{}
end
test "missing user specified" do
- refute User.generate_terms(%{user: :not_a_user})
- |> Map.has_key?("/api/v1/accounts")
+ assert User.generate_terms(%{user: :not_a_user}) == %{}
end
end
setup do
user = insert(:user)
- {:ok, User.generate_terms(%{user: user})}
+ terms = User.generate_terms(%{user: user})
+ %{terms: terms, user: user}
end
- test "account is rendered", %{"/api/v1/accounts": accounts} do
- assert %{acct: user, username: user} = accounts
+ test "account is rendered", %{terms: terms, user: user} do
+ account = terms[:"/api/v1/accounts/#{user.id}"]
+ assert %{acct: user, username: user} = account
end
end
end