Skip to content

Commit

Permalink
Actually send out direct message after creation (#2056)
Browse files Browse the repository at this point in the history
Fixes #2054
  • Loading branch information
mattwr18 authored Oct 9, 2024
1 parent b8baad3 commit 078227b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/controllers/organizations/contributors_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 11 additions & 1 deletion spec/requests/contributors_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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
Expand Down

0 comments on commit 078227b

Please sign in to comment.