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.Metadata.Providers.TwitterCard
13 alias Pleroma.Web.Metadata.Utils
14 alias Pleroma.Web.Router
16 setup do: clear_config([Pleroma.Web.Metadata, :unfurl_nsfw])
18 test "it renders twitter card for user info" do
19 user = insert(:user, name: "Jimmy Hendriks", bio: "born 19 March 1994")
20 avatar_url = Utils.attachment_url(User.avatar_url(user))
21 res = TwitterCard.build_tags(%{user: user})
24 {:meta, [property: "twitter:title", content: Utils.user_name_string(user)], []},
25 {:meta, [property: "twitter:description", content: "born 19 March 1994"], []},
26 {:meta, [property: "twitter:image", content: avatar_url], []},
27 {:meta, [property: "twitter:card", content: "summary"], []}
31 test "it uses summary twittercard if post has no attachment" do
32 user = insert(:user, name: "Jimmy Hendriks", bio: "born 19 March 1994")
33 {:ok, activity} = CommonAPI.post(user, %{status: "HI"})
38 "actor" => user.ap_id,
40 "id" => "https://pleroma.gov/objects/whatever",
41 "content" => "pleroma in a nutshell"
45 result = TwitterCard.build_tags(%{object: note, user: user, activity_id: activity.id})
48 {:meta, [property: "twitter:title", content: Utils.user_name_string(user)], []},
49 {:meta, [property: "twitter:description", content: "“pleroma in a nutshell”"], []},
50 {:meta, [property: "twitter:image", content: "http://localhost:4001/images/avi.png"],
52 {:meta, [property: "twitter:card", content: "summary"], []}
56 test "it renders avatar not attachment if post is nsfw and unfurl_nsfw is disabled" do
57 clear_config([Pleroma.Web.Metadata, :unfurl_nsfw], false)
58 user = insert(:user, name: "Jimmy Hendriks", bio: "born 19 March 1994")
59 {:ok, activity} = CommonAPI.post(user, %{status: "HI"})
64 "actor" => user.ap_id,
66 "id" => "https://pleroma.gov/objects/whatever",
67 "content" => "pleroma in a nutshell",
71 "url" => [%{"mediaType" => "image/png", "href" => "https://pleroma.gov/tenshi.png"}]
76 "mediaType" => "application/octet-stream",
77 "href" => "https://pleroma.gov/fqa/badapple.sfc"
83 %{"mediaType" => "video/webm", "href" => "https://pleroma.gov/about/juche.webm"}
90 result = TwitterCard.build_tags(%{object: note, user: user, activity_id: activity.id})
93 {:meta, [property: "twitter:title", content: Utils.user_name_string(user)], []},
94 {:meta, [property: "twitter:description", content: "“pleroma in a nutshell”"], []},
95 {:meta, [property: "twitter:image", content: "http://localhost:4001/images/avi.png"],
97 {:meta, [property: "twitter:card", content: "summary"], []}
101 test "it renders supported types of attachments and skips unknown types" do
102 user = insert(:user, name: "Jimmy Hendriks", bio: "born 19 March 1994")
103 {:ok, activity} = CommonAPI.post(user, %{status: "HI"})
108 "actor" => user.ap_id,
110 "id" => "https://pleroma.gov/objects/whatever",
111 "content" => "pleroma in a nutshell",
114 "url" => [%{"mediaType" => "image/png", "href" => "https://pleroma.gov/tenshi.png"}]
119 "mediaType" => "application/octet-stream",
120 "href" => "https://pleroma.gov/fqa/badapple.sfc"
126 %{"mediaType" => "video/webm", "href" => "https://pleroma.gov/about/juche.webm"}
133 result = TwitterCard.build_tags(%{object: note, user: user, activity_id: activity.id})
136 {:meta, [property: "twitter:title", content: Utils.user_name_string(user)], []},
137 {:meta, [property: "twitter:description", content: "“pleroma in a nutshell”"], []},
138 {:meta, [property: "twitter:card", content: "summary_large_image"], []},
139 {:meta, [property: "twitter:player", content: "https://pleroma.gov/tenshi.png"], []},
140 {:meta, [property: "twitter:card", content: "player"], []},
143 property: "twitter:player",
144 content: Router.Helpers.o_status_url(Endpoint, :notice_player, activity.id)
146 {:meta, [property: "twitter:player:width", content: "480"], []},
147 {:meta, [property: "twitter:player:height", content: "480"], []}