commit e1d95889bba6399d79acdd5ca69ce2d4abc8e5f1
parent 73a62160f3843551f11ca5a04043b0fde1840fb5
Author: srfsh <dev@srf.sh>
Date: Wed, 3 Aug 2022 10:24:09 +0300
ZenflowsTest.Help.AbsinCase: improve functions
I added run!/2 so that in future, we can use ctx and vars in queries,
along with auth? (which allows us to (un)skip authentication).
This allows us to better use Absinthe. A possible todo is to convert each
test using query!/1 and mutation!/1 to use run!/2.
Diffstat:
1 file changed, 13 insertions(+), 5 deletions(-)
diff --git a/test/help/absin_case.ex b/test/help/absin_case.ex
@@ -42,16 +42,24 @@ end
@spec query!(String.t()) :: Absinthe.run_result()
def query!(doc) do
- run!("query { #{doc} }")
+ Absinthe.run!("query { #{doc} }", Zenflows.GQL.Schema, context: %{authenticate_calls?: false})
end
@spec mutation!(String.t()) :: Absinthe.run_result()
def mutation!(doc) do
- run!("mutation { #{doc} }")
+ Absinthe.run!("mutation { #{doc} }", Zenflows.GQL.Schema, context: %{authenticate_calls?: false})
end
-@spec run!(String.t()) :: Absinthe.run_result()
-def run!(doc) do
- Absinthe.run!(doc, Zenflows.GQL.Schema)
+@spec run!(String.t(), Keyword.t()) :: Absinthe.run_result()
+def run!(doc, opts \\ []) do
+ auth? = Keyword.get(opts, :auth?, false)
+ ctx = Keyword.get(opts, :ctx, Keyword.get(opts, :context, %{}))
+ ctx = Map.put(ctx, :authenticate_calls?, auth?)
+ vars = Keyword.get(opts, :vars, Keyword.get(opts, :variables, %{}))
+ opts =
+ opts
+ |> Keyword.put(:context, ctx)
+ |> Keyword.put(:variables, vars)
+ Absinthe.run!(doc, Zenflows.GQL.Schema, opts)
end
end