Skip to content

Commit

Permalink
Move date to policy checker
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rjlynch committed Jul 1, 2024
1 parent c6df4e4 commit bceb2da
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
end

let(:contract_start_date) do
Policies::InternationalRelocationPayments::Eligibility
Policies::InternationalRelocationPayments::PolicyEligibilityChecker
.earliest_eligible_contract_start_date
end

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
end

let(:contract_start_date) do
Policies::InternationalRelocationPayments::Eligibility
Policies::InternationalRelocationPayments::PolicyEligibilityChecker
.earliest_eligible_contract_start_date
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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

Expand Down

0 comments on commit bceb2da

Please sign in to comment.