From 34695276379659316e965bdd46483a4d1c305d3f Mon Sep 17 00:00:00 2001 From: Colin Darie Date: Thu, 1 Aug 2024 16:38:39 +0200 Subject: [PATCH] fix(contact): use user email when no email was specified --- app/jobs/helpscout_create_conversation_job.rb | 2 +- spec/jobs/helpscout_create_conversation_job_spec.rb | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) 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