feat: Add filter APIs for Contacts and Conversations (#3264)

This commit is contained in:
Tejaswini Chile
2021-11-01 13:57:04 +05:30
committed by GitHub
parent 68fa694268
commit 372bd75028
13 changed files with 470 additions and 19 deletions

View File

@@ -233,10 +233,12 @@ RSpec.describe 'Contacts API', type: :request do
let!(:contact2) { create(:contact, :with_email, name: 'testcontact', account: account, email: 'test@test.com') }
it 'returns all contacts when query is empty' do
get "/api/v1/accounts/#{account.id}/contacts/filter",
params: { q: [] },
headers: admin.create_new_auth_token,
as: :json
post "/api/v1/accounts/#{account.id}/contacts/filter",
params: {
payload: []
},
headers: admin.create_new_auth_token,
as: :json
expect(response).to have_http_status(:success)
expect(response.body).to include(contact2.email)

View File

@@ -112,7 +112,7 @@ RSpec.describe 'Conversations API', type: :request do
describe 'GET /api/v1/accounts/{account.id}/conversations/filter' do
context 'when it is an unauthenticated user' do
it 'returns unauthorized' do
get "/api/v1/accounts/#{account.id}/conversations/filter", params: { q: 'test' }
post "/api/v1/accounts/#{account.id}/conversations/filter", params: { q: 'test' }
expect(response).to have_http_status(:unauthorized)
end
@@ -129,16 +129,15 @@ RSpec.describe 'Conversations API', type: :request do
end
it 'returns all conversations with empty query' do
get "/api/v1/accounts/#{account.id}/conversations/filter",
headers: agent.create_new_auth_token,
params: { q: 'test1' },
as: :json
post "/api/v1/accounts/#{account.id}/conversations/filter",
headers: agent.create_new_auth_token,
params: { payload: [] },
as: :json
expect(response).to have_http_status(:success)
response_data = JSON.parse(response.body, symbolize_names: true)
expect(response_data.count).to eq(1)
expect(response_data[0][:messages][0][:content]).to include(Message.first.content)
expect(response_data.count).to eq(2)
end
end
end