feat: Export contact improvements (#8895)
This pull request enhances the export contacts feature by adding a confirmation step before exporting. Previously, clicking the export button would trigger the export action without confirmation. Additionally, it ensures that only the intended recipient receives the export email, addressing the previous behaviour where all administrators received it. Fixes: #8504 Co-authored-by: Sojan Jose <sojan@pepalo.com>
This commit is contained in:
@@ -197,7 +197,7 @@ 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).once
|
||||
expect(Account::ContactsExportJob).to receive(:perform_later).with(account.id, nil, admin.email).once
|
||||
|
||||
get "/api/v1/accounts/#{account.id}/contacts/export",
|
||||
headers: admin.create_new_auth_token,
|
||||
@@ -207,7 +207,7 @@ RSpec.describe 'Contacts API', type: :request do
|
||||
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
|
||||
expect(Account::ContactsExportJob).to receive(:perform_later).with(account.id, %w[phone_number email], admin.email).once
|
||||
|
||||
get "/api/v1/accounts/#{account.id}/contacts/export",
|
||||
headers: admin.create_new_auth_token,
|
||||
|
||||
@@ -24,17 +24,17 @@ RSpec.describe Account::ContactsExportJob do
|
||||
allow(AdministratorNotifications::ChannelNotificationsMailer).to receive(:with).with(account: account).and_return(mailer)
|
||||
allow(mailer).to receive(:contact_export_complete)
|
||||
|
||||
described_class.perform_now(account.id, [])
|
||||
described_class.perform_now(account.id, [], 'test@test.com')
|
||||
|
||||
file_url = Rails.application.routes.url_helpers.rails_blob_url(account.contacts_export)
|
||||
|
||||
expect(account.contacts_export).to be_present
|
||||
expect(file_url).to be_present
|
||||
expect(mailer).to have_received(:contact_export_complete).with(file_url)
|
||||
expect(mailer).to have_received(:contact_export_complete).with(file_url, 'test@test.com')
|
||||
end
|
||||
|
||||
it 'generates valid data export file' do
|
||||
described_class.perform_now(account.id, [])
|
||||
described_class.perform_now(account.id, [], 'test@test.com')
|
||||
|
||||
csv_data = CSV.parse(account.contacts_export.download, headers: true)
|
||||
emails = csv_data.pluck('email')
|
||||
|
||||
@@ -10,7 +10,6 @@ RSpec.describe AdministratorNotifications::ChannelNotificationsMailer do
|
||||
before do
|
||||
allow(described_class).to receive(:new).and_return(class_instance)
|
||||
allow(class_instance).to receive(:smtp_config_set_or_development?).and_return(true)
|
||||
Account::ContactsExportJob.perform_now(account.id, [])
|
||||
end
|
||||
|
||||
describe 'slack_disconnect' do
|
||||
@@ -92,8 +91,8 @@ RSpec.describe AdministratorNotifications::ChannelNotificationsMailer do
|
||||
end
|
||||
|
||||
describe 'contact_export_complete' do
|
||||
let!(:file_url) { Rails.application.routes.url_helpers.rails_blob_url(account.contacts_export) }
|
||||
let(:mail) { described_class.with(account: account).contact_export_complete(file_url).deliver_now }
|
||||
let!(:file_url) { 'http://test.com/test' }
|
||||
let(:mail) { described_class.with(account: account).contact_export_complete(file_url, administrator.email).deliver_now }
|
||||
|
||||
it 'renders the subject' do
|
||||
expect(mail.subject).to eq("Your contact's export file is available to download.")
|
||||
|
||||
Reference in New Issue
Block a user