72b3ec35f8
The warnings revealed two bad tests, the code still worked but the test didn't actually test for it. Activating this for CI to prevent issues like these in the future.
93 lines
3.1 KiB
Elixir
93 lines
3.1 KiB
Elixir
# Pleroma: A lightweight social networking server
|
|
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
defmodule Pleroma.Web.ActivityPub.Transmogrifier.EmojiReactHandlingTest do
|
|
use Pleroma.DataCase, async: true
|
|
|
|
alias Pleroma.Activity
|
|
alias Pleroma.Object
|
|
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)
|
|
{:ok, activity} = CommonAPI.post(user, %{status: "hello"})
|
|
|
|
data =
|
|
File.read!("test/fixtures/emoji-reaction.json")
|
|
|> Jason.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"] == "👌"
|
|
|
|
object = Object.get_by_ap_id(data["object"])
|
|
|
|
assert object.data["reaction_count"] == 1
|
|
assert match?([["👌", _]], object.data["reactions"])
|
|
end
|
|
|
|
test "it works for incoming unqualified emoji reactions" do
|
|
user = insert(:user)
|
|
other_user = insert(:user, local: false)
|
|
{:ok, activity} = CommonAPI.post(user, %{status: "hello"})
|
|
|
|
# woman detective emoji, unqualified
|
|
unqualified_emoji = [0x1F575, 0x200D, 0x2640] |> List.to_string()
|
|
|
|
data =
|
|
File.read!("test/fixtures/emoji-reaction.json")
|
|
|> Jason.decode!()
|
|
|> Map.put("object", activity.data["object"])
|
|
|> Map.put("actor", other_user.ap_id)
|
|
|> Map.put("content", unqualified_emoji)
|
|
|
|
{: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"]
|
|
# woman detective emoji, fully qualified
|
|
emoji = [0x1F575, 0xFE0F, 0x200D, 0x2640, 0xFE0F] |> List.to_string()
|
|
assert data["content"] == emoji
|
|
|
|
object = Object.get_by_ap_id(data["object"])
|
|
|
|
assert object.data["reaction_count"] == 1
|
|
assert match?([[^emoji, _]], object.data["reactions"])
|
|
end
|
|
|
|
test "it reject invalid emoji reactions" do
|
|
user = insert(:user)
|
|
other_user = insert(:user, local: false)
|
|
{:ok, activity} = CommonAPI.post(user, %{status: "hello"})
|
|
|
|
data =
|
|
File.read!("test/fixtures/emoji-reaction-too-long.json")
|
|
|> Jason.decode!()
|
|
|> Map.put("object", activity.data["object"])
|
|
|> Map.put("actor", other_user.ap_id)
|
|
|
|
assert {:error, _} = Transmogrifier.handle_incoming(data)
|
|
|
|
data =
|
|
File.read!("test/fixtures/emoji-reaction-no-emoji.json")
|
|
|> Jason.decode!()
|
|
|> Map.put("object", activity.data["object"])
|
|
|> Map.put("actor", other_user.ap_id)
|
|
|
|
assert {:error, _} = Transmogrifier.handle_incoming(data)
|
|
end
|
|
end
|