1 defmodule Pleroma.Web.RichMedia.ParserTest do
2 use ExUnit.Case, async: true
8 url: "http://example.com/ogp"
10 %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/ogp.html")}
14 url: "http://example.com/non-ogp"
16 %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/non_ogp_embed.html")}
20 url: "http://example.com/ogp-missing-title"
24 body: File.read!("test/fixtures/rich_media/ogp-missing-title.html")
29 url: "http://example.com/twitter-card"
31 %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/twitter_card.html")}
35 url: "http://example.com/oembed"
37 %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/oembed.html")}
41 url: "http://example.com/oembed.json"
43 %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/oembed.json")}
45 %{method: :get, url: "http://example.com/empty"} ->
46 %Tesla.Env{status: 200, body: "hello"}
52 test "returns error when no metadata present" do
53 assert {:error, _} = Pleroma.Web.RichMedia.Parser.parse("http://example.com/empty")
56 test "doesn't just add a title" do
57 assert Pleroma.Web.RichMedia.Parser.parse("http://example.com/non-ogp") ==
58 {:error, "Found metadata was invalid or incomplete: %{}"}
62 assert Pleroma.Web.RichMedia.Parser.parse("http://example.com/ogp") ==
65 image: "http://ia.media-imdb.com/images/rock.jpg",
68 "Directed by Michael Bay. With Sean Connery, Nicolas Cage, Ed Harris, John Spencer.",
70 url: "http://www.imdb.com/title/tt0117500/"
74 test "falls back to <title> when ogp:title is missing" do
75 assert Pleroma.Web.RichMedia.Parser.parse("http://example.com/ogp-missing-title") ==
78 image: "http://ia.media-imdb.com/images/rock.jpg",
79 title: "The Rock (1996)",
81 "Directed by Michael Bay. With Sean Connery, Nicolas Cage, Ed Harris, John Spencer.",
83 url: "http://www.imdb.com/title/tt0117500/"
87 test "parses twitter card" do
88 assert Pleroma.Web.RichMedia.Parser.parse("http://example.com/twitter-card") ==
93 image: "https://farm6.staticflickr.com/5510/14338202952_93595258ff_z.jpg",
94 title: "Small Island Developing States Photo Submission",
95 description: "View the album on Flickr."
99 test "parses OEmbed" do
100 assert Pleroma.Web.RichMedia.Parser.parse("http://example.com/oembed") ==
103 author_name: "bees",
104 author_url: "https://www.flickr.com/photos/bees/",
106 flickr_type: "photo",
109 "<a data-flickr-embed=\"true\" href=\"https://www.flickr.com/photos/bees/2362225867/\" title=\"Bacon Lollys by bees, on Flickr\"><img src=\"https://farm4.staticflickr.com/3040/2362225867_4a87ab8baf_b.jpg\" width=\"1024\" height=\"768\" alt=\"Bacon Lollys\"></a><script async src=\"https://embedr.flickr.com/assets/client-code.js\" charset=\"utf-8\"></script>",
110 license: "All Rights Reserved",
112 provider_name: "Flickr",
113 provider_url: "https://www.flickr.com/",
114 thumbnail_height: 150,
115 thumbnail_url: "https://farm4.staticflickr.com/3040/2362225867_4a87ab8baf_q.jpg",
116 thumbnail_width: 150,
117 title: "Bacon Lollys",
119 url: "https://farm4.staticflickr.com/3040/2362225867_4a87ab8baf_b.jpg",
121 web_page: "https://www.flickr.com/photos/bees/2362225867/",
122 web_page_short_url: "https://flic.kr/p/4AK2sc",
127 test "rejects invalid OGP data" do
128 assert {:error, _} = Pleroma.Web.RichMedia.Parser.parse("http://example.com/malformed")