53fe1d550f87e09fed0efb26230e2e9af82d6aee
[akkoma] / test / pleroma / web / activity_pub / transmogrifier / like_handling_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.ActivityPub.Transmogrifier.LikeHandlingTest do
6 use Pleroma.DataCase
7
8 alias Pleroma.Activity
9 alias Pleroma.Web.ActivityPub.Transmogrifier
10 alias Pleroma.Web.CommonAPI
11
12 import Pleroma.Factory
13
14 test "it works for incoming likes" do
15 user = insert(:user)
16
17 {:ok, activity} = CommonAPI.post(user, %{status: "hello"})
18
19 data =
20 File.read!("test/fixtures/mastodon-like.json")
21 |> Poison.decode!()
22 |> Map.put("object", activity.data["object"])
23
24 _actor = insert(:user, ap_id: data["actor"], local: false)
25
26 {:ok, %Activity{data: data, local: false} = activity} = Transmogrifier.handle_incoming(data)
27
28 refute Enum.empty?(activity.recipients)
29
30 assert data["actor"] == "http://mastodon.example.org/users/admin"
31 assert data["type"] == "Like"
32 assert data["id"] == "http://mastodon.example.org/users/admin#likes/2"
33 assert data["object"] == activity.data["object"]
34 end
35
36 test "it works for incoming misskey likes, turning them into EmojiReacts" do
37 user = insert(:user)
38
39 {:ok, activity} = CommonAPI.post(user, %{status: "hello"})
40
41 data =
42 File.read!("test/fixtures/misskey-like.json")
43 |> Poison.decode!()
44 |> Map.put("object", activity.data["object"])
45
46 _actor = insert(:user, ap_id: data["actor"], local: false)
47
48 {:ok, %Activity{data: activity_data, local: false}} = Transmogrifier.handle_incoming(data)
49
50 assert activity_data["actor"] == data["actor"]
51 assert activity_data["type"] == "EmojiReact"
52 assert activity_data["id"] == data["id"]
53 assert activity_data["object"] == activity.data["object"]
54 assert activity_data["content"] == "🍮"
55 end
56
57 test "it works for incoming misskey likes that contain unicode emojis, turning them into EmojiReacts" do
58 user = insert(:user)
59
60 {:ok, activity} = CommonAPI.post(user, %{status: "hello"})
61
62 data =
63 File.read!("test/fixtures/misskey-like.json")
64 |> Poison.decode!()
65 |> Map.put("object", activity.data["object"])
66 |> Map.put("_misskey_reaction", "⭐")
67
68 _actor = insert(:user, ap_id: data["actor"], local: false)
69
70 {:ok, %Activity{data: activity_data, local: false}} = Transmogrifier.handle_incoming(data)
71
72 assert activity_data["actor"] == data["actor"]
73 assert activity_data["type"] == "EmojiReact"
74 assert activity_data["id"] == data["id"]
75 assert activity_data["object"] == activity.data["object"]
76 assert activity_data["content"] == "⭐"
77 end
78 end