Merge branch 'activitypub-dereference-activity-id' into 'develop'
[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 %{method: :get, url: "http://example.com/empty"} ->
19 %Tesla.Env{status: 200, body: "hello"}
20 end)
21
22 :ok
23 end
24
25 test "returns error when no metadata present" do
26 assert {:error, _} = Pleroma.Web.RichMedia.Parser.parse("http://example.com/empty")
27 end
28
29 test "parses ogp" do
30 assert Pleroma.Web.RichMedia.Parser.parse("http://example.com/ogp") ==
31 {:ok,
32 %{
33 image: "http://ia.media-imdb.com/images/rock.jpg",
34 title: "The Rock",
35 type: "video.movie",
36 url: "http://www.imdb.com/title/tt0117500/"
37 }}
38 end
39
40 test "parses twitter card" do
41 assert Pleroma.Web.RichMedia.Parser.parse("http://example.com/twitter-card") ==
42 {:ok,
43 %{
44 card: "summary",
45 site: "@flickr",
46 image: "https://farm6.staticflickr.com/5510/14338202952_93595258ff_z.jpg",
47 title: "Small Island Developing States Photo Submission",
48 description: "View the album on Flickr."
49 }}
50 end
51 end