summaryrefslogtreecommitdiff
path: root/test/support/conn_case.ex
diff options
context:
space:
mode:
authorEgor Kislitsyn <egor@kislitsyn.com>2020-04-27 14:33:00 +0400
committerEgor Kislitsyn <egor@kislitsyn.com>2020-04-27 14:33:00 +0400
commitf1ca917bb0d733445657e0be92440dedc2f8d3c6 (patch)
tree175db64bc7d9c32bc5c2f2e7b443daa040e4d65c /test/support/conn_case.ex
parent1b06a27746ccbbdec77b7bc1571783a64ade4431 (diff)
parent01cc93b6873b5c50c0fc54774a3b004bf660e46b (diff)
downloadpleroma-f1ca917bb0d733445657e0be92440dedc2f8d3c6.tar.gz
pleroma-f1ca917bb0d733445657e0be92440dedc2f8d3c6.zip
Merge branch 'develop' into openapi/account
Diffstat (limited to 'test/support/conn_case.ex')
-rw-r--r--test/support/conn_case.ex36
1 files changed, 36 insertions, 0 deletions
diff --git a/test/support/conn_case.ex b/test/support/conn_case.ex
index 36ce372c2..8099461cc 100644
--- a/test/support/conn_case.ex
+++ b/test/support/conn_case.ex
@@ -56,6 +56,42 @@ defmodule Pleroma.Web.ConnCase do
[conn: conn]
end
+ defp json_response_and_validate_schema(conn, status \\ nil) do
+ content_type =
+ conn
+ |> Plug.Conn.get_resp_header("content-type")
+ |> List.first()
+ |> String.split(";")
+ |> List.first()
+
+ status = status || conn.status
+
+ %{private: %{open_api_spex: %{operation_id: op_id, operation_lookup: lookup, spec: spec}}} =
+ conn
+
+ schema = lookup[op_id].responses[status].content[content_type].schema
+ json = json_response(conn, status)
+
+ case OpenApiSpex.cast_value(json, schema, spec) do
+ {:ok, _data} ->
+ json
+
+ {:error, errors} ->
+ errors =
+ Enum.map(errors, fn error ->
+ message = OpenApiSpex.Cast.Error.message(error)
+ path = OpenApiSpex.Cast.Error.path_to_string(error)
+ "#{message} at #{path}"
+ end)
+
+ flunk(
+ "Response does not conform to schema of #{op_id} operation: #{
+ Enum.join(errors, "\n")
+ }\n#{inspect(json)}"
+ )
+ end
+ end
+
defp ensure_federating_or_authenticated(conn, url, user) do
initial_setting = Config.get([:instance, :federating])
on_exit(fn -> Config.put([:instance, :federating], initial_setting) end)