Sha256: 376b894d4cdb15b7aa086c93a2212eadd82dd87ec0aee4eea1267a77453f2027

Contents?: true

Size: 1.6 KB

Versions: 23

Compression:

Stored size: 1.6 KB

Contents

# frozen_string_literal: true
require "spec_helper"
require "generators/graphql/union_generator"

class GraphQLGeneratorsUnionGeneratorTest < BaseGeneratorTest
  tests Graphql::Generators::UnionGenerator

  test "it generates a union with possible types" do
    commands = [
      # GraphQL-style:
      ["WingedCreature", "Insect", "Bird"],
      # Ruby-style:
      ["Types::WingedCreatureType", "Types::InsectType", "Types::BirdType"],
    ]

    expected_content = <<-RUBY
Types::WingedCreatureType = GraphQL::UnionType.define do
  name "WingedCreature"
  possible_types [Types::InsectType, Types::BirdType]
end
RUBY

    commands.each do |c|
      prepare_destination
      run_generator(c)
      assert_file "app/graphql/types/winged_creature_type.rb", expected_content
    end
  end

  test "it works with no possible types" do
    commands = [
      # GraphQL-style:
      ["WingedCreature"],
      # Ruby-style:
      ["Types::WingedCreatureType"],
    ]

    expected_content = <<-RUBY
Types::WingedCreatureType = GraphQL::UnionType.define do
  name "WingedCreature"
end
RUBY

    commands.each do |c|
      prepare_destination
      run_generator(c)
      assert_file "app/graphql/types/winged_creature_type.rb", expected_content
    end
  end

  test "it accepts a user-specified directory" do
    command = ["WingedCreature", "--directory", "app/mydirectory"]

    expected_content = <<-RUBY
Types::WingedCreatureType = GraphQL::UnionType.define do
  name "WingedCreature"
end
RUBY

    prepare_destination
    run_generator(command)
    assert_file "app/mydirectory/types/winged_creature_type.rb", expected_content
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
graphql-1.8.1 spec/generators/graphql/union_generator_spec.rb
graphql-1.8.0 spec/generators/graphql/union_generator_spec.rb
graphql-1.8.0.pre11 spec/generators/graphql/union_generator_spec.rb
graphql-1.8.0.pre10 spec/generators/graphql/union_generator_spec.rb
graphql-1.7.14 spec/generators/graphql/union_generator_spec.rb
graphql-1.8.0.pre9 spec/generators/graphql/union_generator_spec.rb
graphql-1.8.0.pre8 spec/generators/graphql/union_generator_spec.rb
graphql-1.7.13 spec/generators/graphql/union_generator_spec.rb
graphql-1.8.0.pre7 spec/generators/graphql/union_generator_spec.rb
graphql-1.7.12 spec/generators/graphql/union_generator_spec.rb
graphql-1.7.11 spec/generators/graphql/union_generator_spec.rb
graphql-1.7.10 spec/generators/graphql/union_generator_spec.rb
graphql-1.8.0.pre6 spec/generators/graphql/union_generator_spec.rb
graphql-1.8.0.pre5 spec/generators/graphql/union_generator_spec.rb
graphql-1.7.9 spec/generators/graphql/union_generator_spec.rb
graphql-1.8.0.pre4 spec/generators/graphql/union_generator_spec.rb
graphql-1.8.0.pre3 spec/generators/graphql/union_generator_spec.rb
graphql-1.7.8 spec/generators/graphql/union_generator_spec.rb
graphql-1.8.0.pre2 spec/generators/graphql/union_generator_spec.rb
graphql-1.7.7 spec/generators/graphql/union_generator_spec.rb