feat: exporting contacts takes the filters into account (#9347)
- This PR allows contacts to be exported using the current filter in CRM view Co-authored-by: Sojan Jose <sojan@pepalo.com>
This commit is contained in:
@@ -2,6 +2,16 @@ require 'rails_helper'
|
||||
|
||||
RSpec.describe 'Contacts API', type: :request do
|
||||
let(:account) { create(:account) }
|
||||
let(:email_filter) do
|
||||
{
|
||||
attribute_key: 'email',
|
||||
filter_operator: 'contains',
|
||||
values: 'looped',
|
||||
query_operator: 'and',
|
||||
attribute_model: 'standard',
|
||||
custom_attribute_type: ''
|
||||
}
|
||||
end
|
||||
|
||||
describe 'GET /api/v1/accounts/{account.id}/contacts' do
|
||||
context 'when it is an unauthenticated user' do
|
||||
@@ -175,7 +185,7 @@ RSpec.describe 'Contacts API', type: :request do
|
||||
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"
|
||||
post "/api/v1/accounts/#{account.id}/contacts/export"
|
||||
|
||||
expect(response).to have_http_status(:unauthorized)
|
||||
end
|
||||
@@ -185,9 +195,9 @@ RSpec.describe 'Contacts API', type: :request 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
|
||||
post "/api/v1/accounts/#{account.id}/contacts/export",
|
||||
headers: agent.create_new_auth_token,
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:unauthorized)
|
||||
end
|
||||
@@ -197,21 +207,35 @@ RSpec.describe 'Contacts API', type: :request 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, admin.email).once
|
||||
expect(Account::ContactsExportJob).to receive(:perform_later).with(account.id, admin.id, nil, { :payload => nil, :label => nil }).once
|
||||
|
||||
get "/api/v1/accounts/#{account.id}/contacts/export",
|
||||
headers: admin.create_new_auth_token,
|
||||
params: { column_names: nil }
|
||||
post "/api/v1/accounts/#{account.id}/contacts/export",
|
||||
headers: admin.create_new_auth_token
|
||||
|
||||
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], admin.email).once
|
||||
expect(Account::ContactsExportJob).to receive(:perform_later).with(account.id, admin.id, %w[phone_number email],
|
||||
{ :payload => nil, :label => nil }).once
|
||||
|
||||
get "/api/v1/accounts/#{account.id}/contacts/export",
|
||||
headers: admin.create_new_auth_token,
|
||||
params: { column_names: %w[phone_number email] }
|
||||
post "/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
|
||||
|
||||
it 'enqueues a contact export job with payload' do
|
||||
expect(Account::ContactsExportJob).to receive(:perform_later).with(account.id, admin.id, nil,
|
||||
{
|
||||
:payload => [ActionController::Parameters.new(email_filter).permit!],
|
||||
:label => nil
|
||||
}).once
|
||||
|
||||
post "/api/v1/accounts/#{account.id}/contacts/export",
|
||||
headers: admin.create_new_auth_token,
|
||||
params: { payload: [email_filter] }
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user