X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=test%2Fweb%2Fmastodon_api%2Fcontrollers%2Faccount_controller%2Fupdate_credentials_test.exs;h=b693c1a47603401240fee96c0d7a89191c13aaf8;hb=af820f8cf1c621dc8b57579c1cf8a740b6ba206a;hp=519b56d6cb64255f00ba55e34baffe74ad783012;hpb=10ff01acd95d42314b4eb923e5b7a7191356b73e;p=akkoma
diff --git a/test/web/mastodon_api/controllers/account_controller/update_credentials_test.exs b/test/web/mastodon_api/controllers/account_controller/update_credentials_test.exs
index 519b56d6c..b693c1a47 100644
--- a/test/web/mastodon_api/controllers/account_controller/update_credentials_test.exs
+++ b/test/web/mastodon_api/controllers/account_controller/update_credentials_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2019 Pleroma Authors
+# Copyright © 2017-2020 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
@@ -9,16 +9,15 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
use Pleroma.Web.ConnCase
import Pleroma.Factory
- clear_config([:instance, :max_account_fields])
+
+ setup do: clear_config([:instance, :max_account_fields])
describe "updating credentials" do
- test "sets user settings in a generic way", %{conn: conn} do
- user = insert(:user)
+ setup do: oauth_access(["write:accounts"])
+ test "sets user settings in a generic way", %{conn: conn} do
res_conn =
- conn
- |> assign(:user, user)
- |> patch("/api/v1/accounts/update_credentials", %{
+ patch(conn, "/api/v1/accounts/update_credentials", %{
"pleroma_settings_store" => %{
pleroma_fe: %{
theme: "bla"
@@ -26,10 +25,10 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
}
})
- assert user = json_response(res_conn, 200)
- assert user["pleroma"]["settings_store"] == %{"pleroma_fe" => %{"theme" => "bla"}}
+ assert user_data = json_response(res_conn, 200)
+ assert user_data["pleroma"]["settings_store"] == %{"pleroma_fe" => %{"theme" => "bla"}}
- user = Repo.get(User, user["id"])
+ user = Repo.get(User, user_data["id"])
res_conn =
conn
@@ -42,15 +41,15 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
}
})
- assert user = json_response(res_conn, 200)
+ assert user_data = json_response(res_conn, 200)
- assert user["pleroma"]["settings_store"] ==
+ assert user_data["pleroma"]["settings_store"] ==
%{
"pleroma_fe" => %{"theme" => "bla"},
"masto_fe" => %{"theme" => "bla"}
}
- user = Repo.get(User, user["id"])
+ user = Repo.get(User, user_data["id"])
res_conn =
conn
@@ -63,9 +62,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
}
})
- assert user = json_response(res_conn, 200)
+ assert user_data = json_response(res_conn, 200)
- assert user["pleroma"]["settings_store"] ==
+ assert user_data["pleroma"]["settings_store"] ==
%{
"pleroma_fe" => %{"theme" => "bla"},
"masto_fe" => %{"theme" => "blub"}
@@ -73,82 +72,79 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
end
test "updates the user's bio", %{conn: conn} do
- user = insert(:user)
user2 = insert(:user)
conn =
- conn
- |> assign(:user, user)
- |> patch("/api/v1/accounts/update_credentials", %{
- "note" => "I drink #cofe with @#{user2.nickname}"
+ patch(conn, "/api/v1/accounts/update_credentials", %{
+ "note" => "I drink #cofe with @#{user2.nickname}\n\nsuya.."
})
- assert user = json_response(conn, 200)
+ assert user_data = json_response(conn, 200)
- assert user["note"] ==
+ assert user_data["note"] ==
~s(I drink #cofe with @#{user2.nickname})
+ }" class="u-url mention" href="#{user2.ap_id}" rel="ugc">@#{user2.nickname}
suya..)
end
test "updates the user's locking status", %{conn: conn} do
- user = insert(:user)
+ conn = patch(conn, "/api/v1/accounts/update_credentials", %{locked: "true"})
- conn =
- conn
- |> assign(:user, user)
- |> patch("/api/v1/accounts/update_credentials", %{locked: "true"})
+ assert user_data = json_response(conn, 200)
+ assert user_data["locked"] == true
+ end
+
+ test "updates the user's allow_following_move", %{user: user, conn: conn} do
+ assert user.allow_following_move == true
+
+ conn = patch(conn, "/api/v1/accounts/update_credentials", %{allow_following_move: "false"})
- assert user = json_response(conn, 200)
- assert user["locked"] == true
+ assert refresh_record(user).allow_following_move == false
+ assert user_data = json_response(conn, 200)
+ assert user_data["pleroma"]["allow_following_move"] == false
end
test "updates the user's default scope", %{conn: conn} do
- user = insert(:user)
+ conn = patch(conn, "/api/v1/accounts/update_credentials", %{default_scope: "cofe"})
- conn =
- conn
- |> assign(:user, user)
- |> patch("/api/v1/accounts/update_credentials", %{default_scope: "cofe"})
-
- assert user = json_response(conn, 200)
- assert user["source"]["privacy"] == "cofe"
+ assert user_data = json_response(conn, 200)
+ assert user_data["source"]["privacy"] == "cofe"
end
test "updates the user's hide_followers status", %{conn: conn} do
- user = insert(:user)
+ conn = patch(conn, "/api/v1/accounts/update_credentials", %{hide_followers: "true"})
- conn =
- conn
- |> assign(:user, user)
- |> patch("/api/v1/accounts/update_credentials", %{hide_followers: "true"})
+ assert user_data = json_response(conn, 200)
+ assert user_data["pleroma"]["hide_followers"] == true
+ end
+
+ test "updates the user's discoverable status", %{conn: conn} do
+ assert %{"source" => %{"pleroma" => %{"discoverable" => true}}} =
+ conn
+ |> patch("/api/v1/accounts/update_credentials", %{discoverable: "true"})
+ |> json_response(:ok)
- assert user = json_response(conn, 200)
- assert user["pleroma"]["hide_followers"] == true
+ assert %{"source" => %{"pleroma" => %{"discoverable" => false}}} =
+ conn
+ |> patch("/api/v1/accounts/update_credentials", %{discoverable: "false"})
+ |> json_response(:ok)
end
test "updates the user's hide_followers_count and hide_follows_count", %{conn: conn} do
- user = insert(:user)
-
conn =
- conn
- |> assign(:user, user)
- |> patch("/api/v1/accounts/update_credentials", %{
+ patch(conn, "/api/v1/accounts/update_credentials", %{
hide_followers_count: "true",
hide_follows_count: "true"
})
- assert user = json_response(conn, 200)
- assert user["pleroma"]["hide_followers_count"] == true
- assert user["pleroma"]["hide_follows_count"] == true
+ assert user_data = json_response(conn, 200)
+ assert user_data["pleroma"]["hide_followers_count"] == true
+ assert user_data["pleroma"]["hide_follows_count"] == true
end
- test "updates the user's skip_thread_containment option", %{conn: conn} do
- user = insert(:user)
-
+ test "updates the user's skip_thread_containment option", %{user: user, conn: conn} do
response =
conn
- |> assign(:user, user)
|> patch("/api/v1/accounts/update_credentials", %{skip_thread_containment: "true"})
|> json_response(200)
@@ -157,104 +153,68 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
end
test "updates the user's hide_follows status", %{conn: conn} do
- user = insert(:user)
+ conn = patch(conn, "/api/v1/accounts/update_credentials", %{hide_follows: "true"})
- conn =
- conn
- |> assign(:user, user)
- |> patch("/api/v1/accounts/update_credentials", %{hide_follows: "true"})
-
- assert user = json_response(conn, 200)
- assert user["pleroma"]["hide_follows"] == true
+ assert user_data = json_response(conn, 200)
+ assert user_data["pleroma"]["hide_follows"] == true
end
test "updates the user's hide_favorites status", %{conn: conn} do
- user = insert(:user)
+ conn = patch(conn, "/api/v1/accounts/update_credentials", %{hide_favorites: "true"})
- conn =
- conn
- |> assign(:user, user)
- |> patch("/api/v1/accounts/update_credentials", %{hide_favorites: "true"})
-
- assert user = json_response(conn, 200)
- assert user["pleroma"]["hide_favorites"] == true
+ assert user_data = json_response(conn, 200)
+ assert user_data["pleroma"]["hide_favorites"] == true
end
test "updates the user's show_role status", %{conn: conn} do
- user = insert(:user)
-
- conn =
- conn
- |> assign(:user, user)
- |> patch("/api/v1/accounts/update_credentials", %{show_role: "false"})
+ conn = patch(conn, "/api/v1/accounts/update_credentials", %{show_role: "false"})
- assert user = json_response(conn, 200)
- assert user["source"]["pleroma"]["show_role"] == false
+ assert user_data = json_response(conn, 200)
+ assert user_data["source"]["pleroma"]["show_role"] == false
end
test "updates the user's no_rich_text status", %{conn: conn} do
- user = insert(:user)
+ conn = patch(conn, "/api/v1/accounts/update_credentials", %{no_rich_text: "true"})
- conn =
- conn
- |> assign(:user, user)
- |> patch("/api/v1/accounts/update_credentials", %{no_rich_text: "true"})
-
- assert user = json_response(conn, 200)
- assert user["source"]["pleroma"]["no_rich_text"] == true
+ assert user_data = json_response(conn, 200)
+ assert user_data["source"]["pleroma"]["no_rich_text"] == true
end
test "updates the user's name", %{conn: conn} do
- user = insert(:user)
-
conn =
- conn
- |> assign(:user, user)
- |> patch("/api/v1/accounts/update_credentials", %{"display_name" => "markorepairs"})
+ patch(conn, "/api/v1/accounts/update_credentials", %{"display_name" => "markorepairs"})
- assert user = json_response(conn, 200)
- assert user["display_name"] == "markorepairs"
+ assert user_data = json_response(conn, 200)
+ assert user_data["display_name"] == "markorepairs"
end
- test "updates the user's avatar", %{conn: conn} do
- user = insert(:user)
-
+ test "updates the user's avatar", %{user: user, conn: conn} do
new_avatar = %Plug.Upload{
content_type: "image/jpg",
path: Path.absname("test/fixtures/image.jpg"),
filename: "an_image.jpg"
}
- conn =
- conn
- |> assign(:user, user)
- |> patch("/api/v1/accounts/update_credentials", %{"avatar" => new_avatar})
+ conn = patch(conn, "/api/v1/accounts/update_credentials", %{"avatar" => new_avatar})
assert user_response = json_response(conn, 200)
assert user_response["avatar"] != User.avatar_url(user)
end
- test "updates the user's banner", %{conn: conn} do
- user = insert(:user)
-
+ test "updates the user's banner", %{user: user, conn: conn} do
new_header = %Plug.Upload{
content_type: "image/jpg",
path: Path.absname("test/fixtures/image.jpg"),
filename: "an_image.jpg"
}
- conn =
- conn
- |> assign(:user, user)
- |> patch("/api/v1/accounts/update_credentials", %{"header" => new_header})
+ conn = patch(conn, "/api/v1/accounts/update_credentials", %{"header" => new_header})
assert user_response = json_response(conn, 200)
assert user_response["header"] != User.banner_url(user)
end
test "updates the user's background", %{conn: conn} do
- user = insert(:user)
-
new_header = %Plug.Upload{
content_type: "image/jpg",
path: Path.absname("test/fixtures/image.jpg"),
@@ -262,9 +222,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
}
conn =
- conn
- |> assign(:user, user)
- |> patch("/api/v1/accounts/update_credentials", %{
+ patch(conn, "/api/v1/accounts/update_credentials", %{
"pleroma_background_image" => new_header
})
@@ -272,13 +230,13 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
assert user_response["pleroma"]["background_image"]
end
- test "requires 'write:accounts' permission", %{conn: conn} do
+ test "requires 'write:accounts' permission" do
token1 = insert(:oauth_token, scopes: ["read"])
token2 = insert(:oauth_token, scopes: ["write", "follow"])
for token <- [token1, token2] do
conn =
- conn
+ build_conn()
|> put_req_header("authorization", "Bearer #{token.token}")
|> patch("/api/v1/accounts/update_credentials", %{})
@@ -291,53 +249,44 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
end
end
- test "updates profile emojos", %{conn: conn} do
- user = insert(:user)
-
+ test "updates profile emojos", %{user: user, conn: conn} do
note = "*sips :blank:*"
name = "I am :firefox:"
- conn =
- conn
- |> assign(:user, user)
- |> patch("/api/v1/accounts/update_credentials", %{
+ ret_conn =
+ patch(conn, "/api/v1/accounts/update_credentials", %{
"note" => note,
"display_name" => name
})
- assert json_response(conn, 200)
+ assert json_response(ret_conn, 200)
- conn =
- conn
- |> get("/api/v1/accounts/#{user.id}")
+ conn = get(conn, "/api/v1/accounts/#{user.id}")
- assert user = json_response(conn, 200)
+ assert user_data = json_response(conn, 200)
- assert user["note"] == note
- assert user["display_name"] == name
- assert [%{"shortcode" => "blank"}, %{"shortcode" => "firefox"}] = user["emojis"]
+ assert user_data["note"] == note
+ assert user_data["display_name"] == name
+ assert [%{"shortcode" => "blank"}, %{"shortcode" => "firefox"}] = user_data["emojis"]
end
test "update fields", %{conn: conn} do
- user = insert(:user)
-
fields = [
%{"name" => "foo", "value" => ""},
%{"name" => "link", "value" => "cofe.io"}
]
- account =
+ account_data =
conn
- |> assign(:user, user)
|> patch("/api/v1/accounts/update_credentials", %{"fields_attributes" => fields})
|> json_response(200)
- assert account["fields"] == [
- %{"name" => "foo", "value" => "bar"},
+ assert account_data["fields"] == [
+ %{"name" => "foo", "value" => "bar"},
%{"name" => "link", "value" => ~S(cofe.io)}
]
- assert account["source"]["fields"] == [
+ assert account_data["source"]["fields"] == [
%{
"name" => "foo",
"value" => ""
@@ -357,12 +306,11 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
account =
conn
|> put_req_header("content-type", "application/x-www-form-urlencoded")
- |> assign(:user, user)
|> patch("/api/v1/accounts/update_credentials", fields)
|> json_response(200)
assert account["fields"] == [
- %{"name" => "foo", "value" => "bar"},
+ %{"name" => "foo", "value" => "bar"},
%{"name" => "link", "value" => ~S(cofe.io)}
]
@@ -383,7 +331,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
assert %{"error" => "Invalid request"} ==
conn
- |> assign(:user, user)
|> patch("/api/v1/accounts/update_credentials", %{"fields_attributes" => fields})
|> json_response(403)
@@ -393,7 +340,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
assert %{"error" => "Invalid request"} ==
conn
- |> assign(:user, user)
|> patch("/api/v1/accounts/update_credentials", %{"fields_attributes" => fields})
|> json_response(403)
@@ -406,7 +352,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
assert %{"error" => "Invalid request"} ==
conn
- |> assign(:user, user)
|> patch("/api/v1/accounts/update_credentials", %{"fields_attributes" => fields})
|> json_response(403)
@@ -417,7 +362,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
account =
conn
- |> assign(:user, user)
|> patch("/api/v1/accounts/update_credentials", %{"fields_attributes" => fields})
|> json_response(200)