mobilizon.chapril.org-mobil.../test/support/absinthe_helpers.ex
Thomas Citharel 52fe274c5a
Allow to pass file uploads to AbsintheHelpers.graphql_query/2
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
2021-08-01 10:51:21 +02:00

52 lines
989 B
Elixir

defmodule Mobilizon.GraphQL.AbsintheHelpers do
@moduledoc """
Absinthe helpers for tests
"""
import Phoenix.ConnTest
alias Plug.Conn
@endpoint Mobilizon.Web.Endpoint
def query_skeleton(query, query_name) do
%{
"operationName" => "#{query_name}",
"query" => "query #{query_name} #{query}",
"variables" => "{}"
}
end
def mutation_skeleton(query) do
%{
"operationName" => "",
"query" => "#{query}",
"variables" => ""
}
end
@spec graphql_query(Conn.t(), Keyword.t()) :: map | no_return
def graphql_query(conn, options) do
conn
|> post(
"/api",
build_query(
options[:query],
Keyword.get(options, :variables, %{}),
Keyword.get(options, :uploads, %{})
)
)
|> json_response(200)
end
defp build_query(query, variables, uploads) do
Map.merge(
%{
"query" => query,
"variables" => variables
},
uploads
)
end
end