Sha256: b7912a8fba50fbece40847a98630a9eb8a090b3a340cbdced9f3d72283173dc6

Contents?: true

Size: 1.29 KB

Versions: 5

Compression:

Stored size: 1.29 KB

Contents

require 'spec_helper'

describe GraphQL::ObjectType do
  let(:type) { CheeseType }

  it 'has a name' do
    assert_equal("Cheese", type.name)
    type.name = "Fromage"
    assert_equal("Fromage", type.name)
    type.name = "Cheese"
  end

  it 'has a description' do
    assert_equal(22, type.description.length)
  end

  it 'may have interfaces' do
    assert_equal([EdibleInterface, AnimalProductInterface], type.interfaces)
  end

  it 'becomes non-null with !' do
    non_null_type = !type
    assert_equal(GraphQL::TypeKinds::NON_NULL, non_null_type.kind)
    assert_equal(type, non_null_type.of_type)
    assert_equal(GraphQL::TypeKinds::NON_NULL, (!GraphQL::STRING_TYPE).kind)
  end

  it 'can be compared' do
    assert_equal(!GraphQL::INT_TYPE, !GraphQL::INT_TYPE)
    refute_equal(!GraphQL::FLOAT_TYPE, GraphQL::FLOAT_TYPE)
    assert_equal(
      GraphQL::ListType.new(of_type: MilkType),
      GraphQL::ListType.new(of_type: MilkType)
    )
    refute_equal(
      GraphQL::ListType.new(of_type: MilkType),
      GraphQL::ListType.new(of_type: !MilkType)
    )
  end

  describe '.fields ' do
    it 'exposes fields' do
      field = type.fields["id"]
      assert_equal(GraphQL::TypeKinds::NON_NULL, field.type.kind)
      assert_equal(GraphQL::TypeKinds::SCALAR, field.type.of_type.kind)
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
graphql-0.7.1 spec/graphql/object_type_spec.rb
graphql-0.7.0 spec/graphql/object_type_spec.rb
graphql-0.6.2 spec/graphql/object_type_spec.rb
graphql-0.6.1 spec/graphql/object_type_spec.rb
graphql-0.6.0 spec/graphql/object_type_spec.rb