[#1505] Restricted max thread distance for fetching replies on incoming federation...
[akkoma] / test / web / rich_media / parsers / twitter_card_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.RichMedia.Parsers.TwitterCardTest do
6 use ExUnit.Case, async: true
7 alias Pleroma.Web.RichMedia.Parsers.TwitterCard
8
9 test "returns error when html not contains twitter card" do
10 assert TwitterCard.parse("", %{}) == {:error, "No twitter card metadata found"}
11 end
12
13 test "parses twitter card with only name attributes" do
14 html = File.read!("test/fixtures/nypd-facial-recognition-children-teenagers3.html")
15
16 assert TwitterCard.parse(html, %{}) ==
17 {:ok,
18 %{
19 "app:id:googleplay": "com.nytimes.android",
20 "app:name:googleplay": "NYTimes",
21 "app:url:googleplay": "nytimes://reader/id/100000006583622",
22 site: nil,
23 title:
24 "She Was Arrested at 14. Then Her Photo Went to a Facial Recognition Database. - The New York Times"
25 }}
26 end
27
28 test "parses twitter card with only property attributes" do
29 html = File.read!("test/fixtures/nypd-facial-recognition-children-teenagers2.html")
30
31 assert TwitterCard.parse(html, %{}) ==
32 {:ok,
33 %{
34 card: "summary_large_image",
35 description:
36 "With little oversight, the N.Y.P.D. has been using powerful surveillance technology on photos of children and teenagers.",
37 image:
38 "https://static01.nyt.com/images/2019/08/01/nyregion/01nypd-juveniles-promo/01nypd-juveniles-promo-videoSixteenByNineJumbo1600.jpg",
39 "image:alt": "",
40 title:
41 "She Was Arrested at 14. Then Her Photo Went to a Facial Recognition Database.",
42 url:
43 "https://www.nytimes.com/2019/08/01/nyregion/nypd-facial-recognition-children-teenagers.html"
44 }}
45 end
46
47 test "parses twitter card with name & property attributes" do
48 html = File.read!("test/fixtures/nypd-facial-recognition-children-teenagers.html")
49
50 assert TwitterCard.parse(html, %{}) ==
51 {:ok,
52 %{
53 "app:id:googleplay": "com.nytimes.android",
54 "app:name:googleplay": "NYTimes",
55 "app:url:googleplay": "nytimes://reader/id/100000006583622",
56 card: "summary_large_image",
57 description:
58 "With little oversight, the N.Y.P.D. has been using powerful surveillance technology on photos of children and teenagers.",
59 image:
60 "https://static01.nyt.com/images/2019/08/01/nyregion/01nypd-juveniles-promo/01nypd-juveniles-promo-videoSixteenByNineJumbo1600.jpg",
61 "image:alt": "",
62 site: nil,
63 title:
64 "She Was Arrested at 14. Then Her Photo Went to a Facial Recognition Database.",
65 url:
66 "https://www.nytimes.com/2019/08/01/nyregion/nypd-facial-recognition-children-teenagers.html"
67 }}
68 end
69
70 test "respect only first title tag on the page" do
71 image_path =
72 "https://assets.atlasobscura.com/media/W1siZiIsInVwbG9hZHMvYXNzZXRzLzkwYzgyMzI4LThlMDUtNGRiNS05MDg3LTUzMGUxZTM5N2RmMmVkOTM5ZDM4MGM4OTIx" <>
73 "YTQ5MF9EQVIgZXhodW1hdGlvbiBvZiBNYXJnYXJldCBDb3JiaW4gZ3JhdmUgMTkyNi5qcGciXSxbInAiLCJjb252ZXJ0IiwiIl0sWyJwIiwiY29udmVydCIsIi1xdWFsaXR5IDgxIC1hdXRvLW9" <>
74 "yaWVudCJdLFsicCIsInRodW1iIiwiNjAweD4iXV0/DAR%20exhumation%20of%20Margaret%20Corbin%20grave%201926.jpg"
75
76 html = File.read!("test/fixtures/margaret-corbin-grave-west-point.html")
77
78 assert TwitterCard.parse(html, %{}) ==
79 {:ok,
80 %{
81 site: "@atlasobscura",
82 title:
83 "The Missing Grave of Margaret Corbin, Revolutionary War Veteran - Atlas Obscura",
84 card: "summary_large_image",
85 image: image_path
86 }}
87 end
88
89 test "takes first founded title in html head if there is html markup error" do
90 html = File.read!("test/fixtures/nypd-facial-recognition-children-teenagers4.html")
91
92 assert TwitterCard.parse(html, %{}) ==
93 {:ok,
94 %{
95 site: nil,
96 title:
97 "She Was Arrested at 14. Then Her Photo Went to a Facial Recognition Database. - The New York Times",
98 "app:id:googleplay": "com.nytimes.android",
99 "app:name:googleplay": "NYTimes",
100 "app:url:googleplay": "nytimes://reader/id/100000006583622"
101 }}
102 end
103 end