logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma

emoji_react_handling_test.exs (1995B)


  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. defmodule Pleroma.Web.ActivityPub.Transmogrifier.EmojiReactHandlingTest do
  5. use Pleroma.DataCase
  6. alias Pleroma.Activity
  7. alias Pleroma.Object
  8. alias Pleroma.Web.ActivityPub.Transmogrifier
  9. alias Pleroma.Web.CommonAPI
  10. import Pleroma.Factory
  11. test "it works for incoming emoji reactions" do
  12. user = insert(:user)
  13. other_user = insert(:user, local: false)
  14. {:ok, activity} = CommonAPI.post(user, %{status: "hello"})
  15. data =
  16. File.read!("test/fixtures/emoji-reaction.json")
  17. |> Poison.decode!()
  18. |> Map.put("object", activity.data["object"])
  19. |> Map.put("actor", other_user.ap_id)
  20. {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
  21. assert data["actor"] == other_user.ap_id
  22. assert data["type"] == "EmojiReact"
  23. assert data["id"] == "http://mastodon.example.org/users/admin#reactions/2"
  24. assert data["object"] == activity.data["object"]
  25. assert data["content"] == "👌"
  26. object = Object.get_by_ap_id(data["object"])
  27. assert object.data["reaction_count"] == 1
  28. assert match?([["👌", _]], object.data["reactions"])
  29. end
  30. test "it reject invalid emoji reactions" do
  31. user = insert(:user)
  32. other_user = insert(:user, local: false)
  33. {:ok, activity} = CommonAPI.post(user, %{status: "hello"})
  34. data =
  35. File.read!("test/fixtures/emoji-reaction-too-long.json")
  36. |> Poison.decode!()
  37. |> Map.put("object", activity.data["object"])
  38. |> Map.put("actor", other_user.ap_id)
  39. assert {:error, _} = Transmogrifier.handle_incoming(data)
  40. data =
  41. File.read!("test/fixtures/emoji-reaction-no-emoji.json")
  42. |> Poison.decode!()
  43. |> Map.put("object", activity.data["object"])
  44. |> Map.put("actor", other_user.ap_id)
  45. assert {:error, _} = Transmogrifier.handle_incoming(data)
  46. end
  47. end