mirror of
				https://github.com/lingble/chatwoot.git
				synced 2025-11-03 20:48:07 +00:00 
			
		
		
		
	feat: Contact Exports (#7258)
This commit is contained in:
		@@ -168,6 +168,52 @@ RSpec.describe 'Contacts API', type: :request do
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  describe 'POST /api/v1/accounts/{account.id}/contacts/export' do
 | 
			
		||||
    context 'when it is an unauthenticated user' do
 | 
			
		||||
      it 'returns unauthorized' do
 | 
			
		||||
        get "/api/v1/accounts/#{account.id}/contacts/export"
 | 
			
		||||
 | 
			
		||||
        expect(response).to have_http_status(:unauthorized)
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    context 'when it is an authenticated user with out permission' do
 | 
			
		||||
      let(:agent) { create(:user, account: account, role: :agent) }
 | 
			
		||||
 | 
			
		||||
      it 'returns unauthorized' do
 | 
			
		||||
        get "/api/v1/accounts/#{account.id}/contacts/export",
 | 
			
		||||
            headers: agent.create_new_auth_token,
 | 
			
		||||
            as: :json
 | 
			
		||||
 | 
			
		||||
        expect(response).to have_http_status(:unauthorized)
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    context 'when it is an authenticated user' do
 | 
			
		||||
      let(:admin) { create(:user, account: account, role: :administrator) }
 | 
			
		||||
 | 
			
		||||
      it 'enqueues a contact export job' do
 | 
			
		||||
        expect(Account::ContactsExportJob).to receive(:perform_later).with(account.id, nil).once
 | 
			
		||||
 | 
			
		||||
        get "/api/v1/accounts/#{account.id}/contacts/export",
 | 
			
		||||
            headers: admin.create_new_auth_token,
 | 
			
		||||
            params: { column_names: nil }
 | 
			
		||||
 | 
			
		||||
        expect(response).to have_http_status(:success)
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      it 'enqueues a contact export job with sent_columns' do
 | 
			
		||||
        expect(Account::ContactsExportJob).to receive(:perform_later).with(account.id, %w[phone_number email]).once
 | 
			
		||||
 | 
			
		||||
        get "/api/v1/accounts/#{account.id}/contacts/export",
 | 
			
		||||
            headers: admin.create_new_auth_token,
 | 
			
		||||
            params: { column_names: %w[phone_number email] }
 | 
			
		||||
 | 
			
		||||
        expect(response).to have_http_status(:success)
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  describe 'GET /api/v1/accounts/{account.id}/contacts/active' do
 | 
			
		||||
    context 'when it is an unauthenticated user' do
 | 
			
		||||
      it 'returns unauthorized' do
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user