2020-05-05 05:20:53 -04:00
|
|
|
# Pleroma: A lightweight social networking server
|
|
|
|
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
defmodule Pleroma.Web.ActivityPub.Transmogrifier.EmojiReactHandlingTest do
|
|
|
|
use Pleroma.DataCase
|
|
|
|
|
|
|
|
alias Pleroma.Activity
|
2020-05-05 06:11:46 -04:00
|
|
|
alias Pleroma.Object
|
2020-05-05 05:20:53 -04:00
|
|
|
alias Pleroma.Web.ActivityPub.Transmogrifier
|
|
|
|
alias Pleroma.Web.CommonAPI
|
|
|
|
|
|
|
|
import Pleroma.Factory
|
|
|
|
|
|
|
|
test "it works for incoming emoji reactions" do
|
|
|
|
user = insert(:user)
|
|
|
|
other_user = insert(:user, local: false)
|
2020-05-12 15:59:26 -04:00
|
|
|
{:ok, activity} = CommonAPI.post(user, %{status: "hello"})
|
2020-05-05 05:20:53 -04:00
|
|
|
|
|
|
|
data =
|
|
|
|
File.read!("test/fixtures/emoji-reaction.json")
|
|
|
|
|> Poison.decode!()
|
|
|
|
|> Map.put("object", activity.data["object"])
|
|
|
|
|> Map.put("actor", other_user.ap_id)
|
|
|
|
|
|
|
|
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
|
|
|
|
|
|
|
|
assert data["actor"] == other_user.ap_id
|
|
|
|
assert data["type"] == "EmojiReact"
|
|
|
|
assert data["id"] == "http://mastodon.example.org/users/admin#reactions/2"
|
|
|
|
assert data["object"] == activity.data["object"]
|
|
|
|
assert data["content"] == "👌"
|
2020-05-05 06:11:46 -04:00
|
|
|
|
|
|
|
object = Object.get_by_ap_id(data["object"])
|
|
|
|
|
|
|
|
assert object.data["reaction_count"] == 1
|
|
|
|
assert match?([["👌", _]], object.data["reactions"])
|
2020-05-05 05:20:53 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
test "it reject invalid emoji reactions" do
|
|
|
|
user = insert(:user)
|
|
|
|
other_user = insert(:user, local: false)
|
2020-05-12 15:59:26 -04:00
|
|
|
{:ok, activity} = CommonAPI.post(user, %{status: "hello"})
|
2020-05-05 05:20:53 -04:00
|
|
|
|
|
|
|
data =
|
|
|
|
File.read!("test/fixtures/emoji-reaction-too-long.json")
|
|
|
|
|> Poison.decode!()
|
|
|
|
|> Map.put("object", activity.data["object"])
|
|
|
|
|> Map.put("actor", other_user.ap_id)
|
|
|
|
|
2020-05-05 06:11:46 -04:00
|
|
|
assert {:error, _} = Transmogrifier.handle_incoming(data)
|
2020-05-05 05:20:53 -04:00
|
|
|
|
|
|
|
data =
|
|
|
|
File.read!("test/fixtures/emoji-reaction-no-emoji.json")
|
|
|
|
|> Poison.decode!()
|
|
|
|
|> Map.put("object", activity.data["object"])
|
|
|
|
|> Map.put("actor", other_user.ap_id)
|
|
|
|
|
2020-05-05 06:11:46 -04:00
|
|
|
assert {:error, _} = Transmogrifier.handle_incoming(data)
|
2020-05-05 05:20:53 -04:00
|
|
|
end
|
|
|
|
end
|