1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 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 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})
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"], []}
29 test "it uses summary twittercard if post has no attachment" do
30 user = insert(:user, name: "Jimmy Hendriks", bio: "born 19 March 1994")
31 {:ok, activity} = CommonAPI.post(user, %{"status" => "HI"})
36 "actor" => user.ap_id,
38 "id" => "https://pleroma.gov/objects/whatever",
39 "content" => "pleroma in a nutshell"
43 result = TwitterCard.build_tags(%{object: note, user: user, activity_id: activity.id})
46 {:meta, [property: "twitter:title", content: Utils.user_name_string(user)], []},
47 {:meta, [property: "twitter:description", content: "“pleroma in a nutshell”"], []},
48 {:meta, [property: "twitter:image", content: "http://localhost:4001/images/avi.png"],
50 {:meta, [property: "twitter:card", content: "summary"], []}
54 test "it renders avatar not attachment if post is nsfw and unfurl_nsfw is disabled" do
55 Pleroma.Config.put([Pleroma.Web.Metadata, :unfurl_nsfw], false)
56 user = insert(:user, name: "Jimmy Hendriks", bio: "born 19 March 1994")
57 {:ok, activity} = CommonAPI.post(user, %{"status" => "HI"})
62 "actor" => user.ap_id,
64 "id" => "https://pleroma.gov/objects/whatever",
65 "content" => "pleroma in a nutshell",
69 "url" => [%{"mediaType" => "image/png", "href" => "https://pleroma.gov/tenshi.png"}]
74 "mediaType" => "application/octet-stream",
75 "href" => "https://pleroma.gov/fqa/badapple.sfc"
81 %{"mediaType" => "video/webm", "href" => "https://pleroma.gov/about/juche.webm"}
88 result = TwitterCard.build_tags(%{object: note, user: user, activity_id: activity.id})
91 {:meta, [property: "twitter:title", content: Utils.user_name_string(user)], []},
92 {:meta, [property: "twitter:description", content: "“pleroma in a nutshell”"], []},
93 {:meta, [property: "twitter:image", content: "http://localhost:4001/images/avi.png"],
95 {:meta, [property: "twitter:card", content: "summary"], []}
99 test "it renders supported types of attachments and skips unknown types" do
100 user = insert(:user, name: "Jimmy Hendriks", bio: "born 19 March 1994")
101 {:ok, activity} = CommonAPI.post(user, %{"status" => "HI"})
106 "actor" => user.ap_id,
108 "id" => "https://pleroma.gov/objects/whatever",
109 "content" => "pleroma in a nutshell",
112 "url" => [%{"mediaType" => "image/png", "href" => "https://pleroma.gov/tenshi.png"}]
117 "mediaType" => "application/octet-stream",
118 "href" => "https://pleroma.gov/fqa/badapple.sfc"
124 %{"mediaType" => "video/webm", "href" => "https://pleroma.gov/about/juche.webm"}
131 result = TwitterCard.build_tags(%{object: note, user: user, activity_id: activity.id})
134 {:meta, [property: "twitter:title", content: Utils.user_name_string(user)], []},
135 {:meta, [property: "twitter:description", content: "“pleroma in a nutshell”"], []},
136 {:meta, [property: "twitter:card", content: "summary_large_image"], []},
137 {:meta, [property: "twitter:player", content: "https://pleroma.gov/tenshi.png"], []},
138 {:meta, [property: "twitter:card", content: "player"], []},
141 property: "twitter:player",
142 content: Router.Helpers.o_status_url(Endpoint, :notice_player, activity.id)
144 {:meta, [property: "twitter:player:width", content: "480"], []},
145 {:meta, [property: "twitter:player:height", content: "480"], []}