Merge remote-tracking branch 'MAIN/develop' into feature/jobs
[akkoma] / test / web / rich_media / parser_test.exs
1 defmodule Pleroma.Web.RichMedia.ParserTest do
2 use ExUnit.Case, async: true
3
4 setup do
5 Tesla.Mock.mock(fn
6 %{
7 method: :get,
8 url: "http://example.com/ogp"
9 } ->
10 %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/ogp.html")}
11
12 %{
13 method: :get,
14 url: "http://example.com/twitter-card"
15 } ->
16 %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/twitter_card.html")}
17
18 %{
19 method: :get,
20 url: "http://example.com/oembed"
21 } ->
22 %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/oembed.html")}
23
24 %{
25 method: :get,
26 url: "http://example.com/oembed.json"
27 } ->
28 %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/oembed.json")}
29
30 %{method: :get, url: "http://example.com/empty"} ->
31 %Tesla.Env{status: 200, body: "hello"}
32 end)
33
34 :ok
35 end
36
37 test "returns error when no metadata present" do
38 assert {:error, _} = Pleroma.Web.RichMedia.Parser.parse("http://example.com/empty")
39 end
40
41 test "parses ogp" do
42 assert Pleroma.Web.RichMedia.Parser.parse("http://example.com/ogp") ==
43 {:ok,
44 %{
45 image: "http://ia.media-imdb.com/images/rock.jpg",
46 title: "The Rock",
47 type: "video.movie",
48 url: "http://www.imdb.com/title/tt0117500/"
49 }}
50 end
51
52 test "parses twitter card" do
53 assert Pleroma.Web.RichMedia.Parser.parse("http://example.com/twitter-card") ==
54 {:ok,
55 %{
56 card: "summary",
57 site: "@flickr",
58 image: "https://farm6.staticflickr.com/5510/14338202952_93595258ff_z.jpg",
59 title: "Small Island Developing States Photo Submission",
60 description: "View the album on Flickr."
61 }}
62 end
63
64 test "parses OEmbed" do
65 assert Pleroma.Web.RichMedia.Parser.parse("http://example.com/oembed") ==
66 {:ok,
67 %{
68 author_name: "‮‭‬bees‬",
69 author_url: "https://www.flickr.com/photos/bees/",
70 cache_age: 3600,
71 flickr_type: "photo",
72 height: "768",
73 html:
74 "<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>",
75 license: "All Rights Reserved",
76 license_id: 0,
77 provider_name: "Flickr",
78 provider_url: "https://www.flickr.com/",
79 thumbnail_height: 150,
80 thumbnail_url: "https://farm4.staticflickr.com/3040/2362225867_4a87ab8baf_q.jpg",
81 thumbnail_width: 150,
82 title: "Bacon Lollys",
83 type: "photo",
84 url: "https://farm4.staticflickr.com/3040/2362225867_4a87ab8baf_b.jpg",
85 version: "1.0",
86 web_page: "https://www.flickr.com/photos/bees/2362225867/",
87 web_page_short_url: "https://flic.kr/p/4AK2sc",
88 width: "1024"
89 }}
90 end
91 end