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/twitter-card"
16 %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/twitter_card.html")}
20 url: "http://example.com/oembed"
22 %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/oembed.html")}
26 url: "http://example.com/oembed.json"
28 %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/oembed.json")}
30 %{method: :get, url: "http://example.com/empty"} ->
31 %Tesla.Env{status: 200, body: "hello"}
37 test "returns error when no metadata present" do
38 assert {:error, _} = Pleroma.Web.RichMedia.Parser.parse("http://example.com/empty")
42 assert Pleroma.Web.RichMedia.Parser.parse("http://example.com/ogp") ==
45 image: "http://ia.media-imdb.com/images/rock.jpg",
48 "Directed by Michael Bay. With Sean Connery, Nicolas Cage, Ed Harris, John Spencer.",
50 url: "http://www.imdb.com/title/tt0117500/"
54 test "parses twitter card" do
55 assert Pleroma.Web.RichMedia.Parser.parse("http://example.com/twitter-card") ==
60 image: "https://farm6.staticflickr.com/5510/14338202952_93595258ff_z.jpg",
61 title: "Small Island Developing States Photo Submission",
62 description: "View the album on Flickr."
66 test "parses OEmbed" do
67 assert Pleroma.Web.RichMedia.Parser.parse("http://example.com/oembed") ==
70 author_name: "bees",
71 author_url: "https://www.flickr.com/photos/bees/",
76 "<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>",
77 license: "All Rights Reserved",
79 provider_name: "Flickr",
80 provider_url: "https://www.flickr.com/",
81 thumbnail_height: 150,
82 thumbnail_url: "https://farm4.staticflickr.com/3040/2362225867_4a87ab8baf_q.jpg",
84 title: "Bacon Lollys",
86 url: "https://farm4.staticflickr.com/3040/2362225867_4a87ab8baf_b.jpg",
88 web_page: "https://www.flickr.com/photos/bees/2362225867/",
89 web_page_short_url: "https://flic.kr/p/4AK2sc",
94 test "rejects invalid OGP data" do
95 assert {:error, _} = Pleroma.Web.RichMedia.Parser.parse("http://example.com/malformed")