1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.ActivityPub.Transmogrifier.LikeHandlingTest do
6 use Pleroma.DataCase, async: true
9 alias Pleroma.Web.ActivityPub.Transmogrifier
10 alias Pleroma.Web.CommonAPI
12 import Pleroma.Factory
14 test "it works for incoming likes" do
17 {:ok, activity} = CommonAPI.post(user, %{status: "hello"})
20 File.read!("test/fixtures/mastodon-like.json")
22 |> Map.put("object", activity.data["object"])
24 _actor = insert(:user, ap_id: data["actor"], local: false)
26 {:ok, %Activity{data: data, local: false} = activity} = Transmogrifier.handle_incoming(data)
28 refute Enum.empty?(activity.recipients)
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"]
36 test "it works for incoming misskey likes, turning them into EmojiReacts" do
39 {:ok, activity} = CommonAPI.post(user, %{status: "hello"})
42 File.read!("test/fixtures/misskey-like.json")
44 |> Map.put("object", activity.data["object"])
46 _actor = insert(:user, ap_id: data["actor"], local: false)
48 {:ok, %Activity{data: activity_data, local: false}} = Transmogrifier.handle_incoming(data)
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"] == ":pudding:"
57 test "it works for incoming misskey likes that contain unicode emojis, turning them into EmojiReacts" do
60 {:ok, activity} = CommonAPI.post(user, %{status: "hello"})
63 File.read!("test/fixtures/misskey-like.json")
65 |> Map.put("object", activity.data["object"])
66 |> Map.put("_misskey_reaction", "⭐")
68 _actor = insert(:user, ap_id: data["actor"], local: false)
70 {:ok, %Activity{data: activity_data, local: false}} = Transmogrifier.handle_incoming(data)
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"] == "⭐"