Chore: Minor bugfixes and housekeeping tasks (#896)

This commit is contained in:
Sojan Jose
2020-06-02 23:50:39 +05:30
committed by GitHub
parent 93d8a25877
commit dafabac796
21 changed files with 271 additions and 51 deletions

View File

@@ -119,6 +119,18 @@ RSpec.describe 'Conversations API', type: :request do
expect(response).to have_http_status(:success)
expect(conversation.reload.status).to eq('open')
end
it 'toggles the conversation status to specific status when parameter is passed' do
expect(conversation.status).to eq('open')
post "/api/v1/accounts/#{account.id}/conversations/#{conversation.display_id}/toggle_status",
headers: agent.create_new_auth_token,
params: { status: 'bot' },
as: :json
expect(response).to have_http_status(:success)
expect(conversation.reload.status).to eq('bot')
end
end
end

View File

@@ -0,0 +1,25 @@
require 'rails_helper'
RSpec.describe 'Super Admin agent-bots API', type: :request do
let(:super_admin) { create(:super_admin) }
describe 'GET /super_admin/agent_bots' do
context 'when it is an unauthenticated super admin' do
it 'returns unauthorized' do
get '/super_admin/agent_bots'
expect(response).to have_http_status(:redirect)
end
end
context 'when it is an authenticated super admin' do
let!(:agent_bot) { create(:agent_bot) }
it 'shows the list of users' do
sign_in super_admin
get '/super_admin/agent_bots'
expect(response).to have_http_status(:success)
expect(response.body).to include(agent_bot.name)
end
end
end
end

View File

@@ -15,6 +15,7 @@ describe ::MessageFinder do
create(:message, account: account, inbox: inbox, conversation: conversation)
create(:message, message_type: 'activity', account: account, inbox: inbox, conversation: conversation)
create(:message, message_type: 'activity', account: account, inbox: inbox, conversation: conversation)
# this outgoing message creates 3 additional messages because of the hook execution service
create(:message, message_type: 'outgoing', account: account, inbox: inbox, conversation: conversation)
end

View File

@@ -4,7 +4,8 @@ require 'rails_helper'
RSpec.describe ConversationReplyMailer, type: :mailer do
describe 'reply_with_summary' do
let(:agent) { create(:user, email: 'agent1@example.com') }
let!(:account) { create(:account) }
let!(:agent) { create(:user, email: 'agent1@example.com', account: account) }
let(:class_instance) { described_class.new }
before do
@@ -33,8 +34,10 @@ RSpec.describe ConversationReplyMailer, type: :mailer do
end
context 'when custom domain and email is not enabled' do
let(:conversation) { create(:conversation, assignee: agent) }
let(:message) { create(:message, conversation: conversation) }
let(:inbox) { create(:inbox, account: account) }
let(:inbox_member) { create(:inbox_member, user: agent, inbox: inbox) }
let(:conversation) { create(:conversation, assignee: agent, inbox: inbox_member.inbox, account: account) }
let!(:message) { create(:message, conversation: conversation, account: account) }
let(:mail) { described_class.reply_with_summary(message.conversation, Time.zone.now).deliver_now }
it 'renders the receiver email' do

View File

@@ -17,7 +17,32 @@ RSpec.describe Conversation, type: :model do
it 'creates a UUID for every conversation automatically' do
uuid_pattern = /[0-9a-f]{8}\b-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-\b[0-9a-f]{12}$/i
expect(conversation.uuid).to match(uuid_pattern)
expect(conversation.uuid).to match(uuid_pattern)
end
end
describe '.after_create' do
let(:account) { create(:account) }
let(:agent) { create(:user, email: 'agent1@example.com', account: account) }
let(:inbox) { create(:inbox, account: account) }
let(:conversation) do
create(
:conversation,
account: account,
contact: create(:contact, account: account),
inbox: inbox,
assignee: nil
)
end
before do
allow(Rails.configuration.dispatcher).to receive(:dispatch)
end
it 'runs after_create callbacks' do
# send_events
expect(Rails.configuration.dispatcher).to have_received(:dispatch)
.with(described_class::CONVERSATION_CREATED, kind_of(Time), conversation: conversation)
end
end
@@ -68,7 +93,7 @@ RSpec.describe Conversation, type: :model do
end
end
describe '.after_create' do
describe '#round robin' do
let(:account) { create(:account) }
let(:agent) { create(:user, email: 'agent1@example.com', account: account) }
let(:inbox) { create(:inbox, account: account) }
@@ -83,15 +108,10 @@ RSpec.describe Conversation, type: :model do
end
before do
allow(Rails.configuration.dispatcher).to receive(:dispatch)
allow(Redis::Alfred).to receive(:rpoplpush).and_return(agent.id)
end
it 'runs after_create callbacks' do
# send_events
expect(Rails.configuration.dispatcher).to have_received(:dispatch)
.with(described_class::CONVERSATION_CREATED, kind_of(Time), conversation: conversation)
it 'runs round robin on after_save callbacks' do
# run_round_robin
expect(conversation.reload.assignee).to eq(agent)
end
@@ -99,13 +119,36 @@ RSpec.describe Conversation, type: :model do
it 'will not auto assign agent if enable_auto_assignment is false' do
inbox.update(enable_auto_assignment: false)
# send_events
expect(Rails.configuration.dispatcher).to have_received(:dispatch)
.with(described_class::CONVERSATION_CREATED, kind_of(Time), conversation: conversation)
# run_round_robin
expect(conversation.reload.assignee).to eq(nil)
end
it 'will not auto assign agent if its a bot conversation' do
conversation = create(
:conversation,
account: account,
contact: create(:contact, account: account),
inbox: inbox,
status: 'bot',
assignee: nil
)
# run_round_robin
expect(conversation.reload.assignee).to eq(nil)
end
it 'gets triggered on update only when status changes to open' do
conversation.status = 'resolved'
conversation.save!
expect(conversation.reload.assignee).to eq(agent)
# round robin changes assignee in this case since agent doesn't have access to inbox
agent2 = create(:user, email: 'agent2@example.com', account: account)
allow(Redis::Alfred).to receive(:rpoplpush).and_return(agent2.id)
conversation.status = 'open'
conversation.save!
expect(conversation.reload.assignee).to eq(agent2)
end
end
describe '#update_assignee' do