I am trying to test a graphql request with Faraday, but I first need to authenticate with omniauth/auth0.
I got it to authenticate by setting
def sign_in(user, invalid=false, strategy = :auth0)
invalid ? mock_invalid_auth_hash : mock_valid_auth_hash(user)
Rails.application.env_config["omniauth.auth"] = OmniAuth.config.mock_auth[strategy.to_sym]
visit "/auth/#{strategy.to_s}/callback"
end
But when graphql gets tested it totally loses that cookie since this is a brand new request:
require 'graphlient'
RSpec.shared_context "GraphQL Client", shared_context: :metadata do
let(:client) do
Graphlient::Client.new('https://www.example.org/graphql') do |client|
client.http do |h|
h.connection do |c|
c.use Faraday::Adapter::Rack, app
end
end
end
end
end
How can I set the environment via Faraday to be authenticated before it connects to GraphQL? Or is there a better way to test GraphQL?