Skip to content

Commit

Permalink
Add eligibility check for contract start date
Browse files Browse the repository at this point in the history
We want to reject claimants if their contract start date is earlier than
6 months before the autumn term. This commit updates the eligibility
checker to do so and also adds some missing tests.
  • Loading branch information
rjlynch committed Jun 28, 2024
1 parent 99ab65c commit 9e4ecf4
Show file tree
Hide file tree
Showing 7 changed files with 178 additions and 18 deletions.
14 changes: 13 additions & 1 deletion app/models/academic_year.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ class AcademicYear

ACADEMIC_YEAR_REGEXP = /\A20\d{2}\/20\d{2}\z/

AUTUMN_TERM_START_MONTH = 9
AUTUMN_TERM_START_DAY = 1

attr_reader :start_year, :end_year

# Defines a custom ActiveRecord::Type for AcademicYear that means we can
Expand Down Expand Up @@ -52,7 +55,12 @@ def next
def for(date)
return if date.nil?

start_of_autumn_term = Date.new(date.year, 9, 1)
start_of_autumn_term = Date.new(
date.year,
AUTUMN_TERM_START_MONTH,
AUTUMN_TERM_START_DAY
)

if date < start_of_autumn_term
new(date.year - 1)
else
Expand Down Expand Up @@ -132,4 +140,8 @@ def -(other)
def +(other)
AcademicYear.new(start_year + other)
end

def start_of_autumn_term
Date.new(start_year, AUTUMN_TERM_START_MONTH, AUTUMN_TERM_START_DAY)
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ 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 All @@ -12,11 +21,6 @@ def ineligible?
def policy
Policies::InternationalRelocationPayments
end

def self.earliest_eligible_contract_start_date
# FIXME RL - waiting on policy to get back to us for what this should
# be
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,25 @@ def ineligible_reason
"taught subject not accepted"
in visa_type: "Other"
"visa not accepted"
in start_date: Date unless contract_start_date_eligible?
"contract start date must be after #{earliest_eligible_contract_start_date}"
in date_of_entry: Date, start_date: Date unless date_of_entry_eligible?
"cannot enter the UK more than 3 months before your contract start date"
else
nil
end
end

def contract_start_date_eligible?
return false unless answers.start_date

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,8 @@
end

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

before do
Expand Down Expand Up @@ -59,8 +60,6 @@
end
end

# FIXME RL waiting on feedback from policy team to determine what the cut
# off date is for contracts
context "ineligible - contract start date" do
it "shows the ineligible page" do
when_i_start_the_form
Expand All @@ -70,7 +69,8 @@
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: Polices::InternationalRelocationPayments.earliest_eligible_contract_start_date - 1.day
date: Policies::InternationalRelocationPayments::Eligibility
.earliest_eligible_contract_start_date - 1.day
)
then_i_see_the_ineligible_page
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
end

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

let(:entry_date) do
Expand Down
6 changes: 6 additions & 0 deletions spec/models/academic_year_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -186,4 +186,10 @@
expect(AcademicYear.new(2014).hash).not_to eql 2014.hash
end
end

describe "#start_of_autumn_term" do
it "returns September 1st of the start year" do
expect(AcademicYear.new(2014).start_of_autumn_term).to eq Date.new(2014, 9, 1)
end
end
end
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
require "rails_helper"

describe Policies::InternationalRelocationPayments::PolicyEligibilityChecker do
before do
create(:journey_configuration, :get_a_teacher_relocation_payment)
end

let(:answers) do
build(
:get_a_teacher_relocation_payment_answers,
application_route: application_route
attributes: attributes
)
end

Expand All @@ -14,19 +18,31 @@
subject { checker.status }

context "when the application route is 'other'" do
let(:application_route) { "other" }
let(:attributes) do
{
application_route: "other"
}
end

it { is_expected.to eq(:ineligible) }
end

context "when the application route is 'teacher'" do
let(:application_route) { "teacher" }
let(:attributes) do
{
application_route: "teacher"
}
end

it { is_expected.to eq(:eligible_now) }
end

context "when the application route is 'salaried_trainee'" do
let(:application_route) { "salaried_trainee" }
let(:attributes) do
{
application_route: "salaried_trainee"
}
end

it { is_expected.to eq(:ineligible) }
end
Expand All @@ -36,21 +52,130 @@
subject { checker.ineligible? }

context "when the application route is 'other'" do
let(:application_route) { "other" }
let(:attributes) do
{
application_route: "other"
}
end

it { is_expected.to eq(true) }
end

context "when the application route is 'teacher'" do
let(:application_route) { "teacher" }
let(:attributes) do
{
application_route: "teacher"
}
end

it { is_expected.to eq(false) }
end

context "when the application route is 'salaried_trainee'" do
let(:application_route) { "salaried_trainee" }
let(:attributes) do
{
application_route: "salaried_trainee"
}
end

it { is_expected.to eq(true) }
end

context "with a non state funded secondary school" do
let(:attributes) do
{
application_route: "teacher",
state_funded_secondary_school: false
}
end

it { is_expected.to eq(true) }
end

context "with a contract duration of less than one year" do
let(:attributes) do
{
application_route: "teacher",
state_funded_secondary_school: true,
one_year: false
}
end

it { is_expected.to eq(true) }
end

context "with a taught subject of 'other'" do
let(:attributes) do
{
application_route: "teacher",
state_funded_secondary_school: true,
one_year: true,
subject: "other"
}
end

it { is_expected.to eq(true) }
end

context "with a visa type of 'Other'" do
let(:attributes) do
{
application_route: "teacher",
state_funded_secondary_school: true,
one_year: true,
subject: "physics",
visa_type: "Other"
}
end

it { is_expected.to eq(true) }
end

context "with a contract start date before the earliest eligible date" do
let(:attributes) do
{
application_route: "teacher",
state_funded_secondary_school: true,
one_year: true,
subject: "physics",
visa_type: "British National (Overseas) visa",
start_date: Policies::InternationalRelocationPayments::Eligibility.earliest_eligible_contract_start_date - 1.day
}
end

it { is_expected.to eq(true) }
end

context "with an entry date more than 3 months before the contract start date" do
let(:attributes) do
{
application_route: "teacher",
state_funded_secondary_school: true,
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
}
end

it { is_expected.to eq(true) }
end

context "with an eligible application" do
let(:attributes) do
{
application_route: "teacher",
state_funded_secondary_school: true,
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
}
end

it { is_expected.to eq(false) }
end
end
end

0 comments on commit 9e4ecf4

Please sign in to comment.