From 5869a43fe722c878fca1d87816cd1437f2bb49fe Mon Sep 17 00:00:00 2001 From: Maxim Filippov Date: Tue, 26 Nov 2019 01:06:54 +0900 Subject: [PATCH] Fix tests --- test/support/helpers.ex | 17 +++++++++++++++++ .../admin_api/admin_api_controller_test.exs | 19 +++++++------------ 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/test/support/helpers.ex b/test/support/helpers.ex index ce39dd9d8..af2b2eddf 100644 --- a/test/support/helpers.ex +++ b/test/support/helpers.ex @@ -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) diff --git a/test/web/admin_api/admin_api_controller_test.exs b/test/web/admin_api/admin_api_controller_test.exs index 12dba7773..c6ff1a065 100644 --- a/test/web/admin_api/admin_api_controller_test.exs +++ b/test/web/admin_api/admin_api_controller_test.exs @@ -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