diff --git a/app/controllers/journeys/additional_payments_for_teaching/reminders_controller.rb b/app/controllers/journeys/additional_payments_for_teaching/reminders_controller.rb deleted file mode 100644 index 8c75859477..0000000000 --- a/app/controllers/journeys/additional_payments_for_teaching/reminders_controller.rb +++ /dev/null @@ -1,96 +0,0 @@ -module Journeys - module AdditionalPaymentsForTeaching - class RemindersController < BasePublicController - include PartOfClaimJourney - - after_action :clear_sessions, only: :show - helper_method :current_reminder - - include FormSubmittable - include RemindersFormCallbacks - - private - - def load_form_if_exists - @form ||= AdditionalPaymentsForTeaching::FORMS.dig( - "reminders", params[:slug] - )&.new(reminder: current_reminder, journey: Journeys::AdditionalPaymentsForTeaching, journey_session:, params:) - end - - def slugs - journey.slug_sequence::REMINDER_SLUGS - end - - def next_slug - slugs[current_slug_index + 1] - end - - def current_slug - slugs[current_slug_index] - end - - def current_slug_index - slugs.index(params[:slug]) || 0 - end - - def current_template - "reminders/#{current_slug.underscore}" - end - - def current_reminder - @current_reminder ||= - reminder_from_session || - build_reminder_from_claim || - default_reminder - end - - def reminder_from_session - return unless answers&.reminder_id - - Reminder.find(answers.reminder_id) - end - - def submitted_claim - @submitted_claim ||= Claim.includes(:eligibility).find_by(id: session[:submitted_claim_id]) - end - - def build_reminder_from_claim - return unless model_for_reminder_attributes - - Reminder.new( - full_name: model_for_reminder_attributes.full_name, - email_address: model_for_reminder_attributes.email_address, - itt_academic_year: next_academic_year, - itt_subject: model_for_reminder_attributes.eligible_itt_subject, - email_verified: model_for_reminder_attributes.email_verified? # allows the OTP to be skipped if already verified - ) - end - - # Reminders can be set for in progress and submitted claims - # We can tell if we're setting a reminder for a submitted claim as the - # journey session will be nil given that we clear it on claim submission. - def model_for_reminder_attributes - @model_for_reminder_attributes ||= answers || submitted_claim - end - - def send_to_start? - model_for_reminder_attributes.nil? - end - - # Fallback reminder will set reminder date to the next academic year - def default_reminder - Reminder.new(itt_academic_year: next_academic_year) - end - - def next_academic_year - journey_configuration.current_academic_year + 1 - end - - def clear_sessions - return unless current_slug == "set" - - session.delete(journey_session_key) - end - end - end -end diff --git a/app/controllers/journeys/additional_payments_for_teaching/reminders_form_callbacks.rb b/app/controllers/journeys/additional_payments_for_teaching/reminders_form_callbacks.rb deleted file mode 100644 index fe5c115279..0000000000 --- a/app/controllers/journeys/additional_payments_for_teaching/reminders_form_callbacks.rb +++ /dev/null @@ -1,81 +0,0 @@ -module Journeys - module AdditionalPaymentsForTeaching - module RemindersFormCallbacks - def personal_details_before_show - try_mailer { set_a_reminder_immediately_if_possible } - end - - def email_verification_before_show - try_mailer { set_a_reminder_immediately_if_possible } - end - - def email_verification_before_update - inject_sent_one_time_password_at_into_the_form - end - - def personal_details_after_form_save_success - answers.reminder_id = current_reminder.to_param - answers.email_verification_secret = ROTP::Base32.random - journey_session.save! - try_mailer { send_verification_email } || return - redirect_to_next_slug - end - - def email_verification_after_form_save_success - try_mailer { send_reminder_set_email } || return - redirect_to_next_slug - end - - private - - def set_a_reminder_immediately_if_possible - return if current_reminder.persisted? - - if current_reminder.email_verified? && current_reminder.save - ReminderMailer.reminder_set(current_reminder).deliver_now - - redirect_to reminder_path(current_journey_routing_name, "set") - end - end - - def inject_sent_one_time_password_at_into_the_form - params[:form]&.[]=(:sent_one_time_password_at, session[:sent_one_time_password_at]) - end - - def send_verification_email - otp = OneTimePassword::Generator.new(secret: answers.email_verification_secret) - ReminderMailer.email_verification(current_reminder, otp.code).deliver_now - session[:sent_one_time_password_at] = Time.now - end - - def send_reminder_set_email - ReminderMailer.reminder_set(current_reminder).deliver_now - end - - def try_mailer(&block) - yield if block - true - rescue Notifications::Client::BadRequestError => e - if notify_email_error?(e.message) - render_template_for_current_slug - false - else - raise - end - end - - def notify_email_error?(msg) - case msg - when "ValidationError: email_address is a required property" - @form.errors.add(:email_address, :invalid, message: @form.i18n_errors_path(:"email_address.invalid")) - true - when "BadRequestError: Can’t send to this recipient using a team-only API key" - @form.errors.add(:email_address, :invalid, message: @form.i18n_errors_path(:"email_address.unauthorised")) - true - else - false - end - end - end - end -end diff --git a/app/controllers/reminders_controller.rb b/app/controllers/reminders_controller.rb index 057c5afc5d..fa924fd1cb 100644 --- a/app/controllers/reminders_controller.rb +++ b/app/controllers/reminders_controller.rb @@ -4,7 +4,11 @@ class RemindersController < BasePublicController def show @form = form_from_slug - render view_file + if @form.set_reminder_from_claim + redirect_to independent_reminder_path(journey: journey::ROUTING_NAME, slug: "confirmation") + else + render view_file + end end def update @@ -70,7 +74,8 @@ def form_from_slug form_class_from_slug.new( journey_session:, journey:, - params: + params:, + session: ) end end diff --git a/app/forms/journeys/additional_payments_for_teaching/reminders/email_verification_form.rb b/app/forms/journeys/additional_payments_for_teaching/reminders/email_verification_form.rb deleted file mode 100644 index 098d921de8..0000000000 --- a/app/forms/journeys/additional_payments_for_teaching/reminders/email_verification_form.rb +++ /dev/null @@ -1,67 +0,0 @@ -module Journeys - module AdditionalPaymentsForTeaching - module Reminders - class EmailVerificationForm < Form - attribute :one_time_password - attribute :sent_one_time_password_at - - # Required for shared partial in the view - delegate :email_address, to: :answers - - validate :sent_one_time_password_must_be_valid - validate :otp_must_be_valid, if: :sent_one_time_password_at? - - def self.model_name - ActiveModel::Name.new(Form) - end - - before_validation do - self.one_time_password = one_time_password.gsub(/\D/, "") - end - - attr_reader :reminder - - def initialize(reminder:, journey_session:, journey:, params:) - @reminder = reminder - super(journey_session:, journey:, params:) - - assign_attributes(attributes_with_current_value) - end - - def save - return false unless valid? - - reminder.update!(email_verified: true) - end - - private - - def sent_one_time_password_must_be_valid - return if sent_one_time_password_at? - - errors.add(:one_time_password, i18n_errors_path(:"one_time_password.invalid")) - end - - def otp_must_be_valid - otp = OneTimePassword::Validator.new( - one_time_password, - sent_one_time_password_at, - secret: journey_session.answers.email_verification_secret - ) - - errors.add(:one_time_password, otp.warning) unless otp.valid? - end - - def sent_one_time_password_at? - sent_one_time_password_at&.to_datetime || false - rescue Date::Error - false - end - - def load_current_value(attribute) - reminder.public_send(attribute) if reminder.has_attribute?(attribute) - end - end - end - end -end diff --git a/app/forms/journeys/additional_payments_for_teaching/reminders/personal_details_form.rb b/app/forms/journeys/additional_payments_for_teaching/reminders/personal_details_form.rb deleted file mode 100644 index 5addd759af..0000000000 --- a/app/forms/journeys/additional_payments_for_teaching/reminders/personal_details_form.rb +++ /dev/null @@ -1,46 +0,0 @@ -module Journeys - module AdditionalPaymentsForTeaching - module Reminders - class PersonalDetailsForm < Form - attribute :full_name - attribute :email_address - - validates :full_name, presence: {message: i18n_error_message(:"full_name.blank")} - validates :full_name, length: {maximum: 100, message: i18n_error_message(:"full_name.length")} - - validates :email_address, presence: {message: i18n_error_message(:"email_address.blank")} - validates :email_address, format: {with: Rails.application.config.email_regexp, message: i18n_error_message(:"email_address.invalid")}, - length: {maximum: 256, message: i18n_error_message(:"email_address.length")}, if: -> { email_address.present? } - - def self.model_name - ActiveModel::Name.new(Form) - end - - attr_reader :reminder - - def initialize(reminder:, journey_session:, journey:, params:) - @reminder = reminder - super(journey_session:, journey:, params:) - - assign_attributes(attributes_with_current_value) - end - - def save - return false unless valid? - - reminder.update!(attributes) - end - - private - - def i18n_form_namespace - "reminders.#{super}" - end - - def load_current_value(attribute) - reminder.public_send(attribute) if reminder.has_attribute?(attribute) - end - end - end - end -end diff --git a/app/forms/reminders/confirmation_form.rb b/app/forms/reminders/confirmation_form.rb index 7c24e119aa..10c2f17c55 100644 --- a/app/forms/reminders/confirmation_form.rb +++ b/app/forms/reminders/confirmation_form.rb @@ -1,18 +1,44 @@ module Reminders class ConfirmationForm < Form def reminder - @reminder ||= Reminder.find_by( - full_name: journey_session.answers.reminder_full_name, - email_address: journey_session.answers.reminder_email_address, - email_verified: true, - itt_academic_year: next_academic_year.to_s - ) + @reminder ||= if submitted_claim + Reminder.find_by( + full_name: submitted_claim.full_name, + email_address: submitted_claim.email_address, + email_verified: true, + itt_subject: itt_subject_for_submitted_claim, + itt_academic_year: next_academic_year.to_s + ) + else + Reminder.find_by( + full_name: journey_session.answers.reminder_full_name, + email_address: journey_session.answers.reminder_email_address, + email_verified: true, + itt_subject:, + itt_academic_year: next_academic_year.to_s + ) + end + end + + def set_reminder_from_claim end private + def itt_subject + journey_session.answers.eligible_itt_subject + end + + def itt_subject_for_submitted_claim + submitted_claim.eligible_itt_subject + end + + def submitted_claim + Claim.find_by(id: session["submitted_claim_id"]) + end + def next_academic_year - AcademicYear.next + journey.configuration.current_academic_year + 1 end end end diff --git a/app/forms/reminders/email_verification_form.rb b/app/forms/reminders/email_verification_form.rb index a95bc6ae2b..1e6be2bc80 100644 --- a/app/forms/reminders/email_verification_form.rb +++ b/app/forms/reminders/email_verification_form.rb @@ -4,6 +4,10 @@ class EmailVerificationForm < Form validate :validate_otp_correct + def reminder_email_address + journey_session.answers.reminder_email_address + end + def save! return false if invalid? @@ -16,16 +20,24 @@ def save! full_name: journey_session.answers.reminder_full_name, email_address: journey_session.answers.reminder_email_address, email_verified: true, - itt_academic_year: next_academic_year.to_s + itt_academic_year: next_academic_year.to_s, + itt_subject: ) ReminderMailer.reminder_set(reminder).deliver_now end + def set_reminder_from_claim + end + private + def itt_subject + journey_session.answers.eligible_itt_subject + end + def next_academic_year - AcademicYear.next + journey.configuration.current_academic_year + 1 end def validate_otp_correct diff --git a/app/forms/reminders/personal_details_form.rb b/app/forms/reminders/personal_details_form.rb index 51c2296298..34963b0680 100644 --- a/app/forms/reminders/personal_details_form.rb +++ b/app/forms/reminders/personal_details_form.rb @@ -42,8 +42,36 @@ def save! journey_session.save! end + def set_reminder_from_claim + if submitted_claim.present? && submitted_claim.email_verified? + reminder = Reminder.find_or_create_by( + full_name: submitted_claim.full_name, + email_address: submitted_claim.email_address, + email_verified: true, + itt_subject: itt_subject_for_submitted_claim, + itt_academic_year: next_academic_year.to_s + ) + + ReminderMailer.reminder_set(reminder).deliver_now + else + false + end + end + private + def submitted_claim + Claim.find_by(id: session["submitted_claim_id"]) + end + + def itt_subject_for_submitted_claim + submitted_claim.eligible_itt_subject + end + + def next_academic_year + journey.configuration.current_academic_year + 1 + end + def reminder @reminder ||= Reminder.new( full_name: reminder_full_name, diff --git a/app/models/journeys/additional_payments_for_teaching.rb b/app/models/journeys/additional_payments_for_teaching.rb index 14cbaa4a3f..83c2dbafb6 100644 --- a/app/models/journeys/additional_payments_for_teaching.rb +++ b/app/models/journeys/additional_payments_for_teaching.rb @@ -27,10 +27,6 @@ module AdditionalPaymentsForTeaching "correct-school" => CorrectSchoolForm, "reset-claim" => ResetClaimForm, "select-home-address" => SelectHomeAddressForm - }, - "reminders" => { - "personal-details" => Reminders::PersonalDetailsForm, - "email-verification" => Reminders::EmailVerificationForm } }.freeze diff --git a/app/models/journeys/further_education_payments/session_answers.rb b/app/models/journeys/further_education_payments/session_answers.rb index c89fcae1aa..2a5e2779d0 100644 --- a/app/models/journeys/further_education_payments/session_answers.rb +++ b/app/models/journeys/further_education_payments/session_answers.rb @@ -26,12 +26,6 @@ class SessionAnswers < Journeys::SessionAnswers attribute :half_teaching_hours, :boolean attribute :award_amount, :decimal - # TODO: extract - attribute :reminder_full_name, :string - attribute :reminder_email_address, :string - attribute :reminder_otp_secret, :string - attribute :reminder_otp_confirmed, :boolean, default: false # whether or not they have confirmed email via otp - def policy Policies::FurtherEducationPayments end diff --git a/app/models/journeys/session_answers.rb b/app/models/journeys/session_answers.rb index 8d5afb0228..c1d973c93d 100644 --- a/app/models/journeys/session_answers.rb +++ b/app/models/journeys/session_answers.rb @@ -59,6 +59,11 @@ class SessionAnswers attribute :hmrc_validation_attempt_count, :integer attribute :reminder_id, :string + attribute :reminder_full_name, :string + attribute :reminder_email_address, :string + attribute :reminder_otp_secret, :string + attribute :reminder_otp_confirmed, :boolean, default: false # whether or not they have confirmed email via otp + def has_attribute?(name) attribute_names.include?(name.to_s) end diff --git a/app/models/policies/further_education_payments/eligibility.rb b/app/models/policies/further_education_payments/eligibility.rb index 231f27375b..33375244af 100644 --- a/app/models/policies/further_education_payments/eligibility.rb +++ b/app/models/policies/further_education_payments/eligibility.rb @@ -90,6 +90,10 @@ def provider_email verification.dig("verifier", "email") end + def eligible_itt_subject + nil + end + private def provider_and_claimant_names_match? diff --git a/app/views/additional_payments/claims/eligible_later.html.erb b/app/views/additional_payments/claims/eligible_later.html.erb index 05d00c1ca9..e85d0f1542 100644 --- a/app/views/additional_payments/claims/eligible_later.html.erb +++ b/app/views/additional_payments/claims/eligible_later.html.erb @@ -61,6 +61,6 @@ Receive a reminder email so you know when to apply. We cannot issue payments unless you apply.

- <%= link_to "Set reminder", new_reminder_path, class: "govuk-button", role: :button, data: { module: "govuk-button"} %> + <%= link_to "Set reminder", independent_reminder_path(journey: journey::ROUTING_NAME, slug: "personal-details"), class: "govuk-button", role: :button, data: { module: "govuk-button"} %> diff --git a/app/views/additional_payments/claims/future_eligibility.html.erb b/app/views/additional_payments/claims/future_eligibility.html.erb index 791614f671..da07573556 100644 --- a/app/views/additional_payments/claims/future_eligibility.html.erb +++ b/app/views/additional_payments/claims/future_eligibility.html.erb @@ -18,6 +18,6 @@ Receive a reminder email so you know when to check your eligibility and apply. We cannot issue payments unless you apply.

- <%= link_to "Set reminder", new_reminder_path, class: "govuk-button", role: :button, data: { module: "govuk-button"} %> + <%= link_to "Set reminder", independent_reminder_path(journey: journey::ROUTING_NAME, slug: "personal-details"), class: "govuk-button", role: :button, data: { module: "govuk-button"} %> diff --git a/app/views/additional_payments/reminders/_one_time_password.html.erb b/app/views/additional_payments/reminders/_one_time_password.html.erb deleted file mode 100644 index 46481dbf21..0000000000 --- a/app/views/additional_payments/reminders/_one_time_password.html.erb +++ /dev/null @@ -1,36 +0,0 @@ -
-
- Email verification - - <%= form_for @form, url: reminder_path(current_journey_routing_name), builder: GOVUKDesignSystemFormBuilder::FormBuilder do |f| %> - <%= f.govuk_error_summary %> - - <%= f.govuk_text_field :one_time_password, - autocomplete: "off", - width: 5, - label: { - text: t("one_time_password.title"), - size: "l", - tag: "h1" - }, - hint: -> do %> -

- <%= t("one_time_password.hint1_html", email_or_mobile_message: "an email", email_or_mobile_value: @form.email_address) %> -

- -

- <%= t("one_time_password.validity_duration", duration_valid: one_time_password_validity_duration) %> -

- <% end %> - -
- <%= govuk_link_to "Resend passcode (you will be sent back to the email address page)", new_reminder_path, no_visited_state: true %> -
- -
- <%= f.govuk_submit "Confirm" %> - <%= govuk_button_link_to "Change email address", new_reminder_path, secondary: true %> -
- <% end %> -
-
diff --git a/app/views/additional_payments/reminders/email_verification.html.erb b/app/views/additional_payments/reminders/email_verification.html.erb deleted file mode 100644 index 6605ea5391..0000000000 --- a/app/views/additional_payments/reminders/email_verification.html.erb +++ /dev/null @@ -1,3 +0,0 @@ -<% content_for(:page_title, page_title(t("one_time_password.title"), journey: current_journey_routing_name, show_error: @form.errors.any?)) %> - -<%= render partial: "reminders/one_time_password", locals: {current_journey_routing_name: current_journey_routing_name, show_caption: true} %> diff --git a/app/views/additional_payments/reminders/personal_details.html.erb b/app/views/additional_payments/reminders/personal_details.html.erb deleted file mode 100644 index e55bbb5e12..0000000000 --- a/app/views/additional_payments/reminders/personal_details.html.erb +++ /dev/null @@ -1,48 +0,0 @@ -<% content_for(:page_title, page_title(t("questions.personal_details"), journey: current_journey_routing_name, show_error: @form.errors.any?)) %> - -
-
- <%= form_for @form, url: reminder_path(current_journey_routing_name), builder: GOVUKDesignSystemFormBuilder::FormBuilder do |f| %> - <%= f.govuk_error_summary %> - -

- <%= t("questions.personal_details") %> -

- - <%= f.govuk_text_field :full_name, - label: { - text: t("additional_payments.reminders.full_name"), - size: "l" - }, - spellcheck: "false", autocomplete: "name" %> - - <%= f.govuk_text_field :email_address, - label: { - text: t("questions.email_address"), - size: "l" - }, - spellcheck: "false", - autocomplete: "email", - hint: -> do %> -

- Tell us the email you want us to send reminders to. - We recommend you use a non-work email address in case your circumstances change. -

- -

- To verify your email address we will send you an email with a 6-digit passcode. - You can enter the passcode on the next screen. -

- <% end %> - - <%= govuk_details(summary_text: "Get help with access codes") do %> -

- If you have any issues with the passcode, email us at: - <%= govuk_mail_to support_email_address, support_email_address -%>. -

- <% end %> - - <%= f.govuk_submit "Continue" %> - <% end %> -
-
diff --git a/app/views/additional_payments/reminders/set.html.erb b/app/views/additional_payments/reminders/set.html.erb deleted file mode 100644 index d7ac32f19e..0000000000 --- a/app/views/additional_payments/reminders/set.html.erb +++ /dev/null @@ -1,36 +0,0 @@ -<% content_for(:page_title, page_title("We have set your reminders", journey: current_journey_routing_name)) %> - -
-
-
-

We have set your reminder

-
- -

What happens next

- -

- We will send you a verification email now. If you don’t receive one, - contact us on <%= mail_to t("support_email_address"), t("support_email_address"), class: "govuk-link" %>. -

- -

When will your reminder be sent?

- -

- We will send you a reminder by email in September <%= current_reminder.send_year -%>. You will be able to check your eligibility and apply at this time. -

- -

- Each application window will be open for 6 months from September in the year stated. If any of your employment circumstances change it might affect your eligibility. -

- -

- It is your responsibility to apply for each payment you are eligible for. The Department for Education will not - issue payments unless you apply, also we will not issue payments for claims made after the window has closed. -

- -

- <%= link_to "What do you think of this service?", done_page_url, class: "govuk-link" %> - (takes 30 seconds) -

-
-
diff --git a/app/views/additional_payments/submissions/_reminder.html.erb b/app/views/additional_payments/submissions/_reminder.html.erb index b96d4bd276..3b205df9e2 100644 --- a/app/views/additional_payments/submissions/_reminder.html.erb +++ b/app/views/additional_payments/submissions/_reminder.html.erb @@ -10,4 +10,4 @@ Receive a reminder email so you know when you can apply next year. We cannot issue payments unless you apply.

-<%= link_to "Set reminder", new_reminder_path, class: "govuk-button", role: :button, data: { module: "govuk-button" } %> +<%= govuk_button_link_to "Set reminder", independent_reminder_path(journey: journey::ROUTING_NAME, slug: "personal-details") %> diff --git a/config/locales/en.yml b/config/locales/en.yml index cad6e61fe4..38a136ba55 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -571,17 +571,16 @@ en: errors: blank: Select an additional payment inclusion: Select a valid additional payment - reminders: - personal_details: &reminders_personal_details - errors: - full_name: - blank: Enter full name - length: Full name must be 100 characters or less - email_address: - blank: Enter an email address - invalid: Enter an email address in the correct format, like name@example.com - length: Email address must be 256 characters or less - unauthorised: Only authorised email addresses can be used when using a team-only API key + personal_details: &reminders_personal_details + errors: + full_name: + blank: Enter full name + length: Full name must be 100 characters or less + email_address: + blank: Enter an email address + invalid: Enter an email address in the correct format, like name@example.com + length: Email address must be 256 characters or less + unauthorised: Only authorised email addresses can be used when using a team-only API key check_your_answers: part_one: primary_heading: Check your answers diff --git a/config/routes.rb b/config/routes.rb index 87614e70ff..7680e70a6f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -65,7 +65,7 @@ def matches?(request) end end - scope constraints: {journey: /further-education-payments/} do + scope constraints: {journey: /further-education-payments|additional-payments/} do resources :reminders, only: [:show, :update], param: :slug, @@ -76,24 +76,6 @@ def matches?(request) } end - scope constraints: {journey: "additional-payments"} do - get "reminder", as: :new_reminder, to: "journeys/additional_payments_for_teaching/reminders#new" - - post "reminders/:slug", - constraints: {slug: %r{#{Journeys::AdditionalPaymentsForTeaching::SlugSequence::REMINDER_SLUGS.join("|")}}}, - defaults: {slug: "personal-details"}, - as: :reminders, - to: "journeys/additional_payments_for_teaching/reminders#create" - - resources :reminders, - only: [:show, :update], - param: :slug, - controller: "journeys/additional_payments_for_teaching/reminders", - constraints: { - slug: %r{#{Journeys::AdditionalPaymentsForTeaching::SlugSequence::REMINDER_SLUGS.join("|")}} - } - end - scope constraints: {journey: "further-education-payments-provider"} do get "auth/callback", to: "omniauth_callbacks#callback" get "auth/sign-out", to: "omniauth_callbacks#sign_out" diff --git a/spec/features/further_education_payments/happy_path_spec.rb b/spec/features/further_education_payments/happy_path_spec.rb index 046645fa5d..89b58870d7 100644 --- a/spec/features/further_education_payments/happy_path_spec.rb +++ b/spec/features/further_education_payments/happy_path_spec.rb @@ -141,7 +141,7 @@ click_on "Continue" expect(page).to have_content("Email address") - fill_in "Email address", with: "johndoe@example.com" + fill_in "Email address", with: "john.doe@example.com" click_on "Continue" expect(page).to have_content("Enter the 6-digit passcode") @@ -187,22 +187,11 @@ expect(eligibility.teacher_reference_number).to eql("1234567") expect(page).to have_content("You applied for a further education targeted retention incentive payment") - click_link "Set reminder" - - expect(page).to have_content("Personal details") - fill_in "Full name", with: "John Doe" - fill_in "Email address", with: "john.doe@example.com" - click_button "Continue" - - expect(page).to have_content("Enter the 6-digit passcode") - mail = ActionMailer::Base.deliveries.last - otp_in_mail_sent = mail[:personalisation].decoded.scan(/\b[0-9]{6}\b/).first - fill_in "Enter the 6-digit passcode", with: otp_in_mail_sent expect do - click_on "Confirm" - end.to change { ActionMailer::Base.deliveries.count }.by(1) - .and change { Reminder.count }.by(1) + click_link "Set reminder" + end.to change { Reminder.count }.by(1) + .and change { ActionMailer::Base.deliveries.count }.by(1) reminder = Reminder.last @@ -210,6 +199,7 @@ expect(reminder.email_address).to eql("john.doe@example.com") expect(reminder.email_verified).to be_truthy expect(reminder.itt_academic_year).to eql(AcademicYear.next.to_s) + expect(reminder.itt_subject).to be_nil expect(page).to have_content("We have set your reminder") end diff --git a/spec/features/reminders_spec.rb b/spec/features/reminders_spec.rb index 28dba59c23..c7b42ff999 100644 --- a/spec/features/reminders_spec.rb +++ b/spec/features/reminders_spec.rb @@ -67,7 +67,7 @@ fill_in "Full name", with: "David Tau" fill_in "Email address", with: "david.tau1988@hotmail.co.uk" click_on "Continue" - fill_in "form-one-time-password-field", with: get_otp_from_email + fill_in "claim-one-time-password-field", with: get_otp_from_email click_on "Confirm" reminder = Reminder.order(:created_at).last @@ -147,13 +147,13 @@ fill_in "Email address", with: "david.tau1988@hotmail.co.uk" click_on "Continue" - expect(page).to have_link("Resend passcode (you will be sent back to the email address page)", href: new_reminder_path(journey: Journeys::AdditionalPaymentsForTeaching::ROUTING_NAME)) + expect(page).to have_link("Resend passcode (you will be sent back to the email address page)", href: independent_reminder_path(journey: journey_session.journey, slug: "personal-details")) click_link "Resend passcode" expect(page).to have_text("Personal details") click_on "Continue" - fill_in "form-one-time-password-field", with: get_otp_from_email + fill_in "claim-one-time-password-field", with: get_otp_from_email click_on "Confirm" reminder = Reminder.order(:created_at).last diff --git a/spec/features/trainee_teacher_subjourney_for_lup_schools_spec.rb b/spec/features/trainee_teacher_subjourney_for_lup_schools_spec.rb index abcae383b8..3c1c66a520 100644 --- a/spec/features/trainee_teacher_subjourney_for_lup_schools_spec.rb +++ b/spec/features/trainee_teacher_subjourney_for_lup_schools_spec.rb @@ -41,7 +41,7 @@ fill_in "Full name", with: "David Tau" fill_in "Email address", with: "david.tau1988@hotmail.co.uk" click_on "Continue" - fill_in "form-one-time-password-field", with: get_otp_from_email + fill_in "claim-one-time-password-field", with: get_otp_from_email click_on "Confirm" reminder = Reminder.order(:created_at).last @@ -76,7 +76,7 @@ fill_in "Full name", with: "David Tau" fill_in "Email address", with: "david.tau1988@hotmail.co.uk" click_on "Continue" - fill_in "form-one-time-password-field", with: get_otp_from_email + fill_in "claim-one-time-password-field", with: get_otp_from_email click_on "Confirm" reminder = Reminder.order(:created_at).last diff --git a/spec/forms/journeys/additional_payments_for_teaching/reminders/email_verification_form_spec.rb b/spec/forms/journeys/additional_payments_for_teaching/reminders/email_verification_form_spec.rb deleted file mode 100644 index 7b42e4c5cf..0000000000 --- a/spec/forms/journeys/additional_payments_for_teaching/reminders/email_verification_form_spec.rb +++ /dev/null @@ -1,55 +0,0 @@ -require "rails_helper" - -RSpec.describe Journeys::AdditionalPaymentsForTeaching::Reminders::EmailVerificationForm do - subject(:form) do - described_class.new(reminder: reminder, journey:, journey_session:, params:) - end - - let(:secret) { ROTP::Base32.random } - let(:journey) { Journeys::AdditionalPaymentsForTeaching } - let(:answers) do - {email_verification_secret: secret} - end - let(:journey_session) { build(:additional_payments_session, answers:) } - let(:reminder) { Reminder.create! } - let(:slug) { "email-verification" } - let(:params) { ActionController::Parameters.new({slug:, form: form_params}) } - let(:form_params) { {one_time_password: "123456"} } - - describe ".model_name" do - it { expect(form.model_name).to eq(ActiveModel::Name.new(Form)) } - end - - describe "#save" do - subject(:save) { form.save } - - context "valid params" do - let(:form_params) do - { - "one_time_password" => OneTimePassword::Generator.new(secret:).code, - "sent_one_time_password_at" => Time.now - } - end - - it "saves the attributes" do - expect(save).to eq(true) - expect(reminder.reload.email_verified).to be true - end - end - - context "invalid params" do - let(:form_params) do - { - "one_time_password" => OneTimePassword::Generator.new(secret:).code, - "sent_one_time_password_at" => "" - } - end - - it "does not save the attributes" do - expect { expect(save).to eq(false) }.not_to( - change { reminder.reload.email_verified } - ) - end - end - end -end diff --git a/spec/forms/journeys/additional_payments_for_teaching/reminders/personal_details_form_spec.rb b/spec/forms/journeys/additional_payments_for_teaching/reminders/personal_details_form_spec.rb deleted file mode 100644 index 02cafaa0da..0000000000 --- a/spec/forms/journeys/additional_payments_for_teaching/reminders/personal_details_form_spec.rb +++ /dev/null @@ -1,53 +0,0 @@ -require "rails_helper" - -RSpec.describe Journeys::AdditionalPaymentsForTeaching::Reminders::PersonalDetailsForm, type: :model do - subject(:form) { described_class.new(reminder: form_data_object, journey:, journey_session:, params:) } - - let(:journey) { Journeys::AdditionalPaymentsForTeaching } - let(:journey_session) { build(:additional_payments_session) } - let(:form_data_object) { Reminder.new } - let(:slug) { "personal-details" } - let(:params) { ActionController::Parameters.new({slug:, form: form_params}) } - let(:form_params) { {full_name: "John Doe"} } - - it { is_expected.to be_a(Form) } - - describe "validations" do - it { is_expected.to validate_presence_of(:full_name).with_message(form.i18n_errors_path(:"full_name.blank")) } - it { is_expected.to validate_length_of(:full_name).is_at_most(100).with_message(form.i18n_errors_path(:"full_name.length")) } - - it { is_expected.to validate_presence_of(:email_address).with_message(form.i18n_errors_path(:"email_address.blank")) } - it { is_expected.to validate_length_of(:email_address).is_at_most(256).with_message(form.i18n_errors_path(:"email_address.length")) } - - it { is_expected.to allow_value("valid@email.com").for(:email_address) } - it { is_expected.not_to allow_value("in valid@email.com").for(:email_address) } - end - - describe ".model_name" do - it { expect(form.model_name).to eq(ActiveModel::Name.new(Form)) } - end - - describe "#save" do - subject(:save) { form.save } - - context "valid params" do - let(:form_params) { {"full_name" => "John Doe", "email_address" => "john.doe@email.com"} } - - it "saves the attributes" do - expect(save).to eq(true) - expect(form_data_object.full_name).to eq("John Doe") - expect(form_data_object.email_address).to eq("john.doe@email.com") - end - end - - context "invalid params" do - let(:form_params) { {"full_name" => "John Doe", "email_address" => ""} } - - it "does not save the attributes" do - expect(save).to eq(false) - expect(form_data_object.full_name).to be_nil - expect(form_data_object.email_address).to be_nil - end - end - end -end diff --git a/spec/requests/reminders_spec.rb b/spec/requests/reminders_spec.rb index 3497d468fa..1f8a5794fc 100644 --- a/spec/requests/reminders_spec.rb +++ b/spec/requests/reminders_spec.rb @@ -7,19 +7,19 @@ end describe "#create" do - let(:submit_form) { post reminders_path("additional-payments", params: form_params) } + let(:submit_form) { put independent_reminder_path(journey: "additional-payments", slug: "personal-details", params: form_params) } context "with full name and valid email address" do - let(:form_params) { {form: {full_name: "Joe Bloggs", email_address: "joe.bloggs@example.com"}} } + let(:form_params) { {claim: {reminder_full_name: "Joe Bloggs", reminder_email_address: "joe.bloggs@example.com"}} } it "redirects to /email-verfication slug" do submit_form - expect(response).to redirect_to("/additional-payments/reminders/email-verification?form%5Bemail_address%5D=joe.bloggs%40example.com&form%5Bfull_name%5D=Joe+Bloggs") + expect(response).to redirect_to("/additional-payments/reminders/email-verification") end end context "with empty form" do - let(:form_params) { {form: {full_name: "", email_address: ""}} } + let(:form_params) { {claim: {reminder_full_name: "", reminder_email_address: ""}} } before { submit_form } @@ -33,7 +33,7 @@ end context "invalid email address" do - let(:form_params) { {form: {full_name: "Joe Bloggs", email_address: "joe.bloggs.example.com"}} } + let(:form_params) { {claim: {reminder_full_name: "Joe Bloggs", reminder_email_address: "joe.bloggs.example.com"}} } it "renders errors containing invalid email address" do submit_form @@ -41,42 +41,8 @@ end end - context "Notify returns an error about email address is required" do - let(:form_params) { {form: {full_name: "Joe Bloggs", email_address: "joe.bloggs@example.com"}} } - - let(:mailer) { double("notify") } - let(:notifications_error_response) { double("response", code: 400, body: "ValidationError: email_address is a required property") } - - before do - allow(mailer).to receive(:deliver_now).and_raise(Notifications::Client::BadRequestError, notifications_error_response) - allow(ReminderMailer).to receive(:email_verification).and_return(mailer) - end - - it "renders errors containing invalid email address" do - submit_form - expect(response.body).to include "Enter an email address in the correct format, like name@example.com" - end - end - - context "Notify returns an error about team only API key" do - let(:form_params) { {form: {full_name: "Joe Bloggs", email_address: "joe.bloggs@example.com"}} } - - let(:mailer) { double("notify") } - let(:notifications_error_response) { double("response", code: 400, body: "BadRequestError: Can’t send to this recipient using a team-only API key") } - - before do - allow(mailer).to receive(:deliver_now).and_raise(Notifications::Client::BadRequestError, notifications_error_response) - allow(ReminderMailer).to receive(:email_verification).and_return(mailer) - end - - it "renders errors containing team only API key" do - submit_form - expect(response.body).to include "Only authorised email addresses can be used when using a team-only API key" - end - end - context "Notify returns an unknown error" do - let(:form_params) { {form: {full_name: "Joe Bloggs", email_address: "joe.bloggs@example.com"}} } + let(:form_params) { {claim: {reminder_full_name: "Joe Bloggs", reminder_email_address: "joe.bloggs@example.com"}} } let(:mailer) { double("notify") } let(:notifications_error_response) { double("response", code: 400, body: "Something unexpected") }