discourse/spec/jobs/invite_email_spec.rb
Dan Ungureanu fb19ee9eee
FIX: Correctly use invite to topic email templates (#12411)
It was used both when inviting from a topic page and when creating
invites with "Send to topic on first login", while it should be used
only in the former case.
2021-03-16 17:08:54 +02:00

41 lines
1.2 KiB
Ruby

# frozen_string_literal: true
require 'rails_helper'
describe Jobs::InviteEmail do
context '.execute' do
it 'raises an error when the invite_id is missing' do
expect { Jobs::InviteEmail.new.execute({}) }.to raise_error(Discourse::InvalidParameters)
end
context 'with an invite id' do
let (:mailer) { Mail::Message.new(to: 'eviltrout@test.domain') }
fab!(:invite) { Fabricate(:invite) }
it 'delegates to the test mailer' do
Email::Sender.any_instance.expects(:send)
InviteMailer.expects(:send_invite).with(invite, anything).returns(mailer)
Jobs::InviteEmail.new.execute(invite_id: invite.id)
end
it "aborts without error when the invite doesn't exist anymore" do
invite.destroy
InviteMailer.expects(:send_invite).never
Jobs::InviteEmail.new.execute(invite_id: invite.id)
end
it "updates invite emailed_status" do
invite.emailed_status = Invite.emailed_status_types[:pending]
invite.save!
Jobs::InviteEmail.new.execute(invite_id: invite.id)
invite.reload
expect(invite.emailed_status).to eq(Invite.emailed_status_types[:sent])
end
end
end
end