From fff578134b9f1320b794236ec056bba90bcad2bb Mon Sep 17 00:00:00 2001 From: Jack S Date: Mon, 7 Aug 2023 12:54:39 +0100 Subject: [PATCH] Use reconfirmable template only if not confirmed --- app/models/user.rb | 2 +- app/views/users/show.html.erb | 7 +++--- spec/features/user_spec.rb | 2 +- spec/mailers/resend_invitation_mailer_spec.rb | 24 ++++++++++++++++++- 4 files changed, 28 insertions(+), 7 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index 3f9f20a02..eccdaec47 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -133,7 +133,7 @@ class User < ApplicationRecord USER_REACTIVATED_TEMPLATE_ID elsif was_migrated_from_softwire? && last_sign_in_at.blank? BETA_ONBOARDING_TEMPLATE_ID - elsif initial_confirmation_sent + elsif initial_confirmation_sent && !confirmed? RECONFIRMABLE_TEMPLATE_ID else CONFIRMABLE_TEMPLATE_ID diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index 844a0c965..bcdfd02b2 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -111,12 +111,11 @@ <%= govuk_button_to "Resend invite link", resend_invite_user_path(@user), secondary: true %> <% end %> <% else %> - - This user has been deactivated. <%= govuk_button_link_to "Reactivate user", reactivate_user_path(@user) %> - + + This user has been deactivated. <%= govuk_button_link_to "Reactivate user", reactivate_user_path(@user) %> + <% end %> <% end %> - diff --git a/spec/features/user_spec.rb b/spec/features/user_spec.rb index f568ef96b..e1cb65f66 100644 --- a/spec/features/user_spec.rb +++ b/spec/features/user_spec.rb @@ -529,7 +529,7 @@ RSpec.describe "User Features" do end before do - other_user.update!(initial_confirmation_sent: true) + other_user.update!(initial_confirmation_sent: true, confirmed_at: nil) allow(user).to receive(:need_two_factor_authentication?).and_return(false) sign_in(user) visit(user_path(user.id)) diff --git a/spec/mailers/resend_invitation_mailer_spec.rb b/spec/mailers/resend_invitation_mailer_spec.rb index 02a6189d4..a5eadad20 100644 --- a/spec/mailers/resend_invitation_mailer_spec.rb +++ b/spec/mailers/resend_invitation_mailer_spec.rb @@ -57,9 +57,31 @@ RSpec.describe ResendInvitationMailer do end it "sends a reinvitation" do - expect(notify_client).to receive(:send_email).with(email_address: "active_user@example.com", template_id: User::RECONFIRMABLE_TEMPLATE_ID, personalisation:).once + expect(notify_client).to receive(:send_email).with(email_address: "active_user@example.com", template_id: User::CONFIRMABLE_TEMPLATE_ID, personalisation:).once described_class.new.resend_invitation_email(active_user) end end + + context "with unconfirmed user after the initial invitation has been sent" do + let!(:unconfirmed_user) { create(:user, organisation:, confirmation_token: "dluch", initial_confirmation_sent: true, old_user_id: "234", sign_in_count: 0, confirmed_at: nil) } + + let(:personalisation) do + { + name: unconfirmed_user.name, + email: unconfirmed_user.email, + organisation: unconfirmed_user.organisation.name, + link: include("/account/confirmation?confirmation_token=#{unconfirmed_user.confirmation_token}"), + } + end + + before do + LegacyUser.destroy_all + end + + it "sends a reinvitation" do + expect(notify_client).to receive(:send_email).with(email_address: unconfirmed_user.email, template_id: User::RECONFIRMABLE_TEMPLATE_ID, personalisation:).once + described_class.new.resend_invitation_email(unconfirmed_user) + end + end end end