aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHaelwenn <contact+git.pleroma.social@hacktivis.me>2019-02-06 18:39:13 +0000
committerHaelwenn <contact+git.pleroma.social@hacktivis.me>2019-02-06 18:39:13 +0000
commit1220a171466ff613978c39eb977902ee9492b187 (patch)
tree58dd04e84aa785a3a797c86fad4a54262a2cef79
parent18e783bcb225f59dd9efc652c82d6e23492edbec (diff)
parent26670b09a7a1fb144a8a2b0141d64c0d85cd6ad6 (diff)
downloadpleroma-1220a171466ff613978c39eb977902ee9492b187.tar.gz
Merge branch 'bugfix/rich-media-card' into 'develop'
rich media cards: bugfixes and regression tests See merge request pleroma/pleroma!785
-rw-r--r--lib/pleroma/web/mastodon_api/views/status_view.ex6
-rw-r--r--test/web/mastodon_api/status_view_test.exs55
2 files changed, 59 insertions, 2 deletions
diff --git a/lib/pleroma/web/mastodon_api/views/status_view.ex b/lib/pleroma/web/mastodon_api/views/status_view.ex
index c0e289ef8..a227d742d 100644
--- a/lib/pleroma/web/mastodon_api/views/status_view.ex
+++ b/lib/pleroma/web/mastodon_api/views/status_view.ex
@@ -182,11 +182,13 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
end
def render("card.json", %{rich_media: rich_media, page_url: page_url}) do
+ page_url_data = URI.parse(page_url)
+
page_url_data =
if rich_media[:url] != nil do
- URI.merge(URI.parse(page_url), URI.parse(rich_media[:url]))
+ URI.merge(page_url_data, URI.parse(rich_media[:url]))
else
- page_url
+ page_url_data
end
page_url = page_url_data |> to_string
diff --git a/test/web/mastodon_api/status_view_test.exs b/test/web/mastodon_api/status_view_test.exs
index c6a5783c6..2106253f2 100644
--- a/test/web/mastodon_api/status_view_test.exs
+++ b/test/web/mastodon_api/status_view_test.exs
@@ -235,4 +235,59 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
]
end
end
+
+ describe "rich media cards" do
+ test "a rich media card without a site name renders correctly" do
+ page_url = "http://example.com"
+
+ card = %{
+ url: page_url,
+ image: page_url <> "/example.jpg",
+ title: "Example website"
+ }
+
+ %{provider_name: "example.com"} =
+ StatusView.render("card.json", %{page_url: page_url, rich_media: card})
+ end
+
+ test "a rich media card without a site name or image renders correctly" do
+ page_url = "http://example.com"
+
+ card = %{
+ url: page_url,
+ title: "Example website"
+ }
+
+ %{provider_name: "example.com"} =
+ StatusView.render("card.json", %{page_url: page_url, rich_media: card})
+ end
+
+ test "a rich media card without an image renders correctly" do
+ page_url = "http://example.com"
+
+ card = %{
+ url: page_url,
+ site_name: "Example site name",
+ title: "Example website"
+ }
+
+ %{provider_name: "Example site name"} =
+ StatusView.render("card.json", %{page_url: page_url, rich_media: card})
+ end
+
+ test "a rich media card with all relevant data renders correctly" do
+ page_url = "http://example.com"
+
+ card = %{
+ url: page_url,
+ site_name: "Example site name",
+ title: "Example website",
+ image: page_url <> "/example.jpg",
+ description: "Example description"
+ }
+
+ %{provider_name: "Example site name"} =
+ StatusView.render("card.json", %{page_url: page_url, rich_media: card})
+ end
+ end
end