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>
50 lines
1.7 KiB
Ruby
50 lines
1.7 KiB
Ruby
require 'rails_helper'
|
|
|
|
RSpec.describe Account::ContactsExportJob do
|
|
subject(:job) { described_class.perform_later }
|
|
|
|
let!(:account) { create(:account) }
|
|
|
|
it 'enqueues the job' do
|
|
expect { job }.to have_enqueued_job(described_class)
|
|
.on_queue('low')
|
|
end
|
|
|
|
context 'when export_contacts' do
|
|
before do
|
|
create(:contact, account: account, phone_number: '+910808080818', email: 'test1@text.example')
|
|
8.times do
|
|
create(:contact, account: account)
|
|
end
|
|
create(:contact, account: account, phone_number: '+910808080808', email: 'test2@text.example')
|
|
end
|
|
|
|
it 'generates CSV file and attach to account' do
|
|
mailer = double
|
|
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, [], '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, 'test@test.com')
|
|
end
|
|
|
|
it 'generates valid data export file' do
|
|
described_class.perform_now(account.id, [], 'test@test.com')
|
|
|
|
csv_data = CSV.parse(account.contacts_export.download, headers: true)
|
|
emails = csv_data.pluck('email')
|
|
phone_numbers = csv_data.pluck('phone_number')
|
|
|
|
expect(csv_data.length).to eq(account.contacts.count)
|
|
|
|
expect(emails).to include('test1@text.example', 'test2@text.example')
|
|
expect(phone_numbers).to include('+910808080818', '+910808080808')
|
|
end
|
|
end
|
|
end
|