Commit cc92b94a authored by Alex Buijs's avatar Alex Buijs

Add Member#send_invitation_reminder method

For use in the invitation reminder emails worker
parent 58f318e0
......@@ -370,6 +370,14 @@ class Member < ApplicationRecord
send_invite
end
def send_invitation_reminder(reminder_index)
return unless invite?
generate_invite_token! unless @raw_invite_token
run_after_commit_or_now { notification_service.invite_member_reminder(self, @raw_invite_token, reminder_index) }
end
def create_notification_setting
user.notification_settings.find_or_create_for(source)
end
......
......@@ -676,6 +676,45 @@ RSpec.describe Member do
end
end
describe '#send_invitation_reminder' do
subject { member.send_invitation_reminder(0) }
context 'an invited group member' do
let!(:member) { create(:group_member, :invited) }
it 'sends a reminder' do
expect_any_instance_of(NotificationService).to receive(:invite_member_reminder).with(member, member.raw_invite_token, 0)
subject
end
end
context 'an invited member without a raw invite token set' do
let!(:member) { create(:group_member, :invited) }
before do
member.instance_variable_set(:@raw_invite_token, nil)
allow_any_instance_of(NotificationService).to receive(:invite_member_reminder)
end
it 'generates a new token' do
expect(member).to receive(:generate_invite_token!)
subject
end
end
context 'an uninvited member' do
let!(:member) { create(:group_member) }
it 'does not send a reminder' do
expect_any_instance_of(NotificationService).not_to receive(:invite_member_reminder)
subject
end
end
end
describe "#invite_to_unknown_user?" do
subject { member.invite_to_unknown_user? }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment