honkoma/test/web/rich_media/parser_test.exs

52 lines
1.5 KiB
Elixir
Raw Normal View History

2019-01-01 20:26:40 +00:00
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")}
2019-01-02 14:02:50 +00:00
2019-01-10 18:09:56 +00:00
%{
method: :get,
url: "http://example.com/twitter-card"
} ->
%Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/twitter_card.html")}
2019-01-02 14:02:50 +00:00
%{method: :get, url: "http://example.com/empty"} ->
%Tesla.Env{status: 200, body: "hello"}
2019-01-01 20:26:40 +00:00
end)
:ok
end
2019-01-02 14:02:50 +00:00
test "returns error when no metadata present" do
assert {:error, _} = Pleroma.Web.RichMedia.Parser.parse("http://example.com/empty")
end
2019-01-01 20:26:40 +00:00
test "parses ogp" do
assert Pleroma.Web.RichMedia.Parser.parse("http://example.com/ogp") ==
2019-01-02 14:02:50 +00:00
{:ok,
%{
image: "http://ia.media-imdb.com/images/rock.jpg",
title: "The Rock",
type: "video.movie",
url: "http://www.imdb.com/title/tt0117500/"
}}
2019-01-01 20:26:40 +00:00
end
2019-01-10 18:09:56 +00:00
test "parses twitter card" do
assert Pleroma.Web.RichMedia.Parser.parse("http://example.com/twitter-card") ==
{:ok,
%{
card: "summary",
site: "@flickr",
image: "https://farm6.staticflickr.com/5510/14338202952_93595258ff_z.jpg",
title: "Small Island Developing States Photo Submission",
description: "View the album on Flickr."
}}
end
2019-01-01 20:26:40 +00:00
end