Fix object id in OpenGraph test
[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 "id" => "https://pleroma.gov/objects/whatever",
18 "content" => "pleroma in a nutshell",
19 "attachment" => [
20 %{
21 "url" => [
22 %{"mediaType" => "image/png", "href" => "https://pleroma.gov/tenshi.png"}
23 ]
24 },
25 %{
26 "url" => [
27 %{
28 "mediaType" => "application/octet-stream",
29 "href" => "https://pleroma.gov/fqa/badapple.sfc"
30 }
31 ]
32 },
33 %{
34 "url" => [
35 %{"mediaType" => "video/webm", "href" => "https://pleroma.gov/about/juche.webm"}
36 ]
37 },
38 %{
39 "url" => [
40 %{
41 "mediaType" => "audio/basic",
42 "href" => "http://www.gnu.org/music/free-software-song.au"
43 }
44 ]
45 }
46 ]
47 }
48 })
49
50 note_activity =
51 insert(:note_activity, %{
52 data: %{
53 "actor" => note.data["actor"],
54 "to" => note.data["to"],
55 "object" => note.data,
56 "context" => note.data["context"]
57 },
58 actor: note.data["actor"],
59 recipients: note.data["to"]
60 })
61
62 result = OpenGraph.build_tags(%{activity: note_activity, user: user})
63
64 assert Enum.all?(
65 [
66 {:meta, [property: "og:image", content: "https://pleroma.gov/tenshi.png"], []},
67 {:meta,
68 [property: "og:audio", content: "http://www.gnu.org/music/free-software-song.au"],
69 []},
70 {:meta, [property: "og:video", content: "https://pleroma.gov/about/juche.webm"],
71 []}
72 ],
73 fn element -> element in result end
74 )
75 end
76
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"}]})
80
81 note =
82 insert(:note, %{
83 data: %{
84 "actor" => user.ap_id,
85 "id" => "https://pleroma.gov/objects/whatever",
86 "content" => "#cuteposting #nsfw #hambaga",
87 "tag" => ["cuteposting", "nsfw", "hambaga"],
88 "attachment" => [
89 %{
90 "url" => [
91 %{"mediaType" => "image/png", "href" => "https://misskey.microsoft/corndog.png"}
92 ]
93 }
94 ]
95 }
96 })
97
98 note_activity =
99 insert(:note_activity, %{
100 data: %{
101 "actor" => note.data["actor"],
102 "to" => note.data["to"],
103 "object" => note.data,
104 "context" => note.data["context"]
105 },
106 actor: note.data["actor"],
107 recipients: note.data["to"]
108 })
109
110 result = OpenGraph.build_tags(%{activity: note_activity, user: user})
111
112 assert {:meta, [property: "og:image", content: "https://pleroma.gov/tenshi.png"], []} in result
113
114 refute {:meta, [property: "og:image", content: "https://misskey.microsoft/corndog.png"], []} in result
115 end
116 end