Browse Source

CLDC-2328: Email test refactor.

pull/1680/head
Aaron Spencer 3 years ago
parent
commit
b3935315ce
  1. 66
      spec/features/user_spec.rb
  2. 2
      spec/requests/users_controller_spec.rb

66
spec/features/user_spec.rb

@ -453,9 +453,13 @@ RSpec.describe "User Features" do
end end
end end
context "when reinviting a user after initial confirmation email has been sent" do end
let!(:other_user) { FactoryBot.create(:user, name: "new user", organisation: user.organisation, email: "new_user@example.com", initial_confirmation_sent: true) }
context "when signed in as support" do
let!(:user) { FactoryBot.create(:user, :support) }
let!(:other_user) { FactoryBot.create(:user, name: "new user", organisation: user.organisation, email: "new_user@example.com", confirmation_token: "abc") }
context "when reinviting a user before initial confirmation email has been sent" do
let(:personalisation) do let(:personalisation) do
{ {
name: "new user", name: "new user",
@ -466,25 +470,66 @@ RSpec.describe "User Features" do
end end
before do before do
other_user.update!(confirmation_token: "abc") other_user.update!(initial_confirmation_sent: false)
visit(lettings_logs_path) allow(user).to receive(:need_two_factor_authentication?).and_return(false)
fill_in("user[email]", with: user.email) sign_in(user)
fill_in("user[password]", with: "pAssword1") visit(user_path(user.id))
click_button("Sign in") end
visit("/users/#{other_user.id}")
it "sends initial confirmable template email when the resend invite link is clicked" do
other_user.legacy_users.destroy_all
visit(user_path(other_user))
expect(notify_client).to receive(:send_email).with(email_address: "new_user@example.com", template_id: User::CONFIRMABLE_TEMPLATE_ID, personalisation:).once
click_button("Resend invite link")
end
end
context "when reinviting a user after initial confirmation email has been sent" do
let(:personalisation) do
{
name: "new user",
email: "new_user@example.com",
organisation: other_user.organisation.name,
link: include("/account/confirmation?confirmation_token=#{other_user.confirmation_token}"),
}
end
before do
other_user.update!(initial_confirmation_sent: true)
allow(user).to receive(:need_two_factor_authentication?).and_return(false)
sign_in(user)
visit(user_path(user.id))
end end
it "sends and email when the resend invite link is clicked" do it "sends and email when the resend invite link is clicked" do
other_user.legacy_users.destroy_all other_user.legacy_users.destroy_all
visit(user_path(other_user)) visit(user_path(other_user))
expect(notify_client).to receive(:send_email).with(email_address: "new_user@example.com", template_id: User::RECONFIRMABLE_TEMPLATE_ID, personalisation:).once expect(notify_client).to receive(:send_email).with(email_address: "new_user@example.com", template_id: User::RECONFIRMABLE_TEMPLATE_ID, personalisation:).once
click_link("Resend invite link") click_button("Resend invite link")
end
end
context "when reinviting a legacy user" do
let(:personalisation) do
{
name: "new user",
email: "new_user@example.com",
organisation: other_user.organisation.name,
link: include("/account/confirmation?confirmation_token=#{other_user.confirmation_token}"),
}
end
before do
other_user.update!(initial_confirmation_sent: true)
allow(user).to receive(:need_two_factor_authentication?).and_return(false)
sign_in(user)
visit(user_path(user.id))
end end
it "sends beta onboarding email to be sent when user is legacy" do it "sends beta onboarding email to be sent when user is legacy" do
visit(user_path(other_user)) visit(user_path(other_user))
expect(notify_client).to receive(:send_email).with(email_address: "new_user@example.com", template_id: User::BETA_ONBOARDING_TEMPLATE_ID, personalisation:).once expect(notify_client).to receive(:send_email).with(email_address: "new_user@example.com", template_id: User::BETA_ONBOARDING_TEMPLATE_ID, personalisation:).once
click_link("Resend invite link") click_button("Resend invite link")
end end
end end
end end
@ -685,5 +730,6 @@ RSpec.describe "User Features" do
end end
end end
end end
end end
end end

2
spec/requests/users_controller_spec.rb

@ -145,7 +145,7 @@ RSpec.describe UsersController, type: :request do
end end
it "does not allow resending invitation emails" do it "does not allow resending invitation emails" do
expect(page).not_to have_link("Resend invite link", href: "/users/#{other_user.id}/resend-invite") expect(page).not_to have_link("Resend invite link")
end end
end end
end end

Loading…
Cancel
Save