diff --git a/app/controllers/organizations/contributors_controller.rb b/app/controllers/organizations/contributors_controller.rb index 0528451d7..c6befa1e6 100644 --- a/app/controllers/organizations/contributors_controller.rb +++ b/app/controllers/organizations/contributors_controller.rb @@ -18,6 +18,7 @@ def message text = message_params[:text] message = Message.create!(text: text, request: request, recipient: contributor, sender: current_user) + message.send! redirect_to message.chat_message_link, flash: { success: I18n.t('contributor.message-send', name: contributor.name) } end diff --git a/spec/requests/contributors_spec.rb b/spec/requests/contributors_spec.rb index b24589217..ac0b37761 100644 --- a/spec/requests/contributors_spec.rb +++ b/spec/requests/contributors_spec.rb @@ -252,7 +252,7 @@ describe 'given a contributor of the organization' do let(:params) { {} } - let(:contributor) { create(:contributor, organization: organization, **params) } + let(:contributor) { create(:contributor, :telegram_contributor, organization: organization, **params) } describe 'response' do before(:each) { subject.call } @@ -267,10 +267,20 @@ describe 'response' do before(:each) { subject.call } let(:newest_message) { Message.reorder(created_at: :desc).first } + it do expect(response) .to redirect_to(newest_message.chat_message_link) end + + it 'schedules a job to send out the message' do + expect(TelegramAdapter::Outbound::Text).to have_been_enqueued.with( + organization_id: newest_message.organization.id, + contributor_id: newest_message.recipient.id, + text: newest_message.text, + message: newest_message + ) + end end end end