chore: Update conversations API to include unattended conversations. (#4708)
* Update conversations API to include unattended conversations.
This commit is contained in:
@@ -51,6 +51,7 @@ class ConversationFinder
|
||||
filter_by_team if @team
|
||||
filter_by_labels if params[:labels]
|
||||
filter_by_query if params[:q]
|
||||
filter_by_reply_status
|
||||
end
|
||||
|
||||
def set_inboxes
|
||||
@@ -90,6 +91,10 @@ class ConversationFinder
|
||||
@conversations
|
||||
end
|
||||
|
||||
def filter_by_reply_status
|
||||
@conversations = @conversations.where(first_reply_created_at: nil) if params[:reply_status] == 'unattended'
|
||||
end
|
||||
|
||||
def filter_by_query
|
||||
allowed_message_types = [Message.message_types[:incoming], Message.message_types[:outgoing]]
|
||||
@conversations = conversations.joins(:messages).where('messages.content ILIKE :search', search: "%#{params[:q]}%")
|
||||
|
||||
@@ -15,6 +15,8 @@ RSpec.describe 'Conversations API', type: :request do
|
||||
context 'when it is an authenticated user' do
|
||||
let(:agent) { create(:user, account: account, role: :agent) }
|
||||
let(:conversation) { create(:conversation, account: account) }
|
||||
let(:attended_conversation) { create(:conversation, account: account, first_reply_created_at: Time.now.utc) }
|
||||
let(:unattended_conversation) { create(:conversation, account: account, first_reply_created_at: nil) }
|
||||
|
||||
before do
|
||||
create(:inbox_member, user: agent, inbox: conversation.inbox)
|
||||
@@ -43,6 +45,22 @@ RSpec.describe 'Conversations API', type: :request do
|
||||
expect(body[:data][:meta][:all_count]).to eq(1)
|
||||
expect(body[:data][:payload].first[:messages]).to eq([])
|
||||
end
|
||||
|
||||
it 'returns unattended conversations' do
|
||||
agent_1 = create(:user, account: account, role: :agent)
|
||||
create(:inbox_member, user: agent_1, inbox: attended_conversation.inbox)
|
||||
create(:inbox_member, user: agent_1, inbox: unattended_conversation.inbox)
|
||||
|
||||
get "/api/v1/accounts/#{account.id}/conversations",
|
||||
headers: agent_1.create_new_auth_token,
|
||||
params: { reply_status: 'unattended' },
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
body = JSON.parse(response.body, symbolize_names: true)
|
||||
expect(body[:data][:meta][:all_count]).to eq(1)
|
||||
expect(body[:data][:payload].count).to eq(1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user