summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Gleason <alex@alexgleason.me>2021-05-04 18:21:43 -0500
committerAlex Gleason <alex@alexgleason.me>2021-05-04 18:21:43 -0500
commit3a4ad366d524ed4b90f46ede22991ce5249b9a84 (patch)
tree08c21a90ffa35ac6674ed69f6c06b970910f3254
parent0afa091e6ce7e2d9db594a0822c7ad8a6ed81531 (diff)
Fix existing tests
-rw-r--r--lib/pleroma/web/rich_media/parser/card.ex17
-rw-r--r--test/pleroma/web/mastodon_api/controllers/status_controller_test.exs31
-rw-r--r--test/pleroma/web/rich_media/parser/card_test.exs10
3 files changed, 33 insertions, 25 deletions
diff --git a/lib/pleroma/web/rich_media/parser/card.ex b/lib/pleroma/web/rich_media/parser/card.ex
index f6193728a..fc0e3f6a4 100644
--- a/lib/pleroma/web/rich_media/parser/card.ex
+++ b/lib/pleroma/web/rich_media/parser/card.ex
@@ -24,8 +24,10 @@ defmodule Pleroma.Web.RichMedia.Parser.Card do
embed_url: "",
blurhash: nil
- def parse(%{url: url, oembed: %{"type" => type, "title" => title} = oembed} = embed)
- when type in @types do
+ def parse(%Embed{url: url, oembed: %{"type" => type, "title" => title} = oembed} = embed)
+ when type in @types and is_binary(url) do
+ uri = URI.parse(url)
+
%Card{
url: url,
title: title,
@@ -33,8 +35,8 @@ defmodule Pleroma.Web.RichMedia.Parser.Card do
type: oembed["type"],
author_name: oembed["author_name"],
author_url: oembed["author_url"],
- provider_name: oembed["provider_name"] || URI.parse(url).host,
- provider_url: oembed["provider_url"],
+ provider_name: oembed["provider_name"] || uri.host,
+ provider_url: oembed["provider_url"] || "#{uri.scheme}://#{uri.host}",
html: oembed["html"],
width: oembed["width"],
height: oembed["height"],
@@ -44,13 +46,16 @@ defmodule Pleroma.Web.RichMedia.Parser.Card do
|> validate()
end
- def parse(%{url: url} = embed) do
+ def parse(%Embed{url: url} = embed) when is_binary(url) do
+ uri = URI.parse(url)
+
%Card{
url: url,
title: get_title(embed),
description: get_description(embed),
type: "link",
- provider_name: URI.parse(url).host,
+ provider_name: uri.host,
+ provider_url: "#{uri.scheme}://#{uri.host}",
image: get_image(embed) |> proxy()
}
|> validate()
diff --git a/test/pleroma/web/mastodon_api/controllers/status_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/status_controller_test.exs
index e76c2760d..d200cdf72 100644
--- a/test/pleroma/web/mastodon_api/controllers/status_controller_test.exs
+++ b/test/pleroma/web/mastodon_api/controllers/status_controller_test.exs
@@ -1331,16 +1331,13 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
"url" => "https://example.com/ogp",
"description" =>
"Directed by Michael Bay. With Sean Connery, Nicolas Cage, Ed Harris, John Spencer.",
- "pleroma" => %{
- "opengraph" => %{
- "image" => "http://ia.media-imdb.com/images/rock.jpg",
- "title" => "The Rock",
- "type" => "video.movie",
- "url" => "https://example.com/ogp",
- "description" =>
- "Directed by Michael Bay. With Sean Connery, Nicolas Cage, Ed Harris, John Spencer."
- }
- }
+ "author_name" => "",
+ "author_url" => "",
+ "blurhash" => nil,
+ "embed_url" => "",
+ "height" => 0,
+ "html" => "",
+ "width" => 0
}
response =
@@ -1380,13 +1377,13 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
"provider_name" => "example.com",
"provider_url" => "https://example.com",
"url" => "https://example.com/ogp-missing-data",
- "pleroma" => %{
- "opengraph" => %{
- "title" => "Pleroma",
- "type" => "website",
- "url" => "https://example.com/ogp-missing-data"
- }
- }
+ "author_name" => "",
+ "author_url" => "",
+ "blurhash" => nil,
+ "embed_url" => "",
+ "height" => 0,
+ "html" => "",
+ "width" => 0
}
end
end
diff --git a/test/pleroma/web/rich_media/parser/card_test.exs b/test/pleroma/web/rich_media/parser/card_test.exs
index 489d2d848..e09dfa6db 100644
--- a/test/pleroma/web/rich_media/parser/card_test.exs
+++ b/test/pleroma/web/rich_media/parser/card_test.exs
@@ -10,10 +10,13 @@ defmodule Pleroma.Web.RichMedia.Parser.CardTest do
describe "parse/1" do
test "converts an %Embed{} into a %Card{}" do
+ url =
+ "https://www.nytimes.com/2019/08/01/nyregion/nypd-facial-recognition-children-teenagers.html"
+
embed =
File.read!("test/fixtures/nypd-facial-recognition-children-teenagers.html")
|> Floki.parse_document!()
- |> TwitterCard.parse(%Embed{})
+ |> TwitterCard.parse(%Embed{url: url})
expected = %Card{
description:
@@ -21,7 +24,10 @@ defmodule Pleroma.Web.RichMedia.Parser.CardTest do
image:
"https://static01.nyt.com/images/2019/08/01/nyregion/01nypd-juveniles-promo/01nypd-juveniles-promo-videoSixteenByNineJumbo1600.jpg",
title: "She Was Arrested at 14. Then Her Photo Went to a Facial Recognition Database.",
- type: "link"
+ type: "link",
+ provider_name: "www.nytimes.com",
+ provider_url: "https://www.nytimes.com",
+ url: url
}
assert Card.parse(embed) == {:ok, expected}