Merge branch 'develop' into chore/notification-logging
This commit is contained in:
@@ -97,9 +97,8 @@ RSpec.describe 'Integration Hooks API', type: :request do
|
||||
params: params,
|
||||
headers: agent.create_new_auth_token,
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
expect(response.parsed_body['message']).to eq('No processor found')
|
||||
expect(response).to have_http_status(:unprocessable_entity)
|
||||
expect(response.parsed_body['error']).to eq 'No processor found'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -50,7 +50,7 @@ RSpec.describe 'Session', type: :request do
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
expect(response.parsed_body['data']['permissions']).to eq(['agent'])
|
||||
expect(response.parsed_body['data']['accounts'].first['permissions']).to eq(['agent'])
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ RSpec.describe Integrations::Openai::ProcessorService do
|
||||
.to_return(status: 200, body: openai_response, headers: {})
|
||||
|
||||
result = subject.perform
|
||||
expect(result).to eq('This is a reply from openai.')
|
||||
expect(result).to eq({ :message => 'This is a reply from openai.' })
|
||||
end
|
||||
|
||||
it 'returns empty string if openai response is blank' do
|
||||
@@ -63,7 +63,7 @@ RSpec.describe Integrations::Openai::ProcessorService do
|
||||
.to_return(status: 200, body: '{}', headers: {})
|
||||
|
||||
result = subject.perform
|
||||
expect(result).to eq('')
|
||||
expect(result).to eq({ :message => '' })
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -81,9 +81,7 @@ describe Webhooks::InstagramEventsJob do
|
||||
end
|
||||
|
||||
it 'handle instagram unsend message event' do
|
||||
create(:message,
|
||||
source_id: 'message-id-to-delete',
|
||||
inbox_id: instagram_inbox.id)
|
||||
message = create(:message, inbox_id: instagram_inbox.id, source_id: 'message-id-to-delete')
|
||||
allow(Koala::Facebook::API).to receive(:new).and_return(fb_object)
|
||||
allow(fb_object).to receive(:get_object).and_return(
|
||||
{
|
||||
@@ -93,10 +91,15 @@ describe Webhooks::InstagramEventsJob do
|
||||
profile_pic: 'https://chatwoot-assets.local/sample.png'
|
||||
}.with_indifferent_access
|
||||
)
|
||||
message.attachments.new(file_type: :image, external_url: 'https://www.example.com/test.jpeg')
|
||||
|
||||
expect(instagram_inbox.messages.count).to be 1
|
||||
|
||||
instagram_webhook.perform_now(unsend_event[:entry])
|
||||
|
||||
expect(instagram_inbox.messages.last.content).to eq 'This message was deleted'
|
||||
expect(instagram_inbox.messages.last.deleted).to be true
|
||||
expect(instagram_inbox.messages.last.attachments.count).to be 0
|
||||
expect(instagram_inbox.messages.last.reload.deleted).to be true
|
||||
end
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ RSpec.describe Integrations::Openai::ProcessorService do
|
||||
.to_return(status: 200, body: openai_response, headers: {})
|
||||
|
||||
result = subject.perform
|
||||
expect(result).to eq('This is a reply from openai.')
|
||||
expect(result).to eq({ :message => 'This is a reply from openai.' })
|
||||
end
|
||||
end
|
||||
|
||||
@@ -76,7 +76,7 @@ RSpec.describe Integrations::Openai::ProcessorService do
|
||||
.to_return(status: 200, body: openai_response, headers: {})
|
||||
|
||||
result = subject.perform
|
||||
expect(result).to eq('This is a reply from openai.')
|
||||
expect(result).to eq({ :message => 'This is a reply from openai.' })
|
||||
end
|
||||
end
|
||||
|
||||
@@ -101,7 +101,7 @@ RSpec.describe Integrations::Openai::ProcessorService do
|
||||
.to_return(status: 200, body: openai_response, headers: {})
|
||||
|
||||
result = subject.perform
|
||||
expect(result).to eq('This is a reply from openai.')
|
||||
expect(result).to eq({ :message => 'This is a reply from openai.' })
|
||||
end
|
||||
end
|
||||
|
||||
@@ -140,7 +140,7 @@ RSpec.describe Integrations::Openai::ProcessorService do
|
||||
.to_return(status: 200, body: openai_response, headers: {})
|
||||
|
||||
result = subject.perform
|
||||
expect(result).to eq('This is a reply from openai.')
|
||||
expect(result).to eq({ :message => 'This is a reply from openai.' })
|
||||
end
|
||||
end
|
||||
|
||||
@@ -162,7 +162,7 @@ RSpec.describe Integrations::Openai::ProcessorService do
|
||||
.to_return(status: 200, body: openai_response, headers: {})
|
||||
|
||||
result = subject.perform
|
||||
expect(result).to eq('This is a reply from openai.')
|
||||
expect(result).to eq({ :message => 'This is a reply from openai.' })
|
||||
end
|
||||
end
|
||||
|
||||
@@ -184,7 +184,7 @@ RSpec.describe Integrations::Openai::ProcessorService do
|
||||
.to_return(status: 200, body: openai_response, headers: {})
|
||||
|
||||
result = subject.perform
|
||||
expect(result).to eq('This is a reply from openai.')
|
||||
expect(result).to eq({ :message => 'This is a reply from openai.' })
|
||||
end
|
||||
end
|
||||
|
||||
@@ -206,7 +206,7 @@ RSpec.describe Integrations::Openai::ProcessorService do
|
||||
.to_return(status: 200, body: openai_response, headers: {})
|
||||
|
||||
result = subject.perform
|
||||
expect(result).to eq('This is a reply from openai.')
|
||||
expect(result).to eq({ :message => 'This is a reply from openai.' })
|
||||
end
|
||||
end
|
||||
|
||||
@@ -228,7 +228,7 @@ RSpec.describe Integrations::Openai::ProcessorService do
|
||||
.to_return(status: 200, body: openai_response, headers: {})
|
||||
|
||||
result = subject.perform
|
||||
expect(result).to eq('This is a reply from openai.')
|
||||
expect(result).to eq({ :message => 'This is a reply from openai.' })
|
||||
end
|
||||
end
|
||||
|
||||
@@ -250,7 +250,7 @@ RSpec.describe Integrations::Openai::ProcessorService do
|
||||
.to_return(status: 200, body: openai_response, headers: {})
|
||||
|
||||
result = subject.perform
|
||||
expect(result).to eq('This is a reply from openai.')
|
||||
expect(result).to eq({ :message => 'This is a reply from openai.' })
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -525,6 +525,7 @@ RSpec.describe Conversation do
|
||||
id: conversation.display_id,
|
||||
messages: [],
|
||||
labels: [],
|
||||
last_activity_at: conversation.last_activity_at.to_i,
|
||||
inbox_id: conversation.inbox_id,
|
||||
status: conversation.status,
|
||||
contact_inbox: conversation.contact_inbox,
|
||||
@@ -881,4 +882,39 @@ RSpec.describe Conversation do
|
||||
expect(conversation.cached_label_list_array).to eq %w[customer-support enterprise paid-customer]
|
||||
end
|
||||
end
|
||||
|
||||
describe '#last_activity_at' do
|
||||
let(:conversation) { create(:conversation) }
|
||||
let(:message_params) do
|
||||
{
|
||||
conversation: conversation,
|
||||
account: conversation.account,
|
||||
inbox: conversation.inbox,
|
||||
sender: conversation.assignee
|
||||
}
|
||||
end
|
||||
|
||||
context 'when a new conversation is created' do
|
||||
it 'sets last_activity_at to the created_at time' do
|
||||
expect(conversation.last_activity_at).to eq(conversation.created_at)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when a new message is added' do
|
||||
it 'updates the last_activity_at to the new message\'s created_at time' do
|
||||
message = create(:message, created_at: 1.hour.from_now, **message_params)
|
||||
conversation.reload
|
||||
expect(conversation.last_activity_at).to be_within(1.second).of(message.created_at)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when multiple messages are added' do
|
||||
it 'sets last_activity_at to the most recent message\'s created_at time' do
|
||||
create(:message, created_at: 2.hours.ago, **message_params)
|
||||
latest_message = create(:message, created_at: 1.hour.from_now, **message_params)
|
||||
conversation.reload
|
||||
expect(conversation.last_activity_at).to be_within(1.second).of(latest_message.created_at)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -37,7 +37,7 @@ RSpec.describe Integrations::Hook do
|
||||
|
||||
it 'returns no processor found for hooks with out processor defined' do
|
||||
hook = create(:integrations_hook, account: account)
|
||||
expect(hook.process_event(params)).to eq('No processor found')
|
||||
expect(hook.process_event(params)).to eq({ :error => 'No processor found' })
|
||||
end
|
||||
|
||||
it 'returns results from procesor for openai hook' do
|
||||
|
||||
Reference in New Issue
Block a user