Skip to content

Commit 2e74ff7

Browse files
committed
Remove re-invitation tests and simplify user invitation logic in CustomDeviseMailer specs
1 parent eaf1f98 commit 2e74ff7

1 file changed

Lines changed: 6 additions & 81 deletions

File tree

spec/mailers/custom_devise_mailer_spec.rb

Lines changed: 6 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
RSpec.describe CustomDeviseMailer, type: :mailer do
22
describe "#invitation_instructions" do
33
let(:user) { create(:partner_user) }
4-
let(:invitation_sent_at) { nil }
4+
# let(:invitation_sent_at) { nil }
55
let(:mail) { described_class.invitation_instructions(user, SecureRandom.uuid) }
66

77
context "when partner is invited" do
@@ -14,7 +14,7 @@
1414
end
1515

1616
let(:user) do
17-
create(:partner_user, partner: partner, invitation_sent_at: invitation_sent_at)
17+
create(:partner_user, partner: partner)
1818
end
1919

2020
it "invites to primary user" do
@@ -26,96 +26,21 @@
2626

2727
context "when other partner users invited" do
2828
let(:partner) { create(:partner) }
29-
let(:user) { create(:partner_user, partner: partner, invitation_sent_at: invitation_sent_at) }
29+
let(:user) { create(:partner_user, partner: partner) }
3030

3131
it "invites to partner user" do
3232
expect(mail.subject).to eq("You've been invited to #{user.partner.name}'s Human Essentials account")
3333
expect(mail.html_part.body).to include("You've been invited to <strong>#{user.partner.name}'s</strong> account for requesting items from <strong>#{user.partner.organization.name}!")
3434
end
3535
end
3636

37-
context "when user is re-invited" do
37+
context "when user is invited" do
3838
let(:invitation_sent_at) { Time.zone.now }
3939
let(:user) { create(:user, invitation_sent_at: invitation_sent_at) }
40-
let(:role_name) { "org_user" }
4140

4241
it "invites to user" do
43-
expect(mail.subject).to eq("You've been re-invited to be a #{role_name} in your Human Essentials App Account")
44-
expect(mail.html_part.body).to include("You've been re-invited to become a <strong>#{role_name}</strong> in your Human Essentials App Account")
45-
end
46-
47-
it "has invite expiration message and reset instructions" do
48-
expect(mail.html_part.body).to include("This invitation will expire at #{user.invitation_due_at.strftime("%B %d, %Y %I:%M %p")} GMT or if a new password reset is triggered.")
49-
end
50-
51-
it "has reset instructions" do
52-
expect(mail.html_part.body).to match(%r{<p>If your invitation has an expired message, go <a href="http://.+?/users/password/new">here</a> and enter your email address to reset your password.</p>})
53-
expect(mail.html_part.body).to include("Feel free to ignore this email if you are not interested or if you feel it was sent by mistake.")
54-
end
55-
end
56-
57-
context "when partner is re-invited" do
58-
let(:invitation_sent_at) { Time.zone.now }
59-
let(:user) { create(:partner_user, invitation_sent_at: invitation_sent_at) }
60-
let(:role_name) { "partner" }
61-
62-
it "invites to user" do
63-
expect(mail.subject).to eq("You've been re-invited to be a #{role_name} in your Human Essentials App Account")
64-
expect(mail.html_part.body).to include("You've been re-invited to become a <strong>#{role_name}</strong> in your Human Essentials App Account")
65-
end
66-
67-
it "has invite expiration message and reset instructions" do
68-
expect(mail.html_part.body).to include("This invitation will expire at #{user.invitation_due_at.strftime("%B %d, %Y %I:%M %p")} GMT or if a new password reset is triggered.")
69-
end
70-
71-
it "has reset instructions" do
72-
expect(mail.html_part.body).to match(%r{<p>If your invitation has an expired message, go <a href="http://.+?/users/password/new">here</a> and enter your email address to reset your password.</p>})
73-
expect(mail.html_part.body).to include("Feel free to ignore this email if you are not interested or if you feel it was sent by mistake.")
74-
end
75-
end
76-
77-
context "when user is re-invited and has two roles" do
78-
let(:invitation_sent_at) { Time.zone.now }
79-
let(:user) { create(:partner_user, invitation_sent_at: invitation_sent_at) }
80-
let(:role_name) { "org_user" }
81-
let(:organization) { create(:organization) }
82-
83-
it "invites to user" do
84-
user.add_role(Role::ORG_USER, organization)
85-
expect(mail.subject).to eq("You've been re-invited to be a #{role_name} in your Human Essentials App Account")
86-
expect(mail.html_part.body).to include("You've been re-invited to become a <strong>#{role_name}</strong> in your Human Essentials App Account")
87-
end
88-
89-
it "has invite expiration message and reset instructions" do
90-
expect(mail.html_part.body).to include("This invitation will expire at #{user.invitation_due_at.strftime("%B %d, %Y %I:%M %p")} GMT or if a new password reset is triggered.")
91-
end
92-
93-
it "has reset instructions" do
94-
expect(mail.html_part.body).to match(%r{<p>If your invitation has an expired message, go <a href="http://.+?/users/password/new">here</a> and enter your email address to reset your password.</p>})
95-
expect(mail.html_part.body).to include("Feel free to ignore this email if you are not interested or if you feel it was sent by mistake.")
96-
end
97-
end
98-
99-
context "when user is re-invited and has three roles" do
100-
let(:invitation_sent_at) { Time.zone.now }
101-
let(:user) { create(:partner_user, invitation_sent_at: invitation_sent_at) }
102-
let(:role_name) { "org_admin" }
103-
let(:organization) { create(:organization) }
104-
105-
it "invites to user" do
106-
user.add_role(Role::ORG_ADMIN, organization)
107-
user.add_role(Role::ORG_USER, organization)
108-
expect(mail.subject).to eq("You've been re-invited to be a #{role_name} in your Human Essentials App Account")
109-
expect(mail.html_part.body).to include("You've been re-invited to become a <strong>#{role_name}</strong> in your Human Essentials App Account")
110-
end
111-
112-
it "has invite expiration message and reset instructions" do
113-
expect(mail.html_part.body).to include("This invitation will expire at #{user.invitation_due_at.strftime("%B %d, %Y %I:%M %p")} GMT or if a new password reset is triggered.")
114-
end
115-
116-
it "has reset instructions" do
117-
expect(mail.html_part.body).to match(%r{<p>If your invitation has an expired message, go <a href="http://.+?/users/password/new">here</a> and enter your email address to reset your password.</p>})
118-
expect(mail.html_part.body).to include("Feel free to ignore this email if you are not interested or if you feel it was sent by mistake.")
42+
expect(mail.subject).to eq("Your Human Essentials App Account Approval")
43+
expect(mail.html_part.body).to include("Your request has been approved and you're invited to become an user of the Human Essentials inventory management system!")
11944
end
12045
end
12146
end

0 commit comments

Comments
 (0)