diff --git a/app/jobs/helpscout_create_conversation_job.rb b/app/jobs/helpscout_create_conversation_job.rb index f12cab839..a0f3801ea 100644 --- a/app/jobs/helpscout_create_conversation_job.rb +++ b/app/jobs/helpscout_create_conversation_job.rb @@ -29,7 +29,7 @@ class HelpscoutCreateConversationJob < ApplicationJob def create_conversation response = api.create_conversation( - contact_form.email, + contact_form.email.presence || contact_form.user.email, contact_form.subject, contact_form.text, safe_blob diff --git a/spec/jobs/helpscout_create_conversation_job_spec.rb b/spec/jobs/helpscout_create_conversation_job_spec.rb index 5b45084f4..054166703 100644 --- a/spec/jobs/helpscout_create_conversation_job_spec.rb +++ b/spec/jobs/helpscout_create_conversation_job_spec.rb @@ -8,7 +8,8 @@ RSpec.describe HelpscoutCreateConversationJob, type: :job do let(:tags) { ["first tag"] } let(:question_type) { "lost" } let(:phone) { nil } - let(:contact_form) { create(:contact_form, email:, subject: subject_text, text:, tags:, phone:, question_type:) } + let(:user) { nil } + let(:contact_form) { create(:contact_form, email:, user:, subject: subject_text, text:, tags:, phone:, question_type:) } describe '#perform' do before do @@ -82,5 +83,15 @@ RSpec.describe HelpscoutCreateConversationJob, type: :job do expect(api).to have_received(:add_phone_number).with(email, phone) end end + + context 'attached to an user' do + let(:email) { nil } + let(:user) { users(:default_user) } + + it 'associates the email from user' do + subject + expect(api).to have_received(:create_conversation).with(user.email, subject_text, text, nil) + end + end end end