Skip to content

Commit

Permalink
Merge pull request #2943 from DFE-Digital/CAPT-1747/reject-ineligible…
Browse files Browse the repository at this point in the history
…-contract-start-dates

Add eligibility check for contract start date
  • Loading branch information
rjlynch authored Jul 1, 2024
2 parents cc05def + bceb2da commit 3fd9cbf
Show file tree
Hide file tree
Showing 7 changed files with 177 additions and 23 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 @@ -12,11 +12,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
@@ -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 @@ -35,13 +46,21 @@ 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 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,11 +8,8 @@
end

let(:contract_start_date) do
Date.new(
journey_configuration.current_academic_year.start_year,
1,
1
)
Policies::InternationalRelocationPayments::PolicyEligibilityChecker
.earliest_eligible_contract_start_date
end

before do
Expand Down Expand Up @@ -63,9 +60,7 @@
end
end

# FIXME RL waiting on feedback from policy team to determine what the cut
# off date is for contracts
xcontext "ineligible - contract start date" do
context "ineligible - contract start date" do
it "shows the ineligible page" do
when_i_start_the_form
and_i_complete_application_route_question_with(
Expand All @@ -74,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::PolicyEligibilityChecker
.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
Date.yesterday
Policies::InternationalRelocationPayments::PolicyEligibilityChecker
.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::PolicyEligibilityChecker.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::PolicyEligibilityChecker.earliest_eligible_contract_start_date,
date_of_entry: Policies::InternationalRelocationPayments::PolicyEligibilityChecker.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::PolicyEligibilityChecker.earliest_eligible_contract_start_date,
date_of_entry: Policies::InternationalRelocationPayments::PolicyEligibilityChecker.earliest_eligible_contract_start_date - 1.week
}
end

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

0 comments on commit 3fd9cbf

Please sign in to comment.