Fix tests
authorMaxim Filippov <colixer@gmail.com>
Mon, 25 Nov 2019 16:06:54 +0000 (01:06 +0900)
committerMaxim Filippov <colixer@gmail.com>
Mon, 25 Nov 2019 16:06:54 +0000 (01:06 +0900)
test/support/helpers.ex
test/web/admin_api/admin_api_controller_test.exs

index ce39dd9d8fad52ccaa405d36a10388068e3a8a45..af2b2eddf7bea5815e6dd05960eef6a839a5e213 100644 (file)
@@ -75,6 +75,23 @@ defmodule Pleroma.Tests.Helpers do
         |> Poison.decode!()
       end
 
+      def stringify_keys(nil), do: nil
+
+      def stringify_keys(key) when key in [true, false], do: key
+      def stringify_keys(key) when is_atom(key), do: Atom.to_string(key)
+
+      def stringify_keys(map) when is_map(map) do
+        map
+        |> Enum.map(fn {k, v} -> {stringify_keys(k), stringify_keys(v)} end)
+        |> Enum.into(%{})
+      end
+
+      def stringify_keys([head | rest] = list) when is_list(list) do
+        [stringify_keys(head) | stringify_keys(rest)]
+      end
+
+      def stringify_keys(key), do: key
+
       defmacro guards_config(config_path) do
         quote do
           initial_setting = Pleroma.Config.get(config_path)
index 12dba7773b3f4831cb907e3cb8ee55ba3f3a86d1..c6ff1a0653895ccfa62e7e90a84ccf82f9da01a3 100644 (file)
@@ -1654,9 +1654,10 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
                  NaiveDateTime.from_iso8601!(act.data["published"])
                end).data["published"]
 
-      assert first_group["status"] == StatusView.render("show.json", %{activity: first_status})
+      assert first_group["status"] ==
+               stringify_keys(StatusView.render("show.json", %{activity: first_status}))
 
-      assert first_group["account"]["id"] == target_user.id
+      assert(first_group["account"]["id"] == target_user.id)
 
       assert length(first_group["actors"]) == 1
       assert hd(first_group["actors"])["id"] == reporter.id
@@ -1669,11 +1670,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
                  NaiveDateTime.from_iso8601!(act.data["published"])
                end).data["published"]
 
-      assert second_group["status"] == %{
-               "id" => second_status.data["id"],
-               "content" => second_status.object.data["content"],
-               "published" => second_status.object.data["published"]
-             }
+      assert second_group["status"] ==
+               stringify_keys(StatusView.render("show.json", %{activity: second_status}))
 
       assert second_group["account"]["id"] == target_user.id
 
@@ -1688,11 +1686,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
                  NaiveDateTime.from_iso8601!(act.data["published"])
                end).data["published"]
 
-      assert third_group["status"] == %{
-               "id" => third_status.data["id"],
-               "content" => third_status.object.data["content"],
-               "published" => third_status.object.data["published"]
-             }
+      assert third_group["status"] ==
+               stringify_keys(StatusView.render("show.json", %{activity: third_status}))
 
       assert third_group["account"]["id"] == target_user.id