diff --git a/spec/controllers/workshop_invitation_controller_spec.rb b/spec/controllers/workshop_invitation_controller_spec.rb index 1d494754d..2e8a3762e 100644 --- a/spec/controllers/workshop_invitation_controller_spec.rb +++ b/spec/controllers/workshop_invitation_controller_spec.rb @@ -8,6 +8,13 @@ before { login(member) } + # The invitation mailer sends multipart/mixed > multipart/alternative > text/html; + # the root body is empty, so read the nested html part. + def html_body(mail) + parts = mail.parts.flat_map { |part| part.multipart? ? part.parts : [part] } + parts.find { |part| part.content_type.match?('text/html') }&.body&.decoded + end + describe 'GET #show' do it 'returns http success' do get :show, params: { id: invitation.token } @@ -181,6 +188,27 @@ post :reject, params: { id: invitation.token } expect(waitlisted_invitation.reload.attending).to be true end + + it 'emails the promoted member a confirmation they are attending' do + post :reject, params: { id: invitation.token } + + mail = ActionMailer::Base.deliveries.find { |m| m.to.include?(waitlisted_member.email) } + expect(mail).not_to be_nil + expect(html_body(mail)).to include('been confirmed') + end + + it 'sends the promotion variant of the email (waiting-list flag set)' do + post :reject, params: { id: invitation.token } + + mail = ActionMailer::Base.deliveries.find { |m| m.to.include?(waitlisted_member.email) } + expect(html_body(mail)).to include('A spot became available and your attendance has now been confirmed!') + end + + it 'does not email anyone else (the rejecting member gets no promotion copy)' do + expect do + post :reject, params: { id: invitation.token } + end.to change { ActionMailer::Base.deliveries.count }.by(1) + end end context 'when a coach is waitlisted and a student seat frees up' do