Add RichMediaController and tests
[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 %{method: :get, url: "http://example.com/empty"} ->
13 %Tesla.Env{status: 200, body: "hello"}
14 end)
15
16 :ok
17 end
18
19 test "returns error when no metadata present" do
20 assert {:error, _} = Pleroma.Web.RichMedia.Parser.parse("http://example.com/empty")
21 end
22
23 test "parses ogp" do
24 assert Pleroma.Web.RichMedia.Parser.parse("http://example.com/ogp") ==
25 {:ok,
26 %{
27 image: "http://ia.media-imdb.com/images/rock.jpg",
28 title: "The Rock",
29 type: "video.movie",
30 url: "http://www.imdb.com/title/tt0117500/"
31 }}
32 end
33 end