ObjectValidator tests: Extract emoji react testing
authorlain <lain@soykaf.club>
Mon, 6 Jul 2020 13:02:35 +0000 (15:02 +0200)
committerlain <lain@soykaf.club>
Mon, 6 Jul 2020 13:02:35 +0000 (15:02 +0200)
test/web/activity_pub/object_validator_test.exs
test/web/activity_pub/object_validators/emoji_react_validation_test.exs [new file with mode: 0644]

index b052c0a9ebd866818df0abf8f08836a72a373e32..4a8e1a0fbbe8cd336277c8cd7c1dc04a6643420c 100644 (file)
@@ -6,7 +6,6 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidatorTest do
   use Pleroma.DataCase
 
   alias Pleroma.Object
-  alias Pleroma.Web.ActivityPub.ActivityPub
   alias Pleroma.Web.ActivityPub.Builder
   alias Pleroma.Web.ActivityPub.ObjectValidator
   alias Pleroma.Web.ActivityPub.ObjectValidators.LikeValidator
@@ -15,46 +14,6 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidatorTest do
 
   import Pleroma.Factory
 
-  describe "EmojiReacts" do
-    setup do
-      user = insert(:user)
-      {:ok, post_activity} = CommonAPI.post(user, %{status: "uguu"})
-
-      object = Pleroma.Object.get_by_ap_id(post_activity.data["object"])
-
-      {:ok, valid_emoji_react, []} = Builder.emoji_react(user, object, "👌")
-
-      %{user: user, post_activity: post_activity, valid_emoji_react: valid_emoji_react}
-    end
-
-    test "it validates a valid EmojiReact", %{valid_emoji_react: valid_emoji_react} do
-      assert {:ok, _, _} = ObjectValidator.validate(valid_emoji_react, [])
-    end
-
-    test "it is not valid without a 'content' field", %{valid_emoji_react: valid_emoji_react} do
-      without_content =
-        valid_emoji_react
-        |> Map.delete("content")
-
-      {:error, cng} = ObjectValidator.validate(without_content, [])
-
-      refute cng.valid?
-      assert {:content, {"can't be blank", [validation: :required]}} in cng.errors
-    end
-
-    test "it is not valid with a non-emoji content field", %{valid_emoji_react: valid_emoji_react} do
-      without_emoji_content =
-        valid_emoji_react
-        |> Map.put("content", "x")
-
-      {:error, cng} = ObjectValidator.validate(without_emoji_content, [])
-
-      refute cng.valid?
-
-      assert {:content, {"must be a single character emoji", []}} in cng.errors
-    end
-  end
-
   describe "Undos" do
     setup do
       user = insert(:user)
diff --git a/test/web/activity_pub/object_validators/emoji_react_validation_test.exs b/test/web/activity_pub/object_validators/emoji_react_validation_test.exs
new file mode 100644 (file)
index 0000000..582e6d7
--- /dev/null
@@ -0,0 +1,53 @@
+# 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.ObjectValidators.EmojiReactHandlingTest do
+  use Pleroma.DataCase
+
+  alias Pleroma.Web.ActivityPub.Builder
+  alias Pleroma.Web.ActivityPub.ObjectValidator
+  alias Pleroma.Web.CommonAPI
+
+  import Pleroma.Factory
+
+  describe "EmojiReacts" do
+    setup do
+      user = insert(:user)
+      {:ok, post_activity} = CommonAPI.post(user, %{status: "uguu"})
+
+      object = Pleroma.Object.get_by_ap_id(post_activity.data["object"])
+
+      {:ok, valid_emoji_react, []} = Builder.emoji_react(user, object, "👌")
+
+      %{user: user, post_activity: post_activity, valid_emoji_react: valid_emoji_react}
+    end
+
+    test "it validates a valid EmojiReact", %{valid_emoji_react: valid_emoji_react} do
+      assert {:ok, _, _} = ObjectValidator.validate(valid_emoji_react, [])
+    end
+
+    test "it is not valid without a 'content' field", %{valid_emoji_react: valid_emoji_react} do
+      without_content =
+        valid_emoji_react
+        |> Map.delete("content")
+
+      {:error, cng} = ObjectValidator.validate(without_content, [])
+
+      refute cng.valid?
+      assert {:content, {"can't be blank", [validation: :required]}} in cng.errors
+    end
+
+    test "it is not valid with a non-emoji content field", %{valid_emoji_react: valid_emoji_react} do
+      without_emoji_content =
+        valid_emoji_react
+        |> Map.put("content", "x")
+
+      {:error, cng} = ObjectValidator.validate(without_emoji_content, [])
+
+      refute cng.valid?
+
+      assert {:content, {"must be a single character emoji", []}} in cng.errors
+    end
+  end
+end