fix: Manage Twilio SMS channel via inbox API (#11457)
- Currently Chatwoot manages Twilio Inbox creation in a separate controller , We want to move this to inboxes api so that we have a unified API for inbox related changes --------- Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com>
This commit is contained in:
@@ -147,6 +147,32 @@ RSpec.describe 'Inboxes API', type: :request do
|
||||
expect(data[:imap_login]).to eq('test@test.com')
|
||||
end
|
||||
|
||||
context 'when it is a Twilio inbox' do
|
||||
let(:twilio_channel) { create(:channel_twilio_sms, account: account, account_sid: 'AC123', auth_token: 'secrettoken') }
|
||||
let(:twilio_inbox) { create(:inbox, channel: twilio_channel, account: account) }
|
||||
|
||||
it 'returns auth_token and account_sid for admin' do
|
||||
get "/api/v1/accounts/#{account.id}/inboxes/#{twilio_inbox.id}",
|
||||
headers: admin.create_new_auth_token,
|
||||
as: :json
|
||||
expect(response).to have_http_status(:success)
|
||||
data = JSON.parse(response.body, symbolize_names: true)
|
||||
expect(data[:auth_token]).to eq('secrettoken')
|
||||
expect(data[:account_sid]).to eq('AC123')
|
||||
end
|
||||
|
||||
it "doesn't return auth_token and account_sid for agent" do
|
||||
create(:inbox_member, user: agent, inbox: twilio_inbox)
|
||||
get "/api/v1/accounts/#{account.id}/inboxes/#{twilio_inbox.id}",
|
||||
headers: agent.create_new_auth_token,
|
||||
as: :json
|
||||
expect(response).to have_http_status(:success)
|
||||
data = JSON.parse(response.body, symbolize_names: true)
|
||||
expect(data[:auth_token]).to be_nil
|
||||
expect(data[:account_sid]).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
it 'fetch API inbox without hmac token when agent' do
|
||||
api_channel = create(:channel_api, account: account)
|
||||
api_inbox = create(:inbox, channel: api_channel, account: account)
|
||||
@@ -518,6 +544,22 @@ RSpec.describe 'Inboxes API', type: :request do
|
||||
expect(email_channel.reload.email).to eq('emailtest@email.test')
|
||||
end
|
||||
|
||||
it 'updates twilio sms inbox when administrator' do
|
||||
twilio_sms_channel = create(:channel_twilio_sms, account: account)
|
||||
twilio_sms_inbox = create(:inbox, channel: twilio_sms_channel, account: account)
|
||||
expect(twilio_sms_inbox.reload.channel.account_sid).not_to eq('account_sid')
|
||||
expect(twilio_sms_inbox.reload.channel.auth_token).not_to eq('new_auth_token')
|
||||
|
||||
patch "/api/v1/accounts/#{account.id}/inboxes/#{twilio_sms_inbox.id}",
|
||||
headers: admin.create_new_auth_token,
|
||||
params: { channel: { account_sid: 'account_sid', auth_token: 'new_auth_token' } },
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
expect(twilio_sms_inbox.reload.channel.account_sid).to eq('account_sid')
|
||||
expect(twilio_sms_inbox.reload.channel.auth_token).to eq('new_auth_token')
|
||||
end
|
||||
|
||||
it 'updates email inbox with imap when administrator' do
|
||||
email_channel = create(:channel_email, account: account)
|
||||
email_inbox = create(:inbox, channel: email_channel, account: account)
|
||||
|
||||
Reference in New Issue
Block a user