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
context "when reinviting a user after initial confirmation email has been sent" do
let!(:other_user) { FactoryBot.create(:user, name: "new user", organisation: user.organisation, email: "new_user@example.com", initial_confirmation_sent: true) }
end
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
{
name: "new user",
@ -466,25 +470,66 @@ RSpec.describe "User Features" do
end
before do
other_user.update!(confirmation_token: "abc")
visit(lettings_logs_path)
fill_in("user[email]", with: user.email)
fill_in("user[password]", with: "pAssword1")
click_button("Sign in")
visit("/users/#{other_user.id}")
other_user.update!(initial_confirmation_sent: false)
allow(user).to receive(:need_two_factor_authentication?).and_return(false)
sign_in(user)
visit(user_path(user.id))
end
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
it "sends and 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::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
it "sends beta onboarding email to be sent when user is legacy" do
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
click_link("Resend invite link")
click_button("Resend invite link")
end
end
end
@ -685,5 +730,6 @@ RSpec.describe "User Features" do
end
end
end
end
end

2
spec/requests/users_controller_spec.rb

@ -145,7 +145,7 @@ RSpec.describe UsersController, type: :request do
end
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

Loading…
Cancel
Save