module AuthenticationHelper
  def sign_in_to_api(user)
    request.headers.merge!(api_authentication_header(user))
  end

  def api_authentication_header(user)
    token = Knock::AuthToken.new(payload: { sub: user.id }).token
    {
      'Authorization': "Bearer #{token}"
    }
  end
end

RSpec.configure do |config|
  config.include AuthenticationHelper, type: :controller
end
