Skip to content

Commit

Permalink
Merge pull request #1508 from yeti-switch/YETI-WEB-1395-AccountBalanc…
Browse files Browse the repository at this point in the history
…eNotify

allow to ContactEmailSender to create email log even when there is SMTP setting
  • Loading branch information
dmitry-sinina authored Jul 17, 2024
2 parents f58e84c + 0e052ab commit d80346a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 2 additions & 0 deletions app/domain/contact_email_sender.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ def initialize(contact)
# @param message [String,nil]
# @param attachments [Array<Notification::Attachment,nil]
def send_email(subject:, message: nil, attachments: nil)
return if contact.smtp_connection.nil?

ApplicationRecord.transaction do
email_log = create_email_log(
subject: subject,
Expand Down
15 changes: 14 additions & 1 deletion spec/domain/contact_email_sender_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
expect { subject }.to change { Log::EmailLog.count }.by(1)
email_log = Log::EmailLog.last!
expect(email_log).to have_attributes(expected_email_log_attrs)
expect(Worker::SendEmailLogJob).to have_been_enqueued.with(email_log.id)
end

it 'enqueues Worker::SendEmailLogJob' do
Expand Down Expand Up @@ -99,13 +98,27 @@

include_examples :creates_email_log
end

context 'when there is NO any SMTP connection' do
let(:global_smtp_connection) { nil }

it 'should NOT create Email Log' do
expect { subject }.not_to change(Log::EmailLog, :count)
end

it 'should NOT enqueue Job' do
subject
expect(Worker::SendEmailLogJob).not_to have_been_enqueued
end
end
end

describe '.batch_send_emails' do
subject do
described_class.batch_send_emails(contacts, **service_params)
end

let!(:global_smtp_conn) { FactoryBot.create(:smtp_connection, global: true) }
let!(:contacts) do
[
FactoryBot.create(:contact, contractor: FactoryBot.create(:customer)),
Expand Down

0 comments on commit d80346a

Please sign in to comment.