1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4 defmodule Pleroma.Web.Metadata.Providers.OpenGraphTest do
7 alias Pleroma.Web.Metadata.Providers.OpenGraph
9 test "it renders all supported types of attachments and skips unknown types" do
15 "actor" => user.ap_id,
17 "id" => "https://pleroma.gov/objects/whatever",
18 "content" => "pleroma in a nutshell",
22 %{"mediaType" => "image/png", "href" => "https://pleroma.gov/tenshi.png"}
28 "mediaType" => "application/octet-stream",
29 "href" => "https://pleroma.gov/fqa/badapple.sfc"
35 %{"mediaType" => "video/webm", "href" => "https://pleroma.gov/about/juche.webm"}
41 "mediaType" => "audio/basic",
42 "href" => "http://www.gnu.org/music/free-software-song.au"
51 insert(:note_activity, %{
53 "actor" => note.data["actor"],
54 "to" => note.data["to"],
55 "object" => note.data,
56 "context" => note.data["context"]
58 actor: note.data["actor"],
59 recipients: note.data["to"]
62 result = OpenGraph.build_tags(%{activity: note_activity, user: user})
66 {:meta, [property: "og:image", content: "https://pleroma.gov/tenshi.png"], []},
68 [property: "og:audio", content: "http://www.gnu.org/music/free-software-song.au"],
70 {:meta, [property: "og:video", content: "https://pleroma.gov/about/juche.webm"],
73 fn element -> element in result end
77 test "it does not render attachments if post is nsfw" do
78 Pleroma.Config.put([Pleroma.Web.Metadata, :unfurl_nsfw], false)
79 user = insert(:user, avatar: %{"url" => [%{"href" => "https://pleroma.gov/tenshi.png"}]})
84 "actor" => user.ap_id,
85 "id" => "https://pleroma.gov/objects/whatever",
86 "content" => "#cuteposting #nsfw #hambaga",
87 "tag" => ["cuteposting", "nsfw", "hambaga"],
91 %{"mediaType" => "image/png", "href" => "https://misskey.microsoft/corndog.png"}
99 insert(:note_activity, %{
101 "actor" => note.data["actor"],
102 "to" => note.data["to"],
103 "object" => note.data,
104 "context" => note.data["context"]
106 actor: note.data["actor"],
107 recipients: note.data["to"]
110 result = OpenGraph.build_tags(%{activity: note_activity, user: user})
112 assert {:meta, [property: "og:image", content: "https://pleroma.gov/tenshi.png"], []} in result
114 refute {:meta, [property: "og:image", content: "https://misskey.microsoft/corndog.png"], []} in result