feat: Add ability to filter Conversations by underlying source_id (#6979)
This change adds the ability to include a `source_id` param when querying the `/api/v1/accounts/{account_id}/conversations/search` endpoint. It restricts to results to only conversations related to a contact_inbox with the provided parameter. My motivation for adding this feature was to allow an external API to communicate with a specific conversation with only an awareness of the conversation `source_id` from the client.
Co-authored-by: Sojan Jose <sojan@pepalo.com>
This commit is contained in:
@@ -8,6 +8,7 @@ describe ::ConversationFinder do
|
||||
let!(:user_2) { create(:user, account: account) }
|
||||
let!(:admin) { create(:user, account: account, role: :administrator) }
|
||||
let!(:inbox) { create(:inbox, account: account, enable_auto_assignment: false) }
|
||||
let!(:contact_inbox) { create(:contact_inbox, inbox: inbox, source_id: 'testing_source_id') }
|
||||
let!(:restricted_inbox) { create(:inbox, account: account) }
|
||||
|
||||
before do
|
||||
@@ -16,7 +17,7 @@ describe ::ConversationFinder do
|
||||
create(:conversation, account: account, inbox: inbox, assignee: user_1)
|
||||
create(:conversation, account: account, inbox: inbox, assignee: user_1)
|
||||
create(:conversation, account: account, inbox: inbox, assignee: user_1, status: 'resolved')
|
||||
create(:conversation, account: account, inbox: inbox, assignee: user_2)
|
||||
create(:conversation, account: account, inbox: inbox, assignee: user_2, contact_inbox: contact_inbox)
|
||||
# unassigned conversation
|
||||
create(:conversation, account: account, inbox: inbox)
|
||||
Current.account = account
|
||||
@@ -127,6 +128,24 @@ describe ::ConversationFinder do
|
||||
end
|
||||
end
|
||||
|
||||
context 'with source_id' do
|
||||
let(:params) { { source_id: 'testing_source_id' } }
|
||||
|
||||
it 'filter conversations by source id' do
|
||||
result = conversation_finder.perform
|
||||
expect(result[:conversations].length).to be 1
|
||||
end
|
||||
end
|
||||
|
||||
context 'without source' do
|
||||
let(:params) { {} }
|
||||
|
||||
it 'returns conversations with any source' do
|
||||
result = conversation_finder.perform
|
||||
expect(result[:conversations].length).to be 4
|
||||
end
|
||||
end
|
||||
|
||||
context 'with pagination' do
|
||||
let(:params) { { status: 'open', assignee_type: 'me', page: 1 } }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user