Merge branch 'develop' of akkoma.dev:AkkomaGang/akkoma into develop
[akkoma] / test / pleroma / web / activity_pub / builder_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.ActivityPub.BuilderTest do
6 alias Pleroma.Web.ActivityPub.Builder
7 alias Pleroma.Web.CommonAPI.ActivityDraft
8 use Pleroma.DataCase
9
10 import Pleroma.Factory
11
12 describe "note/1" do
13 test "returns note data" do
14 user = insert(:user)
15 note = insert(:note)
16 quote = insert(:note)
17 user2 = insert(:user)
18 user3 = insert(:user)
19
20 draft = %ActivityDraft{
21 user: user,
22 to: [user2.ap_id],
23 context: "2hu",
24 content_html: "<h1>This is :moominmamma: note</h1>",
25 in_reply_to: note.id,
26 tags: [name: "jimm"],
27 summary: "test summary",
28 cc: [user3.ap_id],
29 extra: %{"custom_tag" => "test"},
30 quote: quote
31 }
32
33 expected = %{
34 "actor" => user.ap_id,
35 "attachment" => [],
36 "cc" => [user3.ap_id],
37 "content" => "<h1>This is :moominmamma: note</h1>",
38 "context" => "2hu",
39 "sensitive" => false,
40 "summary" => "test summary",
41 "tag" => ["jimm"],
42 "to" => [user2.ap_id],
43 "type" => "Note",
44 "custom_tag" => "test",
45 "quoteUri" => quote.data["id"]
46 }
47
48 assert {:ok, ^expected, []} = Builder.note(draft)
49 end
50 end
51
52 describe "emoji_react/1" do
53 test "unicode emoji" do
54 user = insert(:user)
55 note = insert(:note)
56
57 assert {:ok, %{"content" => "👍", "type" => "EmojiReact"}, []} =
58 Builder.emoji_react(user, note, "👍")
59 end
60
61 test "custom emoji" do
62 user = insert(:user)
63 note = insert(:note)
64
65 assert {:ok,
66 %{
67 "content" => ":dinosaur:",
68 "type" => "EmojiReact",
69 "tag" => [
70 %{
71 "name" => ":dinosaur:",
72 "id" => "http://localhost:4001/emoji/dino walking.gif",
73 "icon" => %{
74 "type" => "Image",
75 "url" => "http://localhost:4001/emoji/dino walking.gif"
76 }
77 }
78 ]
79 }, []} = Builder.emoji_react(user, note, ":dinosaur:")
80 end
81
82 test "remote custom emoji" do
83 user = insert(:user)
84 other_user = insert(:user, local: false)
85
86 note =
87 insert(:note,
88 data: %{"reactions" => [["wow", [other_user.ap_id], "https://remote/emoji/wow"]]}
89 )
90
91 assert {:ok,
92 %{
93 "content" => ":wow:",
94 "type" => "EmojiReact",
95 "tag" => [
96 %{
97 "name" => ":wow:",
98 "id" => "https://remote/emoji/wow",
99 "icon" => %{
100 "type" => "Image",
101 "url" => "https://remote/emoji/wow"
102 }
103 }
104 ]
105 }, []} = Builder.emoji_react(user, note, ":wow@remote:")
106 end
107 end
108 end