Sha256: 60267729f858399efde98782acf5536172c1a091f07b449858cb2ba766635712

Contents?: true

Size: 1.48 KB

Versions: 20

Compression:

Stored size: 1.48 KB

Contents

require 'rails_helper'

RSpec.describe 'Account confirmation' do
  include_context 'with graphql query request'

  let(:user)     { create(:user, confirmed_at: nil) }
  let(:redirect) { Faker::Internet.url }
  let(:query) do
    <<-GRAPHQL
      {
        userConfirmAccount(
          confirmationToken: "#{token}"
          redirectUrl:       "#{redirect}"
        ) {
          email
          name
        }
      }
    GRAPHQL
  end

  context 'when confirmation token is correct' do
    let(:token) { user.confirmation_token }

    before { user.send_confirmation_instructions(template_path: ['graphql_devise/mailer']) }

    it 'confirms the resource and redirects to the sent url' do
      expect do
        get_request
        user.reload
      end.to(change(user, :confirmed_at).from(nil))

      expect(response).to redirect_to "#{redirect}?account_confirmation_success=true"
      expect(user).to be_active_for_authentication
    end
  end

  context 'when reset password token is not found' do
    let(:token) { "#{user.confirmation_token}-invalid" }

    it 'does *NOT* confirm the user nor does the redirection' do
      expect do
        get_request
        user.reload
      end.not_to(change(user, :confirmed_at).from(nil))

      expect(response).not_to be_redirect
      expect(json_response[:errors]).to contain_exactly(
        hash_including(
          message: 'Invalid confirmation token. Please try again',
          extensions: { code: 'USER_ERROR' }
        )
      )
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
graphql_devise-0.12.1 spec/requests/queries/confirm_account_spec.rb
graphql_devise-0.12.0 spec/requests/queries/confirm_account_spec.rb
graphql_devise-0.11.4 spec/requests/queries/confirm_account_spec.rb
graphql_devise-0.11.3 spec/requests/queries/confirm_account_spec.rb
graphql_devise-0.11.2 spec/requests/queries/confirm_account_spec.rb
graphql_devise-0.11.1 spec/requests/queries/confirm_account_spec.rb
graphql_devise-0.11.0 spec/requests/queries/confirm_account_spec.rb
graphql_devise-0.10.1 spec/requests/queries/confirm_account_spec.rb
graphql_devise-0.10.0 spec/requests/queries/confirm_account_spec.rb
graphql_devise-0.9.2 spec/requests/queries/confirm_account_spec.rb
graphql_devise-0.9.1 spec/requests/queries/confirm_account_spec.rb
graphql_devise-0.9.0 spec/requests/queries/confirm_account_spec.rb
graphql_devise-0.8.1 spec/requests/queries/confirm_account_spec.rb
graphql_devise-0.8.0 spec/requests/queries/confirm_account_spec.rb
graphql_devise-0.7.0 spec/requests/queries/confirm_account_spec.rb
graphql_devise-0.6.0 spec/requests/queries/confirm_account_spec.rb
graphql_devise-0.5.0 spec/requests/queries/confirm_account_spec.rb
graphql_devise-0.4.1 spec/requests/queries/confirm_account_spec.rb
graphql_devise-0.4.0 spec/requests/queries/confirm_account_spec.rb
graphql_devise-0.3.0 spec/requests/queries/confirm_account_spec.rb