2019-04-30 10:27:42 +10:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-07-28 05:27:38 +03:00
|
|
|
RSpec.describe InviteMailer do
|
2013-02-05 14:16:51 -05:00
|
|
|
describe "send_invite" do
|
2022-07-27 18:14:14 +02:00
|
|
|
context "when inviting to site" do
|
|
|
|
context "with default invite message" do
|
2023-11-09 16:47:59 -06:00
|
|
|
fab!(:invite)
|
2016-06-05 22:52:46 +05:30
|
|
|
let(:invite_mail) { InviteMailer.send_invite(invite) }
|
2014-07-08 22:33:11 +05:30
|
|
|
|
2016-06-05 22:52:46 +05:30
|
|
|
it "renders the invitee email" do
|
|
|
|
expect(invite_mail.to).to eql([invite.email])
|
|
|
|
end
|
2014-07-08 22:33:11 +05:30
|
|
|
|
2016-06-05 22:52:46 +05:30
|
|
|
it "renders the subject" do
|
|
|
|
expect(invite_mail.subject).to be_present
|
|
|
|
end
|
2014-07-10 10:57:40 +05:30
|
|
|
|
2016-06-05 22:52:46 +05:30
|
|
|
it "renders site domain name in subject" do
|
|
|
|
expect(invite_mail.subject).to match(Discourse.current_hostname)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "renders the body" do
|
|
|
|
expect(invite_mail.body).to be_present
|
|
|
|
end
|
2014-07-08 22:33:11 +05:30
|
|
|
|
2016-06-05 22:52:46 +05:30
|
|
|
it "renders the inviter email" do
|
|
|
|
expect(invite_mail.from).to eql([SiteSetting.notification_email])
|
|
|
|
end
|
|
|
|
|
|
|
|
it "renders invite link" do
|
|
|
|
expect(invite_mail.body.encoded).to match(
|
|
|
|
"#{Discourse.base_url}/invites/#{invite.invite_key}",
|
|
|
|
)
|
|
|
|
end
|
2014-07-08 22:33:11 +05:30
|
|
|
end
|
|
|
|
|
2022-07-27 18:14:14 +02:00
|
|
|
context "with custom invite message" do
|
2019-07-05 14:51:03 -04:00
|
|
|
fab!(:invite) do
|
|
|
|
Fabricate(:invite, custom_message: "Hey, you <b>should</b> join this forum!\n\nWelcome!")
|
2023-01-09 11:18:21 +00:00
|
|
|
end
|
2016-06-05 22:52:46 +05:30
|
|
|
|
2022-07-27 18:14:14 +02:00
|
|
|
context "when custom message includes invite link" do
|
2017-06-30 16:09:37 +05:30
|
|
|
let(:custom_invite_mail) { InviteMailer.send_invite(invite) }
|
2016-06-05 22:52:46 +05:30
|
|
|
|
|
|
|
it "renders the invitee email" do
|
|
|
|
expect(custom_invite_mail.to).to eql([invite.email])
|
|
|
|
end
|
|
|
|
|
|
|
|
it "renders the subject" do
|
|
|
|
expect(custom_invite_mail.subject).to be_present
|
|
|
|
end
|
|
|
|
|
|
|
|
it "renders site domain name in subject" do
|
|
|
|
expect(custom_invite_mail.subject).to match(Discourse.current_hostname)
|
|
|
|
end
|
|
|
|
|
2016-06-08 18:04:25 +05:30
|
|
|
it "renders the body" do
|
|
|
|
expect(custom_invite_mail.body).to be_present
|
2016-06-05 22:52:46 +05:30
|
|
|
end
|
|
|
|
|
2019-07-05 14:51:03 -04:00
|
|
|
it "renders custom_message, stripping HTML" do
|
|
|
|
expect(custom_invite_mail.body.encoded).to match(
|
|
|
|
"Hey, you should join this forum! Welcome!",
|
|
|
|
)
|
2016-06-05 22:52:46 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it "renders the inviter email" do
|
|
|
|
expect(custom_invite_mail.from).to eql([SiteSetting.notification_email])
|
|
|
|
end
|
|
|
|
|
|
|
|
it "renders invite link" do
|
2016-06-08 18:04:25 +05:30
|
|
|
expect(custom_invite_mail.body.encoded).to match(
|
|
|
|
"#{Discourse.base_url}/invites/#{invite.invite_key}",
|
|
|
|
)
|
2016-06-05 22:52:46 +05:30
|
|
|
end
|
|
|
|
end
|
2014-07-08 22:33:11 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-07-27 18:14:14 +02:00
|
|
|
context "when inviting to topic" do
|
2024-01-29 17:52:02 +08:00
|
|
|
fab!(:trust_level_2)
|
2017-02-02 23:08:25 +05:30
|
|
|
let(:topic) do
|
|
|
|
Fabricate(
|
|
|
|
:topic,
|
|
|
|
excerpt: "Topic invite support is now available in Discourse!",
|
|
|
|
user: trust_level_2,
|
|
|
|
)
|
2023-01-09 11:18:21 +00:00
|
|
|
end
|
2013-02-05 14:16:51 -05:00
|
|
|
|
2022-07-27 18:14:14 +02:00
|
|
|
context "with default invite message" do
|
2018-02-26 12:46:15 +08:00
|
|
|
let(:invite) do
|
|
|
|
topic.invite(topic.user, "name@example.com")
|
|
|
|
Invite.find_by(invited_by_id: topic.user.id)
|
|
|
|
end
|
|
|
|
|
2021-03-16 17:08:54 +02:00
|
|
|
let(:invite_mail) { InviteMailer.send_invite(invite, invite_to_topic: true) }
|
2014-07-08 22:33:11 +05:30
|
|
|
|
2016-06-07 22:54:45 +05:30
|
|
|
it "renders the invitee email" do
|
|
|
|
expect(invite_mail.to).to eql(["name@example.com"])
|
|
|
|
end
|
2014-07-08 22:33:11 +05:30
|
|
|
|
2016-06-07 22:54:45 +05:30
|
|
|
it "renders the subject" do
|
|
|
|
expect(invite_mail.subject).to be_present
|
|
|
|
end
|
2014-07-10 10:03:09 +05:30
|
|
|
|
2016-06-07 22:54:45 +05:30
|
|
|
it "renders topic title in subject" do
|
|
|
|
expect(invite_mail.subject).to match(topic.title)
|
|
|
|
end
|
2014-07-10 10:03:09 +05:30
|
|
|
|
2016-06-07 22:54:45 +05:30
|
|
|
it "renders site domain name in subject" do
|
|
|
|
expect(invite_mail.subject).to match(Discourse.current_hostname)
|
|
|
|
end
|
2014-07-08 22:33:11 +05:30
|
|
|
|
2016-06-07 22:54:45 +05:30
|
|
|
it "renders the body" do
|
|
|
|
expect(invite_mail.body).to be_present
|
|
|
|
end
|
2014-07-08 22:33:11 +05:30
|
|
|
|
2016-06-07 22:54:45 +05:30
|
|
|
it "renders the inviter email" do
|
|
|
|
expect(invite_mail.from).to eql([SiteSetting.notification_email])
|
|
|
|
end
|
|
|
|
|
|
|
|
it "renders invite link" do
|
|
|
|
expect(invite_mail.body.encoded).to match(
|
|
|
|
"#{Discourse.base_url}/invites/#{invite.invite_key}",
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "renders topic title" do
|
|
|
|
expect(invite_mail.body.encoded).to match(topic.title)
|
|
|
|
end
|
2017-04-24 15:26:06 -04:00
|
|
|
|
|
|
|
it "respects the private_email setting" do
|
|
|
|
SiteSetting.private_email = true
|
|
|
|
|
|
|
|
message = invite_mail
|
|
|
|
expect(message.body.to_s).not_to include(topic.title)
|
|
|
|
expect(message.body.to_s).not_to include(topic.slug)
|
|
|
|
end
|
2014-07-08 22:33:11 +05:30
|
|
|
end
|
|
|
|
|
2022-07-27 18:14:14 +02:00
|
|
|
context "with custom invite message" do
|
2018-02-26 12:46:15 +08:00
|
|
|
let(:invite) do
|
|
|
|
topic.invite(
|
|
|
|
topic.user,
|
|
|
|
"name@example.com",
|
|
|
|
nil,
|
|
|
|
"Hey, I thought you might enjoy this topic!",
|
|
|
|
)
|
|
|
|
|
|
|
|
Invite.find_by(invited_by_id: topic.user.id)
|
|
|
|
end
|
2017-06-30 16:09:37 +05:30
|
|
|
let(:custom_invite_mail) { InviteMailer.send_invite(invite) }
|
2016-06-07 22:54:45 +05:30
|
|
|
|
|
|
|
it "renders custom_message" do
|
2016-06-08 18:04:25 +05:30
|
|
|
expect(custom_invite_mail.body.encoded).to match(
|
|
|
|
"Hey, I thought you might enjoy this topic!",
|
|
|
|
)
|
2016-06-07 22:54:45 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it "renders invite link" do
|
2016-06-08 18:04:25 +05:30
|
|
|
expect(custom_invite_mail.body.encoded).to match(
|
|
|
|
"#{Discourse.base_url}/invites/#{invite.invite_key}",
|
|
|
|
)
|
2016-06-07 22:54:45 +05:30
|
|
|
end
|
2014-07-08 22:33:11 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|