Sha256: 011b57d4ab0c53b91a326a5cda16763962f1fcfe41ca9aa375372fb8ba1dbd4e

Contents?: true

Size: 1.8 KB

Versions: 11

Compression:

Stored size: 1.8 KB

Contents

require 'rails_helper'

RSpec.describe 'Additional Mutations' do
  include_context 'with graphql query request'

  let(:name)                  { Faker::Name.name }
  let(:password)              { Faker::Internet.password }
  let(:password_confirmation) { password }
  let(:email)                 { Faker::Internet.email }
  let(:redirect)              { Faker::Internet.url }

  context 'when using the user model' do
    let(:query) do
      <<-GRAPHQL
        mutation {
          registerConfirmedUser(
            email:                "#{email}",
            name:                 "#{name}",
            password:             "#{password}",
            passwordConfirmation: "#{password_confirmation}"
          ) {
            user {
              email
              name
            }
          }
        }
      GRAPHQL
    end

    context 'when params are correct' do
      it 'creates a new resource that is already confirmed' do
        expect { post_request }.to(
          change(User, :count).by(1)
          .and(not_change(ActionMailer::Base.deliveries, :count))
        )

        user = User.last

        expect(user).to be_confirmed
        expect(json_response[:data][:registerConfirmedUser]).to include(
          user: {
            email: email,
            name:  name
          }
        )
      end
    end

    context 'when params are incorrect' do
      let(:password_confirmation) { 'not the same' }

      it 'returns descriptive errors' do
        expect { post_request }.to not_change(User, :count)

        expect(json_response[:errors]).to contain_exactly(
          hash_including(
            message:    'Custom registration failed',
            extensions: { code: 'USER_ERROR', detailed_errors: ["Password confirmation doesn't match Password"] }
          )
        )
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
graphql_devise-0.12.3 spec/requests/mutations/additional_mutations_spec.rb
graphql_devise-0.12.2 spec/requests/mutations/additional_mutations_spec.rb
graphql_devise-0.12.1 spec/requests/mutations/additional_mutations_spec.rb
graphql_devise-0.12.0 spec/requests/mutations/additional_mutations_spec.rb
graphql_devise-0.11.4 spec/requests/mutations/additional_mutations_spec.rb
graphql_devise-0.11.3 spec/requests/mutations/additional_mutations_spec.rb
graphql_devise-0.11.2 spec/requests/mutations/additional_mutations_spec.rb
graphql_devise-0.11.1 spec/requests/mutations/additional_mutations_spec.rb
graphql_devise-0.11.0 spec/requests/mutations/additional_mutations_spec.rb
graphql_devise-0.10.1 spec/requests/mutations/additional_mutations_spec.rb
graphql_devise-0.10.0 spec/requests/mutations/additional_mutations_spec.rb