Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions app/services/invitation_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ def send_event_emails(event, chapter)

invite_coaches_to_event(event, chapter) unless event.audience.eql?('Students')
invite_students_to_event(event, chapter) unless event.audience.eql?('Coaches')
rescue StandardError => e
Rollbar.error(e, event_id: event.id, chapter_id: chapter.id)
raise
end
handle_asynchronously :send_event_emails

Expand Down Expand Up @@ -120,7 +123,7 @@ def invite_students_to_event(event, chapter)
invitation = Invitation.new(event: event, member: student, role: 'Student')
next unless invitation.save

EventInvitationMailer.invite_student(event, student, invitation).deliver_now
EventInvitationMailer.invite_student(event, student, invitation).deliver_later
rescue StandardError => e
log_event_meeting_invitation_failure("event_id=#{event.id}", student, e)
end
Expand All @@ -131,7 +134,7 @@ def invite_coaches_to_event(event, chapter)
invitation = Invitation.new(event: event, member: coach, role: 'Coach')
next unless invitation.save

EventInvitationMailer.invite_coach(event, coach, invitation).deliver_now
EventInvitationMailer.invite_coach(event, coach, invitation).deliver_later
rescue StandardError => e
log_event_meeting_invitation_failure("event_id=#{event.id}", coach, e)
end
Expand Down
21 changes: 21 additions & 0 deletions spec/services/invitation_manager_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,27 @@

manager.send_event_emails(event, chapter)
end

it 'sends invitation emails for all eligible members' do
event = Fabricate(:event, chapters: [chapter])

expect do
manager.send_event_emails(event, chapter)
end.to change { ActionMailer::Base.deliveries.count }.by(students.count + coaches.count)
end

it 'reports batch-level failures to Rollbar' do
event = Fabricate(:event, chapters: [chapter])
allow(event).to receive(:invitable?).and_raise(StandardError.new('DB connection error'))

expect(Rollbar).to receive(:error).with(
an_instance_of(StandardError),
event_id: event.id,
chapter_id: chapter.id
)

expect { manager.send_event_emails(event, chapter) }.to raise_error(StandardError, 'DB connection error')
end
end

describe '#send_monthly_attendance_reminder_emails' do
Expand Down