Sha256: 947b763a4aa44b5329bebeeae1a1174d1acd5f554a90f0d014982102d3c98e11

Contents?: true

Size: 875 Bytes

Versions: 9

Compression:

Stored size: 875 Bytes

Contents

require "spec_helper"

describe GraphQL::UnionType do
  let(:type_1) { OpenStruct.new(kind: GraphQL::TypeKinds::OBJECT)}
  let(:type_2) { OpenStruct.new(kind: GraphQL::TypeKinds::OBJECT)}
  let(:type_3) { OpenStruct.new(kind: GraphQL::TypeKinds::SCALAR)}
  let(:union) {
    types = [type_1, type_2]
    GraphQL::UnionType.define {
      name("MyUnion")
      description("Some items")
      possible_types(types)
    }
  }
  it "has a name" do
    assert_equal("MyUnion", union.name)
  end


  it "infers type from an object" do
    assert_equal(CheeseType, DairyProductUnion.resolve_type(CHEESES[1], OpenStruct.new(schema: DummySchema)))
  end

  it '#include? returns true if type in in possible_types' do
    assert union.include?(type_1)
  end

  it '#include? returns false if type is not in possible_types' do
    assert_equal(false, union.include?(type_3))
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
graphql-0.16.0 spec/graphql/union_type_spec.rb
graphql-0.15.3 spec/graphql/union_type_spec.rb
graphql-0.15.2 spec/graphql/union_type_spec.rb
graphql-0.14.2 spec/graphql/union_type_spec.rb
graphql-0.15.1 spec/graphql/union_type_spec.rb
graphql-0.15.0 spec/graphql/union_type_spec.rb
graphql-0.14.1 spec/graphql/union_type_spec.rb
graphql-0.14.0 spec/graphql/union_type_spec.rb
graphql-0.13.0 spec/graphql/union_type_spec.rb