2020-05-04 12:45:28 +00:00
|
|
|
# Pleroma: A lightweight social networking server
|
2021-01-13 06:49:20 +00:00
|
|
|
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
2020-05-04 12:45:28 +00:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
defmodule Pleroma.Web.ActivityPub.Transmogrifier.LikeHandlingTest do
|
2020-12-21 11:21:40 +00:00
|
|
|
use Pleroma.DataCase, async: true
|
2020-05-04 12:45:28 +00:00
|
|
|
|
|
|
|
alias Pleroma.Activity
|
|
|
|
alias Pleroma.Web.ActivityPub.Transmogrifier
|
|
|
|
alias Pleroma.Web.CommonAPI
|
|
|
|
|
|
|
|
import Pleroma.Factory
|
|
|
|
|
|
|
|
test "it works for incoming likes" do
|
|
|
|
user = insert(:user)
|
|
|
|
|
2020-05-12 19:59:26 +00:00
|
|
|
{:ok, activity} = CommonAPI.post(user, %{status: "hello"})
|
2020-05-04 12:45:28 +00:00
|
|
|
|
|
|
|
data =
|
|
|
|
File.read!("test/fixtures/mastodon-like.json")
|
2020-11-23 19:28:55 +00:00
|
|
|
|> Jason.decode!()
|
2020-05-04 12:45:28 +00:00
|
|
|
|> Map.put("object", activity.data["object"])
|
|
|
|
|
|
|
|
_actor = insert(:user, ap_id: data["actor"], local: false)
|
|
|
|
|
|
|
|
{:ok, %Activity{data: data, local: false} = activity} = Transmogrifier.handle_incoming(data)
|
|
|
|
|
|
|
|
refute Enum.empty?(activity.recipients)
|
|
|
|
|
|
|
|
assert data["actor"] == "http://mastodon.example.org/users/admin"
|
|
|
|
assert data["type"] == "Like"
|
|
|
|
assert data["id"] == "http://mastodon.example.org/users/admin#likes/2"
|
|
|
|
assert data["object"] == activity.data["object"]
|
|
|
|
end
|
|
|
|
|
|
|
|
test "it works for incoming misskey likes, turning them into EmojiReacts" do
|
|
|
|
user = insert(:user)
|
|
|
|
|
2020-05-12 19:59:26 +00:00
|
|
|
{:ok, activity} = CommonAPI.post(user, %{status: "hello"})
|
2020-05-04 12:45:28 +00:00
|
|
|
|
|
|
|
data =
|
|
|
|
File.read!("test/fixtures/misskey-like.json")
|
2020-11-23 19:28:55 +00:00
|
|
|
|> Jason.decode!()
|
2020-05-04 12:45:28 +00:00
|
|
|
|> Map.put("object", activity.data["object"])
|
|
|
|
|
|
|
|
_actor = insert(:user, ap_id: data["actor"], local: false)
|
|
|
|
|
|
|
|
{:ok, %Activity{data: activity_data, local: false}} = Transmogrifier.handle_incoming(data)
|
|
|
|
|
|
|
|
assert activity_data["actor"] == data["actor"]
|
|
|
|
assert activity_data["type"] == "EmojiReact"
|
|
|
|
assert activity_data["id"] == data["id"]
|
|
|
|
assert activity_data["object"] == activity.data["object"]
|
2022-06-11 13:08:54 +00:00
|
|
|
assert activity_data["content"] == ":pudding:"
|
2020-05-04 12:45:28 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
test "it works for incoming misskey likes that contain unicode emojis, turning them into EmojiReacts" do
|
|
|
|
user = insert(:user)
|
|
|
|
|
2020-05-12 19:59:26 +00:00
|
|
|
{:ok, activity} = CommonAPI.post(user, %{status: "hello"})
|
2020-05-04 12:45:28 +00:00
|
|
|
|
|
|
|
data =
|
|
|
|
File.read!("test/fixtures/misskey-like.json")
|
2020-11-23 19:28:55 +00:00
|
|
|
|> Jason.decode!()
|
2020-05-04 12:45:28 +00:00
|
|
|
|> Map.put("object", activity.data["object"])
|
2023-03-10 18:46:49 +00:00
|
|
|
|> Map.put("content", "⭐")
|
2020-05-04 12:45:28 +00:00
|
|
|
|
|
|
|
_actor = insert(:user, ap_id: data["actor"], local: false)
|
|
|
|
|
|
|
|
{:ok, %Activity{data: activity_data, local: false}} = Transmogrifier.handle_incoming(data)
|
|
|
|
|
|
|
|
assert activity_data["actor"] == data["actor"]
|
|
|
|
assert activity_data["type"] == "EmojiReact"
|
|
|
|
assert activity_data["id"] == data["id"]
|
|
|
|
assert activity_data["object"] == activity.data["object"]
|
|
|
|
assert activity_data["content"] == "⭐"
|
|
|
|
end
|
|
|
|
end
|