2018-11-06 10:30:27 +01:00
|
|
|
defmodule MobilizonWeb.AbsintheHelpers do
|
2019-10-16 19:03:31 +02:00
|
|
|
use Phoenix.ConnTest
|
|
|
|
@endpoint MobilizonWeb.Endpoint
|
|
|
|
|
2019-01-03 14:59:59 +01:00
|
|
|
@moduledoc """
|
|
|
|
Absinthe helpers for tests
|
|
|
|
"""
|
2018-11-06 10:30:27 +01: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
|
2019-10-16 19:03:31 +02:00
|
|
|
|
|
|
|
def graphql_query(conn, options) do
|
|
|
|
conn
|
|
|
|
|> post(
|
|
|
|
"/api",
|
2019-12-03 11:29:51 +01:00
|
|
|
build_query(options[:query], Keyword.get(options, :variables, %{}))
|
2019-10-16 19:03:31 +02:00
|
|
|
)
|
|
|
|
|> json_response(200)
|
|
|
|
end
|
|
|
|
|
|
|
|
defp build_query(query, variables) do
|
|
|
|
%{
|
|
|
|
"query" => query,
|
|
|
|
"variables" => variables
|
|
|
|
}
|
|
|
|
end
|
2018-11-06 10:30:27 +01:00
|
|
|
end
|