defmodule Pleroma.Web.RichMedia.ParserTest do use ExUnit.Case, async: true setup do Tesla.Mock.mock(fn %{ method: :get, url: "http://example.com/ogp" } -> %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/ogp.html")} %{ method: :get, url: "http://example.com/non-ogp" } -> %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/non_ogp_embed.html")} %{ method: :get, url: "http://example.com/ogp-missing-title" } -> %Tesla.Env{ status: 200, body: File.read!("test/fixtures/rich_media/ogp-missing-title.html") } %{ method: :get, url: "http://example.com/twitter-card" } -> %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/twitter_card.html")} %{ method: :get, url: "http://example.com/oembed" } -> %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/oembed.html")} %{ method: :get, url: "http://example.com/oembed.json" } -> %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/oembed.json")} %{method: :get, url: "http://example.com/empty"} -> %Tesla.Env{status: 200, body: "hello"} end) :ok end test "returns error when no metadata present" do assert {:error, _} = Pleroma.Web.RichMedia.Parser.parse("http://example.com/empty") end test "doesn't just add a title" do assert Pleroma.Web.RichMedia.Parser.parse("http://example.com/non-ogp") == {:error, "Found metadata was invalid or incomplete: %{}"} end test "parses ogp" do assert Pleroma.Web.RichMedia.Parser.parse("http://example.com/ogp") == {:ok, %{ image: "http://ia.media-imdb.com/images/rock.jpg", title: "The Rock", description: "Directed by Michael Bay. With Sean Connery, Nicolas Cage, Ed Harris, John Spencer.", type: "video.movie", url: "http://www.imdb.com/title/tt0117500/" }} end test "falls back to