Skip to content

Commit

Permalink
tidy up. spec added for sign in form
Browse files Browse the repository at this point in the history
  • Loading branch information
alkesh committed Jul 23, 2024
1 parent e64d646 commit a1f0ee3
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/forms/sign_in_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 0 additions & 2 deletions app/forms/signed_in_form.rb

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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: "[email protected]"} }
end
end
end
52 changes: 52 additions & 0 deletions spec/forms/sign_in_form_spec.rb
Original file line number Diff line number Diff line change
@@ -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: "[email protected]", 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

0 comments on commit a1f0ee3

Please sign in to comment.