fix: Add missing contact information to fix invalid activity messages (#4195)

Co-authored-by: Tejaswini <tejaswini@chatwoot.com>
This commit is contained in:
Pranav Raj S
2022-03-18 13:43:02 +05:30
committed by GitHub
parent 40f31cb0a3
commit b77fad52fb
3 changed files with 13 additions and 1 deletions

View File

@@ -47,7 +47,7 @@ class Api::V1::Widget::ConversationsController < Api::V1::Widget::BaseController
def toggle_status
head :not_found && return if conversation.nil?
unless conversation.resolved?
conversation.status = 'resolved'
conversation.status = :resolved
conversation.save
end
head :ok

View File

@@ -14,6 +14,8 @@ module WebsiteTokenHelper
)
@contact = @contact_inbox&.contact
raise ActiveRecord::RecordNotFound unless @contact
Current.contact = @contact
end
def permitted_params

View File

@@ -123,6 +123,7 @@ RSpec.describe '/api/v1/widget/conversations/toggle_typing', type: :request do
context 'when user end conversation from widget' do
it 'resolves the conversation' do
expect(conversation.open?).to be true
get '/api/v1/widget/conversations/toggle_status',
headers: { 'X-Auth-Token' => token },
params: { website_token: web_widget.website_token },
@@ -130,6 +131,15 @@ RSpec.describe '/api/v1/widget/conversations/toggle_typing', type: :request do
expect(response).to have_http_status(:success)
expect(conversation.reload.resolved?).to be true
expect(Conversations::ActivityMessageJob).to have_been_enqueued.at_least(:once).with(
conversation,
{
account_id: conversation.account_id,
inbox_id: conversation.inbox_id,
message_type: :activity,
content: "Conversation was resolved by #{contact.name}"
}
)
end
end
end