+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Web.TwitterAPI.UserViewTest do
use Pleroma.DataCase
alias Pleroma.User
alias Pleroma.Web.TwitterAPI.UserView
alias Pleroma.Web.CommonAPI.Utils
- alias Pleroma.Builders.UserBuilder
import Pleroma.Factory
[user: user]
end
+ test "A user with only a nickname", %{user: user} do
+ user = %{user | name: nil, nickname: "scarlett@catgirl.science"}
+ represented = UserView.render("show.json", %{user: user})
+ assert represented["name"] == user.nickname
+ assert represented["name_html"] == user.nickname
+ end
+
test "A user with an avatar object", %{user: user} do
image = "image"
user = %{user | avatar: %{"url" => [%{"href" => image}]}}
assert represented["profile_image_url"] == image
end
- test "A user with emoji in username", %{user: user} do
+ test "A user with emoji in username" do
expected =
"<img height=\"32px\" width=\"32px\" alt=\"karjalanpiirakka\" title=\"karjalanpiirakka\" src=\"/file.png\" /> man"
- user = %{
- user
- | info: %{
- "source_data" => %{
+ user =
+ insert(:user, %{
+ info: %{
+ source_data: %{
"tag" => [
%{
"type" => "Emoji",
}
]
}
- }
- }
+ },
+ name: ":karjalanpiirakka: man"
+ })
- user = %{user | name: ":karjalanpiirakka: man"}
represented = UserView.render("show.json", %{user: user})
assert represented["name_html"] == expected
end
"follows_you" => false,
"statusnet_blocking" => false,
"rights" => %{
- "delete_others_notice" => false
+ "delete_others_notice" => false,
+ "admin" => false
},
"statusnet_profile_url" => user.ap_id,
"cover_photo" => banner,
"locked" => false,
"default_scope" => "public",
"no_rich_text" => false,
- "fields" => []
+ "hide_follows" => false,
+ "hide_followers" => false,
+ "fields" => [],
+ "pleroma" => %{
+ "confirmation_pending" => false,
+ "tags" => []
+ }
}
assert represented == UserView.render("show.json", %{user: user})
end
test "A user for a given other follower", %{user: user} do
- {:ok, follower} = UserBuilder.insert(%{following: [User.ap_followers(user)]})
+ follower = insert(:user, %{following: [User.ap_followers(user)]})
{:ok, user} = User.update_follower_count(user)
image = "http://localhost:4001/images/avi.png"
banner = "http://localhost:4001/images/banner.png"
"follows_you" => false,
"statusnet_blocking" => false,
"rights" => %{
- "delete_others_notice" => false
+ "delete_others_notice" => false,
+ "admin" => false
},
"statusnet_profile_url" => user.ap_id,
"cover_photo" => banner,
"locked" => false,
"default_scope" => "public",
"no_rich_text" => false,
- "fields" => []
+ "hide_follows" => false,
+ "hide_followers" => false,
+ "fields" => [],
+ "pleroma" => %{
+ "confirmation_pending" => false,
+ "tags" => []
+ }
}
assert represented == UserView.render("show.json", %{user: user, for: follower})
"follows_you" => true,
"statusnet_blocking" => false,
"rights" => %{
- "delete_others_notice" => false
+ "delete_others_notice" => false,
+ "admin" => false
},
"statusnet_profile_url" => follower.ap_id,
"cover_photo" => banner,
"locked" => false,
"default_scope" => "public",
"no_rich_text" => false,
- "fields" => []
+ "hide_follows" => false,
+ "hide_followers" => false,
+ "fields" => [],
+ "pleroma" => %{
+ "confirmation_pending" => false,
+ "tags" => []
+ }
}
assert represented == UserView.render("show.json", %{user: follower, for: user})
end
test "a user that is a moderator" do
- user = insert(:user, %{info: %{"is_moderator" => true}})
+ user = insert(:user, %{info: %{is_moderator: true}})
represented = UserView.render("show.json", %{user: user, for: user})
assert represented["rights"]["delete_others_notice"]
+ assert represented["role"] == "moderator"
+ end
+
+ test "a user that is a admin" do
+ user = insert(:user, %{info: %{is_admin: true}})
+ represented = UserView.render("show.json", %{user: user, for: user})
+
+ assert represented["rights"]["admin"]
+ assert represented["role"] == "admin"
+ end
+
+ test "A moderator with hidden role for another user", %{user: user} do
+ admin = insert(:user, %{info: %{is_moderator: true, show_role: false}})
+ represented = UserView.render("show.json", %{user: admin, for: user})
+
+ assert represented["role"] == nil
+ end
+
+ test "An admin with hidden role for another user", %{user: user} do
+ admin = insert(:user, %{info: %{is_admin: true, show_role: false}})
+ represented = UserView.render("show.json", %{user: admin, for: user})
+
+ assert represented["role"] == nil
+ end
+
+ test "A regular user for the admin", %{user: user} do
+ admin = insert(:user, %{info: %{is_admin: true}})
+ represented = UserView.render("show.json", %{user: user, for: admin})
+
+ assert represented["pleroma"]["deactivated"] == false
end
test "A blocked user for the blocker" do
"follows_you" => false,
"statusnet_blocking" => true,
"rights" => %{
- "delete_others_notice" => false
+ "delete_others_notice" => false,
+ "admin" => false
},
"statusnet_profile_url" => user.ap_id,
"cover_photo" => banner,
"locked" => false,
"default_scope" => "public",
"no_rich_text" => false,
- "fields" => []
+ "hide_follows" => false,
+ "hide_followers" => false,
+ "fields" => [],
+ "pleroma" => %{
+ "confirmation_pending" => false,
+ "tags" => []
+ }
}
blocker = Repo.get(User, blocker.id)
assert represented == UserView.render("show.json", %{user: user, for: blocker})
end
+
+ test "a user with mastodon fields" do
+ fields = [
+ %{
+ "name" => "Pronouns",
+ "value" => "she/her"
+ },
+ %{
+ "name" => "Website",
+ "value" => "https://example.org/"
+ }
+ ]
+
+ user =
+ insert(:user, %{
+ info: %{
+ source_data: %{
+ "attachment" =>
+ Enum.map(fields, fn field -> Map.put(field, "type", "PropertyValue") end)
+ }
+ }
+ })
+
+ userview = UserView.render("show.json", %{user: user})
+ assert userview["fields"] == fields
+ end
end