1
0
Fork 0
mirror of https://framagit.org/framasoft/mobilizon.git synced 2024-12-30 20:06:07 +00:00
mobilizon/test/support/absinthe_helpers.ex

52 lines
989 B
Elixir
Raw Normal View History

2020-01-26 19:34:25 +00:00
defmodule Mobilizon.GraphQL.AbsintheHelpers do
@moduledoc """
Absinthe helpers for tests
"""
2020-01-26 19:34:25 +00:00
import Phoenix.ConnTest
alias Plug.Conn
2020-01-26 19:34:25 +00:00
2020-01-26 20:36:50 +00:00
@endpoint Mobilizon.Web.Endpoint
2020-01-26 19:34:25 +00:00
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