Sha256: 7872893237b9ae7250c6533c23b02b57203ce396989a4f39922c206fcf78366b

Contents?: true

Size: 1.38 KB

Versions: 1

Compression:

Stored size: 1.38 KB

Contents

RSpec.describe 'Update<%= @camelize_name %>', type: :request do
  include_context 'authenticated user'

  def query()
  <%= "  <<~GQL" %>
    mutation Update<%= @camelize_name %>($id: ID!, <%= @update_test_define_line %>) {
      update<%= @camelize_name %>(input: {id: $id, <%= @update_test_input_line %>}) {
          id
          <%= 
            @parsed_fields.filter{|f| !f[:reference].present? }.map{|field| 
              var = field[:name].camelize
              var[0] = var[0].downcase
              if field[:reference].present? then var += ' { id } ' end
              var
            }.join("\n          ")
          %>
        }
      }
    GQL
  end

  it 'update_<%= @snake_case_name %> success' do
    <%= @snake_case_name%> = create(:<%= @snake_case_name %>)
    updated_<%= @snake_case_name%> = build(:updated_<%= @snake_case_name %>)
    updated_<%= @snake_case_name%> = <%= @snake_case_name %>.id
    variables = updated_<%= @snake_case_name%>.to_json

    json = graphql(query, variables: variables)
    data = json['update<%= @camelize_name %>']

    expect(data).to include('id' => <%= @snake_case_name%>.id)
    <%= 
      @parsed_fields.filter{|f| !f[:reference].present? }.map{|field| 
        var = field[:name].camelize
        var[0] = var[0].downcase
        "expect(data).to include('#{var}' => updated_#{@snake_case_name}.#{field[:name]})"
      }.join("\n    ")
    %>
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
graphql_helper_generator-0.0.26 lib/graphql_helper_generator/graphql_model/templates/tests/update_test_template.erb