summaryrefslogtreecommitdiff
path: root/test/web/mastodon_api
diff options
context:
space:
mode:
authorIvan Tashkinov <ivantashkinov@gmail.com>2020-05-01 18:45:24 +0300
committerIvan Tashkinov <ivantashkinov@gmail.com>2020-05-01 18:45:24 +0300
commitd5cdc907e3fda14c2ce78ddbb124739441330ecc (patch)
treee6d214d87f18a7389f42049e5bae244e4d99aa77 /test/web/mastodon_api
parented4e9e6435cdc4740cf12464f01ffdb5a6a96583 (diff)
downloadpleroma-d5cdc907e3fda14c2ce78ddbb124739441330ecc.tar.gz
pleroma-d5cdc907e3fda14c2ce78ddbb124739441330ecc.zip
Restricted embedding of relationships where applicable (statuses / notifications / accounts rendering).
Added support for :skip_notifications for accounts listing (index.json). Adjusted tests.
Diffstat (limited to 'test/web/mastodon_api')
-rw-r--r--test/web/mastodon_api/controllers/notification_controller_test.exs4
-rw-r--r--test/web/mastodon_api/controllers/status_controller_test.exs2
-rw-r--r--test/web/mastodon_api/controllers/timeline_controller_test.exs26
-rw-r--r--test/web/mastodon_api/views/notification_view_test.exs25
-rw-r--r--test/web/mastodon_api/views/status_view_test.exs14
5 files changed, 43 insertions, 28 deletions
diff --git a/test/web/mastodon_api/controllers/notification_controller_test.exs b/test/web/mastodon_api/controllers/notification_controller_test.exs
index db380f76a..e2d98ef3e 100644
--- a/test/web/mastodon_api/controllers/notification_controller_test.exs
+++ b/test/web/mastodon_api/controllers/notification_controller_test.exs
@@ -12,9 +12,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
import Pleroma.Factory
- test "does NOT render account/pleroma/relationship if this is disabled by default" do
- clear_config([:extensions, :output_relationships_in_statuses_by_default], false)
-
+ test "does NOT render account/pleroma/relationship by default" do
%{user: user, conn: conn} = oauth_access(["read:notifications"])
other_user = insert(:user)
diff --git a/test/web/mastodon_api/controllers/status_controller_test.exs b/test/web/mastodon_api/controllers/status_controller_test.exs
index 85068edd0..00e026087 100644
--- a/test/web/mastodon_api/controllers/status_controller_test.exs
+++ b/test/web/mastodon_api/controllers/status_controller_test.exs
@@ -1058,7 +1058,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
end
test "bookmarks" do
- bookmarks_uri = "/api/v1/bookmarks?with_relationships=true"
+ bookmarks_uri = "/api/v1/bookmarks"
%{conn: conn} = oauth_access(["write:bookmarks", "read:bookmarks"])
author = insert(:user)
diff --git a/test/web/mastodon_api/controllers/timeline_controller_test.exs b/test/web/mastodon_api/controllers/timeline_controller_test.exs
index 06efdc901..b8bb83af7 100644
--- a/test/web/mastodon_api/controllers/timeline_controller_test.exs
+++ b/test/web/mastodon_api/controllers/timeline_controller_test.exs
@@ -20,12 +20,10 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
describe "home" do
setup do: oauth_access(["read:statuses"])
- test "does NOT render account/pleroma/relationship if this is disabled by default", %{
+ test "does NOT render account/pleroma/relationship by default", %{
user: user,
conn: conn
} do
- clear_config([:extensions, :output_relationships_in_statuses_by_default], false)
-
other_user = insert(:user)
{:ok, _} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"})
@@ -41,7 +39,7 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
end)
end
- test "the home timeline", %{user: user, conn: conn} do
+ test "embeds account relationships with `with_relationships=true`", %{user: user, conn: conn} do
uri = "/api/v1/timelines/home?with_relationships=true"
following = insert(:user, nickname: "followed")
@@ -69,13 +67,19 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
}
}
},
- "account" => %{"pleroma" => %{"relationship" => %{"following" => true}}}
+ "account" => %{
+ "pleroma" => %{
+ "relationship" => %{"following" => true}
+ }
+ }
},
%{
"content" => "post",
"account" => %{
"acct" => "followed",
- "pleroma" => %{"relationship" => %{"following" => true}}
+ "pleroma" => %{
+ "relationship" => %{"following" => true}
+ }
}
}
] = json_response(ret_conn, :ok)
@@ -95,13 +99,19 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
}
}
},
- "account" => %{"pleroma" => %{"relationship" => %{"following" => true}}}
+ "account" => %{
+ "pleroma" => %{
+ "relationship" => %{"following" => true}
+ }
+ }
},
%{
"content" => "post",
"account" => %{
"acct" => "followed",
- "pleroma" => %{"relationship" => %{"following" => true}}
+ "pleroma" => %{
+ "relationship" => %{"following" => true}
+ }
}
}
] = json_response(ret_conn, :ok)
diff --git a/test/web/mastodon_api/views/notification_view_test.exs b/test/web/mastodon_api/views/notification_view_test.exs
index c3ec9dfec..e1f9c3ac4 100644
--- a/test/web/mastodon_api/views/notification_view_test.exs
+++ b/test/web/mastodon_api/views/notification_view_test.exs
@@ -42,7 +42,12 @@ defmodule Pleroma.Web.MastodonAPI.NotificationViewTest do
id: to_string(notification.id),
pleroma: %{is_seen: false},
type: "mention",
- account: AccountView.render("show.json", %{user: user, for: mentioned_user}),
+ account:
+ AccountView.render("show.json", %{
+ user: user,
+ for: mentioned_user,
+ skip_relationships: true
+ }),
status: StatusView.render("show.json", %{activity: activity, for: mentioned_user}),
created_at: Utils.to_masto_date(notification.inserted_at)
}
@@ -62,7 +67,8 @@ defmodule Pleroma.Web.MastodonAPI.NotificationViewTest do
id: to_string(notification.id),
pleroma: %{is_seen: false},
type: "favourite",
- account: AccountView.render("show.json", %{user: another_user, for: user}),
+ account:
+ AccountView.render("show.json", %{user: another_user, for: user, skip_relationships: true}),
status: StatusView.render("show.json", %{activity: create_activity, for: user}),
created_at: Utils.to_masto_date(notification.inserted_at)
}
@@ -82,7 +88,8 @@ defmodule Pleroma.Web.MastodonAPI.NotificationViewTest do
id: to_string(notification.id),
pleroma: %{is_seen: false},
type: "reblog",
- account: AccountView.render("show.json", %{user: another_user, for: user}),
+ account:
+ AccountView.render("show.json", %{user: another_user, for: user, skip_relationships: true}),
status: StatusView.render("show.json", %{activity: reblog_activity, for: user}),
created_at: Utils.to_masto_date(notification.inserted_at)
}
@@ -100,7 +107,8 @@ defmodule Pleroma.Web.MastodonAPI.NotificationViewTest do
id: to_string(notification.id),
pleroma: %{is_seen: false},
type: "follow",
- account: AccountView.render("show.json", %{user: follower, for: followed}),
+ account:
+ AccountView.render("show.json", %{user: follower, for: followed, skip_relationships: true}),
created_at: Utils.to_masto_date(notification.inserted_at)
}
@@ -143,8 +151,10 @@ defmodule Pleroma.Web.MastodonAPI.NotificationViewTest do
id: to_string(notification.id),
pleroma: %{is_seen: false},
type: "move",
- account: AccountView.render("show.json", %{user: old_user, for: follower}),
- target: AccountView.render("show.json", %{user: new_user, for: follower}),
+ account:
+ AccountView.render("show.json", %{user: old_user, for: follower, skip_relationships: true}),
+ target:
+ AccountView.render("show.json", %{user: new_user, for: follower, skip_relationships: true}),
created_at: Utils.to_masto_date(notification.inserted_at)
}
@@ -169,7 +179,8 @@ defmodule Pleroma.Web.MastodonAPI.NotificationViewTest do
pleroma: %{is_seen: false},
type: "pleroma:emoji_reaction",
emoji: "☕",
- account: AccountView.render("show.json", %{user: other_user, for: user}),
+ account:
+ AccountView.render("show.json", %{user: other_user, for: user, skip_relationships: true}),
status: StatusView.render("show.json", %{activity: activity, for: user}),
created_at: Utils.to_masto_date(notification.inserted_at)
}
diff --git a/test/web/mastodon_api/views/status_view_test.exs b/test/web/mastodon_api/views/status_view_test.exs
index 6791c2fb0..91d4ded2c 100644
--- a/test/web/mastodon_api/views/status_view_test.exs
+++ b/test/web/mastodon_api/views/status_view_test.exs
@@ -555,7 +555,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
end
end
- test "embeds a relationship in the account" do
+ test "does not embed a relationship in the account" do
user = insert(:user)
other_user = insert(:user)
@@ -566,11 +566,10 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
result = StatusView.render("show.json", %{activity: activity, for: other_user})
- assert result[:account][:pleroma][:relationship] ==
- AccountView.render("relationship.json", %{user: other_user, target: user})
+ assert result[:account][:pleroma][:relationship] == %{}
end
- test "embeds a relationship in the account in reposts" do
+ test "does not embed a relationship in the account in reposts" do
user = insert(:user)
other_user = insert(:user)
@@ -583,11 +582,8 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
result = StatusView.render("show.json", %{activity: activity, for: user})
- assert result[:account][:pleroma][:relationship] ==
- AccountView.render("relationship.json", %{user: user, target: other_user})
-
- assert result[:reblog][:account][:pleroma][:relationship] ==
- AccountView.render("relationship.json", %{user: user, target: user})
+ assert result[:account][:pleroma][:relationship] == %{}
+ assert result[:reblog][:account][:pleroma][:relationship] == %{}
end
test "visibility/list" do