summaryrefslogtreecommitdiff
path: root/test/web/rich_media
diff options
context:
space:
mode:
Diffstat (limited to 'test/web/rich_media')
-rw-r--r--test/web/rich_media/aws_signed_url_test.exs3
-rw-r--r--test/web/rich_media/helpers_test.exs4
-rw-r--r--test/web/rich_media/parsers/twitter_card_test.exs69
3 files changed, 73 insertions, 3 deletions
diff --git a/test/web/rich_media/aws_signed_url_test.exs b/test/web/rich_media/aws_signed_url_test.exs
index 122787bc2..a3a50cbb1 100644
--- a/test/web/rich_media/aws_signed_url_test.exs
+++ b/test/web/rich_media/aws_signed_url_test.exs
@@ -60,7 +60,8 @@ defmodule Pleroma.Web.RichMedia.TTL.AwsSignedUrlTest do
{:ok, cache_ttl} = Cachex.ttl(:rich_media_cache, url)
# as there is delay in setting and pulling the data from cache we ignore 1 second
- assert_in_delta(valid_till * 1000, cache_ttl, 1000)
+ # make it 2 seconds for flakyness
+ assert_in_delta(valid_till * 1000, cache_ttl, 2000)
end
defp construct_s3_url(timestamp, valid_till) do
diff --git a/test/web/rich_media/helpers_test.exs b/test/web/rich_media/helpers_test.exs
index 92198f3d9..48884319d 100644
--- a/test/web/rich_media/helpers_test.exs
+++ b/test/web/rich_media/helpers_test.exs
@@ -15,12 +15,12 @@ defmodule Pleroma.Web.RichMedia.HelpersTest do
setup do
mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
- rich_media = Config.get([:rich_media, :enabled])
- on_exit(fn -> Config.put([:rich_media, :enabled], rich_media) end)
:ok
end
+ clear_config([:rich_media, :enabled])
+
test "refuses to crawl incomplete URLs" do
user = insert(:user)
diff --git a/test/web/rich_media/parsers/twitter_card_test.exs b/test/web/rich_media/parsers/twitter_card_test.exs
new file mode 100644
index 000000000..f8e1c9b40
--- /dev/null
+++ b/test/web/rich_media/parsers/twitter_card_test.exs
@@ -0,0 +1,69 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.RichMedia.Parsers.TwitterCardTest do
+ use ExUnit.Case, async: true
+ alias Pleroma.Web.RichMedia.Parsers.TwitterCard
+
+ test "returns error when html not contains twitter card" do
+ assert TwitterCard.parse("", %{}) == {:error, "No twitter card metadata found"}
+ end
+
+ test "parses twitter card with only name attributes" do
+ html = File.read!("test/fixtures/nypd-facial-recognition-children-teenagers3.html")
+
+ assert TwitterCard.parse(html, %{}) ==
+ {:ok,
+ %{
+ "app:id:googleplay": "com.nytimes.android",
+ "app:name:googleplay": "NYTimes",
+ "app:url:googleplay": "nytimes://reader/id/100000006583622",
+ site: nil,
+ title:
+ "She Was Arrested at 14. Then Her Photo Went to a Facial Recognition Database. - The New York Times"
+ }}
+ end
+
+ test "parses twitter card with only property attributes" do
+ html = File.read!("test/fixtures/nypd-facial-recognition-children-teenagers2.html")
+
+ assert TwitterCard.parse(html, %{}) ==
+ {:ok,
+ %{
+ card: "summary_large_image",
+ description:
+ "With little oversight, the N.Y.P.D. has been using powerful surveillance technology on photos of children and teenagers.",
+ image:
+ "https://static01.nyt.com/images/2019/08/01/nyregion/01nypd-juveniles-promo/01nypd-juveniles-promo-videoSixteenByNineJumbo1600.jpg",
+ "image:alt": "",
+ title:
+ "She Was Arrested at 14. Then Her Photo Went to a Facial Recognition Database.",
+ url:
+ "https://www.nytimes.com/2019/08/01/nyregion/nypd-facial-recognition-children-teenagers.html"
+ }}
+ end
+
+ test "parses twitter card with name & property attributes" do
+ html = File.read!("test/fixtures/nypd-facial-recognition-children-teenagers.html")
+
+ assert TwitterCard.parse(html, %{}) ==
+ {:ok,
+ %{
+ "app:id:googleplay": "com.nytimes.android",
+ "app:name:googleplay": "NYTimes",
+ "app:url:googleplay": "nytimes://reader/id/100000006583622",
+ card: "summary_large_image",
+ description:
+ "With little oversight, the N.Y.P.D. has been using powerful surveillance technology on photos of children and teenagers.",
+ image:
+ "https://static01.nyt.com/images/2019/08/01/nyregion/01nypd-juveniles-promo/01nypd-juveniles-promo-videoSixteenByNineJumbo1600.jpg",
+ "image:alt": "",
+ site: nil,
+ title:
+ "She Was Arrested at 14. Then Her Photo Went to a Facial Recognition Database.",
+ url:
+ "https://www.nytimes.com/2019/08/01/nyregion/nypd-facial-recognition-children-teenagers.html"
+ }}
+ end
+end