Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store current school on the journey session #2793

Merged
merged 6 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions app/forms/current_school_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,28 @@ def initialize(claim:, journey_session:, journey:, params:)
super

load_schools
self.current_school_id = permitted_params[:current_school_id]
end

def save
return false unless valid?

update!({"eligibility_attributes" => {"current_school_id" => current_school_id}})
journey_session.answers.assign_attributes(current_school_id:)
journey_session.save!
update!("eligibility_attributes" => {"current_school_id" => current_school_id})
end

def current_school_name
claim.eligibility.current_school_name
end
delegate :name, to: :current_school, prefix: true, allow_nil: true

def no_search_results?
params[:school_search].present? && errors.empty?
end

private

def current_school
@current_school ||= School.find_by(id: current_school_id)
end

def load_schools
return unless params[:school_search]

Expand All @@ -40,8 +43,8 @@ def load_schools
end

def current_school_must_be_open
if (school = School.find_by(id: current_school_id))
errors.add(:current_school_id, i18n_errors_path("the_selected_school_is_closed")) unless school.open?
if current_school
errors.add(:current_school_id, i18n_errors_path("the_selected_school_is_closed")) unless current_school.open?
else
errors.add(:current_school_id, i18n_errors_path("school_not_found"))
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,10 @@ def induction_question_required?
end

def ecp_school_selected?
return false unless claim.eligibility.current_school
school = answers&.current_school || claim.eligibility.current_school
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering if we can use the shim to do this, it would handle the ORing of this? /cc @rjlynch - would that make sense?

return false unless school

Policies::EarlyCareerPayments::SchoolEligibility.new(claim.eligibility.current_school).eligible?
Policies::EarlyCareerPayments::SchoolEligibility.new(school).eligible?
end

# We only retrieve dqt teacher status when the user is signed in with DfE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ def employment

def identity_confirmation
[
["Current school", eligibility.current_school.name],
["Contact number", eligibility.current_school.phone_number]
["Current school", eligibility.current_school&.name],
["Contact number", eligibility.current_school&.phone_number]
]
end

Expand Down
7 changes: 5 additions & 2 deletions spec/forms/current_school_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
CurrentClaim.new(claims: claims)
end

let(:journey_session) { build(:"#{journey::I18N_NAMESPACE}_session") }
let(:journey_session) { create(:"#{journey::I18N_NAMESPACE}_session") }

let(:slug) { "current-school" }

Expand Down Expand Up @@ -82,9 +82,12 @@
describe "#save" do
context "current_school_id submitted" do
let(:params) { ActionController::Parameters.new({slug: slug, claim: {current_school_id: school.id}}) }

let(:school) { create(:school, :eligible_for_journey, journey: journey) }

it "updates the journey_session" do
expect { form.save }.to change { journey_session.reload.answers.current_school_id }.to(school.id)
end

context "claim eligibility didn't have current_school" do
let(:current_claim) do
claims = journey::POLICIES.map { |policy| create(:claim, policy: policy) }
Expand Down