X-Git-Url: https://git.squeep.com/?a=blobdiff_plain;f=test%2Fweb%2Ftwitter_api%2Fviews%2Fuser_view_test.exs;h=95e52ca46a988d7fea21a72f53af9dd44ae5deff;hb=921571c19bf4a7fcea666aa70744a02fe108d11a;hp=24a5c5bca4f51453812d53687c4174750b00c3e3;hpb=5a8bb3cb3b0cc7de82bd699d68519593349fee53;p=akkoma
diff --git a/test/web/twitter_api/views/user_view_test.exs b/test/web/twitter_api/views/user_view_test.exs
index 24a5c5bca..95e52ca46 100644
--- a/test/web/twitter_api/views/user_view_test.exs
+++ b/test/web/twitter_api/views/user_view_test.exs
@@ -1,10 +1,13 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# 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
@@ -13,6 +16,13 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
[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}]}}
@@ -20,14 +30,14 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
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 =
- "
man"
+ "
man"
- user = %{
- user
- | info: %{
- "source_data" => %{
+ user =
+ insert(:user, %{
+ info: %{
+ source_data: %{
"tag" => [
%{
"type" => "Emoji",
@@ -36,10 +46,10 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
}
]
}
- }
- }
+ },
+ name: ":karjalanpiirakka: man"
+ })
- user = %{user | name: ":karjalanpiirakka: man"}
represented = UserView.render("show.json", %{user: user})
assert represented["name_html"] == expected
end
@@ -80,21 +90,30 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
"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,
"background_image" => nil,
"is_local" => true,
"locked" => false,
- "default_scope" => "public"
+ "default_scope" => "public",
+ "no_rich_text" => false,
+ "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"
@@ -119,14 +138,23 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
"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,
"background_image" => nil,
"is_local" => true,
"locked" => false,
- "default_scope" => "public"
+ "default_scope" => "public",
+ "no_rich_text" => false,
+ "hide_follows" => false,
+ "hide_followers" => false,
+ "fields" => [],
+ "pleroma" => %{
+ "confirmation_pending" => false,
+ "tags" => []
+ }
}
assert represented == UserView.render("show.json", %{user: user, for: follower})
@@ -159,24 +187,56 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
"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,
"background_image" => nil,
"is_local" => true,
"locked" => false,
- "default_scope" => "public"
+ "default_scope" => "public",
+ "no_rich_text" => false,
+ "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 blocked user for the blocker" do
@@ -206,17 +266,52 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest 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,
"background_image" => nil,
"is_local" => true,
"locked" => false,
- "default_scope" => "public"
+ "default_scope" => "public",
+ "no_rich_text" => false,
+ "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