Sha256: ebfcb327e1dd9f8b2cb9e094449a70a2a1ed5bb5e74b178022319c976a3c8074

Contents?: true

Size: 1.92 KB

Versions: 28

Compression:

Stored size: 1.92 KB

Contents

require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")

describe Braintree::GraphQLClient do
  before :each do
      @config = Braintree::Configuration.instantiate
  end

  describe "initialize" do
    it "assigns overriding graphql headers" do
      expect(@config.graphql_client.instance_variable_get("@graphql_headers")).to be_kind_of(Hash)
    end
  end

  describe "query" do
    it "makes valid GraphQL queries when given a definition" do
      definition = <<-GRAPHQL
      query {
        ping
      }
      GRAPHQL

      response = Braintree::GraphQLClient.new(@config).query(definition)

      expect(response[:data]).to eq({:ping=>"pong"})
    end

    it "makes valid GraphQL requests when given a definitiona and variable" do
      definition = <<-GRAPHQL
mutation CreateClientToken($input: CreateClientTokenInput!) {
  createClientToken(input: $input) {
    clientMutationId
    clientToken
  }
}
      GRAPHQL

      variables = {
        input: {
          clientMutationId: "abc123",
          clientToken: {
            merchantAccountId: "ABC123"
          }
        }
      }

      response = Braintree::GraphQLClient.new(@config).query(definition, variables)

      expect(response[:data][:createClientToken][:clientToken]).to be_a(String)
    end

    it "returns results parsable into validation errors" do
      definition = <<-GRAPHQL
query TransactionLevelFeeReport($date: Date!, $merchantAccountId: ID) {
  report {
    transactionLevelFees(date: $date, merchantAccountId: $merchantAccountId) {
      url
    }
  }
}
      GRAPHQL

      variables = {
        date: "2018-01-01",
        merchantAccountId: "some_merchant"
      }

      response = Braintree::GraphQLClient.new(@config).query(definition, variables)
      errors = Braintree::ValidationErrorCollection.new(response)

      expect(errors.size).to eq(1)
      expect(errors.first.message).to eq("Invalid merchant account id: some_merchant")
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
braintree-4.7.0 spec/integration/braintree/graphql_client_spec.rb
braintree-4.6.0 spec/integration/braintree/graphql_client_spec.rb
braintree-4.5.0 spec/integration/braintree/graphql_client_spec.rb
braintree-4.4.0 spec/integration/braintree/graphql_client_spec.rb
braintree-4.3.0 spec/integration/braintree/graphql_client_spec.rb
braintree-4.2.0 spec/integration/braintree/graphql_client_spec.rb
braintree-4.1.0 spec/integration/braintree/graphql_client_spec.rb
braintree-4.0.0 spec/integration/braintree/graphql_client_spec.rb
braintree-3.4.0 spec/integration/braintree/graphql_client_spec.rb
braintree-3.3.0 spec/integration/braintree/graphql_client_spec.rb
braintree-3.2.0 spec/integration/braintree/graphql_client_spec.rb
braintree-3.1.0 spec/integration/braintree/graphql_client_spec.rb
braintree-3.0.1 spec/integration/braintree/graphql_client_spec.rb
braintree-2.104.1 spec/integration/braintree/graphql_client_spec.rb
braintree-2.104.0 spec/integration/braintree/graphql_client_spec.rb
braintree-2.103.0 spec/integration/braintree/graphql_client_spec.rb
braintree-2.102.0 spec/integration/braintree/graphql_client_spec.rb
braintree-2.101.0 spec/integration/braintree/graphql_client_spec.rb
braintree-2.100.0 spec/integration/braintree/graphql_client_spec.rb
braintree-2.99.0 spec/integration/braintree/graphql_client_spec.rb