From 999fb4058fc12f309d3fba794a72e4e8a1a9b0c5 Mon Sep 17 00:00:00 2001 From: Alkesh Vaghmaria Date: Fri, 25 Oct 2024 12:51:27 +0100 Subject: [PATCH] normalise NI number before saving in answers --- app/forms/personal_details_form.rb | 2 +- .../happy_path_spec.rb | 2 +- spec/forms/personal_details_form_spec.rb | 25 ++++++++++++++++--- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/app/forms/personal_details_form.rb b/app/forms/personal_details_form.rb index 2999451e78..38a6e4bcc0 100644 --- a/app/forms/personal_details_form.rb +++ b/app/forms/personal_details_form.rb @@ -56,7 +56,7 @@ def save middle_name:, surname:, date_of_birth:, - national_insurance_number: + national_insurance_number: normalised_ni_number ) reset_dependent_answers_attributes diff --git a/spec/features/further_education_payments/happy_path_spec.rb b/spec/features/further_education_payments/happy_path_spec.rb index 29ed7f5979..046645fa5d 100644 --- a/spec/features/further_education_payments/happy_path_spec.rb +++ b/spec/features/further_education_payments/happy_path_spec.rb @@ -126,7 +126,7 @@ fill_in "Day", with: "28" fill_in "Month", with: "2" fill_in "Year", with: "1988" - fill_in "National Insurance number", with: "PX321499A" + fill_in "National Insurance number", with: "PX321499A " # deliberate trailing space click_on "Continue" expect(page).to have_content("What is your home address?") diff --git a/spec/forms/personal_details_form_spec.rb b/spec/forms/personal_details_form_spec.rb index f02a25f8d5..ad4a4c59cb 100644 --- a/spec/forms/personal_details_form_spec.rb +++ b/spec/forms/personal_details_form_spec.rb @@ -342,10 +342,10 @@ end describe "#save" do - context "with valid params" do - let(:logged_in_with_tid) { nil } - let(:teacher_id_user_info) { {} } + let(:logged_in_with_tid) { nil } + let(:teacher_id_user_info) { {} } + context "with valid params" do let(:params) do { first_name: "Dr", @@ -379,6 +379,25 @@ expect(answers.student_loan_plan).to be nil end end + + context "with a national insurance number with spaces" do + let(:params) do + { + first_name: "Dr", + middle_name: "Bob", + surname: "Loblaw", + day: 1, + month: 1, + year: 1990, + national_insurance_number: "QQ 123456 C " + } + end + + it "strips spaces" do + form.save + expect(journey_session.answers.national_insurance_number).to eq "QQ123456C" + end + end end end