Use json_response_and_validate_schema/2 in tests to validate OpenAPI schema
This commit is contained in:
parent
f1ca917bb0
commit
2efc00b3cf
7 changed files with 330 additions and 358 deletions
|
|
@ -56,7 +56,14 @@ defmodule Pleroma.Web.ConnCase do
|
|||
[conn: conn]
|
||||
end
|
||||
|
||||
defp json_response_and_validate_schema(conn, status \\ nil) do
|
||||
defp json_response_and_validate_schema(
|
||||
%{
|
||||
private: %{
|
||||
open_api_spex: %{operation_id: op_id, operation_lookup: lookup, spec: spec}
|
||||
}
|
||||
} = conn,
|
||||
status
|
||||
) do
|
||||
content_type =
|
||||
conn
|
||||
|> Plug.Conn.get_resp_header("content-type")
|
||||
|
|
@ -64,10 +71,12 @@ defmodule Pleroma.Web.ConnCase do
|
|||
|> String.split(";")
|
||||
|> List.first()
|
||||
|
||||
status = status || conn.status
|
||||
status = Plug.Conn.Status.code(status)
|
||||
|
||||
%{private: %{open_api_spex: %{operation_id: op_id, operation_lookup: lookup, spec: spec}}} =
|
||||
conn
|
||||
unless lookup[op_id].responses[status] do
|
||||
err = "Response schema not found for #{conn.status} #{conn.method} #{conn.request_path}"
|
||||
flunk(err)
|
||||
end
|
||||
|
||||
schema = lookup[op_id].responses[status].content[content_type].schema
|
||||
json = json_response(conn, status)
|
||||
|
|
@ -92,6 +101,10 @@ defmodule Pleroma.Web.ConnCase do
|
|||
end
|
||||
end
|
||||
|
||||
defp json_response_and_validate_schema(conn, _status) do
|
||||
flunk("Response schema not found for #{conn.method} #{conn.request_path} #{conn.status}")
|
||||
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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue