2020-01-26 20:34:25 +01:00
|
|
|
defmodule Mobilizon.GraphQL.AbsintheHelpers do
|
2019-01-03 14:59:59 +01:00
|
|
|
@moduledoc """
|
|
|
|
Absinthe helpers for tests
|
|
|
|
"""
|
2020-01-26 20:34:25 +01:00
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
import Phoenix.ConnTest
|
|
|
|
|
|
|
|
alias Plug.Conn
|
2020-01-26 20:34:25 +01:00
|
|
|
|
2020-01-26 21:36:50 +01:00
|
|
|
@endpoint Mobilizon.Web.Endpoint
|
2020-01-26 20:34:25 +01:00
|
|
|
|
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
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
@spec graphql_query(Conn.t(), Keyword.t()) :: map | no_return
|
2019-10-16 19:03:31 +02:00
|
|
|
def graphql_query(conn, options) do
|
|
|
|
conn
|
2021-07-26 17:28:15 +02:00
|
|
|
|> post(
|
|
|
|
"/api",
|
|
|
|
build_query(
|
|
|
|
options[:query],
|
|
|
|
Keyword.get(options, :variables, %{}),
|
|
|
|
Keyword.get(options, :uploads, %{})
|
|
|
|
)
|
|
|
|
)
|
2019-10-16 19:03:31 +02:00
|
|
|
|> json_response(200)
|
|
|
|
end
|
|
|
|
|
2021-07-26 17:28:15 +02:00
|
|
|
defp build_query(query, variables, uploads) do
|
|
|
|
Map.merge(
|
|
|
|
%{
|
|
|
|
"query" => query,
|
|
|
|
"variables" => variables
|
|
|
|
},
|
|
|
|
uploads
|
|
|
|
)
|
2019-10-16 19:03:31 +02:00
|
|
|
end
|
2018-11-06 10:30:27 +01:00
|
|
|
end
|