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/ogp-missing-title"
18 body: File.read!("test/fixtures/rich_media/ogp-missing-title.html")
23 url: "http://example.com/twitter-card"
25 %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/twitter_card.html")}
29 url: "http://example.com/oembed"
31 %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/oembed.html")}
35 url: "http://example.com/oembed.json"
37 %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/oembed.json")}
39 %{method: :get, url: "http://example.com/empty"} ->
40 %Tesla.Env{status: 200, body: "hello"}
46 test "returns error when no metadata present" do
47 assert {:error, _} = Pleroma.Web.RichMedia.Parser.parse("http://example.com/empty")
51 assert Pleroma.Web.RichMedia.Parser.parse("http://example.com/ogp") ==
54 image: "http://ia.media-imdb.com/images/rock.jpg",
57 "Directed by Michael Bay. With Sean Connery, Nicolas Cage, Ed Harris, John Spencer.",
59 url: "http://www.imdb.com/title/tt0117500/"
63 test "falls back to <title> when ogp:title is missing" do
64 assert Pleroma.Web.RichMedia.Parser.parse("http://example.com/ogp-missing-title") ==
67 image: "http://ia.media-imdb.com/images/rock.jpg",
68 title: "The Rock (1996)",
70 "Directed by Michael Bay. With Sean Connery, Nicolas Cage, Ed Harris, John Spencer.",
72 url: "http://www.imdb.com/title/tt0117500/"
76 test "parses twitter card" do
77 assert Pleroma.Web.RichMedia.Parser.parse("http://example.com/twitter-card") ==
82 image: "https://farm6.staticflickr.com/5510/14338202952_93595258ff_z.jpg",
83 title: "Small Island Developing States Photo Submission",
84 description: "View the album on Flickr."
88 test "parses OEmbed" do
89 assert Pleroma.Web.RichMedia.Parser.parse("http://example.com/oembed") ==
92 author_name: "bees",
93 author_url: "https://www.flickr.com/photos/bees/",
98 "<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>",
99 license: "All Rights Reserved",
101 provider_name: "Flickr",
102 provider_url: "https://www.flickr.com/",
103 thumbnail_height: 150,
104 thumbnail_url: "https://farm4.staticflickr.com/3040/2362225867_4a87ab8baf_q.jpg",
105 thumbnail_width: 150,
106 title: "Bacon Lollys",
108 url: "https://farm4.staticflickr.com/3040/2362225867_4a87ab8baf_b.jpg",
110 web_page: "https://www.flickr.com/photos/bees/2362225867/",
111 web_page_short_url: "https://flic.kr/p/4AK2sc",
116 test "rejects invalid OGP data" do
117 assert {:error, _} = Pleroma.Web.RichMedia.Parser.parse("http://example.com/malformed")