be3f8936499f8948dad802bd28cf36266f94bb15
[akkoma] / test / web / metadata / opengraph_test.exs
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
5 use Pleroma.DataCase
6 import Pleroma.Factory
7 alias Pleroma.Web.Metadata.Providers.OpenGraph
8
9 test "it renders all supported types of attachments and skips unknown types" do
10 user = insert(:user)
11
12 note =
13 insert(:note, %{
14 data: %{
15 "actor" => user.ap_id,
16 "tag" => [],
17 "content" => "pleroma in a nutshell",
18 "attachment" => [
19 %{
20 "url" => [
21 %{"mediaType" => "image/png", "href" => "https://pleroma.gov/tenshi.png"}
22 ]
23 },
24 %{
25 "url" => [
26 %{
27 "mediaType" => "application/octet-stream",
28 "href" => "https://pleroma.gov/fqa/badapple.sfc"
29 }
30 ]
31 },
32 %{
33 "url" => [
34 %{"mediaType" => "video/webm", "href" => "https://pleroma.gov/about/juche.webm"}
35 ]
36 },
37 %{
38 "url" => [
39 %{
40 "mediaType" => "audio/basic",
41 "href" => "http://www.gnu.org/music/free-software-song.au"
42 }
43 ]
44 }
45 ]
46 }
47 })
48
49 note_activity =
50 insert(:note_activity, %{
51 data: %{
52 "actor" => note.data["actor"],
53 "to" => note.data["to"],
54 "object" => note.data,
55 "context" => note.data["context"]
56 },
57 actor: note.data["actor"],
58 recipients: note.data["to"]
59 })
60
61 result = OpenGraph.build_tags(%{activity: note_activity, user: user})
62
63 assert Enum.all?(
64 [
65 {:meta, [property: "og:image", content: "https://pleroma.gov/tenshi.png"], []},
66 {:meta,
67 [property: "og:audio", content: "http://www.gnu.org/music/free-software-song.au"],
68 []},
69 {:meta, [property: "og:video", content: "https://pleroma.gov/about/juche.webm"],
70 []}
71 ],
72 fn element -> element in result end
73 )
74 end
75
76 test "it does not render attachments if post is nsfw" do
77 user = insert(:user, avatar: %{"url" => [%{"href" => "https://pleroma.gov/tenshi.png"}]})
78
79 note =
80 insert(:note, %{
81 data: %{
82 "actor" => user.ap_id,
83 "content" => "#cuteposting #nsfw #hambaga",
84 "tag" => ["cuteposting", "nsfw", "hambaga"],
85 "attachment" => [
86 %{
87 "url" => [
88 %{"mediaType" => "image/png", "href" => "https://misskey.microsoft/corndog.png"}
89 ]
90 }
91 ]
92 }
93 })
94
95 note_activity =
96 insert(:note_activity, %{
97 data: %{
98 "actor" => note.data["actor"],
99 "to" => note.data["to"],
100 "object" => note.data,
101 "context" => note.data["context"]
102 },
103 actor: note.data["actor"],
104 recipients: note.data["to"]
105 })
106
107 result = OpenGraph.build_tags(%{activity: note_activity, user: user})
108
109 assert {:meta, [property: "og:image", content: "https://pleroma.gov/tenshi.png"], []} in result
110
111 refute {:meta, [property: "og:image", content: "https://misskey.microsoft/corndog.png"], []} in result
112 end
113 end