logo

pleroma

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

like_handling_test.exs (2637B)


  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.LikeHandlingTest do
  5. use Pleroma.DataCase
  6. alias Pleroma.Activity
  7. alias Pleroma.Web.ActivityPub.Transmogrifier
  8. alias Pleroma.Web.CommonAPI
  9. import Pleroma.Factory
  10. test "it works for incoming likes" do
  11. user = insert(:user)
  12. {:ok, activity} = CommonAPI.post(user, %{status: "hello"})
  13. data =
  14. File.read!("test/fixtures/mastodon-like.json")
  15. |> Poison.decode!()
  16. |> Map.put("object", activity.data["object"])
  17. _actor = insert(:user, ap_id: data["actor"], local: false)
  18. {:ok, %Activity{data: data, local: false} = activity} = Transmogrifier.handle_incoming(data)
  19. refute Enum.empty?(activity.recipients)
  20. assert data["actor"] == "http://mastodon.example.org/users/admin"
  21. assert data["type"] == "Like"
  22. assert data["id"] == "http://mastodon.example.org/users/admin#likes/2"
  23. assert data["object"] == activity.data["object"]
  24. end
  25. test "it works for incoming misskey likes, turning them into EmojiReacts" do
  26. user = insert(:user)
  27. {:ok, activity} = CommonAPI.post(user, %{status: "hello"})
  28. data =
  29. File.read!("test/fixtures/misskey-like.json")
  30. |> Poison.decode!()
  31. |> Map.put("object", activity.data["object"])
  32. _actor = insert(:user, ap_id: data["actor"], local: false)
  33. {:ok, %Activity{data: activity_data, local: false}} = Transmogrifier.handle_incoming(data)
  34. assert activity_data["actor"] == data["actor"]
  35. assert activity_data["type"] == "EmojiReact"
  36. assert activity_data["id"] == data["id"]
  37. assert activity_data["object"] == activity.data["object"]
  38. assert activity_data["content"] == "🍮"
  39. end
  40. test "it works for incoming misskey likes that contain unicode emojis, turning them into EmojiReacts" do
  41. user = insert(:user)
  42. {:ok, activity} = CommonAPI.post(user, %{status: "hello"})
  43. data =
  44. File.read!("test/fixtures/misskey-like.json")
  45. |> Poison.decode!()
  46. |> Map.put("object", activity.data["object"])
  47. |> Map.put("_misskey_reaction", "⭐")
  48. _actor = insert(:user, ap_id: data["actor"], local: false)
  49. {: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"] == "⭐"
  55. end
  56. end