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 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"})
37 "actor" => user.ap_id,
39 "id" => "https://pleroma.gov/objects/whatever",
40 "content" => "pleroma in a nutshell",
44 "url" => [%{"mediaType" => "image/png", "href" => "https://pleroma.gov/tenshi.png"}]
49 "mediaType" => "application/octet-stream",
50 "href" => "https://pleroma.gov/fqa/badapple.sfc"
56 %{"mediaType" => "video/webm", "href" => "https://pleroma.gov/about/juche.webm"}
63 result = TwitterCard.build_tags(%{object: note, user: user, activity_id: activity.id})
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"],
70 {:meta, [property: "twitter:card", content: "summary_large_image"], []}
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"})
81 "actor" => user.ap_id,
83 "id" => "https://pleroma.gov/objects/whatever",
84 "content" => "pleroma in a nutshell",
87 "url" => [%{"mediaType" => "image/png", "href" => "https://pleroma.gov/tenshi.png"}]
92 "mediaType" => "application/octet-stream",
93 "href" => "https://pleroma.gov/fqa/badapple.sfc"
99 %{"mediaType" => "video/webm", "href" => "https://pleroma.gov/about/juche.webm"}
106 result = TwitterCard.build_tags(%{object: note, user: user, activity_id: activity.id})
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"], []},
116 property: "twitter:player",
117 content: Router.Helpers.o_status_url(Endpoint, :notice_player, activity.id)
119 {:meta, [property: "twitter:player:width", content: "480"], []},
120 {:meta, [property: "twitter:player:height", content: "480"], []}