From bceb2da17231faf5ad16f64b6c37ed4a8aa44cf3 Mon Sep 17 00:00:00 2001 From: Richard Lynch Date: Mon, 1 Jul 2024 10:17:52 +0100 Subject: [PATCH] Move date to policy checker We eventually want to get rid of the policy models, storing their data on the claim itself, so the policy eligibility checker is a better home for this method. --- .../eligibility.rb | 9 --------- .../policy_eligibility_checker.rb | 15 +++++++++++---- .../ineligible_route_completing_the_form_spec.rb | 4 ++-- .../teacher_route_completing_the_form_spec.rb | 2 +- .../policy_eligibility_checker_spec.rb | 10 +++++----- 5 files changed, 19 insertions(+), 21 deletions(-) diff --git a/app/models/policies/international_relocation_payments/eligibility.rb b/app/models/policies/international_relocation_payments/eligibility.rb index abe3ad997c..c5f1b73414 100644 --- a/app/models/policies/international_relocation_payments/eligibility.rb +++ b/app/models/policies/international_relocation_payments/eligibility.rb @@ -3,15 +3,6 @@ module InternationalRelocationPayments class Eligibility < ApplicationRecord self.table_name = "international_relocation_payments_eligibilities" - PRE_ACADEMIC_YEAR_WINDOW_LIMIT = 6.months - - def self.earliest_eligible_contract_start_date - Journeys::GetATeacherRelocationPayment - .configuration - .current_academic_year - .start_of_autumn_term - PRE_ACADEMIC_YEAR_WINDOW_LIMIT - end - has_one :claim, as: :eligibility, inverse_of: :eligibility def ineligible? diff --git a/app/models/policies/international_relocation_payments/policy_eligibility_checker.rb b/app/models/policies/international_relocation_payments/policy_eligibility_checker.rb index 405f63f98d..67bbb0e329 100644 --- a/app/models/policies/international_relocation_payments/policy_eligibility_checker.rb +++ b/app/models/policies/international_relocation_payments/policy_eligibility_checker.rb @@ -1,10 +1,21 @@ module Policies module InternationalRelocationPayments class PolicyEligibilityChecker + PRE_ACADEMIC_YEAR_WINDOW_LIMIT = 6.months + + def self.earliest_eligible_contract_start_date + Journeys::GetATeacherRelocationPayment + .configuration + .current_academic_year + .start_of_autumn_term - PRE_ACADEMIC_YEAR_WINDOW_LIMIT + end + attr_reader :answers delegate_missing_to :answers + delegate :earliest_eligible_contract_start_date, to: :class + def initialize(answers:) @answers = answers end @@ -50,10 +61,6 @@ def contract_start_date_eligible? answers.start_date >= earliest_eligible_contract_start_date end - def earliest_eligible_contract_start_date - Eligibility.earliest_eligible_contract_start_date - end - def date_of_entry_eligible? return false unless answers.date_of_entry && answers.start_date diff --git a/spec/features/get_a_teacher_relocation_payment/ineligible_route_completing_the_form_spec.rb b/spec/features/get_a_teacher_relocation_payment/ineligible_route_completing_the_form_spec.rb index dcf61efe83..142384cbb3 100644 --- a/spec/features/get_a_teacher_relocation_payment/ineligible_route_completing_the_form_spec.rb +++ b/spec/features/get_a_teacher_relocation_payment/ineligible_route_completing_the_form_spec.rb @@ -8,7 +8,7 @@ end let(:contract_start_date) do - Policies::InternationalRelocationPayments::Eligibility + Policies::InternationalRelocationPayments::PolicyEligibilityChecker .earliest_eligible_contract_start_date end @@ -69,7 +69,7 @@ and_i_complete_the_state_funded_secondary_school_step_with(option: "Yes") and_i_complete_the_contract_details_step_with(option: "Yes") and_i_complete_the_contract_start_date_step_with( - date: Policies::InternationalRelocationPayments::Eligibility + date: Policies::InternationalRelocationPayments::PolicyEligibilityChecker .earliest_eligible_contract_start_date - 1.day ) then_i_see_the_ineligible_page diff --git a/spec/features/get_a_teacher_relocation_payment/teacher_route_completing_the_form_spec.rb b/spec/features/get_a_teacher_relocation_payment/teacher_route_completing_the_form_spec.rb index 67c610239e..c9b9f22010 100644 --- a/spec/features/get_a_teacher_relocation_payment/teacher_route_completing_the_form_spec.rb +++ b/spec/features/get_a_teacher_relocation_payment/teacher_route_completing_the_form_spec.rb @@ -8,7 +8,7 @@ end let(:contract_start_date) do - Policies::InternationalRelocationPayments::Eligibility + Policies::InternationalRelocationPayments::PolicyEligibilityChecker .earliest_eligible_contract_start_date end diff --git a/spec/models/policies/international_relocation_payments/policy_eligibility_checker_spec.rb b/spec/models/policies/international_relocation_payments/policy_eligibility_checker_spec.rb index 758253ff2e..f43222143b 100644 --- a/spec/models/policies/international_relocation_payments/policy_eligibility_checker_spec.rb +++ b/spec/models/policies/international_relocation_payments/policy_eligibility_checker_spec.rb @@ -139,7 +139,7 @@ one_year: true, subject: "physics", visa_type: "British National (Overseas) visa", - start_date: Policies::InternationalRelocationPayments::Eligibility.earliest_eligible_contract_start_date - 1.day + start_date: Policies::InternationalRelocationPayments::PolicyEligibilityChecker.earliest_eligible_contract_start_date - 1.day } end @@ -154,8 +154,8 @@ one_year: true, subject: "physics", visa_type: "British National (Overseas) visa", - start_date: Policies::InternationalRelocationPayments::Eligibility.earliest_eligible_contract_start_date, - date_of_entry: Policies::InternationalRelocationPayments::Eligibility.earliest_eligible_contract_start_date - 4.months + start_date: Policies::InternationalRelocationPayments::PolicyEligibilityChecker.earliest_eligible_contract_start_date, + date_of_entry: Policies::InternationalRelocationPayments::PolicyEligibilityChecker.earliest_eligible_contract_start_date - 4.months } end @@ -170,8 +170,8 @@ one_year: true, subject: "physics", visa_type: "British National (Overseas) visa", - start_date: Policies::InternationalRelocationPayments::Eligibility.earliest_eligible_contract_start_date, - date_of_entry: Policies::InternationalRelocationPayments::Eligibility.earliest_eligible_contract_start_date - 1.week + start_date: Policies::InternationalRelocationPayments::PolicyEligibilityChecker.earliest_eligible_contract_start_date, + date_of_entry: Policies::InternationalRelocationPayments::PolicyEligibilityChecker.earliest_eligible_contract_start_date - 1.week } end