From a1f0ee336e98b29fc5a7b491fc3bfbebdf4c3288 Mon Sep 17 00:00:00 2001 From: Alkesh Vaghmaria Date: Tue, 23 Jul 2024 10:41:06 +0100 Subject: [PATCH] tidy up. spec added for sign in form --- app/forms/sign_in_form.rb | 2 +- app/forms/signed_in_form.rb | 2 - .../further_education_payments_answers.rb | 5 ++ spec/forms/sign_in_form_spec.rb | 52 +++++++++++++++++++ 4 files changed, 58 insertions(+), 3 deletions(-) delete mode 100644 app/forms/signed_in_form.rb create mode 100644 spec/forms/sign_in_form_spec.rb diff --git a/app/forms/sign_in_form.rb b/app/forms/sign_in_form.rb index 9d62637bd2..4c6466f918 100644 --- a/app/forms/sign_in_form.rb +++ b/app/forms/sign_in_form.rb @@ -21,7 +21,7 @@ class OneloginUserInfoForm def onelogin_user_info_attributes=(attributes) onelogin_user_info.assign_attributes( - attributes || journey_session.answers.onelogin_user_info # TODO: store answers in journey_session + journey_session.answers.onelogin_user_info ) end diff --git a/app/forms/signed_in_form.rb b/app/forms/signed_in_form.rb deleted file mode 100644 index 12f4293120..0000000000 --- a/app/forms/signed_in_form.rb +++ /dev/null @@ -1,2 +0,0 @@ -class SignedInForm < Form -end diff --git a/spec/factories/journeys/further_education_payments/further_education_payments_answers.rb b/spec/factories/journeys/further_education_payments/further_education_payments_answers.rb index 9c2bf044aa..84bdf96210 100644 --- a/spec/factories/journeys/further_education_payments/further_education_payments_answers.rb +++ b/spec/factories/journeys/further_education_payments/further_education_payments_answers.rb @@ -1,4 +1,9 @@ FactoryBot.define do factory :further_education_payments_answers, class: "Journeys::FurtherEducationPayments::SessionAnswers" do + trait :with_details_from_onelogin do + first_name { "Jo" } + surname { "Bloggs" } + onelogin_user_info { {email: "jo.bloggs@example.com"} } + end end end diff --git a/spec/forms/sign_in_form_spec.rb b/spec/forms/sign_in_form_spec.rb new file mode 100644 index 0000000000..cfc69a5c78 --- /dev/null +++ b/spec/forms/sign_in_form_spec.rb @@ -0,0 +1,52 @@ +require "rails_helper" + +RSpec.describe SignInForm do + let(:journey) { Journeys::FurtherEducationPayments } + let(:journey_session) do + build( + :"#{journey::I18N_NAMESPACE}_session", + answers: attributes_for( + :"#{journey::I18N_NAMESPACE}_answers", + :with_details_from_onelogin + ) + ) + end + + let(:onelogin_user_info) do + {email: "jo.bloggs@example.com", phone: nil} + end + + let(:form) do + described_class.new( + journey: journey, + journey_session: journey_session, + params: params + ) + end + + let(:params) do + ActionController::Parameters.new( + claim: { + # logged_in_with_tid: true + } + ) + end + + describe "#save" do + before { form.save } + + it "keeps the details from onelogin_user_info" do + expect( + journey_session.answers.onelogin_user_info.symbolize_keys + ).to(eq(onelogin_user_info)) + end + + it "keeps the first name" do + expect(journey_session.answers.first_name).to eq "Jo" + end + + it "keeps the surname" do + expect(journey_session.answers.surname).to eq "Bloggs" + end + end +end