From 65a4b9fbea6e1ec331e6aae30abe12e6d4494102 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Wed, 6 Feb 2019 18:02:15 +0000 Subject: [PATCH 1/3] mastodon api: rich media: don't clobber %URI struct with a string --- lib/pleroma/web/mastodon_api/views/status_view.ex | 6 ++++-- 1 file changed, 4 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 @@ def render("status.json", _) 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 From 6eb8c1eb92e1992bb24f64e76f16f133aa978eee Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Wed, 6 Feb 2019 18:12:26 +0000 Subject: [PATCH 2/3] test: add some regression tests for the rich media card rendering --- test/web/mastodon_api/status_view_test.exs | 40 ++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/test/web/mastodon_api/status_view_test.exs b/test/web/mastodon_api/status_view_test.exs index c6a5783c6..f0c4468cf 100644 --- a/test/web/mastodon_api/status_view_test.exs +++ b/test/web/mastodon_api/status_view_test.exs @@ -235,4 +235,44 @@ test "it returns a a dictionary tags" 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 + end end From 26670b09a7a1fb144a8a2b0141d64c0d85cd6ad6 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Wed, 6 Feb 2019 18:27:55 +0000 Subject: [PATCH 3/3] tests: add a rich media card that contains all relevant fields --- test/web/mastodon_api/status_view_test.exs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/test/web/mastodon_api/status_view_test.exs b/test/web/mastodon_api/status_view_test.exs index f0c4468cf..2106253f2 100644 --- a/test/web/mastodon_api/status_view_test.exs +++ b/test/web/mastodon_api/status_view_test.exs @@ -274,5 +274,20 @@ test "a rich media card without an image renders correctly" do %{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