2019-07-12 10:42:54 -06:00
|
|
|
# Pleroma: A lightweight social networking server
|
2021-01-12 23:49:20 -07:00
|
|
|
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
2019-07-12 10:42:54 -06:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
defmodule Pleroma.Web.Metadata.Providers.TwitterCardTest do
|
|
|
|
use Pleroma.DataCase
|
|
|
|
import Pleroma.Factory
|
|
|
|
|
|
|
|
alias Pleroma.User
|
|
|
|
alias Pleroma.Web.CommonAPI
|
|
|
|
alias Pleroma.Web.Endpoint
|
2021-06-09 09:06:44 -06:00
|
|
|
alias Pleroma.Web.MediaProxy
|
2019-07-12 10:42:54 -06:00
|
|
|
alias Pleroma.Web.Metadata.Providers.TwitterCard
|
|
|
|
alias Pleroma.Web.Metadata.Utils
|
|
|
|
|
2020-03-20 09:33:00 -06:00
|
|
|
setup do: clear_config([Pleroma.Web.Metadata, :unfurl_nsfw])
|
2020-02-13 11:55:47 -07:00
|
|
|
|
2019-07-12 10:42:54 -06:00
|
|
|
test "it renders twitter card for user info" do
|
|
|
|
user = insert(:user, name: "Jimmy Hendriks", bio: "born 19 March 1994")
|
2021-06-09 09:06:44 -06:00
|
|
|
avatar_url = MediaProxy.preview_url(User.avatar_url(user))
|
2019-07-12 10:42:54 -06:00
|
|
|
res = TwitterCard.build_tags(%{user: user})
|
|
|
|
|
|
|
|
assert res == [
|
2022-12-19 12:40:08 -07:00
|
|
|
{:meta, [name: "twitter:title", content: Utils.user_name_string(user)], []},
|
|
|
|
{:meta, [name: "twitter:description", content: "born 19 March 1994"], []},
|
|
|
|
{:meta, [name: "twitter:image", content: avatar_url], []},
|
|
|
|
{:meta, [name: "twitter:card", content: "summary"], []}
|
2019-07-12 10:42:54 -06:00
|
|
|
]
|
|
|
|
end
|
|
|
|
|
2019-12-20 15:32:04 -07:00
|
|
|
test "it uses summary twittercard if post has no attachment" do
|
|
|
|
user = insert(:user, name: "Jimmy Hendriks", bio: "born 19 March 1994")
|
2020-05-12 13:59:26 -06:00
|
|
|
{:ok, activity} = CommonAPI.post(user, %{status: "HI"})
|
2019-12-20 15:32:04 -07:00
|
|
|
|
|
|
|
note =
|
|
|
|
insert(:note, %{
|
|
|
|
data: %{
|
|
|
|
"actor" => user.ap_id,
|
|
|
|
"tag" => [],
|
|
|
|
"id" => "https://pleroma.gov/objects/whatever",
|
2022-08-23 06:49:05 -06:00
|
|
|
"summary" => "",
|
2019-12-20 15:32:04 -07:00
|
|
|
"content" => "pleroma in a nutshell"
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
result = TwitterCard.build_tags(%{object: note, user: user, activity_id: activity.id})
|
|
|
|
|
|
|
|
assert [
|
2022-12-19 12:40:08 -07:00
|
|
|
{:meta, [name: "twitter:title", content: Utils.user_name_string(user)], []},
|
|
|
|
{:meta, [name: "twitter:description", content: "pleroma in a nutshell"], []},
|
|
|
|
{:meta, [name: "twitter:image", content: "http://localhost:4001/images/avi.png"],
|
2019-12-20 15:32:04 -07:00
|
|
|
[]},
|
2022-12-19 12:40:08 -07:00
|
|
|
{:meta, [name: "twitter:card", content: "summary"], []}
|
2019-12-20 15:32:04 -07:00
|
|
|
] == result
|
|
|
|
end
|
|
|
|
|
2022-08-23 06:49:05 -06:00
|
|
|
test "it uses summary as description if post has one" do
|
|
|
|
user = insert(:user, name: "Jimmy Hendriks", bio: "born 19 March 1994")
|
|
|
|
{:ok, activity} = CommonAPI.post(user, %{status: "HI"})
|
|
|
|
|
|
|
|
note =
|
|
|
|
insert(:note, %{
|
|
|
|
data: %{
|
|
|
|
"actor" => user.ap_id,
|
|
|
|
"tag" => [],
|
|
|
|
"id" => "https://pleroma.gov/objects/whatever",
|
|
|
|
"summary" => "Public service announcement on caffeine consumption",
|
|
|
|
"content" => "cofe"
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
result = TwitterCard.build_tags(%{object: note, user: user, activity_id: activity.id})
|
|
|
|
|
|
|
|
assert [
|
2022-12-19 12:40:08 -07:00
|
|
|
{:meta, [name: "twitter:title", content: Utils.user_name_string(user)], []},
|
2022-08-23 06:49:05 -06:00
|
|
|
{:meta,
|
|
|
|
[
|
2022-12-19 12:40:08 -07:00
|
|
|
name: "twitter:description",
|
2022-08-23 06:49:05 -06:00
|
|
|
content: "Public service announcement on caffeine consumption"
|
|
|
|
], []},
|
2022-12-19 12:40:08 -07:00
|
|
|
{:meta, [name: "twitter:image", content: "http://localhost:4001/images/avi.png"],
|
2022-08-23 06:49:05 -06:00
|
|
|
[]},
|
2022-12-19 12:40:08 -07:00
|
|
|
{:meta, [name: "twitter:card", content: "summary"], []}
|
2022-08-23 06:49:05 -06:00
|
|
|
] == result
|
|
|
|
end
|
|
|
|
|
2019-12-20 15:32:04 -07:00
|
|
|
test "it renders avatar not attachment if post is nsfw and unfurl_nsfw is disabled" do
|
2021-01-26 10:58:43 -07:00
|
|
|
clear_config([Pleroma.Web.Metadata, :unfurl_nsfw], false)
|
2019-07-12 10:42:54 -06:00
|
|
|
user = insert(:user, name: "Jimmy Hendriks", bio: "born 19 March 1994")
|
2020-05-12 13:59:26 -06:00
|
|
|
{:ok, activity} = CommonAPI.post(user, %{status: "HI"})
|
2019-07-12 10:42:54 -06:00
|
|
|
|
|
|
|
note =
|
|
|
|
insert(:note, %{
|
|
|
|
data: %{
|
|
|
|
"actor" => user.ap_id,
|
|
|
|
"tag" => [],
|
|
|
|
"id" => "https://pleroma.gov/objects/whatever",
|
2022-08-23 06:49:05 -06:00
|
|
|
"summary" => "",
|
2019-07-12 10:42:54 -06:00
|
|
|
"content" => "pleroma in a nutshell",
|
|
|
|
"sensitive" => true,
|
|
|
|
"attachment" => [
|
|
|
|
%{
|
|
|
|
"url" => [%{"mediaType" => "image/png", "href" => "https://pleroma.gov/tenshi.png"}]
|
|
|
|
},
|
|
|
|
%{
|
|
|
|
"url" => [
|
|
|
|
%{
|
|
|
|
"mediaType" => "application/octet-stream",
|
|
|
|
"href" => "https://pleroma.gov/fqa/badapple.sfc"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
%{
|
|
|
|
"url" => [
|
|
|
|
%{"mediaType" => "video/webm", "href" => "https://pleroma.gov/about/juche.webm"}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
result = TwitterCard.build_tags(%{object: note, user: user, activity_id: activity.id})
|
|
|
|
|
|
|
|
assert [
|
2022-12-19 12:40:08 -07:00
|
|
|
{:meta, [name: "twitter:title", content: Utils.user_name_string(user)], []},
|
|
|
|
{:meta, [name: "twitter:description", content: "pleroma in a nutshell"], []},
|
|
|
|
{:meta, [name: "twitter:image", content: "http://localhost:4001/images/avi.png"],
|
2019-07-12 10:42:54 -06:00
|
|
|
[]},
|
2022-12-19 12:40:08 -07:00
|
|
|
{:meta, [name: "twitter:card", content: "summary"], []}
|
2019-07-12 10:42:54 -06:00
|
|
|
] == result
|
|
|
|
end
|
|
|
|
|
|
|
|
test "it renders supported types of attachments and skips unknown types" do
|
|
|
|
user = insert(:user, name: "Jimmy Hendriks", bio: "born 19 March 1994")
|
2020-05-12 13:59:26 -06:00
|
|
|
{:ok, activity} = CommonAPI.post(user, %{status: "HI"})
|
2019-07-12 10:42:54 -06:00
|
|
|
|
|
|
|
note =
|
|
|
|
insert(:note, %{
|
|
|
|
data: %{
|
|
|
|
"actor" => user.ap_id,
|
|
|
|
"tag" => [],
|
|
|
|
"id" => "https://pleroma.gov/objects/whatever",
|
2022-08-23 06:49:05 -06:00
|
|
|
"summary" => "",
|
2019-07-12 10:42:54 -06:00
|
|
|
"content" => "pleroma in a nutshell",
|
|
|
|
"attachment" => [
|
|
|
|
%{
|
2021-06-08 15:19:12 -06:00
|
|
|
"url" => [
|
|
|
|
%{
|
|
|
|
"mediaType" => "image/png",
|
|
|
|
"href" => "https://pleroma.gov/tenshi.png",
|
|
|
|
"height" => 1024,
|
|
|
|
"width" => 1280
|
|
|
|
}
|
|
|
|
]
|
2019-07-12 10:42:54 -06:00
|
|
|
},
|
|
|
|
%{
|
|
|
|
"url" => [
|
|
|
|
%{
|
|
|
|
"mediaType" => "application/octet-stream",
|
|
|
|
"href" => "https://pleroma.gov/fqa/badapple.sfc"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
%{
|
|
|
|
"url" => [
|
2021-06-08 14:59:55 -06:00
|
|
|
%{
|
|
|
|
"mediaType" => "video/webm",
|
|
|
|
"href" => "https://pleroma.gov/about/juche.webm",
|
|
|
|
"height" => 600,
|
|
|
|
"width" => 800
|
|
|
|
}
|
2019-07-12 10:42:54 -06:00
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
result = TwitterCard.build_tags(%{object: note, user: user, activity_id: activity.id})
|
|
|
|
|
|
|
|
assert [
|
2022-12-19 12:40:08 -07:00
|
|
|
{:meta, [name: "twitter:title", content: Utils.user_name_string(user)], []},
|
|
|
|
{:meta, [name: "twitter:description", content: "pleroma in a nutshell"], []},
|
|
|
|
{:meta, [name: "twitter:card", content: "summary_large_image"], []},
|
|
|
|
{:meta, [name: "twitter:player", content: "https://pleroma.gov/tenshi.png"], []},
|
|
|
|
{:meta, [name: "twitter:player:width", content: "1280"], []},
|
|
|
|
{:meta, [name: "twitter:player:height", content: "1024"], []},
|
|
|
|
{:meta, [name: "twitter:card", content: "player"], []},
|
2019-07-12 10:42:54 -06:00
|
|
|
{:meta,
|
|
|
|
[
|
2022-12-19 12:40:08 -07:00
|
|
|
name: "twitter:player",
|
2023-08-15 04:22:18 -06:00
|
|
|
content: url(Endpoint, ~p[/notice/#{activity.id}/embed_player])
|
2019-07-12 10:42:54 -06:00
|
|
|
], []},
|
2022-12-19 12:40:08 -07:00
|
|
|
{:meta, [name: "twitter:player:width", content: "800"], []},
|
|
|
|
{:meta, [name: "twitter:player:height", content: "600"], []},
|
2021-06-07 14:47:50 -06:00
|
|
|
{:meta,
|
|
|
|
[
|
2022-12-19 12:40:08 -07:00
|
|
|
name: "twitter:player:stream",
|
2021-06-07 14:47:50 -06:00
|
|
|
content: "https://pleroma.gov/about/juche.webm"
|
|
|
|
], []},
|
2022-12-19 12:40:08 -07:00
|
|
|
{:meta, [name: "twitter:player:stream:content_type", content: "video/webm"], []}
|
2019-07-12 10:42:54 -06:00
|
|
|
] == result
|
|
|
|
end
|
|
|
|
end
|