aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaksim Pechnikov <parallel588@gmail.com>2019-09-23 22:37:30 +0300
committerMaksim Pechnikov <parallel588@gmail.com>2019-09-23 22:37:30 +0300
commit494bb6bac64361860db194aed57618450a76177d (patch)
tree1fed3fe3d2002745d0a4ddde6ab5390e533d1fd5
parent179fa32dd5d7b4cf1b338fc3df4840ae33525606 (diff)
downloadpleroma-494bb6bac64361860db194aed57618450a76177d.tar.gz
updated tests
-rw-r--r--lib/pleroma/web/mastodon_api/controllers/mastodon_api_controller.ex18
-rw-r--r--lib/pleroma/web/mastodon_api/views/status_view.ex4
-rw-r--r--test/web/mastodon_api/mastodon_api_controller_test.exs39
3 files changed, 35 insertions, 26 deletions
diff --git a/lib/pleroma/web/mastodon_api/controllers/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/controllers/mastodon_api_controller.ex
index 0c2b8dbb7..da74e4aa2 100644
--- a/lib/pleroma/web/mastodon_api/controllers/mastodon_api_controller.ex
+++ b/lib/pleroma/web/mastodon_api/controllers/mastodon_api_controller.ex
@@ -44,6 +44,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
alias Pleroma.Web.OAuth.Authorization
alias Pleroma.Web.OAuth.Scopes
alias Pleroma.Web.OAuth.Token
+ alias Pleroma.Web.RichMedia
alias Pleroma.Web.TwitterAPI.TwitterAPI
alias Pleroma.Web.ControllerHelper
@@ -1530,19 +1531,16 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
end
end
- def status_card(%{assigns: %{user: user}} = conn, %{"id" => status_id}) do
- with %Activity{} = activity <- Activity.get_by_id(status_id),
+ def status_card(%{assigns: %{user: user}} = conn, %{"id" => id}) do
+ with %Activity{} = activity <- Activity.get_by_id(id),
true <- Visibility.visible_for_user?(activity, user) do
- data =
- StatusView.render(
- "card.json",
- Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity)
- )
+ data = RichMedia.Helpers.fetch_data_for_activity(activity)
- json(conn, data)
+ conn
+ |> put_view(StatusView)
+ |> render("card.json", data)
else
- _e ->
- json(conn, %{})
+ _e -> {:error, :not_found}
end
end
diff --git a/lib/pleroma/web/mastodon_api/views/status_view.ex b/lib/pleroma/web/mastodon_api/views/status_view.ex
index ef796cddd..0450ed4d9 100644
--- a/lib/pleroma/web/mastodon_api/views/status_view.ex
+++ b/lib/pleroma/web/mastodon_api/views/status_view.ex
@@ -343,9 +343,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
}
end
- def render("card.json", _) do
- nil
- end
+ def render("card.json", _), do: nil
def render("attachment.json", %{attachment: attachment}) do
[attachment_url | _] = attachment["url"]
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index 46e74fc75..14cd71aa8 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -2798,6 +2798,18 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
%{user: user}
end
+ test "returns empty result when rich_media disabled", %{conn: conn, user: user} do
+ Config.put([:rich_media, :enabled], false)
+ {:ok, activity} = CommonAPI.post(user, %{"status" => "https://example.com/ogp"})
+
+ response =
+ conn
+ |> get("/api/v1/statuses/#{activity.id}/card")
+ |> json_response(200)
+
+ assert response == nil
+ end
+
test "returns rich-media card", %{conn: conn, user: user} do
{:ok, activity} = CommonAPI.post(user, %{"status" => "https://example.com/ogp"})
@@ -2869,22 +2881,23 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
}
end
- test "returns empty object when id invalid", %{conn: conn} do
- response =
- conn
- |> get("/api/v1/statuses/9eoozpwTul5mjSEDRI/card")
- |> json_response(200)
-
- assert response == %{}
+ test "returns 404 response when id invalid", %{conn: conn} do
+ assert %{"error" => "Record not found"} =
+ conn
+ |> get("/api/v1/statuses/9eoozpwTul5mjSEDRI/card")
+ |> json_response(404)
end
- test "returns empty object when id isn't FlakeID", %{conn: conn} do
- response =
- conn
- |> get("/api/v1/statuses/3ebbadd1-eb14-4e20-8118/card")
- |> json_response(200)
+ test "returns 404 response when id isn't FlakeID", %{conn: conn} do
+ assert %{"error" => "Record not found"} =
+ conn
+ |> get("/api/v1/statuses/3ebbadd1-eb14-4e20-8118/card")
+ |> json_response(404)
- assert response == %{}
+ assert %{"error" => "Record not found"} =
+ conn
+ |> get("/api/v1/statuses/8118/card")
+ |> json_response(404)
end
end