Merge branch 'develop' into feature/matstodon-statuses-by-name
[akkoma] / test / web / metadata / 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.Metadata.Providers.TwitterCardTest do
6 use Pleroma.DataCase
7 import Pleroma.Factory
8
9 alias Pleroma.User
10 alias Pleroma.Web.CommonAPI
11 alias Pleroma.Web.Endpoint
12 alias Pleroma.Web.Metadata.Providers.TwitterCard
13 alias Pleroma.Web.Metadata.Utils
14 alias Pleroma.Web.Router
15
16 test "it renders twitter card for user info" do
17 user = insert(:user, name: "Jimmy Hendriks", bio: "born 19 March 1994")
18 avatar_url = Utils.attachment_url(User.avatar_url(user))
19 res = TwitterCard.build_tags(%{user: user})
20
21 assert res == [
22 {:meta, [property: "twitter:title", content: Utils.user_name_string(user)], []},
23 {:meta, [property: "twitter:description", content: "born 19 March 1994"], []},
24 {:meta, [property: "twitter:image", content: avatar_url], []},
25 {:meta, [property: "twitter:card", content: "summary"], []}
26 ]
27 end
28
29 test "it does not render attachments if post is nsfw" do
30 Pleroma.Config.put([Pleroma.Web.Metadata, :unfurl_nsfw], false)
31 user = insert(:user, name: "Jimmy Hendriks", bio: "born 19 March 1994")
32 {:ok, activity} = CommonAPI.post(user, %{"status" => "HI"})
33
34 note =
35 insert(:note, %{
36 data: %{
37 "actor" => user.ap_id,
38 "tag" => [],
39 "id" => "https://pleroma.gov/objects/whatever",
40 "content" => "pleroma in a nutshell",
41 "sensitive" => true,
42 "attachment" => [
43 %{
44 "url" => [%{"mediaType" => "image/png", "href" => "https://pleroma.gov/tenshi.png"}]
45 },
46 %{
47 "url" => [
48 %{
49 "mediaType" => "application/octet-stream",
50 "href" => "https://pleroma.gov/fqa/badapple.sfc"
51 }
52 ]
53 },
54 %{
55 "url" => [
56 %{"mediaType" => "video/webm", "href" => "https://pleroma.gov/about/juche.webm"}
57 ]
58 }
59 ]
60 }
61 })
62
63 result = TwitterCard.build_tags(%{object: note, user: user, activity_id: activity.id})
64
65 assert [
66 {:meta, [property: "twitter:title", content: Utils.user_name_string(user)], []},
67 {:meta, [property: "twitter:description", content: "“pleroma in a nutshell”"], []},
68 {:meta, [property: "twitter:image", content: "http://localhost:4001/images/avi.png"],
69 []},
70 {:meta, [property: "twitter:card", content: "summary_large_image"], []}
71 ] == result
72 end
73
74 test "it renders supported types of attachments and skips unknown types" do
75 user = insert(:user, name: "Jimmy Hendriks", bio: "born 19 March 1994")
76 {:ok, activity} = CommonAPI.post(user, %{"status" => "HI"})
77
78 note =
79 insert(:note, %{
80 data: %{
81 "actor" => user.ap_id,
82 "tag" => [],
83 "id" => "https://pleroma.gov/objects/whatever",
84 "content" => "pleroma in a nutshell",
85 "attachment" => [
86 %{
87 "url" => [%{"mediaType" => "image/png", "href" => "https://pleroma.gov/tenshi.png"}]
88 },
89 %{
90 "url" => [
91 %{
92 "mediaType" => "application/octet-stream",
93 "href" => "https://pleroma.gov/fqa/badapple.sfc"
94 }
95 ]
96 },
97 %{
98 "url" => [
99 %{"mediaType" => "video/webm", "href" => "https://pleroma.gov/about/juche.webm"}
100 ]
101 }
102 ]
103 }
104 })
105
106 result = TwitterCard.build_tags(%{object: note, user: user, activity_id: activity.id})
107
108 assert [
109 {:meta, [property: "twitter:title", content: Utils.user_name_string(user)], []},
110 {:meta, [property: "twitter:description", content: "“pleroma in a nutshell”"], []},
111 {:meta, [property: "twitter:card", content: "summary_large_image"], []},
112 {:meta, [property: "twitter:player", content: "https://pleroma.gov/tenshi.png"], []},
113 {:meta, [property: "twitter:card", content: "player"], []},
114 {:meta,
115 [
116 property: "twitter:player",
117 content: Router.Helpers.o_status_url(Endpoint, :notice_player, activity.id)
118 ], []},
119 {:meta, [property: "twitter:player:width", content: "480"], []},
120 {:meta, [property: "twitter:player:height", content: "480"], []}
121 ] == result
122 end
123 end