mirror of
				https://github.com/lingble/chatwoot.git
				synced 2025-11-04 13:07:55 +00:00 
			
		
		
		
	- Refactor email validation logic to be a service - Use the service for both email/pass signup and Google SSO - fix account email validation during signup - Use `blocked_domain` setting for both email/pass signup and Google Sign In [`BLOCKED_DOMAIN` via GlobalConfig] - add specs for `account_builder` - add specs for the new service --------- Co-authored-by: Sojan Jose <sojan@pepalo.com>
		
			
				
	
	
		
			58 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			Ruby
		
	
	
	
	
	
			
		
		
	
	
			58 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			Ruby
		
	
	
	
	
	
# frozen_string_literal: true
 | 
						|
 | 
						|
require 'rails_helper'
 | 
						|
 | 
						|
RSpec.describe AccountBuilder do
 | 
						|
  let(:email) { 'user@example.com' }
 | 
						|
  let(:user_password) { 'Password123!' }
 | 
						|
  let(:account_name) { 'Test Account' }
 | 
						|
  let(:user_full_name) { 'Test User' }
 | 
						|
  let(:validation_service) { instance_double(Account::SignUpEmailValidationService, perform: true) }
 | 
						|
  let(:account_builder) do
 | 
						|
    described_class.new(
 | 
						|
      account_name: account_name,
 | 
						|
      email: email,
 | 
						|
      user_full_name: user_full_name,
 | 
						|
      user_password: user_password,
 | 
						|
      confirmed: true
 | 
						|
    )
 | 
						|
  end
 | 
						|
 | 
						|
  # Mock the email validation service
 | 
						|
  before do
 | 
						|
    allow(Account::SignUpEmailValidationService).to receive(:new).with(email).and_return(validation_service)
 | 
						|
  end
 | 
						|
 | 
						|
  describe '#perform' do
 | 
						|
    context 'when valid params are passed' do
 | 
						|
      it 'creates a new account with correct name' do
 | 
						|
        _user, account = account_builder.perform
 | 
						|
        expect(account).to be_an(Account)
 | 
						|
        expect(account.name).to eq(account_name)
 | 
						|
      end
 | 
						|
 | 
						|
      it 'creates a new confirmed user with correct details' do
 | 
						|
        user, _account = account_builder.perform
 | 
						|
        expect(user).to be_a(User)
 | 
						|
        expect(user.email).to eq(email)
 | 
						|
        expect(user.name).to eq(user_full_name)
 | 
						|
        expect(user.confirmed?).to be(true)
 | 
						|
      end
 | 
						|
 | 
						|
      it 'links user to account as administrator' do
 | 
						|
        user, account = account_builder.perform
 | 
						|
        expect(user.account_users.first.role).to eq('administrator')
 | 
						|
        expect(user.accounts.first).to eq(account)
 | 
						|
      end
 | 
						|
 | 
						|
      it 'increments the counts of models' do
 | 
						|
        expect do
 | 
						|
          account_builder.perform
 | 
						|
        end.to change(Account, :count).by(1)
 | 
						|
           .and change(User, :count).by(1)
 | 
						|
           .and change(AccountUser, :count).by(1)
 | 
						|
      end
 | 
						|
    end
 | 
						|
  end
 | 
						|
end
 |