logo

pleroma

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

emoji_react_validation_test.exs (1723B)


  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.ObjectValidators.EmojiReactHandlingTest do
  5. use Pleroma.DataCase
  6. alias Pleroma.Web.ActivityPub.Builder
  7. alias Pleroma.Web.ActivityPub.ObjectValidator
  8. alias Pleroma.Web.CommonAPI
  9. import Pleroma.Factory
  10. describe "EmojiReacts" do
  11. setup do
  12. user = insert(:user)
  13. {:ok, post_activity} = CommonAPI.post(user, %{status: "uguu"})
  14. object = Pleroma.Object.get_by_ap_id(post_activity.data["object"])
  15. {:ok, valid_emoji_react, []} = Builder.emoji_react(user, object, "👌")
  16. %{user: user, post_activity: post_activity, valid_emoji_react: valid_emoji_react}
  17. end
  18. test "it validates a valid EmojiReact", %{valid_emoji_react: valid_emoji_react} do
  19. assert {:ok, _, _} = ObjectValidator.validate(valid_emoji_react, [])
  20. end
  21. test "it is not valid without a 'content' field", %{valid_emoji_react: valid_emoji_react} do
  22. without_content =
  23. valid_emoji_react
  24. |> Map.delete("content")
  25. {:error, cng} = ObjectValidator.validate(without_content, [])
  26. refute cng.valid?
  27. assert {:content, {"can't be blank", [validation: :required]}} in cng.errors
  28. end
  29. test "it is not valid with a non-emoji content field", %{valid_emoji_react: valid_emoji_react} do
  30. without_emoji_content =
  31. valid_emoji_react
  32. |> Map.put("content", "x")
  33. {:error, cng} = ObjectValidator.validate(without_emoji_content, [])
  34. refute cng.valid?
  35. assert {:content, {"must be a single character emoji", []}} in cng.errors
  36. end
  37. end
  38. end