From b77fad52fb35f028f61ae9646b710825d3fd822c Mon Sep 17 00:00:00 2001 From: Pranav Raj S Date: Fri, 18 Mar 2022 13:43:02 +0530 Subject: [PATCH] fix: Add missing contact information to fix invalid activity messages (#4195) Co-authored-by: Tejaswini --- .../api/v1/widget/conversations_controller.rb | 2 +- app/controllers/concerns/website_token_helper.rb | 2 ++ .../api/v1/widget/conversations_controller_spec.rb | 10 ++++++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/v1/widget/conversations_controller.rb b/app/controllers/api/v1/widget/conversations_controller.rb index e2ee61424..cc1b16b75 100644 --- a/app/controllers/api/v1/widget/conversations_controller.rb +++ b/app/controllers/api/v1/widget/conversations_controller.rb @@ -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 diff --git a/app/controllers/concerns/website_token_helper.rb b/app/controllers/concerns/website_token_helper.rb index b59f70a17..0158a4107 100644 --- a/app/controllers/concerns/website_token_helper.rb +++ b/app/controllers/concerns/website_token_helper.rb @@ -14,6 +14,8 @@ module WebsiteTokenHelper ) @contact = @contact_inbox&.contact raise ActiveRecord::RecordNotFound unless @contact + + Current.contact = @contact end def permitted_params diff --git a/spec/controllers/api/v1/widget/conversations_controller_spec.rb b/spec/controllers/api/v1/widget/conversations_controller_spec.rb index 13239d820..f6e0ce00f 100644 --- a/spec/controllers/api/v1/widget/conversations_controller_spec.rb +++ b/spec/controllers/api/v1/widget/conversations_controller_spec.rb @@ -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