I'm trying to add authentication to this subscription test, since I keep getting Not Authorized
when I run mix test
.
I've seen that you need to add a login mutation to the push_doc
function but I was wondering. Is there any way to use only the token to authenticate, just like regular mutations that use :
conn =
build_conn()
|> put_req_header("authorization", @token)
|> get("/api", query: @query)
assert json_response(conn, 200) == %{
"data" => %{
"authors" => [%{"name" => "Jennifer"}]
}
}
This is my current subscription test:
test "1. Subscribe to createAuthor", %{socket: socket} do
# setup a subscription
ref = push_doc(socket, @subscription)
assert_reply(ref, :ok, %{subscriptionId: subscription_id})
# run a mutation to trigger the subscription
ref = push_doc(socket, @mutation)
assert_reply(ref, :ok, reply)
assert %{
data: %{
"createAuthor" => %{
"name" => "Jennifer"
}
}
} = reply
# check to see if we got subscription data
expected = %{
result: %{
data: %{
"createAuthor" => %{
"name" => "Jennifer"
}
}
},
subscriptionId: subscription_id
}
assert_push("subscription:data", push)
assert expected == push
end
My general question is. Can I only pass the token
(which I have hardcoded) into a function to authenticate for subscriptions?