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 "content" => "pleroma in a nutshell",
21 %{"mediaType" => "image/png", "href" => "https://pleroma.gov/tenshi.png"}
27 "mediaType" => "application/octet-stream",
28 "href" => "https://pleroma.gov/fqa/badapple.sfc"
34 %{"mediaType" => "video/webm", "href" => "https://pleroma.gov/about/juche.webm"}
40 "mediaType" => "audio/basic",
41 "href" => "http://www.gnu.org/music/free-software-song.au"
50 insert(:note_activity, %{
52 "actor" => note.data["actor"],
53 "to" => note.data["to"],
54 "object" => note.data,
55 "context" => note.data["context"]
57 actor: note.data["actor"],
58 recipients: note.data["to"]
61 result = OpenGraph.build_tags(%{activity: note_activity, user: user})
65 {:meta, [property: "og:image", content: "https://pleroma.gov/tenshi.png"], []},
67 [property: "og:audio", content: "http://www.gnu.org/music/free-software-song.au"],
69 {:meta, [property: "og:video", content: "https://pleroma.gov/about/juche.webm"],
72 fn element -> element in result end
76 test "it does not render attachments if post is nsfw" do
77 Pleroma.Config.put([Pleroma.Web.Metadata, :unfurl_nsfw], false)
78 user = insert(:user, avatar: %{"url" => [%{"href" => "https://pleroma.gov/tenshi.png"}]})
83 "actor" => user.ap_id,
84 "content" => "#cuteposting #nsfw #hambaga",
85 "tag" => ["cuteposting", "nsfw", "hambaga"],
89 %{"mediaType" => "image/png", "href" => "https://misskey.microsoft/corndog.png"}
97 insert(:note_activity, %{
99 "actor" => note.data["actor"],
100 "to" => note.data["to"],
101 "object" => note.data,
102 "context" => note.data["context"]
104 actor: note.data["actor"],
105 recipients: note.data["to"]
108 result = OpenGraph.build_tags(%{activity: note_activity, user: user})
110 assert {:meta, [property: "og:image", content: "https://pleroma.gov/tenshi.png"], []} in result
112 refute {:meta, [property: "og:image", content: "https://misskey.microsoft/corndog.png"], []} in result