updated tests

This commit is contained in:
Maksim Pechnikov 2019-09-23 22:37:30 +03:00
parent 179fa32dd5
commit 494bb6bac6
3 changed files with 35 additions and 26 deletions

View File

@ -44,6 +44,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
alias Pleroma.Web.OAuth.Authorization alias Pleroma.Web.OAuth.Authorization
alias Pleroma.Web.OAuth.Scopes alias Pleroma.Web.OAuth.Scopes
alias Pleroma.Web.OAuth.Token alias Pleroma.Web.OAuth.Token
alias Pleroma.Web.RichMedia
alias Pleroma.Web.TwitterAPI.TwitterAPI alias Pleroma.Web.TwitterAPI.TwitterAPI
alias Pleroma.Web.ControllerHelper alias Pleroma.Web.ControllerHelper
@ -1530,19 +1531,16 @@ defp fetch_suggestion_id(attrs) do
end end
end end
def status_card(%{assigns: %{user: user}} = conn, %{"id" => status_id}) do def status_card(%{assigns: %{user: user}} = conn, %{"id" => id}) do
with %Activity{} = activity <- Activity.get_by_id(status_id), with %Activity{} = activity <- Activity.get_by_id(id),
true <- Visibility.visible_for_user?(activity, user) do true <- Visibility.visible_for_user?(activity, user) do
data = data = RichMedia.Helpers.fetch_data_for_activity(activity)
StatusView.render(
"card.json",
Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity)
)
json(conn, data) conn
|> put_view(StatusView)
|> render("card.json", data)
else else
_e -> _e -> {:error, :not_found}
json(conn, %{})
end end
end end

View File

@ -343,9 +343,7 @@ def render("card.json", %{rich_media: rich_media, page_url: page_url}) do
} }
end end
def render("card.json", _) do def render("card.json", _), do: nil
nil
end
def render("attachment.json", %{attachment: attachment}) do def render("attachment.json", %{attachment: attachment}) do
[attachment_url | _] = attachment["url"] [attachment_url | _] = attachment["url"]

View File

@ -2798,6 +2798,18 @@ test "max pinned statuses", %{conn: conn, user: user, activity: activity_one} do
%{user: user} %{user: user}
end 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 test "returns rich-media card", %{conn: conn, user: user} do
{:ok, activity} = CommonAPI.post(user, %{"status" => "https://example.com/ogp"}) {:ok, activity} = CommonAPI.post(user, %{"status" => "https://example.com/ogp"})
@ -2869,22 +2881,23 @@ test "replaces missing description with an empty string", %{conn: conn, user: us
} }
end end
test "returns empty object when id invalid", %{conn: conn} do test "returns 404 response when id invalid", %{conn: conn} do
response = assert %{"error" => "Record not found"} =
conn conn
|> get("/api/v1/statuses/9eoozpwTul5mjSEDRI/card") |> get("/api/v1/statuses/9eoozpwTul5mjSEDRI/card")
|> json_response(200) |> json_response(404)
assert response == %{}
end end
test "returns empty object when id isn't FlakeID", %{conn: conn} do test "returns 404 response when id isn't FlakeID", %{conn: conn} do
response = assert %{"error" => "Record not found"} =
conn conn
|> get("/api/v1/statuses/3ebbadd1-eb14-4e20-8118/card") |> get("/api/v1/statuses/3ebbadd1-eb14-4e20-8118/card")
|> json_response(200) |> json_response(404)
assert response == %{} assert %{"error" => "Record not found"} =
conn
|> get("/api/v1/statuses/8118/card")
|> json_response(404)
end end
end end