1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.Metadata.Providers.TwitterCardTest do
10 alias Pleroma.Web.CommonAPI
11 alias Pleroma.Web.Endpoint
12 alias Pleroma.Web.MediaProxy
13 alias Pleroma.Web.Metadata.Providers.TwitterCard
14 alias Pleroma.Web.Metadata.Utils
15 alias Pleroma.Web.Router
17 setup do: clear_config([Pleroma.Web.Metadata, :unfurl_nsfw])
19 test "it renders twitter card for user info" do
20 user = insert(:user, name: "Jimmy Hendriks", bio: "born 19 March 1994")
21 avatar_url = MediaProxy.preview_url(User.avatar_url(user))
22 res = TwitterCard.build_tags(%{user: user})
25 {:meta, [name: "twitter:title", content: Utils.user_name_string(user)], []},
26 {:meta, [name: "twitter:description", content: "born 19 March 1994"], []},
27 {:meta, [name: "twitter:image", content: avatar_url], []},
28 {:meta, [name: "twitter:card", content: "summary"], []}
32 test "it uses summary twittercard if post has no attachment" do
33 user = insert(:user, name: "Jimmy Hendriks", bio: "born 19 March 1994")
34 {:ok, activity} = CommonAPI.post(user, %{status: "HI"})
39 "actor" => user.ap_id,
41 "id" => "https://pleroma.gov/objects/whatever",
43 "content" => "pleroma in a nutshell"
47 result = TwitterCard.build_tags(%{object: note, user: user, activity_id: activity.id})
50 {:meta, [name: "twitter:title", content: Utils.user_name_string(user)], []},
51 {:meta, [name: "twitter:description", content: "pleroma in a nutshell"], []},
52 {:meta, [name: "twitter:image", content: "http://localhost:4001/images/avi.png"],
54 {:meta, [name: "twitter:card", content: "summary"], []}
58 test "it uses summary as description if post has one" do
59 user = insert(:user, name: "Jimmy Hendriks", bio: "born 19 March 1994")
60 {:ok, activity} = CommonAPI.post(user, %{status: "HI"})
65 "actor" => user.ap_id,
67 "id" => "https://pleroma.gov/objects/whatever",
68 "summary" => "Public service announcement on caffeine consumption",
73 result = TwitterCard.build_tags(%{object: note, user: user, activity_id: activity.id})
76 {:meta, [name: "twitter:title", content: Utils.user_name_string(user)], []},
79 name: "twitter:description",
80 content: "Public service announcement on caffeine consumption"
82 {:meta, [name: "twitter:image", content: "http://localhost:4001/images/avi.png"],
84 {:meta, [name: "twitter:card", content: "summary"], []}
88 test "it renders avatar not attachment if post is nsfw and unfurl_nsfw is disabled" do
89 clear_config([Pleroma.Web.Metadata, :unfurl_nsfw], false)
90 user = insert(:user, name: "Jimmy Hendriks", bio: "born 19 March 1994")
91 {:ok, activity} = CommonAPI.post(user, %{status: "HI"})
96 "actor" => user.ap_id,
98 "id" => "https://pleroma.gov/objects/whatever",
100 "content" => "pleroma in a nutshell",
104 "url" => [%{"mediaType" => "image/png", "href" => "https://pleroma.gov/tenshi.png"}]
109 "mediaType" => "application/octet-stream",
110 "href" => "https://pleroma.gov/fqa/badapple.sfc"
116 %{"mediaType" => "video/webm", "href" => "https://pleroma.gov/about/juche.webm"}
123 result = TwitterCard.build_tags(%{object: note, user: user, activity_id: activity.id})
126 {:meta, [name: "twitter:title", content: Utils.user_name_string(user)], []},
127 {:meta, [name: "twitter:description", content: "pleroma in a nutshell"], []},
128 {:meta, [name: "twitter:image", content: "http://localhost:4001/images/avi.png"],
130 {:meta, [name: "twitter:card", content: "summary"], []}
134 test "it renders supported types of attachments and skips unknown types" do
135 user = insert(:user, name: "Jimmy Hendriks", bio: "born 19 March 1994")
136 {:ok, activity} = CommonAPI.post(user, %{status: "HI"})
141 "actor" => user.ap_id,
143 "id" => "https://pleroma.gov/objects/whatever",
145 "content" => "pleroma in a nutshell",
150 "mediaType" => "image/png",
151 "href" => "https://pleroma.gov/tenshi.png",
160 "mediaType" => "application/octet-stream",
161 "href" => "https://pleroma.gov/fqa/badapple.sfc"
168 "mediaType" => "video/webm",
169 "href" => "https://pleroma.gov/about/juche.webm",
179 result = TwitterCard.build_tags(%{object: note, user: user, activity_id: activity.id})
182 {:meta, [name: "twitter:title", content: Utils.user_name_string(user)], []},
183 {:meta, [name: "twitter:description", content: "pleroma in a nutshell"], []},
184 {:meta, [name: "twitter:card", content: "summary_large_image"], []},
185 {:meta, [name: "twitter:player", content: "https://pleroma.gov/tenshi.png"], []},
186 {:meta, [name: "twitter:player:width", content: "1280"], []},
187 {:meta, [name: "twitter:player:height", content: "1024"], []},
188 {:meta, [name: "twitter:card", content: "player"], []},
191 name: "twitter:player",
192 content: Router.Helpers.o_status_url(Endpoint, :notice_player, activity.id)
194 {:meta, [name: "twitter:player:width", content: "800"], []},
195 {:meta, [name: "twitter:player:height", content: "600"], []},
198 name: "twitter:player:stream",
199 content: "https://pleroma.gov/about/juche.webm"
201 {:meta, [name: "twitter:player:stream:content_type", content: "video/webm"], []}