diff --git a/app/forms/bank_details_form.rb b/app/forms/bank_details_form.rb index 363a1468ca..8fa1b40326 100644 --- a/app/forms/bank_details_form.rb +++ b/app/forms/bank_details_form.rb @@ -13,7 +13,7 @@ class BankDetailsForm < Form validates :banking_name, presence: {message: i18n_error_message(:enter_banking_name)} validates :bank_sort_code, presence: {message: i18n_error_message(:enter_sort_code)} validates :bank_account_number, presence: {message: i18n_error_message(:enter_account_number)} - validates :building_society_roll_number, presence: {message: i18n_error_message(:enter_roll_number)}, if: -> { claim.building_society? } + validates :building_society_roll_number, presence: {message: i18n_error_message(:enter_roll_number)}, if: -> { answers.building_society? } validate :bank_account_number_must_be_eight_digits validate :bank_sort_code_must_be_six_digits @@ -26,13 +26,15 @@ class BankDetailsForm < Form def save return false unless valid? - update!( - banking_name:, - bank_sort_code:, - bank_account_number:, - building_society_roll_number:, - hmrc_bank_validation_succeeded: + journey_session.answers.assign_attributes( + banking_name: banking_name, + bank_sort_code: normalised_bank_detail(bank_sort_code), + bank_account_number: normalised_bank_detail(bank_account_number), + building_society_roll_number: building_society_roll_number, + hmrc_bank_validation_succeeded: hmrc_bank_validation_succeeded ) + + journey_session.save! end def hmrc_bank_validation_succeeded @@ -50,7 +52,7 @@ def hmrc_api_validation_succeeded? private def normalised_bank_detail(bank_detail) - bank_detail.gsub(/\s|-/, "") + bank_detail&.gsub(/\s|-/, "") end def bank_account_number_must_be_eight_digits @@ -93,8 +95,11 @@ def bank_account_is_valid response = e.response @hmrc_api_response_error = true ensure - new_hmrc_bank_validation_responses_value = claim.hmrc_bank_validation_responses.dup << {code: response.code, body: response.body} - claim.update_attribute :hmrc_bank_validation_responses, new_hmrc_bank_validation_responses_value + new_hmrc_bank_validation_responses_value = journey_session.answers.hmrc_bank_validation_responses.dup << {code: response.code, body: response.body} + journey_session.answers.assign_attributes( + hmrc_bank_validation_responses: new_hmrc_bank_validation_responses_value + ) + journey_session.save! end end diff --git a/app/forms/bank_or_building_society_form.rb b/app/forms/bank_or_building_society_form.rb index 4ceeacb285..d4097cc4ed 100644 --- a/app/forms/bank_or_building_society_form.rb +++ b/app/forms/bank_or_building_society_form.rb @@ -10,8 +10,23 @@ class BankOrBuildingSocietyForm < Form def save return false unless valid? - claim.assign_attributes(bank_or_building_society:) - claim.reset_dependent_answers - claim.save! + if bank_or_building_society_changed? + journey_session.answers.assign_attributes( + banking_name: nil, + bank_account_number: nil, + bank_sort_code: nil, + building_society_roll_number: nil + ) + end + + journey_session.answers.assign_attributes(bank_or_building_society:) + + journey_session.save! + end + + private + + def bank_or_building_society_changed? + answers.bank_or_building_society != bank_or_building_society end end diff --git a/app/forms/claim_submission_base_form.rb b/app/forms/claim_submission_base_form.rb index 742dc76abc..2214764845 100644 --- a/app/forms/claim_submission_base_form.rb +++ b/app/forms/claim_submission_base_form.rb @@ -1,7 +1,7 @@ class ClaimSubmissionBaseForm include ActiveModel::Model - attr_reader :journey_session + attr_reader :journey_session, :claim validate :not_already_submitted validate :email_address_is_preesent @@ -12,12 +12,14 @@ class ClaimSubmissionBaseForm def initialize(journey_session:) @journey_session = journey_session + @claim = build_claim end def save return false unless valid? ApplicationRecord.transaction do + set_attributes_for_claim_submission main_eligibility.save! claim.save! end @@ -26,10 +28,6 @@ def save ClaimVerifierJob.perform_later(claim) end - def claim - @claim ||= build_claim - end - private delegate :answers, to: :journey_session @@ -37,13 +35,6 @@ def claim def build_claim claim = Claim.new - # Temp conditional while we're working with the shim - claim.journey_session = if journey_session.is_a?(ClaimJourneySessionShim) - journey_session.journey_session - else - journey_session - end - claim.eligibility = main_eligibility answers.attributes.each do |name, value| @@ -52,9 +43,6 @@ def build_claim end end - claim.policy_options_provided = generate_policy_options_provided - claim.reference = generate_reference - claim.submitted_at = Time.zone.now claim end @@ -75,6 +63,18 @@ def set_eligibility_attributes(eligibility) end end + def set_attributes_for_claim_submission + # Temp conditional while we're working with the shim + claim.journey_session = if journey_session.is_a?(ClaimJourneySessionShim) + journey_session.journey_session + else + journey_session + end + claim.policy_options_provided = generate_policy_options_provided + claim.reference = generate_reference + claim.submitted_at = Time.zone.now + end + def generate_reference loop { ref = Reference.new.to_s @@ -111,9 +111,13 @@ def mobile_number_verified end end - # TODO RL move the logic out of the claim rather than use send def mobile_number_verified? - claim.send(:submittable_mobile_details?) + return true if answers.using_mobile_number_from_tid? + return true if answers.provide_mobile_number && answers.mobile_number.present? && answers.mobile_verified == true + return true if answers.provide_mobile_number == false && answers.mobile_number.nil? && answers.mobile_verified == false + return true if answers.provide_mobile_number == false && answers.mobile_verified.nil? + + false end def claim_is_eligible diff --git a/app/forms/mobile_number_form.rb b/app/forms/mobile_number_form.rb index e9a5c4bd63..fefdfa9320 100644 --- a/app/forms/mobile_number_form.rb +++ b/app/forms/mobile_number_form.rb @@ -21,11 +21,13 @@ def save Time.now end - update!( + journey_session.answers.assign_attributes( mobile_number: mobile_number, mobile_verified: nil, sent_one_time_password_at: sent_one_time_password_at ) + + journey_session.save! end private @@ -39,6 +41,6 @@ def send_sms_message end def mobile_number_changed? - mobile_number != claim.mobile_number + mobile_number != answers.mobile_number end end diff --git a/app/forms/mobile_verification_form.rb b/app/forms/mobile_verification_form.rb index 4c99225116..6dc62f5d81 100644 --- a/app/forms/mobile_verification_form.rb +++ b/app/forms/mobile_verification_form.rb @@ -2,7 +2,7 @@ class MobileVerificationForm < Form attribute :one_time_password # Required for shared partial in the view - delegate :mobile_number, to: :claim + delegate :mobile_number, to: :answers validate :otp_validate @@ -13,7 +13,9 @@ class MobileVerificationForm < Form def save return false unless valid? - update!(mobile_verified: true) + journey_session.answers.assign_attributes(mobile_verified: true) + + journey_session.save! end private @@ -21,7 +23,7 @@ def save def otp_validate otp = OneTimePassword::Validator.new( one_time_password, - claim.sent_one_time_password_at + answers.sent_one_time_password_at ) errors.add(:one_time_password, otp.warning) unless otp.valid? diff --git a/app/forms/provide_mobile_number_form.rb b/app/forms/provide_mobile_number_form.rb index 50b2b73a60..011053d057 100644 --- a/app/forms/provide_mobile_number_form.rb +++ b/app/forms/provide_mobile_number_form.rb @@ -1,18 +1,31 @@ class ProvideMobileNumberForm < Form attribute :provide_mobile_number, :boolean + # FIXME RL consider moving this to a subclass rather than querying the session validates :provide_mobile_number, inclusion: { in: [true, false], message: "Select yes if you would like to provide your mobile number" }, - if: -> { claim.has_ecp_or_lupp_policy? } + if: -> { answers.class.module_parent == Journeys::AdditionalPaymentsForTeaching } def save return false unless valid? - claim.assign_attributes(provide_mobile_number:) - claim.reset_eligibility_dependent_answers(["provide_mobile_number"]) - claim.save! + if provide_mobile_number_changed? + journey_session.answers.assign_attributes(mobile_verified: nil) + end + + journey_session.answers.assign_attributes( + provide_mobile_number: provide_mobile_number + ) + + journey_session.save! + end + + private + + def provide_mobile_number_changed? + answers.provide_mobile_number != provide_mobile_number end end diff --git a/app/forms/select_mobile_form.rb b/app/forms/select_mobile_form.rb index 0b49a6ac48..298438d77e 100644 --- a/app/forms/select_mobile_form.rb +++ b/app/forms/select_mobile_form.rb @@ -16,21 +16,21 @@ def save case mobile_check when "use" - claim.update( + journey_session.answers.assign_attributes( mobile_number: phone_number, provide_mobile_number: true, mobile_check: mobile_check, mobile_verified: nil ) when "alternative" - claim.update( + journey_session.answers.assign_attributes( mobile_number: nil, provide_mobile_number: true, mobile_check: mobile_check, mobile_verified: nil ) when "declined" - claim.update( + journey_session.answers.assign_attributes( mobile_number: nil, provide_mobile_number: false, mobile_check: mobile_check, @@ -40,6 +40,6 @@ def save fail "Invalid mobile_check: #{mobile_check}" end - true + journey_session.save! end end diff --git a/app/models/claim_journey_session_shim.rb b/app/models/claim_journey_session_shim.rb index 2111e63eaa..d6983caa7f 100644 --- a/app/models/claim_journey_session_shim.rb +++ b/app/models/claim_journey_session_shim.rb @@ -27,27 +27,27 @@ def answers teacher_reference_number: teacher_reference_number, national_insurance_number: journey_session.answers.national_insurance_number, email_address: journey_session.answers.email_address, - bank_sort_code: bank_sort_code, - bank_account_number: bank_account_number, + bank_sort_code: journey_session.answers.bank_sort_code, + bank_account_number: journey_session.answers.bank_account_number, details_check: details_check, payroll_gender: payroll_gender, first_name: journey_session.answers.first_name, middle_name: journey_session.answers.middle_name, surname: journey_session.answers.surname, - banking_name: banking_name, - building_society_roll_number: building_society_roll_number, + banking_name: journey_session.answers.banking_name, + building_society_roll_number: journey_session.answers.building_society_roll_number, academic_year: academic_year, - bank_or_building_society: bank_or_building_society, - provide_mobile_number: provide_mobile_number, - mobile_number: mobile_number, + bank_or_building_society: journey_session.answers.bank_or_building_society, + provide_mobile_number: journey_session.answers.provide_mobile_number, + mobile_number: journey_session.answers.mobile_number, email_verified: journey_session.answers.email_verified, - mobile_verified: mobile_verified, - hmrc_bank_validation_succeeded: hmrc_bank_validation_succeeded, - hmrc_bank_validation_responses: hmrc_bank_validation_responses, + mobile_verified: journey_session.answers.mobile_verified, + hmrc_bank_validation_succeeded: journey_session.answers.hmrc_bank_validation_succeeded, + hmrc_bank_validation_responses: journey_session.answers.hmrc_bank_validation_responses, logged_in_with_tid: logged_in_with_tid, teacher_id_user_info: teacher_id_user_info, email_address_check: journey_session.answers.email_address_check, - mobile_check: mobile_check, + mobile_check: journey_session.answers.mobile_check, qualifications_details_check: qualifications_details_check } end @@ -82,14 +82,6 @@ def teacher_reference_number journey_session.answers.teacher_reference_number.presence || current_claim.teacher_reference_number end - def bank_sort_code - journey_session.answers.bank_sort_code || current_claim.bank_sort_code - end - - def bank_account_number - journey_session.answers.bank_account_number || current_claim.bank_account_number - end - def details_check journey_session.answers.details_check || current_claim.details_check end @@ -98,42 +90,10 @@ def payroll_gender journey_session.answers.payroll_gender || current_claim.payroll_gender end - def banking_name - journey_session.answers.banking_name || current_claim.banking_name - end - - def building_society_roll_number - journey_session.answers.building_society_roll_number || current_claim.building_society_roll_number - end - def academic_year journey_session.answers.academic_year || current_claim.academic_year end - def bank_or_building_society - journey_session.answers.bank_or_building_society || current_claim.bank_or_building_society - end - - def provide_mobile_number - journey_session.answers.provide_mobile_number || current_claim.provide_mobile_number - end - - def mobile_number - journey_session.answers.mobile_number || current_claim.mobile_number - end - - def mobile_verified - journey_session.answers.mobile_verified || current_claim.mobile_verified - end - - def hmrc_bank_validation_succeeded - journey_session.answers.hmrc_bank_validation_succeeded || current_claim.hmrc_bank_validation_succeeded - end - - def hmrc_bank_validation_responses - journey_session.answers.hmrc_bank_validation_responses || current_claim.hmrc_bank_validation_responses - end - def logged_in_with_tid journey_session.answers.logged_in_with_tid || current_claim.logged_in_with_tid end @@ -142,10 +102,6 @@ def teacher_id_user_info journey_session.answers.teacher_id_user_info || current_claim.teacher_id_user_info end - def mobile_check - journey_session.answers.mobile_check || current_claim.mobile_check - end - def qualifications_details_check journey_session.answers.qualifications_details_check || current_claim.qualifications_details_check end diff --git a/app/models/concerns/journeys/sessions/teacher_id.rb b/app/models/concerns/journeys/sessions/teacher_id.rb index 1efe1a5626..05f41f6dd1 100644 --- a/app/models/concerns/journeys/sessions/teacher_id.rb +++ b/app/models/concerns/journeys/sessions/teacher_id.rb @@ -35,6 +35,10 @@ def nino_same_as_tid? def trn_same_as_tid?(claim) teacher_id_user_info["trn"] == claim.teacher_reference_number end + + def using_mobile_number_from_tid? + logged_in_with_tid? && mobile_check == "use" && provide_mobile_number && mobile_number.present? + end end end end diff --git a/app/models/journeys/additional_payments_for_teaching/session_answers.rb b/app/models/journeys/additional_payments_for_teaching/session_answers.rb index fd2b96197c..e93dda58ca 100644 --- a/app/models/journeys/additional_payments_for_teaching/session_answers.rb +++ b/app/models/journeys/additional_payments_for_teaching/session_answers.rb @@ -14,17 +14,6 @@ class SessionAnswers < Journeys::SessionAnswers attribute :school_somewhere_else, :boolean attribute :nqt_in_academic_year_after_itt, :boolean attribute :eligible_degree_subject, :boolean - attribute :qualification, :string - attribute :has_entire_term_contract, :boolean - attribute :employed_directly, :boolean - attribute :subject_to_disciplinary_action, :boolean - attribute :subject_to_formal_performance_action, :boolean - attribute :eligible_itt_subject, :string - attribute :teaching_subject_now, :boolean - attribute :itt_academic_year, AcademicYear::Type.new - attribute :eligible_degree_subject, :boolean - attribute :induction_completed, :boolean - attribute :school_somewhere_else, :boolean def early_career_payments_dqt_teacher_record return unless dqt_teacher_status.present? diff --git a/app/models/journeys/additional_payments_for_teaching/slug_sequence.rb b/app/models/journeys/additional_payments_for_teaching/slug_sequence.rb index d3e7f0805e..1d4ec2aa9b 100644 --- a/app/models/journeys/additional_payments_for_teaching/slug_sequence.rb +++ b/app/models/journeys/additional_payments_for_teaching/slug_sequence.rb @@ -117,7 +117,7 @@ def slugs sequence.delete("select-mobile") end - if answers.logged_in_with_tid? && (claim.mobile_check == "use" || claim.mobile_check == "declined") + if answers.logged_in_with_tid? && (answers.mobile_check == "use" || answers.mobile_check == "declined") sequence.delete("mobile-number") sequence.delete("mobile-verification") end @@ -130,15 +130,15 @@ def slugs sequence.delete("eligibility-confirmed") unless overall_eligibility_status == :eligible_now sequence.delete("eligible-later") unless overall_eligibility_status == :eligible_later - sequence.delete("personal-bank-account") if claim.bank_or_building_society == "building_society" - sequence.delete("building-society-account") if claim.bank_or_building_society == "personal_bank_account" + sequence.delete("personal-bank-account") if answers.building_society? + sequence.delete("building-society-account") if answers.personal_bank_account? sequence.delete("teacher-reference-number") if answers.logged_in_with_tid? && answers.teacher_reference_number.present? sequence.delete("correct-school") unless journey_session.logged_in_with_tid_and_has_recent_tps_school? sequence.delete("current-school") if claim.eligibility.school_somewhere_else == false - if claim.provide_mobile_number == false + if answers.provide_mobile_number == false sequence.delete("mobile-number") sequence.delete("mobile-verification") end diff --git a/app/models/journeys/base_answers_presenter.rb b/app/models/journeys/base_answers_presenter.rb index b5cb2fbe13..48c14d72e7 100644 --- a/app/models/journeys/base_answers_presenter.rb +++ b/app/models/journeys/base_answers_presenter.rb @@ -25,20 +25,20 @@ def identity_answers a << [t("questions.national_insurance_number"), claim.national_insurance_number, "personal-details"] if show_nino? a << [t("questions.email_address"), answers.email_address, "email-address"] unless show_email_select? a << [text_for(:select_email), answers.email_address, "select-email"] if show_email_select? - a << [t("questions.provide_mobile_number"), claim.provide_mobile_number? ? "Yes" : "No", "provide-mobile-number"] unless show_mobile_select? - a << [t("questions.mobile_number"), claim.mobile_number, "mobile-number"] unless show_mobile_select? || !claim.provide_mobile_number? - a << [t("additional_payments.forms.select_mobile_form.questions.which_number"), claim.mobile_number? ? claim.mobile_number : t("additional_payments.forms.select_mobile_form.answers.decline"), "select-mobile"] if show_mobile_select? + a << [t("questions.provide_mobile_number"), answers.provide_mobile_number? ? "Yes" : "No", "provide-mobile-number"] unless show_mobile_select? + a << [t("questions.mobile_number"), answers.mobile_number, "mobile-number"] unless show_mobile_select? || !answers.provide_mobile_number? + a << [t("additional_payments.forms.select_mobile_form.questions.which_number"), answers.mobile_number.present? ? answers.mobile_number : t("additional_payments.forms.select_mobile_form.answers.decline"), "select-mobile"] if show_mobile_select? end end def payment_answers - change_slug = claim.building_society? ? "building-society-account" : "personal-bank-account" + change_slug = answers.building_society? ? "building-society-account" : "personal-bank-account" [].tap do |a| - a << [t("questions.bank_or_building_society"), claim.bank_or_building_society.to_s.humanize, "bank-or-building-society"] - a << ["Name on bank account", claim.banking_name, change_slug] - a << ["Bank sort code", claim.bank_sort_code, change_slug] - a << ["Bank account number", claim.bank_account_number, change_slug] - a << ["Building society roll number", claim.building_society_roll_number, change_slug] if claim.building_society_roll_number.present? + a << [t("questions.bank_or_building_society"), answers.bank_or_building_society.to_s.humanize, "bank-or-building-society"] + a << ["Name on bank account", answers.banking_name, change_slug] + a << ["Bank sort code", answers.bank_sort_code, change_slug] + a << ["Bank account number", answers.bank_account_number, change_slug] + a << ["Building society roll number", answers.building_society_roll_number, change_slug] if answers.building_society_roll_number.present? end end @@ -73,7 +73,7 @@ def show_email_select? end def show_mobile_select? - answers.logged_in_with_tid? && claim.mobile_check.present? + answers.logged_in_with_tid? && answers.mobile_check.present? end end end diff --git a/app/models/journeys/session_answers.rb b/app/models/journeys/session_answers.rb index a9c55dbf7f..c1d572be40 100644 --- a/app/models/journeys/session_answers.rb +++ b/app/models/journeys/session_answers.rb @@ -31,7 +31,7 @@ class SessionAnswers attribute :email_verified, :boolean attribute :mobile_verified, :boolean attribute :hmrc_bank_validation_succeeded, :boolean - attribute :hmrc_bank_validation_responses # , :json + attribute :hmrc_bank_validation_responses, default: [] attribute :logged_in_with_tid, :boolean attribute :details_check, :boolean attribute :teacher_id_user_info, default: {} @@ -55,5 +55,21 @@ def details_check? def email_address_check? !!email_address_check end + + def provide_mobile_number? + !!provide_mobile_number + end + + def building_society? + bank_or_building_society == "building_society" + end + + def personal_bank_account? + bank_or_building_society == "personal_bank_account" + end + + def hmrc_bank_validation_succeeded? + !!hmrc_bank_validation_succeeded + end end end diff --git a/app/models/journeys/teacher_student_loan_reimbursement/slug_sequence.rb b/app/models/journeys/teacher_student_loan_reimbursement/slug_sequence.rb index 24d4f8b531..9e477cdc85 100644 --- a/app/models/journeys/teacher_student_loan_reimbursement/slug_sequence.rb +++ b/app/models/journeys/teacher_student_loan_reimbursement/slug_sequence.rb @@ -83,10 +83,10 @@ def slugs sequence.delete("reset-claim") if skipped_dfe_sign_in? || answers.details_check? sequence.delete("current-school") if claim.eligibility.employed_at_claim_school? || claim.eligibility.employed_at_recent_tps_school? sequence.delete("mostly-performed-leadership-duties") unless claim.eligibility.had_leadership_position? - sequence.delete("personal-bank-account") if claim.bank_or_building_society == "building_society" - sequence.delete("building-society-account") if claim.bank_or_building_society == "personal_bank_account" - sequence.delete("mobile-number") if claim.provide_mobile_number == false - sequence.delete("mobile-verification") if claim.provide_mobile_number == false + sequence.delete("personal-bank-account") if answers.building_society? + sequence.delete("building-society-account") if answers.personal_bank_account? + sequence.delete("mobile-number") if answers.provide_mobile_number == false + sequence.delete("mobile-verification") if answers.provide_mobile_number == false sequence.delete("ineligible") unless claim.eligibility&.ineligible? sequence.delete("personal-details") if answers.logged_in_with_tid? && personal_details_form.valid? && answers.all_personal_details_same_as_tid? sequence.delete("select-email") unless set_by_teacher_id?("email") @@ -100,7 +100,7 @@ def slugs else sequence.delete("select-mobile") end - if answers.logged_in_with_tid? && (claim.mobile_check == "use" || claim.mobile_check == "declined") + if answers.logged_in_with_tid? && (answers.mobile_check == "use" || answers.mobile_check == "declined") sequence.delete("mobile-number") sequence.delete("mobile-verification") end diff --git a/app/views/claims/building_society_account.html.erb b/app/views/claims/building_society_account.html.erb index cd08a65f6e..58e1a44aef 100644 --- a/app/views/claims/building_society_account.html.erb +++ b/app/views/claims/building_society_account.html.erb @@ -1,4 +1,4 @@ -<% bank_or_building_society = current_claim.bank_or_building_society.humanize.downcase %> +<% bank_or_building_society = @form.answers.bank_or_building_society.humanize.downcase %> <% content_for(:page_title, page_title(t("questions.account_details", bank_or_building_society: bank_or_building_society), journey: current_journey_routing_name, show_error: @form.errors.any?)) %>
diff --git a/app/views/claims/personal_bank_account.html.erb b/app/views/claims/personal_bank_account.html.erb index 21c657d12a..49804f9611 100644 --- a/app/views/claims/personal_bank_account.html.erb +++ b/app/views/claims/personal_bank_account.html.erb @@ -1,4 +1,4 @@ -<% bank_or_building_society = current_claim.bank_or_building_society.humanize.downcase %> +<% bank_or_building_society = @form.answers.bank_or_building_society.humanize.downcase %> <% content_for(:page_title, page_title(t("questions.account_details", bank_or_building_society: bank_or_building_society), journey: current_journey_routing_name, show_error: @form.errors.any?)) %>
diff --git a/spec/factories/journeys/additional_payments_for_teaching/session_answers.rb b/spec/factories/journeys/additional_payments_for_teaching/session_answers.rb index c48257ffb9..b3b0fdb38b 100644 --- a/spec/factories/journeys/additional_payments_for_teaching/session_answers.rb +++ b/spec/factories/journeys/additional_payments_for_teaching/session_answers.rb @@ -16,5 +16,25 @@ email_address { generate(:email_address) } email_verified { true } end + + trait :with_mobile_details do + mobile_number { "07474000123" } + provide_mobile_number { true } + mobile_verified { true } + end + + trait :with_bank_details do + bank_or_building_society { :personal_bank_account } + banking_name { "Jo Bloggs" } + bank_sort_code { rand(100000..999999) } + bank_account_number { rand(10000000..99999999) } + end + + trait :submittable do + with_personal_details + with_email_details + with_mobile_details + with_bank_details + end end end diff --git a/spec/factories/journeys/teacher_student_loan_reimbursement/session_answers.rb b/spec/factories/journeys/teacher_student_loan_reimbursement/session_answers.rb index 0a603fe6a6..62af3539aa 100644 --- a/spec/factories/journeys/teacher_student_loan_reimbursement/session_answers.rb +++ b/spec/factories/journeys/teacher_student_loan_reimbursement/session_answers.rb @@ -16,5 +16,25 @@ email_address { generate(:email_address) } email_verified { true } end + + trait :with_mobile_details do + mobile_number { "07474000123" } + provide_mobile_number { true } + mobile_verified { true } + end + + trait :with_bank_details do + bank_or_building_society { :personal_bank_account } + banking_name { "Jo Bloggs" } + bank_sort_code { rand(100000..999999) } + bank_account_number { rand(10000000..99999999) } + end + + trait :submittable do + with_personal_details + with_email_details + with_mobile_details + with_bank_details + end end end diff --git a/spec/features/admin_claim_tasks_update_with_dqt_api_spec.rb b/spec/features/admin_claim_tasks_update_with_dqt_api_spec.rb index 23a889158d..994acd9bb1 100644 --- a/spec/features/admin_claim_tasks_update_with_dqt_api_spec.rb +++ b/spec/features/admin_claim_tasks_update_with_dqt_api_spec.rb @@ -16,7 +16,7 @@ def claimant_submits_claim(claim_attributes:, answers:, post_submission_claim_at journey_session.update!( answers: attributes_for( :"#{journey::I18N_NAMESPACE}_answers", - :with_email_details + :submittable ).merge(answers) ) diff --git a/spec/features/changing_answers_spec.rb b/spec/features/changing_answers_spec.rb index 0513efc814..c99d3e27c7 100644 --- a/spec/features/changing_answers_spec.rb +++ b/spec/features/changing_answers_spec.rb @@ -18,11 +18,7 @@ session = Journeys::TeacherStudentLoanReimbursement::Session.order(:created_at).last session.answers.assign_attributes( - attributes_for( - :student_loans_answers, - :with_personal_details, - :with_email_details - ) + attributes_for(:student_loans_answers, :submittable) ) session.save! @@ -70,11 +66,7 @@ session = Journeys::TeacherStudentLoanReimbursement::Session.order(:created_at).last session.answers.assign_attributes( - attributes_for( - :student_loans_answers, - :with_personal_details, - :with_email_details - ) + attributes_for(:student_loans_answers, :submittable) ) session.save! @@ -118,11 +110,7 @@ claim.eligibility.update!(attributes_for(:student_loans_eligibility, :eligible, had_leadership_position: false, current_school_id: student_loans_school.id, claim_school_id: student_loans_school.id)) session = Journeys::TeacherStudentLoanReimbursement::Session.order(:created_at).last session.answers.assign_attributes( - attributes_for( - :student_loans_answers, - :with_personal_details, - :with_email_details - ) + attributes_for(:student_loans_answers, :submittable) ) session.save! @@ -152,11 +140,7 @@ session = Journeys::TeacherStudentLoanReimbursement::Session.order(:created_at).last session.answers.assign_attributes( - attributes_for( - :student_loans_answers, - :with_personal_details, - :with_email_details - ) + attributes_for(:student_loans_answers, :submittable) ) session.save! @@ -184,11 +168,7 @@ journey_session = Journeys::TeacherStudentLoanReimbursement::Session.order(:created_at).last journey_session.update!( - answers: attributes_for( - :student_loans_answers, - :with_personal_details, - :with_email_details - ) + answers: attributes_for(:student_loans_answers, :submittable) ) answers = journey_session.answers @@ -231,8 +211,7 @@ journey_session.update!( answers: attributes_for( :student_loans_answers, - :with_personal_details, - :with_email_details, + :submittable, middle_name: "Jay" ) ) @@ -291,13 +270,14 @@ choose "Building society" click_on "Continue" - expect(page).to have_content(I18n.t("questions.account_details", bank_or_building_society: claim.reload.bank_or_building_society.humanize.downcase)) + journey_session.reload + expect(page).to have_content(I18n.t("questions.account_details", bank_or_building_society: journey_session.answers.bank_or_building_society.humanize.downcase)) expect(page).to have_content("Building society roll number") - expect(claim.bank_or_building_society).to eq :building_society.to_s - expect(claim.banking_name).to be_nil - expect(claim.bank_sort_code).to be_nil - expect(claim.bank_account_number).to be_nil + expect(journey_session.answers.bank_or_building_society).to eq :building_society.to_s + expect(journey_session.answers.banking_name).to be_nil + expect(journey_session.answers.bank_sort_code).to be_nil + expect(journey_session.answers.bank_account_number).to be_nil fill_in "Name on your account", with: "Miss Jasmine Aniski" fill_in "Sort code", with: "80-78-01" @@ -306,10 +286,11 @@ click_on "Continue" - expect(claim.reload.banking_name).to eq "Miss Jasmine Aniski" - expect(claim.bank_sort_code).to eq "807801" - expect(claim.bank_account_number).to eq "43290701" - expect(claim.building_society_roll_number).to eq "6284/000390713" + journey_session.reload + expect(journey_session.answers.banking_name).to eq "Miss Jasmine Aniski" + expect(journey_session.answers.bank_sort_code).to eq "807801" + expect(journey_session.answers.bank_account_number).to eq "43290701" + expect(journey_session.answers.building_society_roll_number).to eq "6284/000390713" end end @@ -328,9 +309,8 @@ session.answers.assign_attributes( attributes_for( :student_loans_answers, - :with_personal_details, - :with_email_details - ) + :submittable + ).merge(personal_details_attributes) ) session.save! @@ -395,7 +375,7 @@ choose "Yes" click_on "Continue" }.to change { - claim.reload.provide_mobile_number + session.reload.answers.provide_mobile_number }.from(false).to(true) expect(page).not_to have_content("Check your answers before sending your application") @@ -404,7 +384,7 @@ fill_in "claim_mobile_number", with: new_mobile click_on "Continue" - expect(claim.reload.mobile_number).to eql new_mobile + expect(session.reload.answers.mobile_number).to eql new_mobile # - Mobile number one-time password expect(page).to have_text("Mobile number verification") @@ -414,7 +394,7 @@ click_on "Confirm" expect(page).not_to have_text("Some places are both a bank and a building society") - expect(claim.reload.mobile_verified).to eq true + expect(session.reload.answers.mobile_verified).to eq true expect(claim.submittable?).to be true expect(page).to have_content("Check your answers before sending your application") end @@ -446,14 +426,14 @@ let(:old_mobile) { "07813090710" } scenario "is asked to provide the OTP challenge code for validation" do - old_mobile = claim.mobile_number + old_mobile = session.answers.mobile_number expect { page.first("a[href='#{claim_path(Journeys::AdditionalPaymentsForTeaching::ROUTING_NAME, "mobile-number")}']", minimum: 1).click fill_in "Mobile number", with: new_mobile click_on "Continue" }.to change { - claim.reload.mobile_number + session.reload.answers.mobile_number }.from(old_mobile).to(new_mobile) expect(page).not_to have_content("Check your answers before sending your application") @@ -466,7 +446,7 @@ click_on "Confirm" expect(page).not_to have_text("Some places are both a bank and a building society") - expect(claim.reload.mobile_verified).to eq true + expect(session.reload.answers.mobile_verified).to eq true expect(claim.submittable?).to be true expect(page).to have_content("Check your answers before sending your application") end diff --git a/spec/features/claim_journey_does_not_get_cached_spec.rb b/spec/features/claim_journey_does_not_get_cached_spec.rb index fe201aee42..8ae0fdcfa5 100644 --- a/spec/features/claim_journey_does_not_get_cached_spec.rb +++ b/spec/features/claim_journey_does_not_get_cached_spec.rb @@ -8,11 +8,7 @@ claim.update!(attributes_for(:claim, :submittable)) journey_session = Journeys::TeacherStudentLoanReimbursement::Session.last journey_session.update!( - answers: attributes_for( - :student_loans_answers, - :with_details_from_dfe_identity, - :with_email_details - ) + answers: attributes_for(:student_loans_answers, :submittable) ) claim.eligibility = create(:student_loans_eligibility, :eligible) claim.save! diff --git a/spec/features/claim_with_mobile_sms_otp_spec.rb b/spec/features/claim_with_mobile_sms_otp_spec.rb index 3b58d07ab1..5e75662fcf 100644 --- a/spec/features/claim_with_mobile_sms_otp_spec.rb +++ b/spec/features/claim_with_mobile_sms_otp_spec.rb @@ -56,14 +56,18 @@ claim.eligibility = Policies::EarlyCareerPayments::Eligibility.new claim.eligibility.update!(attributes_for(:early_career_payments_eligibility, :eligible)) claim.update!(early_career_payments_personal_details_attributes) + session = Journeys::AdditionalPaymentsForTeaching::Session.last elsif scenario[:policy] == Policies::StudentLoans claim.eligibility = Policies::StudentLoans::Eligibility.new claim.eligibility.update!(attributes_for(:student_loans_eligibility, :eligible)) claim.update!(student_loans_personal_details_attributes) + session = Journeys::TeacherStudentLoanReimbursement::Session.last end + session.update!(answers: {provide_mobile_number: true}) + jump_to_claim_journey_page(claim, "mobile-number") - expect(claim.reload.provide_mobile_number).to eql true + expect(session.reload.answers.provide_mobile_number).to eql true # - Mobile number expect(page).to have_text(I18n.t("questions.mobile_number")) @@ -71,7 +75,7 @@ fill_in "claim_mobile_number", with: scenario[:mobile_number] click_on "Continue" - expect(claim.reload.mobile_number).to eql(scenario[:mobile_number]) + expect(session.reload.answers.mobile_number).to eql(scenario[:mobile_number]) # # - Mobile number one-time password expect(page).to have_text("Mobile number verification") diff --git a/spec/features/combined_teacher_claim_journey_spec.rb b/spec/features/combined_teacher_claim_journey_spec.rb index 3f1767e43f..0afd960dc8 100644 --- a/spec/features/combined_teacher_claim_journey_spec.rb +++ b/spec/features/combined_teacher_claim_journey_spec.rb @@ -2,6 +2,9 @@ RSpec.feature "Levelling up premium payments and early-career payments combined claim journey", :with_stubbed_hmrc_client, :with_hmrc_bank_validation_enabled do let(:claim) { Claim.by_policy(Policies::LevellingUpPremiumPayments).order(:created_at).last } + let(:journey_session) do + Journeys::AdditionalPaymentsForTeaching::Session.order(:created_at).last + end let(:eligibility) { claim.eligibility } before { create(:journey_configuration, :additional_payments) } @@ -191,7 +194,7 @@ click_on "Continue" # - Enter bank account details - expect(page).to have_text(I18n.t("questions.account_details", bank_or_building_society: claim.reload.bank_or_building_society.humanize.downcase)) + expect(page).to have_text(I18n.t("questions.account_details", bank_or_building_society: journey_session.reload.answers.bank_or_building_society.humanize.downcase)) expect(page).not_to have_text("Building society roll number") fill_in "Name on your account", with: "Jo Bloggs" diff --git a/spec/features/early_career_payments_eligible_now_reminder_set_spec.rb b/spec/features/early_career_payments_eligible_now_reminder_set_spec.rb index d330a77e9b..a83377fa25 100644 --- a/spec/features/early_career_payments_eligible_now_reminder_set_spec.rb +++ b/spec/features/early_career_payments_eligible_now_reminder_set_spec.rb @@ -14,11 +14,7 @@ claim.eligibility.update!(eligibility_attributes) session = Journeys::AdditionalPaymentsForTeaching::Session.last session.answers.assign_attributes( - attributes_for( - :additional_payments_answers, - :with_personal_details, - :with_email_details - ) + attributes_for(:additional_payments_answers, :submittable) ) session.save! @@ -87,11 +83,7 @@ session = Journeys::AdditionalPaymentsForTeaching::Session.last session.answers.assign_attributes( - attributes_for( - :additional_payments_answers, - :with_personal_details, - :with_email_details - ) + attributes_for(:additional_payments_answers, :submittable) ) session.save! diff --git a/spec/features/eligible_later_early_career_payments_claim_spec.rb b/spec/features/eligible_later_early_career_payments_claim_spec.rb index 301eb0bc82..033d494b1d 100644 --- a/spec/features/eligible_later_early_career_payments_claim_spec.rb +++ b/spec/features/eligible_later_early_career_payments_claim_spec.rb @@ -8,6 +8,9 @@ let(:lup_claim) { Claim.by_policy(Policies::LevellingUpPremiumPayments).order(:created_at).last } let(:current_school) { create(:school, :early_career_payments_eligible) } let(:itt_subject) { "mathematics" } + let(:journey_session) do + Journeys::AdditionalPaymentsForTeaching::Session.order(:created_at).last + end context "policy year 2022/2023" do it_behaves_like "Eligible later", { diff --git a/spec/features/hmrc_bank_validation_spec.rb b/spec/features/hmrc_bank_validation_spec.rb index 1c12410eae..0740a30d87 100644 --- a/spec/features/hmrc_bank_validation_spec.rb +++ b/spec/features/hmrc_bank_validation_spec.rb @@ -1,8 +1,9 @@ require "rails_helper" RSpec.feature "Bank account validation on claim journey", :with_hmrc_bank_validation_enabled do - let(:claim) { Claim.by_policy(Policies::LevellingUpPremiumPayments).order(:created_at).last } - let(:eligibility) { claim.eligibility } + let(:journey_session) do + Journeys::AdditionalPaymentsForTeaching::Session.order(:created_at).last + end let!(:journey_configuration) { create(:journey_configuration, :additional_payments) } let!(:school) { create(:school, :combined_journey_eligibile_for_all) } let(:bank_name) { "Jo Bloggs" } @@ -128,8 +129,10 @@ def get_to_bank_details_page expect(page).to have_text(I18n.t("forms.gender.questions.payroll_gender")) - expect(claim.reload).to be_hmrc_bank_validation_succeeded - expect(claim.hmrc_bank_validation_responses).not_to be_empty + journey_session.reload + answers = journey_session.answers + expect(answers.hmrc_bank_validation_succeeded?).to eq true + expect(answers.hmrc_bank_validation_responses).not_to be_empty # - HMRC API fails bank details match" click_on "Back" @@ -157,8 +160,10 @@ def get_to_bank_details_page # Third attempt succeeds. expect(page).to have_text(I18n.t("forms.gender.questions.payroll_gender")) - expect(claim.reload).not_to be_hmrc_bank_validation_succeeded - expect(claim.hmrc_bank_validation_responses).not_to be_empty + journey_session.reload + answers = journey_session.answers + expect(answers.hmrc_bank_validation_succeeded?).not_to be true + expect(answers.hmrc_bank_validation_responses).not_to be_empty end end end @@ -176,7 +181,9 @@ def get_to_bank_details_page expect(page).to have_text(I18n.t("forms.gender.questions.payroll_gender")) - expect(claim.reload).not_to be_hmrc_bank_validation_succeeded + journey_session.reload + answers = journey_session.answers + expect(answers.hmrc_bank_validation_succeeded?).not_to be true end end end diff --git a/spec/features/levelling_up_premium_payments_spec.rb b/spec/features/levelling_up_premium_payments_spec.rb index a307fc86a7..1fb07dc7ca 100644 --- a/spec/features/levelling_up_premium_payments_spec.rb +++ b/spec/features/levelling_up_premium_payments_spec.rb @@ -198,7 +198,7 @@ def claim_up_to_check_your_answers click_on "Continue" # - Enter bank account details - expect(page).to have_text(I18n.t("questions.account_details", bank_or_building_society: claim.bank_or_building_society.humanize.downcase)) + expect(page).to have_text(I18n.t("questions.account_details", bank_or_building_society: journey_session.reload.answers.bank_or_building_society.humanize.downcase)) expect(page).not_to have_text("Building society roll number") fill_in "Name on your account", with: "Jo Bloggs" diff --git a/spec/features/student_loans_claim_spec.rb b/spec/features/student_loans_claim_spec.rb index 6da410ac2f..aeb9de8dac 100644 --- a/spec/features/student_loans_claim_spec.rb +++ b/spec/features/student_loans_claim_spec.rb @@ -137,7 +137,7 @@ def fill_in_remaining_personal_details_and_submit choose "No" click_on "Continue" - expect(claim.reload.provide_mobile_number).to eql false + expect(session.reload.answers.provide_mobile_number).to eql false # - Mobile number expect(page).not_to have_text(I18n.t("questions.mobile_number")) @@ -147,9 +147,9 @@ def fill_in_remaining_personal_details_and_submit choose "Building society" click_on "Continue" - expect(claim.reload.bank_or_building_society).to eq "building_society" + expect(session.reload.answers.bank_or_building_society).to eq "building_society" - expect(page).to have_text(I18n.t("questions.account_details", bank_or_building_society: claim.bank_or_building_society.humanize.downcase)) + expect(page).to have_text(I18n.t("questions.account_details", bank_or_building_society: session.answers.bank_or_building_society.humanize.downcase)) expect(page).to have_text("Building society roll number") fill_in "Name on your account", with: "Jo Bloggs" @@ -158,10 +158,12 @@ def fill_in_remaining_personal_details_and_submit fill_in "Building society roll number", with: "1234/123456789" click_on "Continue" - expect(claim.reload.banking_name).to eq("Jo Bloggs") - expect(claim.bank_sort_code).to eq("123456") - expect(claim.bank_account_number).to eq("87654321") - expect(claim.building_society_roll_number).to eq("1234/123456789") + session.reload + answers = session.answers + expect(answers.banking_name).to eq("Jo Bloggs") + expect(answers.bank_sort_code).to eq("123456") + expect(answers.bank_account_number).to eq("87654321") + expect(answers.building_society_roll_number).to eq("1234/123456789") expect(page).to have_text(I18n.t("forms.gender.questions.payroll_gender")) choose "Male" diff --git a/spec/forms/bank_details_form_spec.rb b/spec/forms/bank_details_form_spec.rb index 04cff82261..338283895e 100644 --- a/spec/forms/bank_details_form_spec.rb +++ b/spec/forms/bank_details_form_spec.rb @@ -7,21 +7,29 @@ create(:journey_configuration, :additional_payments) } - let(:current_claim) do - claims = journey::POLICIES.map { |policy| create(:claim, :with_bank_details, policy:) } - CurrentClaim.new(claims: claims) + let(:journey_session) do + create( + :"#{journey::I18N_NAMESPACE}_session", + answers: attributes_for( + :"#{journey::I18N_NAMESPACE}_answers" + ) + ) end - let(:journey_session) { build(:"#{journey::I18N_NAMESPACE}_session") } - let(:slug) { "personal-bank-account" } let(:params) do - {banking_name:, bank_sort_code:, bank_account_number:, building_society_roll_number:, hmrc_validation_attempt_count:} + { + banking_name:, + bank_sort_code:, + bank_account_number:, + building_society_roll_number:, + hmrc_validation_attempt_count: + } end subject(:form) do described_class.new( - claim: current_claim, + claim: CurrentClaim.new(claims: [build(:claim)]), journey_session: journey_session, journey: journey, params: ActionController::Parameters.new(slug:, claim: params) @@ -67,9 +75,14 @@ end context "when building society" do - let(:current_claim) do - claims = journey::POLICIES.map { |policy| create(:claim, :with_bank_details, bank_or_building_society: :building_society, policy:) } - CurrentClaim.new(claims: claims) + let(:journey_session) do + create( + :"#{journey::I18N_NAMESPACE}_session", + answers: attributes_for( + :"#{journey::I18N_NAMESPACE}_answers", + bank_or_building_society: "building_society" + ) + ) end context "with valid building society roll number" do @@ -100,9 +113,10 @@ end it "adds the response to the claim" do - expect { form.valid? }.to change { current_claim.reload.hmrc_bank_validation_responses }.from([]).to [ - {"body" => "Test response", "code" => 200} - ] + expect { form.valid? }.to( + change { journey_session.reload.answers.hmrc_bank_validation_responses } + .from([]).to([{"body" => "Test response", "code" => 200}]) + ) end context "when the sort code doesn't pass basic validation" do @@ -196,9 +210,10 @@ end it "adds the response to the claim" do - expect { form.valid? }.to change { current_claim.reload.hmrc_bank_validation_responses }.from([]).to [ - {"body" => "Test response", "code" => 200} - ] + expect { form.valid? }.to( + change { journey_session.reload.answers.hmrc_bank_validation_responses } + .from([]).to([{"body" => "Test response", "code" => 200}]) + ) end end end @@ -246,9 +261,10 @@ end it "adds the response to the claim" do - expect { form.valid? }.to change { current_claim.reload.hmrc_bank_validation_responses }.from([]).to [ - {"body" => "Test failure", "code" => 429} - ] + expect { form.valid? }.to( + change { journey_session.reload.answers.hmrc_bank_validation_responses } + .from([]).to([{"body" => "Test failure", "code" => 429}]) + ) end end end diff --git a/spec/forms/bank_or_building_society_form_spec.rb b/spec/forms/bank_or_building_society_form_spec.rb index c8e1678761..ffe7672ce0 100644 --- a/spec/forms/bank_or_building_society_form_spec.rb +++ b/spec/forms/bank_or_building_society_form_spec.rb @@ -7,19 +7,23 @@ create(:journey_configuration, :additional_payments) } - let(:current_claim) do - claims = journey::POLICIES.map { |policy| create(:claim, policy: policy) } - CurrentClaim.new(claims:) + let(:journey_session) do + create( + :"#{journey::I18N_NAMESPACE}_session", + answers: attributes_for( + :"#{journey::I18N_NAMESPACE}_answers", + :with_bank_details, + building_society_roll_number: "A123456" + ) + ) end - let(:journey_session) { build(:"#{journey::I18N_NAMESPACE}_session") } - let(:slug) { "bank-or-building-society-form" } let(:claim_params) { {} } subject(:form) do described_class.new( - claim: current_claim, + claim: CurrentClaim.new(claims: [build(:claim)]), journey_session: journey_session, journey: journey, params: ActionController::Parameters.new({slug:, claim: claim_params}) @@ -37,9 +41,41 @@ it "saves bank_or_building_society" do expect(form.save).to be true - current_claim.claims.each do |claim| - expect(claim.bank_or_building_society).to eq "personal_bank_account" - end + expect( + journey_session.reload.answers.bank_or_building_society + ).to eq "personal_bank_account" + end + end + + context "when bank_or_building_society has not changed" do + let(:claim_params) { {bank_or_building_society: "personal_bank_account"} } + + it "doesn't reset dependent answers" do + expect { expect(form.save).to be true }.to( + not_change { journey_session.reload.answers.banking_name }.and( + not_change { journey_session.reload.answers.bank_account_number } + ).and( + not_change { journey_session.reload.answers.bank_sort_code } + ).and( + not_change { journey_session.reload.answers.building_society_roll_number } + ) + ) + end + end + + context "when bank_or_building_society has changed" do + let(:claim_params) { {bank_or_building_society: "building_society"} } + + it "resets dependent answers" do + expect { expect(form.save).to be true }.to( + change { journey_session.reload.answers.banking_name }.to(nil).and( + change { journey_session.reload.answers.bank_account_number }.to(nil) + ).and( + change { journey_session.reload.answers.bank_sort_code }.to(nil) + ).and( + change { journey_session.reload.answers.building_society_roll_number }.to(nil) + ) + ) end end end diff --git a/spec/forms/mobile_number_form_spec.rb b/spec/forms/mobile_number_form_spec.rb index 4285ea8f98..6e94f8abaa 100644 --- a/spec/forms/mobile_number_form_spec.rb +++ b/spec/forms/mobile_number_form_spec.rb @@ -2,21 +2,17 @@ RSpec.describe MobileNumberForm do shared_examples "mobile_number_form" do |journey| - let(:claims) do - journey::POLICIES.map do |policy| - create( - :claim, + let(:journey_session) do + create( + :"#{journey::I18N_NAMESPACE}_session", + answers: attributes_for( + :"#{journey::I18N_NAMESPACE}_answers", :with_details_from_dfe_identity, - policy: policy, mobile_verified: true ) - end + ) end - let(:journey_session) { build(:"#{journey::I18N_NAMESPACE}_session") } - - let(:current_claim) { CurrentClaim.new(claims: claims) } - let(:params) do ActionController::Parameters.new(claim: {mobile_number: mobile_number}) end @@ -25,7 +21,7 @@ described_class.new( journey: journey, journey_session: journey_session, - claim: current_claim, + claim: CurrentClaim.new(claims: [build(:claim)]), params: params ) end @@ -103,15 +99,11 @@ end it "stores the mobile number" do - claims.each do |claim| - expect(claim.mobile_number).to eq(mobile_number) - end + expect(journey_session.reload.answers.mobile_number).to eq(mobile_number) end it "resets dependent attributes" do - claims.each do |claim| - expect(claim.mobile_verified).to be_nil - end + expect(journey_session.reload.answers.mobile_verified).to be_nil end it "sends a text message" do @@ -127,11 +119,9 @@ end it "sets sent_one_time_password_at to the current time" do - claims.each do |claim| - expect(claim.sent_one_time_password_at).to( - eq(DateTime.new(2024, 1, 1, 12, 0, 0)) - ) - end + expect(journey_session.reload.answers.sent_one_time_password_at).to( + eq(DateTime.new(2024, 1, 1, 12, 0, 0)) + ) end end @@ -141,15 +131,11 @@ let(:notify_response) { nil } it "stores the mobile number" do - claims.each do |claim| - expect(claim.mobile_number).to eq(mobile_number) - end + expect(journey_session.reload.answers.mobile_number).to eq(mobile_number) end it "resets dependent attributes" do - claims.each do |claim| - expect(claim.mobile_verified).to be_nil - end + expect(journey_session.reload.answers.mobile_verified).to be_nil end it "sends a text message" do @@ -165,9 +151,7 @@ end it "sets sent_one_time_password_at to nil" do - claims.each do |claim| - expect(claim.sent_one_time_password_at).to be_nil - end + expect(journey_session.reload.answers.sent_one_time_password_at).to be_nil end end end diff --git a/spec/forms/mobile_verification_form_spec.rb b/spec/forms/mobile_verification_form_spec.rb index 0e87aeab67..b57b08b5d9 100644 --- a/spec/forms/mobile_verification_form_spec.rb +++ b/spec/forms/mobile_verification_form_spec.rb @@ -2,20 +2,15 @@ RSpec.describe MobileVerificationForm do shared_examples "mobile_verification" do |journey| - let(:claims) do - journey::POLICIES.map do |policy| - create( - :claim, - policy: policy, + let(:journey_session) do + create( + :"#{journey::I18N_NAMESPACE}_session", + answers: { sent_one_time_password_at: sent_one_time_password_at - ) - end + } + ) end - let(:current_claim) { CurrentClaim.new(claims: claims) } - - let(:journey_session) { build(:"#{journey::I18N_NAMESPACE}_session") } - let(:params) do ActionController::Parameters.new( claim: { @@ -28,7 +23,7 @@ described_class.new( journey: journey, journey_session: journey_session, - claim: current_claim, + claim: CurrentClaim.new(claims: [build(:claim)]), params: params ) end @@ -87,9 +82,7 @@ before { form.save } it "sets the mobile_verified attribute to true" do - claims.each do |claim| - expect(claim.mobile_verified).to be true - end + expect(journey_session.reload.answers.mobile_verified).to be true end end end diff --git a/spec/forms/provide_mobile_number_form_spec.rb b/spec/forms/provide_mobile_number_form_spec.rb index 7ca54ad254..1b36b2b514 100644 --- a/spec/forms/provide_mobile_number_form_spec.rb +++ b/spec/forms/provide_mobile_number_form_spec.rb @@ -7,18 +7,23 @@ create(:journey_configuration, :additional_payments) } - let(:current_claim) do - claims = journey::POLICIES.map { |policy| create(:claim, policy: policy) } - CurrentClaim.new(claims: claims) - end - let(:slug) { "provide-mobile-number" } + let(:params) { ActionController::Parameters.new } - let(:journey_session) { build(:"#{journey::I18N_NAMESPACE}_session") } + + let(:journey_session) do + create( + :"#{journey::I18N_NAMESPACE}_session", + answers: { + provide_mobile_number: provide_mobile_number, + mobile_verified: true + } + ) + end subject(:form) do described_class.new( - claim: current_claim, + claim: CurrentClaim.new(claims: [build(:claim)]), journey_session: journey_session, journey: journey, params: params @@ -26,6 +31,8 @@ end context "unpermitted claim param" do + let(:provide_mobile_number) { nil } + let(:params) { ActionController::Parameters.new({slug: slug, claim: {nonsense_id: 1}}) } it "raises an error" do @@ -34,6 +41,8 @@ end describe "validations" do + let(:provide_mobile_number) { nil } + it { should allow_value(%w[true false]).for(:provide_mobile_number).with_message("Select yes if you would like to provide your mobile number") } end @@ -42,32 +51,63 @@ let(:params) { ActionController::Parameters.new({slug: slug, claim: {provide_mobile_number: "Yes"}}) } context "when claim is missing provide_mobile_number" do - let(:current_claim) do - claims = journey::POLICIES.map { |policy| create(:claim, policy: policy) } - CurrentClaim.new(claims: claims) - end + let(:provide_mobile_number) { nil } it "saves provide_mobile_number" do expect(form.save).to be true - current_claim.claims.each do |claim| - expect(claim.provide_mobile_number).to be_truthy - end + expect( + journey_session.reload.answers.provide_mobile_number + ).to eq true end end context "claim already has provide_mobile_number" do - let(:current_claim) do - claims = journey::POLICIES.map { |policy| create(:claim, policy: policy, provide_mobile_number: false) } - CurrentClaim.new(claims: claims) - end + let(:provide_mobile_number) { false } it "updates provide_mobile_number on claim" do expect(form.save).to be true - current_claim.claims.each do |claim| - expect(claim.provide_mobile_number).to be_truthy - end + expect( + journey_session.reload.answers.provide_mobile_number + ).to eq true + end + end + + context "when provide_mobile_number has not changed" do + let(:provide_mobile_number) { true } + + let(:params) do + ActionController::Parameters.new( + claim: { + provide_mobile_number: "Yes" + } + ) + end + + it "doesn't reset dependent answers" do + form.save + + expect(journey_session.reload.answers.mobile_verified).to eq true + end + end + + context "when provide_mobile_number has changed" do + let(:provide_mobile_number) { false } + + let(:params) do + ActionController::Parameters.new( + claim: { + provide_mobile_number: "Yes" + } + ) + end + + it "resets dependent answers" do + expect { form.save }.to( + change { journey_session.reload.answers.mobile_verified } + .from(true).to(nil) + ) end end end diff --git a/spec/forms/select_mobile_form_spec.rb b/spec/forms/select_mobile_form_spec.rb index 34ac1bc078..d57a7f433b 100644 --- a/spec/forms/select_mobile_form_spec.rb +++ b/spec/forms/select_mobile_form_spec.rb @@ -2,12 +2,6 @@ RSpec.describe SelectMobileForm do shared_examples "select_mobile_form" do |journey| - let(:claims) do - journey::POLICIES.map { |policy| create(:claim, policy: policy) } - end - - let(:current_claim) { CurrentClaim.new(claims: claims) } - let(:journey_session) do create( :"#{journey::I18N_NAMESPACE}_session", @@ -29,7 +23,7 @@ described_class.new( journey: journey, journey_session: journey_session, - claim: current_claim, + claim: CurrentClaim.new(claims: [build(:claim)]), params: params ) end @@ -72,12 +66,12 @@ let(:mobile_check) { "use" } it "updates the claims" do - claims.each do |claim| - expect(claim.mobile_number).to eq("07123456789") - expect(claim.provide_mobile_number).to eq(true) - expect(claim.mobile_check).to eq("use") - expect(claim.mobile_verified).to eq(nil) - end + answers = journey_session.reload.answers + + expect(answers.mobile_number).to eq("07123456789") + expect(answers.provide_mobile_number).to eq(true) + expect(answers.mobile_check).to eq("use") + expect(answers.mobile_verified).to eq(nil) end end @@ -85,12 +79,12 @@ let(:mobile_check) { "alternative" } it "updates the claims" do - claims.each do |claim| - expect(claim.mobile_number).to eq(nil) - expect(claim.provide_mobile_number).to eq(true) - expect(claim.mobile_check).to eq("alternative") - expect(claim.mobile_verified).to eq(nil) - end + answers = journey_session.reload.answers + + expect(answers.mobile_number).to eq(nil) + expect(answers.provide_mobile_number).to eq(true) + expect(answers.mobile_check).to eq("alternative") + expect(answers.mobile_verified).to eq(nil) end end @@ -98,12 +92,12 @@ let(:mobile_check) { "declined" } it "updates the claimms" do - claims.each do |claim| - expect(claim.mobile_number).to eq(nil) - expect(claim.provide_mobile_number).to eq(false) - expect(claim.mobile_check).to eq("declined") - expect(claim.mobile_verified).to eq(nil) - end + answers = journey_session.reload.answers + + expect(answers.mobile_number).to eq(nil) + expect(answers.provide_mobile_number).to eq(false) + expect(answers.mobile_check).to eq("declined") + expect(answers.mobile_verified).to eq(nil) end end end diff --git a/spec/models/journeys/additional_payments_for_teaching/slug_sequence_spec.rb b/spec/models/journeys/additional_payments_for_teaching/slug_sequence_spec.rb index af59ea200e..6311cad43b 100644 --- a/spec/models/journeys/additional_payments_for_teaching/slug_sequence_spec.rb +++ b/spec/models/journeys/additional_payments_for_teaching/slug_sequence_spec.rb @@ -278,13 +278,13 @@ context "when 'provide_mobile_number' is 'No'" do it "excludes the 'mobile-number' slug" do - claim.provide_mobile_number = false + journey_session.answers.provide_mobile_number = false expect(slug_sequence.slugs).not_to include("mobile-number") end it "excludes the 'mobile-verification' slug" do - claim.provide_mobile_number = false + journey_session.answers.provide_mobile_number = false expect(slug_sequence.slugs).not_to include("mobile-verification") end @@ -292,13 +292,13 @@ context "when 'provide_mobile_number' is 'Yes'" do it "includes the 'mobile-number' slug" do - claim.provide_mobile_number = true + journey_session.answers.provide_mobile_number = true expect(slug_sequence.slugs).to include("mobile-number") end it "includes the 'mobile-verification' slug" do - claim.provide_mobile_number = true + journey_session.answers.provide_mobile_number = true expect(slug_sequence.slugs).to include("mobile-verification") end @@ -342,7 +342,7 @@ context "when claim payment details are 'personal bank account'" do it "excludes the 'building-society-account' slug" do - claim.bank_or_building_society = :personal_bank_account + journey_session.answers.bank_or_building_society = :personal_bank_account expect(slug_sequence.slugs).not_to include("building-society-account") end @@ -350,7 +350,7 @@ context "when claim payment details are 'building society'" do it "excludes the 'personal-bank-account' slug" do - claim.bank_or_building_society = :building_society + journey_session.answers.bank_or_building_society = :building_society expect(slug_sequence.slugs).not_to include("personal-bank-account") end diff --git a/spec/models/journeys/page_sequence_spec.rb b/spec/models/journeys/page_sequence_spec.rb index 33c92ad254..51b5ee6645 100644 --- a/spec/models/journeys/page_sequence_spec.rb +++ b/spec/models/journeys/page_sequence_spec.rb @@ -58,11 +58,7 @@ let(:journey_session) do build( :student_loans_session, - answers: attributes_for( - :student_loans_answers, - :with_personal_details, - :with_email_details - ) + answers: attributes_for(:student_loans_answers, :submittable) ) end diff --git a/spec/models/journeys/teacher_student_loan_reimbursement/slug_sequence_spec.rb b/spec/models/journeys/teacher_student_loan_reimbursement/slug_sequence_spec.rb index 4de2d4a245..165a2f212f 100644 --- a/spec/models/journeys/teacher_student_loan_reimbursement/slug_sequence_spec.rb +++ b/spec/models/journeys/teacher_student_loan_reimbursement/slug_sequence_spec.rb @@ -39,7 +39,7 @@ context "when claim payment details are 'personal bank account'" do it "excludes the 'building-society-account' slug" do - claim.bank_or_building_society = :personal_bank_account + journey_session.answers.bank_or_building_society = :personal_bank_account expect(slug_sequence.slugs).not_to include("building-society-account") end @@ -47,7 +47,7 @@ context "when claim payment details are 'building society'" do it "excludes the 'personal-bank-account' slug" do - claim.bank_or_building_society = :building_society + journey_session.answers.bank_or_building_society = :building_society expect(slug_sequence.slugs).not_to include("personal-bank-account") end @@ -55,13 +55,13 @@ context "when 'provide_mobile_number' is 'No'" do it "excludes the 'mobile-number' slug" do - claim.provide_mobile_number = false + journey_session.answers.provide_mobile_number = false expect(slug_sequence.slugs).not_to include("mobile-number") end it "excludes the 'mobile-verification' slug" do - claim.provide_mobile_number = false + journey_session.answers.provide_mobile_number = false expect(slug_sequence.slugs).not_to include("mobile-verification") end @@ -69,13 +69,13 @@ context "when 'provide_mobile_number' is 'Yes'" do it "includes the 'mobile-number' slug" do - claim.provide_mobile_number = true + journey_session.answers.provide_mobile_number = true expect(slug_sequence.slugs).to include("mobile-number") end it "includes the 'mobile-verification' slug" do - claim.provide_mobile_number = true + journey_session.answers.provide_mobile_number = true expect(slug_sequence.slugs).to include("mobile-verification") end diff --git a/spec/requests/claims_spec.rb b/spec/requests/claims_spec.rb index 817d4f67f8..1fa3a991f9 100644 --- a/spec/requests/claims_spec.rb +++ b/spec/requests/claims_spec.rb @@ -332,7 +332,7 @@ def check_slug_redirection expect(response).to be_successful expect(response.body).to include("There is a problem") expect(response.body).to include("Select a school from the list") - expect(response.body).to include(school.name) + expect(response.body).to include(CGI.escapeHTML(school.name)) # eg. apostrophe characters become HTML entities end end diff --git a/spec/requests/submissions_spec.rb b/spec/requests/submissions_spec.rb index eb825b3faf..bb24e6cad7 100644 --- a/spec/requests/submissions_spec.rb +++ b/spec/requests/submissions_spec.rb @@ -20,11 +20,7 @@ in_progress_claim.save! journey_session.update!( - answers: attributes_for( - :student_loans_answers, - :with_personal_details, - :with_email_details - ) + answers: attributes_for(:student_loans_answers, :submittable) ) stub_qualified_teaching_statuses_show( diff --git a/spec/support/eligible_later_shared_examples.rb b/spec/support/eligible_later_shared_examples.rb index 07254756e2..1e553286a2 100644 --- a/spec/support/eligible_later_shared_examples.rb +++ b/spec/support/eligible_later_shared_examples.rb @@ -14,6 +14,10 @@ itt_academic_year: itt_academic_year ) + journey_session.answers.assign_attributes( + attributes_for(:additional_payments_answers, :submittable) + ) + jump_to_claim_journey_page(claim, "check-your-answers-part-one") expect(page).to have_text(I18n.t("additional_payments.check_your_answers.part_one.primary_heading")) diff --git a/spec/support/journey_answers_presenter_shared_examples.rb b/spec/support/journey_answers_presenter_shared_examples.rb index 069967efa9..40043d5665 100644 --- a/spec/support/journey_answers_presenter_shared_examples.rb +++ b/spec/support/journey_answers_presenter_shared_examples.rb @@ -23,9 +23,6 @@ date_of_birth: dob, teacher_reference_number: trn, national_insurance_number: nino, - mobile_check: logged_in_with_tid ? "use" : nil, - provide_mobile_number: true, - mobile_number: "01234567890", payroll_gender: :dont_know, logged_in_with_tid:, teacher_id_user_info: @@ -44,7 +41,10 @@ date_of_birth: dob, national_insurance_number: nino, email_address: "test@email.com", - email_address_check: logged_in_with_tid ? true : false + email_address_check: logged_in_with_tid ? true : false, + mobile_check: logged_in_with_tid ? "use" : nil, + provide_mobile_number: true, + mobile_number: "01234567890" } ) end @@ -108,9 +108,9 @@ context "when the user selected the mobile provided by Teacher ID" do before do - claim.mobile_number = "01234567890" - claim.mobile_check = "use" - claim.provide_mobile_number = true + journey_session.answers.mobile_number = "01234567890" + journey_session.answers.mobile_check = "use" + journey_session.answers.provide_mobile_number = true end it "includes the selected mobile and the change slug is `select-mobile`" do @@ -124,9 +124,9 @@ context "when the user selected to provide an alternative mobile" do before do - claim.mobile_number = "01234567891" - claim.mobile_check = "alternative" - claim.provide_mobile_number = true + journey_session.answers.mobile_number = "01234567891" + journey_session.answers.mobile_check = "alternative" + journey_session.answers.provide_mobile_number = true end it "includes the user-provided mobile and the change slug is `select-mobile`" do @@ -140,9 +140,9 @@ context "when the user declined to be contacted by mobile" do before do - claim.mobile_number = nil - claim.mobile_check = "declined" - claim.provide_mobile_number = false + journey_session.answers.mobile_number = nil + journey_session.answers.mobile_check = "declined" + journey_session.answers.provide_mobile_number = false end it "includes the answer to decline and the change slug is `select-mobile`" do @@ -181,8 +181,8 @@ context "when the user declined to be contacted by mobile" do before do - claim.mobile_number = nil - claim.provide_mobile_number = false + journey_session.answers.mobile_number = nil + journey_session.answers.provide_mobile_number = false end it "excludes the answer to `mobile-number`" do @@ -198,9 +198,20 @@ end describe "#payment_answers" do - let(:claim) { create(:claim, bank_or_building_society: :personal_bank_account, bank_sort_code: "12 34 56", bank_account_number: "12 34 56 78", banking_name: "Jo Bloggs") } + let(:claim) { create(:claim) } + let(:journey_session) do + create( + :additional_payments_session, + answers: { + bank_or_building_society: "personal_bank_account", + bank_sort_code: "123456", + bank_account_number: "12345678", + banking_name: "Jo Bloggs" + } + ) + end - subject(:answers) { described_class.new(current_claim, nil).payment_answers } + subject(:answers) { described_class.new(current_claim, journey_session).payment_answers } context "when a personal bank account is selected" do it "returns an array of questions and answers for displaying to the user for review" do @@ -216,7 +227,19 @@ end context "when a building society is selected" do - let(:claim) { create(:claim, bank_or_building_society: :building_society, bank_sort_code: "65 90 07", bank_account_number: "90 77 02 24", banking_name: "David Badger-Hillary", building_society_roll_number: "5890/87654321") } + let(:claim) { create(:claim) } + let(:journey_session) do + create( + :additional_payments_session, + answers: { + bank_or_building_society: "building_society", + bank_sort_code: "659007", + bank_account_number: "90770224", + banking_name: "David Badger-Hillary", + building_society_roll_number: "5890/87654321" + } + ) + end it "returns an array of questions and answers for displaying to the user for review" do expected_answers = [