feat: Add bulk imports API for contacts (#1724)
This commit is contained in:
@@ -3,7 +3,7 @@ require 'rails_helper'
|
||||
RSpec.describe '/api/v1/accounts/{account.id}/contacts/:id/contact_inboxes', type: :request do
|
||||
let(:account) { create(:account) }
|
||||
let(:contact) { create(:contact, account: account) }
|
||||
let(:inbox_1) { create(:inbox, account: account) }
|
||||
let(:channel_twilio_sms) { create(:channel_twilio_sms, account: account) }
|
||||
let(:channel_api) { create(:channel_api, account: account) }
|
||||
let(:user) { create(:user, account: account) }
|
||||
|
||||
@@ -28,10 +28,10 @@ RSpec.describe '/api/v1/accounts/{account.id}/contacts/:id/contact_inboxes', typ
|
||||
expect(contact.reload.contact_inboxes.map(&:inbox_id)).to include(channel_api.inbox.id)
|
||||
end
|
||||
|
||||
it 'throws error when its not an api inbox' do
|
||||
it 'throws error for invalid source id' do
|
||||
expect do
|
||||
post "/api/v1/accounts/#{account.id}/contacts/#{contact.id}/contact_inboxes",
|
||||
params: { inbox_id: inbox_1.id },
|
||||
params: { inbox_id: channel_twilio_sms.inbox.id },
|
||||
headers: user.create_new_auth_token,
|
||||
as: :json
|
||||
end.to change(ContactInbox, :count).by(0)
|
||||
|
||||
@@ -43,6 +43,43 @@ RSpec.describe 'Contacts API', type: :request do
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST /api/v1/accounts/{account.id}/contacts/import' do
|
||||
context 'when it is an unauthenticated user' do
|
||||
it 'returns unauthorized' do
|
||||
post "/api/v1/accounts/#{account.id}/contacts/import"
|
||||
|
||||
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
|
||||
post "/api/v1/accounts/#{account.id}/contacts/import",
|
||||
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 'creates a data import' do
|
||||
file = fixture_file_upload(Rails.root.join('spec/assets/contacts.csv'), 'text/csv')
|
||||
post "/api/v1/accounts/#{account.id}/contacts/import",
|
||||
headers: admin.create_new_auth_token,
|
||||
params: { import_file: file }
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
expect(account.data_imports.count).to eq(1)
|
||||
expect(account.data_imports.first.import_file.attached?).to eq(true)
|
||||
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