Sha256: 35d17d78c0c0a498edfd890400db8f51f9c87db0949f73325d11d1baf8535639

Contents?: true

Size: 1.21 KB

Versions: 3

Compression:

Stored size: 1.21 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

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

    it 'exposes defined field property' do
      field_without_prop = CheeseType.get_field('flavor')
      field_with_prop = CheeseType.get_field('fatContent')
      assert_equal(field_without_prop.property, nil)
      assert_equal(field_with_prop.property, :fat_content)
    end

    it "looks up from interfaces" do
      field_from_self = CheeseType.get_field('fatContent')
      field_from_iface = MilkType.get_field('fatContent')
      assert_equal(field_from_self.property, :fat_content)
      assert_equal(field_from_iface.property, nil)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
graphql-0.12.1 spec/graphql/object_type_spec.rb
graphql-0.12.0 spec/graphql/object_type_spec.rb
graphql-0.11.1 spec/graphql/object_type_spec.rb