From 9d1f07727f0d0c18cc873f0dcc23645f8f2a617f Mon Sep 17 00:00:00 2001 From: baarkerlounger Date: Wed, 18 May 2022 13:07:21 +0100 Subject: [PATCH] Test redirect and text --- .../devise/passwords/reset_password.html.erb | 2 +- config/locales/en.yml | 3 ++ .../auth/confirmations_controller_spec.rb | 32 +++++++++++++++++++ .../auth/passwords_controller_spec.rb | 2 +- 4 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 spec/requests/auth/confirmations_controller_spec.rb diff --git a/app/views/devise/passwords/reset_password.html.erb b/app/views/devise/passwords/reset_password.html.erb index c0b157dae..307876386 100644 --- a/app/views/devise/passwords/reset_password.html.erb +++ b/app/views/devise/passwords/reset_password.html.erb @@ -1,4 +1,4 @@ -<% content_for :title, @confirmation ? "Set your password" : "Reset your password" %> +<% content_for :title, @confirmation ? I18n.t("user.create_password") : I18n.t("user.reset_password") %> <% content_for :before_content do %> <%= govuk_back_link( diff --git a/config/locales/en.yml b/config/locales/en.yml index 9df3a1083..367a11658 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -34,6 +34,9 @@ en: feedback_form: "https://forms.office.com/Pages/ResponsePage.aspx?id=EGg0v32c3kOociSi7zmVqC4YDsCJ3llAvEZelBFBLUBURFVUTzFDTUJPQlM4M0laTE5DTlNFSjJBQi4u" organisation: updated: "Organisation details updated" + user: + create_password: "Create a password to finish setting up your account" + reset_password: "Reset your password" validations: other_field_missing: "If %{main_field_label} is other then %{other_field_label} must be provided" diff --git a/spec/requests/auth/confirmations_controller_spec.rb b/spec/requests/auth/confirmations_controller_spec.rb new file mode 100644 index 000000000..8e1544b0a --- /dev/null +++ b/spec/requests/auth/confirmations_controller_spec.rb @@ -0,0 +1,32 @@ +require "rails_helper" +require_relative "../../support/devise" + +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 } + + before do + allow(DeviseNotifyMailer).to receive(:new).and_return(devise_notify_mailer) + allow(devise_notify_mailer).to receive(:notify_client).and_return(notify_client) + allow(notify_client).to receive(:send_email).and_return(true) + 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}" + end + + it "marks the user as confirmed" do + expect(user.reload.confirmed_at).to be_a(Time) + end + + it "redirects to the set password page" do + follow_redirect! + expect(page).to have_content(I18n.t("user.create_password")) + end + end +end diff --git a/spec/requests/auth/passwords_controller_spec.rb b/spec/requests/auth/passwords_controller_spec.rb index 3bb285244..0615e8257 100644 --- a/spec/requests/auth/passwords_controller_spec.rb +++ b/spec/requests/auth/passwords_controller_spec.rb @@ -87,7 +87,7 @@ RSpec.describe Auth::PasswordsController, type: :request do it "renders the user edit password view" do _raw, enc = Devise.token_generator.generate(AdminUser, :reset_password_token) get "/admin/password/edit?reset_password_token=#{enc}" - expect(page).to have_css("h1", text: "Reset your password") + expect(page).to have_css("h1", text: I18n.t("user.reset_password")) end context "when passwords entered don't match" do