summaryrefslogtreecommitdiff
path: root/test/web/mastodon_api
diff options
context:
space:
mode:
Diffstat (limited to 'test/web/mastodon_api')
-rw-r--r--test/web/mastodon_api/controllers/account_controller/update_credentials_test.exs38
-rw-r--r--test/web/mastodon_api/controllers/conversation_controller_test.exs183
-rw-r--r--test/web/mastodon_api/controllers/timeline_controller_test.exs11
-rw-r--r--test/web/mastodon_api/views/account_view_test.exs35
4 files changed, 155 insertions, 112 deletions
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 696228203..7c420985d 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
@@ -8,6 +8,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
use Pleroma.Web.ConnCase
+ import Mock
import Pleroma.Factory
setup do: clear_config([:instance, :max_account_fields])
@@ -52,24 +53,31 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
user = Repo.get(User, user_data["id"])
- res_conn =
- conn
- |> assign(:user, user)
- |> patch("/api/v1/accounts/update_credentials", %{
- "pleroma_settings_store" => %{
- masto_fe: %{
- theme: "blub"
+ clear_config([:instance, :federating], true)
+
+ with_mock Pleroma.Web.Federator,
+ publish: fn _activity -> :ok end do
+ res_conn =
+ conn
+ |> assign(:user, user)
+ |> patch("/api/v1/accounts/update_credentials", %{
+ "pleroma_settings_store" => %{
+ masto_fe: %{
+ theme: "blub"
+ }
}
- }
- })
+ })
- assert user_data = json_response_and_validate_schema(res_conn, 200)
+ assert user_data = json_response_and_validate_schema(res_conn, 200)
- assert user_data["pleroma"]["settings_store"] ==
- %{
- "pleroma_fe" => %{"theme" => "bla"},
- "masto_fe" => %{"theme" => "blub"}
- }
+ assert user_data["pleroma"]["settings_store"] ==
+ %{
+ "pleroma_fe" => %{"theme" => "bla"},
+ "masto_fe" => %{"theme" => "blub"}
+ }
+
+ assert_called(Pleroma.Web.Federator.publish(:_))
+ end
end
test "updates the user's bio", %{conn: conn} do
diff --git a/test/web/mastodon_api/controllers/conversation_controller_test.exs b/test/web/mastodon_api/controllers/conversation_controller_test.exs
index 693ba51e5..3e21e6bf1 100644
--- a/test/web/mastodon_api/controllers/conversation_controller_test.exs
+++ b/test/web/mastodon_api/controllers/conversation_controller_test.exs
@@ -12,84 +12,88 @@ defmodule Pleroma.Web.MastodonAPI.ConversationControllerTest do
setup do: oauth_access(["read:statuses"])
- test "returns a list of conversations", %{user: user_one, conn: conn} do
- user_two = insert(:user)
- user_three = insert(:user)
-
- {:ok, user_two} = User.follow(user_two, user_one)
-
- assert User.get_cached_by_id(user_two.id).unread_conversation_count == 0
-
- {:ok, direct} =
- CommonAPI.post(user_one, %{
- status: "Hi @#{user_two.nickname}, @#{user_three.nickname}!",
- visibility: "direct"
- })
-
- assert User.get_cached_by_id(user_two.id).unread_conversation_count == 1
-
- {:ok, _follower_only} =
- CommonAPI.post(user_one, %{
- status: "Hi @#{user_two.nickname}!",
- visibility: "private"
- })
-
- res_conn = get(conn, "/api/v1/conversations")
-
- assert response = json_response_and_validate_schema(res_conn, 200)
-
- assert [
- %{
- "id" => res_id,
- "accounts" => res_accounts,
- "last_status" => res_last_status,
- "unread" => unread
- }
- ] = response
-
- account_ids = Enum.map(res_accounts, & &1["id"])
- assert length(res_accounts) == 2
- assert user_two.id in account_ids
- assert user_three.id in account_ids
- assert is_binary(res_id)
- assert unread == false
- assert res_last_status["id"] == direct.id
- assert User.get_cached_by_id(user_one.id).unread_conversation_count == 0
+ describe "returns a list of conversations" do
+ setup(%{user: user_one, conn: conn}) do
+ user_two = insert(:user)
+ user_three = insert(:user)
+
+ {:ok, user_two} = User.follow(user_two, user_one)
+
+ {:ok, %{user: user_one, user_two: user_two, user_three: user_three, conn: conn}}
+ end
+
+ test "returns correct conversations", %{
+ user: user_one,
+ user_two: user_two,
+ user_three: user_three,
+ conn: conn
+ } do
+ assert User.get_cached_by_id(user_two.id).unread_conversation_count == 0
+ {:ok, direct} = create_direct_message(user_one, [user_two, user_three])
+
+ assert User.get_cached_by_id(user_two.id).unread_conversation_count == 1
+
+ {:ok, _follower_only} =
+ CommonAPI.post(user_one, %{
+ status: "Hi @#{user_two.nickname}!",
+ visibility: "private"
+ })
+
+ res_conn = get(conn, "/api/v1/conversations")
+
+ assert response = json_response_and_validate_schema(res_conn, 200)
+
+ assert [
+ %{
+ "id" => res_id,
+ "accounts" => res_accounts,
+ "last_status" => res_last_status,
+ "unread" => unread
+ }
+ ] = response
+
+ account_ids = Enum.map(res_accounts, & &1["id"])
+ assert length(res_accounts) == 2
+ assert user_two.id in account_ids
+ assert user_three.id in account_ids
+ assert is_binary(res_id)
+ assert unread == false
+ assert res_last_status["id"] == direct.id
+ assert User.get_cached_by_id(user_one.id).unread_conversation_count == 0
+ end
+
+ test "observes limit params", %{
+ user: user_one,
+ user_two: user_two,
+ user_three: user_three,
+ conn: conn
+ } do
+ {:ok, _} = create_direct_message(user_one, [user_two, user_three])
+ {:ok, _} = create_direct_message(user_two, [user_one, user_three])
+ {:ok, _} = create_direct_message(user_three, [user_two, user_one])
+
+ res_conn = get(conn, "/api/v1/conversations?limit=1")
+
+ assert response = json_response_and_validate_schema(res_conn, 200)
+
+ assert Enum.count(response) == 1
+
+ res_conn = get(conn, "/api/v1/conversations?limit=2")
+
+ assert response = json_response_and_validate_schema(res_conn, 200)
+
+ assert Enum.count(response) == 2
+ end
end
test "filters conversations by recipients", %{user: user_one, conn: conn} do
user_two = insert(:user)
user_three = insert(:user)
-
- {:ok, direct1} =
- CommonAPI.post(user_one, %{
- status: "Hi @#{user_two.nickname}!",
- visibility: "direct"
- })
-
- {:ok, _direct2} =
- CommonAPI.post(user_one, %{
- status: "Hi @#{user_three.nickname}!",
- visibility: "direct"
- })
-
- {:ok, direct3} =
- CommonAPI.post(user_one, %{
- status: "Hi @#{user_two.nickname}, @#{user_three.nickname}!",
- visibility: "direct"
- })
-
- {:ok, _direct4} =
- CommonAPI.post(user_two, %{
- status: "Hi @#{user_three.nickname}!",
- visibility: "direct"
- })
-
- {:ok, direct5} =
- CommonAPI.post(user_two, %{
- status: "Hi @#{user_one.nickname}!",
- visibility: "direct"
- })
+ {:ok, direct1} = create_direct_message(user_one, [user_two])
+ {:ok, _direct2} = create_direct_message(user_one, [user_three])
+ {:ok, direct3} = create_direct_message(user_one, [user_two, user_three])
+ {:ok, _direct4} = create_direct_message(user_two, [user_three])
+ {:ok, direct5} = create_direct_message(user_two, [user_one])
assert [conversation1, conversation2] =
conn
@@ -109,12 +113,7 @@ defmodule Pleroma.Web.MastodonAPI.ConversationControllerTest do
test "updates the last_status on reply", %{user: user_one, conn: conn} do
user_two = insert(:user)
-
- {:ok, direct} =
- CommonAPI.post(user_one, %{
- status: "Hi @#{user_two.nickname}",
- visibility: "direct"
- })
+ {:ok, direct} = create_direct_message(user_one, [user_two])
{:ok, direct_reply} =
CommonAPI.post(user_two, %{
@@ -133,12 +132,7 @@ defmodule Pleroma.Web.MastodonAPI.ConversationControllerTest do
test "the user marks a conversation as read", %{user: user_one, conn: conn} do
user_two = insert(:user)
-
- {:ok, direct} =
- CommonAPI.post(user_one, %{
- status: "Hi @#{user_two.nickname}",
- visibility: "direct"
- })
+ {:ok, direct} = create_direct_message(user_one, [user_two])
assert User.get_cached_by_id(user_one.id).unread_conversation_count == 0
assert User.get_cached_by_id(user_two.id).unread_conversation_count == 1
@@ -194,15 +188,22 @@ defmodule Pleroma.Web.MastodonAPI.ConversationControllerTest do
test "(vanilla) Mastodon frontend behaviour", %{user: user_one, conn: conn} do
user_two = insert(:user)
-
- {:ok, direct} =
- CommonAPI.post(user_one, %{
- status: "Hi @#{user_two.nickname}!",
- visibility: "direct"
- })
+ {:ok, direct} = create_direct_message(user_one, [user_two])
res_conn = get(conn, "/api/v1/statuses/#{direct.id}/context")
assert %{"ancestors" => [], "descendants" => []} == json_response(res_conn, 200)
end
+
+ defp create_direct_message(sender, recips) do
+ hellos =
+ recips
+ |> Enum.map(fn s -> "@#{s.nickname}" end)
+ |> Enum.join(", ")
+
+ CommonAPI.post(sender, %{
+ status: "Hi #{hellos}!",
+ visibility: "direct"
+ })
+ end
end
diff --git a/test/web/mastodon_api/controllers/timeline_controller_test.exs b/test/web/mastodon_api/controllers/timeline_controller_test.exs
index 2375ac8e8..65b4079fe 100644
--- a/test/web/mastodon_api/controllers/timeline_controller_test.exs
+++ b/test/web/mastodon_api/controllers/timeline_controller_test.exs
@@ -60,9 +60,9 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
describe "public" do
@tag capture_log: true
test "the public timeline", %{conn: conn} do
- following = insert(:user)
+ user = insert(:user)
- {:ok, _activity} = CommonAPI.post(following, %{status: "test"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "test"})
_activity = insert(:note_activity, local: false)
@@ -77,6 +77,13 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
conn = get(build_conn(), "/api/v1/timelines/public?local=1")
assert [%{"content" => "test"}] = json_response_and_validate_schema(conn, :ok)
+
+ # does not contain repeats
+ {:ok, _} = CommonAPI.repeat(activity.id, user)
+
+ conn = get(build_conn(), "/api/v1/timelines/public?local=true")
+
+ assert [_] = json_response_and_validate_schema(conn, :ok)
end
test "the public timeline includes only public statuses for an authenticated user" do
diff --git a/test/web/mastodon_api/views/account_view_test.exs b/test/web/mastodon_api/views/account_view_test.exs
index 487ec26c2..f91333e5c 100644
--- a/test/web/mastodon_api/views/account_view_test.exs
+++ b/test/web/mastodon_api/views/account_view_test.exs
@@ -54,10 +54,10 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
header_static: "http://localhost:4001/images/banner.png",
emojis: [
%{
- "static_url" => "/file.png",
- "url" => "/file.png",
- "shortcode" => "karjalanpiirakka",
- "visible_in_picker" => false
+ static_url: "/file.png",
+ url: "/file.png",
+ shortcode: "karjalanpiirakka",
+ visible_in_picker: false
}
],
fields: [],
@@ -491,4 +491,31 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
AccountView.render("show.json", %{user: user, for: user})
end
end
+
+ test "uses mediaproxy urls when it's enabled" do
+ clear_config([:media_proxy, :enabled], true)
+
+ user =
+ insert(:user,
+ avatar: %{"url" => [%{"href" => "https://evil.website/avatar.png"}]},
+ banner: %{"url" => [%{"href" => "https://evil.website/banner.png"}]},
+ emoji: %{"joker_smile" => "https://evil.website/society.png"}
+ )
+
+ AccountView.render("show.json", %{user: user})
+ |> Enum.all?(fn
+ {key, url} when key in [:avatar, :avatar_static, :header, :header_static] ->
+ String.starts_with?(url, Pleroma.Web.base_url())
+
+ {:emojis, emojis} ->
+ Enum.all?(emojis, fn %{url: url, static_url: static_url} ->
+ String.starts_with?(url, Pleroma.Web.base_url()) &&
+ String.starts_with?(static_url, Pleroma.Web.base_url())
+ end)
+
+ _ ->
+ true
+ end)
+ |> assert()
+ end
end