From 367379ccd6fd687d50f19f37117e2e6318930586 Mon Sep 17 00:00:00 2001 From: Phil Lee Date: Fri, 19 Jul 2024 10:34:45 +0100 Subject: [PATCH] populate FE award amount placeholder --- .../eligible_form.rb | 4 ++ .../journeys/further_education_payments.rb | 2 +- .../session_answers.rb | 11 ++++ app/models/school.rb | 4 ++ .../claims/eligible.html.erb | 2 +- .../happy_path_spec.rb | 4 ++ .../session_answers_spec.rb | 51 +++++++++++++++++++ 7 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 spec/models/journeys/further_education_payments/session_answers_spec.rb diff --git a/app/forms/journeys/further_education_payments/eligible_form.rb b/app/forms/journeys/further_education_payments/eligible_form.rb index c1cebb5e1b..32e32a998d 100644 --- a/app/forms/journeys/further_education_payments/eligible_form.rb +++ b/app/forms/journeys/further_education_payments/eligible_form.rb @@ -4,6 +4,10 @@ class EligibleForm < Form def save true end + + def award_amount + journey_session.answers.award_amount + end end end end diff --git a/app/models/journeys/further_education_payments.rb b/app/models/journeys/further_education_payments.rb index 883ab5e307..a67c6562a1 100644 --- a/app/models/journeys/further_education_payments.rb +++ b/app/models/journeys/further_education_payments.rb @@ -29,10 +29,10 @@ module FurtherEducationPayments "teaching-qualification" => TeachingQualificationForm, "poor-performance" => PoorPerformanceForm, "check-your-answers" => CheckYourAnswersForm, - "ineligible" => IneligibleForm, "half-teaching-hours" => HalfTeachingHoursForm, "hours-teaching-eligible-subjects" => HoursTeachingEligibleSubjectsForm, "eligible" => EligibleForm, + "ineligible" => IneligibleForm, "teacher-reference-number" => TeacherReferenceNumberForm } } diff --git a/app/models/journeys/further_education_payments/session_answers.rb b/app/models/journeys/further_education_payments/session_answers.rb index afdd8632dd..0b3ccb63b9 100644 --- a/app/models/journeys/further_education_payments/session_answers.rb +++ b/app/models/journeys/further_education_payments/session_answers.rb @@ -119,6 +119,17 @@ def all_selected_courses_ineligible? def less_than_half_hours_teaching_eligible_courses? hours_teaching_eligible_subjects == false end + + def award_amount + case teaching_hours_per_week + when "more_than_12" + school.eligible_fe_provider.max_award_amount + when "between_2_5_and_12" + school.eligible_fe_provider.lower_award_amount + else + 0 + end + end end end end diff --git a/app/models/school.rb b/app/models/school.rb index a9f68f456e..c8262eb124 100644 --- a/app/models/school.rb +++ b/app/models/school.rb @@ -143,6 +143,10 @@ def self.search(search_term, fe_only: false) sql end + def eligible_fe_provider(academic_year: AcademicYear.current) + EligibleFeProvider.find_by(ukprn:, academic_year:) + end + def address [street, locality, town, county, postcode].reject(&:blank?).join(", ") end diff --git a/app/views/further_education_payments/claims/eligible.html.erb b/app/views/further_education_payments/claims/eligible.html.erb index c992d31013..d0a6adf5d1 100644 --- a/app/views/further_education_payments/claims/eligible.html.erb +++ b/app/views/further_education_payments/claims/eligible.html.erb @@ -15,7 +15,7 @@
- £??? + <%= number_to_currency(@form.award_amount, precision: 0) %>
diff --git a/spec/features/further_education_payments/happy_path_spec.rb b/spec/features/further_education_payments/happy_path_spec.rb index 9afa73a707..209568ab09 100644 --- a/spec/features/further_education_payments/happy_path_spec.rb +++ b/spec/features/further_education_payments/happy_path_spec.rb @@ -1,7 +1,10 @@ require "rails_helper" RSpec.feature "Further education payments" do + include ActionView::Helpers::NumberHelper + let(:college) { create(:school, :further_education, :fe_eligible) } + let(:expected_award_amount) { college.eligible_fe_provider.max_award_amount } scenario "happy path claim" do when_further_education_payments_journey_configuration_exists @@ -106,6 +109,7 @@ click_button "Continue" expect(page).to have_content("You’re eligible for a financial incentive payment") + expect(page).to have_content(number_to_currency(expected_award_amount, precision: 0)) expect(page).to have_content("Apply now") click_button "Apply now" diff --git a/spec/models/journeys/further_education_payments/session_answers_spec.rb b/spec/models/journeys/further_education_payments/session_answers_spec.rb new file mode 100644 index 0000000000..bc555d9628 --- /dev/null +++ b/spec/models/journeys/further_education_payments/session_answers_spec.rb @@ -0,0 +1,51 @@ +require "rails_helper" + +RSpec.describe Journeys::FurtherEducationPayments::SessionAnswers do + subject { described_class.new(answers.attributes) } + + let(:school) { create(:school, :further_education, :fe_eligible) } + + describe "#award_amount" do + context "when teaching over 12 hours per week" do + let(:answers) do + build( + :further_education_payments_answers, + school_id: school.id, + teaching_hours_per_week: "more_than_12" + ) + end + + it "returns max award amount" do + expect(subject.award_amount).to eql(school.eligible_fe_provider.max_award_amount) + end + end + + context "when teaching between 2.5 and 12 hours per week" do + let(:answers) do + build( + :further_education_payments_answers, + school_id: school.id, + teaching_hours_per_week: "between_2_5_and_12" + ) + end + + it "returns lower award amount" do + expect(subject.award_amount).to eql(school.eligible_fe_provider.lower_award_amount) + end + end + + context "when teaching less than 2.5 hours per week" do + let(:answers) do + build( + :further_education_payments_answers, + school_id: school.id, + teaching_hours_per_week: "less_than_2_5" + ) + end + + it "returns zero" do + expect(subject.award_amount).to be_zero + end + end + end +end