Sha256: 7653b444ad6b39a998ad53b49e3e7154325fa6af3e1176de68f80fe3ff21d151

Contents?: true

Size: 1.92 KB

Versions: 28

Compression:

Stored size: 1.92 KB

Contents

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

class GraphQLGeneratorsMutationGeneratorTest < BaseGeneratorTest
  tests Graphql::Generators::MutationGenerator

  destination File.expand_path("../../../tmp/dummy", File.dirname(__FILE__))

  def setup(directory = "app/graphql")
    prepare_destination
    FileUtils.cd(File.expand_path("../../../tmp", File.dirname(__FILE__))) do
      `rm -rf dummy`
      `rails new dummy --skip-active-record --skip-test-unit --skip-spring --skip-bundle`
    end

    FileUtils.cd(destination_root) do
      `rails g graphql:install --directory #{directory}`
    end
  end

  UPDATE_NAME_MUTATION = <<-RUBY
module Mutations
  class UpdateName < GraphQL::Schema::RelayClassicMutation
    # TODO: define return fields
    # field :post, Types::PostType, null: false

    # TODO: define arguments
    # argument :name, String, required: true

    # TODO: define resolve method
    # def resolve(name:)
    #   { post: ... }
    # end
  end
end
RUBY

  EXPECTED_MUTATION_TYPE = <<-RUBY
module Types
  class MutationType < Types::BaseObject
    field :updateName, mutation: Mutations::UpdateName
    # TODO: remove me
    field :test_field, String, null: false,
      description: "An example field added by the generator"
    def test_field
      "Hello World"
    end
  end
end
RUBY

  test "it generates an empty resolver by name" do
    setup
    run_generator(["UpdateName"])
    assert_file "app/graphql/mutations/update_name.rb", UPDATE_NAME_MUTATION
  end

  test "it inserts the field into the MutationType" do
    setup
    run_generator(["UpdateName"])
    assert_file "app/graphql/types/mutation_type.rb", EXPECTED_MUTATION_TYPE
  end

  test "it allows for user-specified directory" do
    setup "app/mydirectory"
    run_generator(["UpdateName", "--directory", "app/mydirectory"])

    assert_file "app/mydirectory/mutations/update_name.rb", UPDATE_NAME_MUTATION
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
graphql-1.8.18 spec/integration/rails/generators/graphql/mutation_generator_spec.rb
graphql-1.9.11 spec/integration/rails/generators/graphql/mutation_generator_spec.rb
graphql-1.9.10 spec/integration/rails/generators/graphql/mutation_generator_spec.rb
graphql-1.9.9 spec/integration/rails/generators/graphql/mutation_generator_spec.rb
graphql-1.9.8 spec/integration/rails/generators/graphql/mutation_generator_spec.rb
graphql-1.9.7 spec/integration/rails/generators/graphql/mutation_generator_spec.rb
graphql-1.9.6 spec/integration/rails/generators/graphql/mutation_generator_spec.rb
graphql-1.9.5 spec/integration/rails/generators/graphql/mutation_generator_spec.rb
graphql-1.9.4 spec/integration/rails/generators/graphql/mutation_generator_spec.rb
graphql-1.9.3 spec/integration/rails/generators/graphql/mutation_generator_spec.rb
graphql-1.9.2 spec/integration/rails/generators/graphql/mutation_generator_spec.rb
graphql-1.8.17 spec/integration/rails/generators/graphql/mutation_generator_spec.rb
graphql-1.8.16 spec/integration/rails/generators/graphql/mutation_generator_spec.rb
graphql-1.9.1 spec/integration/rails/generators/graphql/mutation_generator_spec.rb
graphql-1.9.0 spec/integration/rails/generators/graphql/mutation_generator_spec.rb
graphql-1.8.15 spec/integration/rails/generators/graphql/mutation_generator_spec.rb
graphql-1.9.0.pre4 spec/integration/rails/generators/graphql/mutation_generator_spec.rb
graphql-1.8.14 spec/integration/rails/generators/graphql/mutation_generator_spec.rb
graphql-1.9.0.pre3 spec/integration/rails/generators/graphql/mutation_generator_spec.rb
graphql-1.9.0.pre2 spec/integration/rails/generators/graphql/mutation_generator_spec.rb