1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 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, [property: "twitter:title", content: Utils.user_name_string(user)], []},
26 {:meta, [property: "twitter:description", content: "born 19 March 1994"], []},
27 {:meta, [property: "twitter:image", content: avatar_url], []},
28 {:meta, [property: "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",
42 "content" => "pleroma in a nutshell"
46 result = TwitterCard.build_tags(%{object: note, user: user, activity_id: activity.id})
49 {:meta, [property: "twitter:title", content: Utils.user_name_string(user)], []},
50 {:meta, [property: "twitter:description", content: "pleroma in a nutshell"], []},
51 {:meta, [property: "twitter:image", content: "http://localhost:4001/images/avi.png"],
53 {:meta, [property: "twitter:card", content: "summary"], []}
57 test "it renders avatar not attachment if post is nsfw and unfurl_nsfw is disabled" do
58 clear_config([Pleroma.Web.Metadata, :unfurl_nsfw], false)
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 "content" => "pleroma in a nutshell",
72 "url" => [%{"mediaType" => "image/png", "href" => "https://pleroma.gov/tenshi.png"}]
77 "mediaType" => "application/octet-stream",
78 "href" => "https://pleroma.gov/fqa/badapple.sfc"
84 %{"mediaType" => "video/webm", "href" => "https://pleroma.gov/about/juche.webm"}
91 result = TwitterCard.build_tags(%{object: note, user: user, activity_id: activity.id})
94 {:meta, [property: "twitter:title", content: Utils.user_name_string(user)], []},
95 {:meta, [property: "twitter:description", content: "pleroma in a nutshell"], []},
96 {:meta, [property: "twitter:image", content: "http://localhost:4001/images/avi.png"],
98 {:meta, [property: "twitter:card", content: "summary"], []}
102 test "it renders supported types of attachments and skips unknown types" do
103 user = insert(:user, name: "Jimmy Hendriks", bio: "born 19 March 1994")
104 {:ok, activity} = CommonAPI.post(user, %{status: "HI"})
109 "actor" => user.ap_id,
111 "id" => "https://pleroma.gov/objects/whatever",
112 "content" => "pleroma in a nutshell",
117 "mediaType" => "image/png",
118 "href" => "https://pleroma.gov/tenshi.png",
127 "mediaType" => "application/octet-stream",
128 "href" => "https://pleroma.gov/fqa/badapple.sfc"
135 "mediaType" => "video/webm",
136 "href" => "https://pleroma.gov/about/juche.webm",
146 result = TwitterCard.build_tags(%{object: note, user: user, activity_id: activity.id})
149 {:meta, [property: "twitter:title", content: Utils.user_name_string(user)], []},
150 {:meta, [property: "twitter:description", content: "pleroma in a nutshell"], []},
151 {:meta, [property: "twitter:card", content: "summary_large_image"], []},
152 {:meta, [property: "twitter:player", content: "https://pleroma.gov/tenshi.png"], []},
153 {:meta, [property: "twitter:player:width", content: "1280"], []},
154 {:meta, [property: "twitter:player:height", content: "1024"], []},
155 {:meta, [property: "twitter:card", content: "player"], []},
158 property: "twitter:player",
159 content: Router.Helpers.o_status_url(Endpoint, :notice_player, activity.id)
161 {:meta, [property: "twitter:player:width", content: "800"], []},
162 {:meta, [property: "twitter:player:height", content: "600"], []},
165 property: "twitter:player:stream",
166 content: "https://pleroma.gov/about/juche.webm"
168 {:meta, [property: "twitter:player:stream:content_type", content: "video/webm"], []}