From 64c7721746a97bbf1db66786986c82d27e883aa3 Mon Sep 17 00:00:00 2001 From: baarkerlounger Date: Wed, 18 May 2022 14:51:25 +0100 Subject: [PATCH] Add test for resend invite flow --- .../auth/confirmations_controller_spec.rb | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/spec/requests/auth/confirmations_controller_spec.rb b/spec/requests/auth/confirmations_controller_spec.rb index 8e1544b0a..c6264f24f 100644 --- a/spec/requests/auth/confirmations_controller_spec.rb +++ b/spec/requests/auth/confirmations_controller_spec.rb @@ -5,6 +5,7 @@ RSpec.describe Auth::ConfirmationsController, type: :request do let(:page) { Capybara::Node::Simple.new(response.body) } let(:notify_client) { instance_double(Notifications::Client) } let(:devise_notify_mailer) { DeviseNotifyMailer.new } + let(:user) { FactoryBot.create(:user, :data_provider, sign_in_count: 0, confirmed_at: nil) } before do allow(DeviseNotifyMailer).to receive(:new).and_return(devise_notify_mailer) @@ -13,8 +14,6 @@ RSpec.describe Auth::ConfirmationsController, type: :request do end context "when a confirmation link is clicked by a new user" do - let(:user) { FactoryBot.create(:user, :data_provider, sign_in_count: 0, confirmed_at: nil) } - before do user.send_confirmation_instructions get "/account/confirmation?confirmation_token=#{user.confirmation_token}" @@ -29,4 +28,21 @@ RSpec.describe Auth::ConfirmationsController, type: :request do expect(page).to have_content(I18n.t("user.create_password")) end end + + context "when the token has expired" do + let(:period) { Devise::TimeInflector.time_ago_in_words(User.confirm_within.ago) } + + before do + user.send_confirmation_instructions + allow(User).to receive(:find_first_by_auth_conditions).and_return(user) + allow(user).to receive(:confirmation_period_expired?).and_return(true) + get "/account/confirmation?confirmation_token=#{user.confirmation_token}" + end + + it "shows the Resend Invitation page" do + expect(page).to have_selector("#error-summary-title") + expect(page).to have_content(I18n.t("errors.messages.confirmation_period_expired", period:)) + expect(page).to have_content("Resend invitation link") + end + end end