chore: Change the conversation bot status to pending (#2677)

fixes: #2649
This commit is contained in:
Sojan Jose
2021-07-21 22:02:43 +05:30
committed by GitHub
parent a0886d37bc
commit a7ca55c080
22 changed files with 87 additions and 54 deletions

View File

@@ -32,7 +32,7 @@ RSpec.describe 'API Base', type: :request do
describe 'request with api_access_token for bot' do
let!(:agent_bot) { create(:agent_bot) }
let!(:inbox) { create(:inbox, account: account) }
let!(:conversation) { create(:conversation, account: account, inbox: inbox, assignee: user, status: 'bot') }
let!(:conversation) { create(:conversation, account: account, inbox: inbox, assignee: user, status: 'pending') }
context 'when it is an unauthorized url' do
it 'returns unauthorized' do

View File

@@ -200,6 +200,20 @@ RSpec.describe 'Conversations API', type: :request do
end
it 'creates a conversation in specificed status' do
allow(Rails.configuration.dispatcher).to receive(:dispatch)
post "/api/v1/accounts/#{account.id}/conversations",
headers: agent.create_new_auth_token,
params: { source_id: contact_inbox.source_id, status: 'pending' },
as: :json
expect(response).to have_http_status(:success)
response_data = JSON.parse(response.body, symbolize_names: true)
expect(response_data[:status]).to eq('pending')
end
# TODO: remove this spec when we remove the condition check in controller
# Added for backwards compatibility for bot status
it 'creates a conversation as pending if status is specified as bot' do
allow(Rails.configuration.dispatcher).to receive(:dispatch)
post "/api/v1/accounts/#{account.id}/conversations",
headers: agent.create_new_auth_token,
@@ -208,7 +222,7 @@ RSpec.describe 'Conversations API', type: :request do
expect(response).to have_http_status(:success)
response_data = JSON.parse(response.body, symbolize_names: true)
expect(response_data[:status]).to eq('bot')
expect(response_data[:status]).to eq('pending')
end
it 'creates a new conversation with message when message is passed' do
@@ -269,8 +283,8 @@ RSpec.describe 'Conversations API', type: :request do
expect(conversation.reload.status).to eq('resolved')
end
it 'toggles the conversation status to open from bot' do
conversation.update!(status: 'bot')
it 'toggles the conversation status to open from pending' do
conversation.update!(status: 'pending')
post "/api/v1/accounts/#{account.id}/conversations/#{conversation.display_id}/toggle_status",
headers: agent.create_new_auth_token,
@@ -283,13 +297,27 @@ RSpec.describe 'Conversations API', type: :request do
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: 'pending' },
as: :json
expect(response).to have_http_status(:success)
expect(conversation.reload.status).to eq('pending')
end
# TODO: remove this spec when we remove the condition check in controller
# Added for backwards compatibility for bot status
it 'toggles the conversation status to pending status when parameter bot 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')
expect(conversation.reload.status).to eq('pending')
end
end
end

View File

@@ -3,7 +3,7 @@ require 'rails_helper'
describe Integrations::Dialogflow::ProcessorService do
let(:account) { create(:account) }
let(:hook) { create(:integrations_hook, :dialogflow, account: account) }
let(:conversation) { create(:conversation, account: account, status: :bot) }
let(:conversation) { create(:conversation, account: account, status: :pending) }
let(:message) { create(:message, account: account, conversation: conversation) }
let(:event_name) { 'message.created' }
let(:event_data) { { message: message } }

View File

@@ -40,7 +40,7 @@ shared_examples_for 'round_robin_handler' do
account: account,
contact: create(:contact, account: account),
inbox: inbox,
status: 'bot',
status: 'pending',
assignee: nil
)

View File

@@ -345,8 +345,8 @@ RSpec.describe Conversation, type: :model do
let!(:bot_inbox) { create(:agent_bot_inbox) }
let(:conversation) { create(:conversation, inbox: bot_inbox.inbox) }
it 'returns conversation status as bot' do
expect(conversation.status).to eq('bot')
it 'returns conversation status as pending' do
expect(conversation.status).to eq('pending')
end
end
@@ -354,8 +354,8 @@ RSpec.describe Conversation, type: :model do
let(:hook) { create(:integrations_hook, :dialogflow) }
let(:conversation) { create(:conversation, inbox: hook.inbox) }
it 'returns conversation status as bot' do
expect(conversation.status).to eq('bot')
it 'returns conversation status as pending' do
expect(conversation.status).to eq('pending')
end
end