Skip to content

Commit

Permalink
Update contract start date rules (#265) (#360)
Browse files Browse the repository at this point in the history
* Update contract start date rules (#265)

* Update contract start date rules; amendments following review (#265)

* Update contract start date rules; appease rubocop (#265)
  • Loading branch information
eddieleeper authored Dec 20, 2023
1 parent 6f8e760 commit 86f40f3
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 14 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ When adding / removing or editing along side the code changes you will need to u
available environments.
Run the following command `make <environment> edit-app-secrets`

#### Contract Start Date
The custom configuration entry `config.x.form_eligibility.contract_start_months_limit` can be set to `5` to override
the default of six months prior to the current service start date.
`AppSettings.current.service_start_date`.
This should be set to either `5` or `6` anything else will default to `6`.

### SSH access

Access a deploy with the command `make <environment> ssh`.
Expand Down
20 changes: 14 additions & 6 deletions app/models/form/eligibility_check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def failure_reason
in visa_type: "Other"
"visa not accepted"
in start_date: Date unless contract_start_date_eligible?(form.start_date)
"contract must start after the first monday of July of this year"
I18n.t("contract_must_start_within_months", count: months_limit_in_words)
in date_of_entry: Date, start_date: Date unless date_of_entry_eligible?(form.date_of_entry, form.start_date)
"cannot enter the UK more than 3 months before your contract start date"
else
Expand All @@ -46,11 +46,19 @@ def date_of_entry_eligible?(date_of_entry, start_date)
end

def contract_start_date_eligible?(start_date)
current_year = Date.current.year
first_monday_in_july = Date.new(current_year, 7, 1)
.beginning_of_month
.next_occurring(:monday)
months_before_service_start = AppSettings.current.service_start_date.months_ago(months_limit).beginning_of_month
start_date >= months_before_service_start
end

private

# default to 6 and only allow 5 or 6. anything else results in 6.
def months_limit
limit = Rails.configuration.x.form_eligibility.contract_start_months_limit.to_i
[5, 6].include?(limit) ? limit : 6
end

start_date >= first_monday_in_july
def months_limit_in_words
months_limit == 5 ? "five" : "six"
end
end
1 change: 1 addition & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,6 @@ class Application < Rails::Application

config.x.govuk_notify.generic_email_template_id = ENV.fetch("GOVUK_NOTIFY_GENERIC_EMAIL_TEMPLATE_ID")
config.x.events.filtered_attributes = YAML.load_file(Rails.root.join("config/events/filtered_attributes.yml"))
config.x.form_eligibility.contract_start_months_limit = 6
end
end
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,4 @@ en:
ho_missing_header_mappings: "config.header_mappings must be present"
ho_missing_worksheet_name: "config.worksheet_name must be present"
ho_invalid_worksheet_name: "config.worksheet_name not present in file"
contract_must_start_within_months: contract must start within the last %{count} months
8 changes: 4 additions & 4 deletions spec/factories/forms.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,17 @@
"Youth Mobility Scheme",
].sample
end
start_date { Date.new(Date.current.year, 9, 1) }
date_of_entry { Date.new(Date.current.year, 9, 1) }
start_date { 1.month.ago }
date_of_entry { 1.month.ago }
subject { "physics" }
end

trait :complete do
state_funded_secondary_school { true }
one_year { true }
visa_type { "British National (Overseas) visa" }
start_date { Date.new(Date.current.year, 9, 1) }
date_of_entry { Date.new(Date.current.year, 9, 1) }
start_date { 1.month.ago }
date_of_entry { 1.month.ago }
subject { "physics" }
date_of_birth { rand(18..90).years.ago.to_date }
email_address { Faker::Internet.email }
Expand Down
112 changes: 108 additions & 4 deletions spec/models/form/eligibility_check_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,110 @@
it { expect(check.failure_reason).to be_nil }
end

context "in the Jan/Feb 2024 window" do
before do
travel_to Time.zone.local(2024, 1, 2)
AppSettings.current.update!(
service_start_date: Time.zone.today,
service_end_date: 1.month.from_now.end_of_month,
)
travel_to Time.zone.local(2024, 2, 29)
end

let(:form) { build(:form, :eligible) }

context "when the contract start date is September 2023" do
let(:form) do
build(:form, :eligible,
start_date: Date.new(2023, 9, 2),
date_of_entry: Date.new(2023, 9, 2))
end

it { expect(check.failure_reason).to be_nil }
end

context "when the contract start date is Jan 2024" do
let(:form) do
build(:form, :eligible,
start_date: Date.new(2024, 1, 1),
date_of_entry: Date.new(2024, 1, 1))
end

it { expect(check.failure_reason).to be_nil }
end

context "when the contract start date is July 2023" do
let(:form) do
build(:form, :eligible,
start_date: Date.new(2023, 7, 1),
date_of_entry: Date.new(2023, 7, 1))
end

it { expect(check.failure_reason).to be_nil }
end

context "when the contract start date is June 2023" do
let(:form) do
build(:form, :eligible,
start_date: Date.new(2023, 6, 30),
date_of_entry: Date.new(2023, 6, 30))
end
let(:expected) { "contract must start within the last six months" }

it { expect(check.failure_reason).to eq(expected) }
end
end

context "in the Apr/May 2024 window" do
before do
travel_to Time.zone.local(2024, 4, 1)
AppSettings.current.update!(
service_start_date: Time.zone.today,
service_end_date: 1.month.from_now.end_of_month,
)
travel_to Time.zone.local(2024, 5, 31)
Rails.configuration.x.form_eligibility.contract_start_months_limit = 5
end

after do
Rails.configuration.x.form_eligibility.contract_start_months_limit = 6
end

let(:form) { build(:form, :eligible) }

context "when the contract start date is September 2023" do
let(:form) do
build(:form, :eligible,
start_date: Date.new(2023, 9, 30),
date_of_entry: Date.new(2023, 9, 30))
end
let(:expected) { "contract must start within the last five months" }

it { expect(check.failure_reason).to eq(expected) }
end

context "when the contract start date is October 2023" do
let(:form) do
build(:form, :eligible,
start_date: Date.new(2023, 10, 31),
date_of_entry: Date.new(2023, 10, 31))
end
let(:expected) { "contract must start within the last five months" }

it { expect(check.failure_reason).to eq(expected) }
end

context "when the contract start date is Jan 2024" do
let(:form) do
build(:form, :eligible,
start_date: Date.new(2024, 1, 1),
date_of_entry: Date.new(2024, 1, 1))
end

it { expect(check.failure_reason).to be_nil }
end
end

context "when ineligible" do
context "because of chosen application_route" do
let(:form) { build(:form, application_route: "other") }
Expand Down Expand Up @@ -49,8 +153,8 @@
end

context "because of start date too early" do
let(:form) { build(:form, start_date: Date.new(Date.current.year, 6, 30)) }
let(:expected) { "contract must start after the first monday of July of this year" }
let(:form) { build(:form, start_date: 8.months.ago) }
let(:expected) { "contract must start within the last six months" }

it { expect(check.failure_reason).to eq(expected) }
end
Expand All @@ -59,8 +163,8 @@
let(:form) do
build(
:form,
start_date: Date.new(Date.current.year, 8, 30),
date_of_entry: Date.new(Date.current.year, 5, 29),
start_date: 1.month.ago,
date_of_entry: 5.months.ago,
)
end
let(:expected) { "cannot enter the UK more than 3 months before your contract start date" }
Expand Down
3 changes: 3 additions & 0 deletions spec/support/time_helpers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
RSpec.configure do |config|
config.include ActiveSupport::Testing::TimeHelpers
end

0 comments on commit 86f40f3

Please sign in to comment.