transmogrifier_test: test date, anyOf and oneOf completely
authorHaelwenn (lanodan) Monnier <contact@hacktivis.me>
Sun, 14 Jun 2020 20:25:04 +0000 (22:25 +0200)
committerHaelwenn (lanodan) Monnier <contact@hacktivis.me>
Wed, 15 Jul 2020 09:39:54 +0000 (11:39 +0200)
lib/pleroma/web/activity_pub/object_validators/question_options_validator.ex
test/web/activity_pub/transmogrifier_test.exs

index 8291d7b9fb23debe879dbea69475d810d2983dfe..478b3b5cf6e2b65b0954a61e2e91a987270f3473 100644 (file)
@@ -12,7 +12,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.QuestionOptionsValidator do
   embedded_schema do
     field(:name, :string)
 
-    embeds_one :replies, Replies do
+    embeds_one :replies, Replies, primary_key: false do
       field(:totalItems, :integer)
       field(:type, :string)
     end
index 73949b55838ecdbb02d7960b1040b8618a7d1bd7..4184b93cecd9be291a2a4941d25c75f927b6114f 100644 (file)
@@ -224,14 +224,33 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
 
       object = Object.normalize(activity, false)
 
-      assert Enum.all?(object.data["oneOf"], fn choice ->
-               choice["name"] in [
-                 "Dunno",
-                 "Everyone knows that!",
-                 "25 char limit is dumb",
-                 "I can't even fit a funny"
-               ]
-             end)
+      assert object.data["closed"] == "2019-05-11T09:03:36Z"
+
+      assert object.data["anyOf"] == []
+
+      assert Enum.sort(object.data["oneOf"]) ==
+               Enum.sort([
+                 %{
+                   "name" => "25 char limit is dumb",
+                   "replies" => %{"totalItems" => 0, "type" => "Collection"},
+                   "type" => "Note"
+                 },
+                 %{
+                   "name" => "Dunno",
+                   "replies" => %{"totalItems" => 0, "type" => "Collection"},
+                   "type" => "Note"
+                 },
+                 %{
+                   "name" => "Everyone knows that!",
+                   "replies" => %{"totalItems" => 1, "type" => "Collection"},
+                   "type" => "Note"
+                 },
+                 %{
+                   "name" => "I can't even fit a funny",
+                   "replies" => %{"totalItems" => 1, "type" => "Collection"},
+                   "type" => "Note"
+                 }
+               ])
     end
 
     test "it works for incoming listens" do