logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma
commit: 1220a171466ff613978c39eb977902ee9492b187
parent: 18e783bcb225f59dd9efc652c82d6e23492edbec
Author: Haelwenn <contact+git.pleroma.social@hacktivis.me>
Date:   Wed,  6 Feb 2019 18:39:13 +0000

Merge branch 'bugfix/rich-media-card' into 'develop'

rich media cards: bugfixes and regression tests

See merge request pleroma/pleroma!785

Diffstat:

Mlib/pleroma/web/mastodon_api/views/status_view.ex6++++--
Mtest/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 @@ -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 @@ -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