Browse Source
* create method to test whether we are currently in the crossover period and associated tests * update copy, use method for testing whether we are in the crossover period, remove focus from test file * reuse existing method to determine whether we are in a collection period * use the existing method and update validations * fix test broken by changes * update location in same way as scheme * create method on FormHandler that finds the start date of the earliest collection period * ensure that default deactivation and reactivation dates also reflect the changes * create tests for the new validations * lint correction * minor copy change * minor logic change * amend naming error after rebase conflict remove test that is no longer correct after change on another branch to functionality update a test after a copy changepull/1523/head
Arthur Campbell
2 years ago
committed by
GitHub
11 changed files with 182 additions and 21 deletions
@ -0,0 +1,83 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe LocationDeactivationPeriod do |
||||
let(:validator) { LocationDeactivationPeriodValidator.new } |
||||
let(:location) { FactoryBot.create(:location, startdate: now - 2.years) } |
||||
let(:record) { FactoryBot.create(:location_deactivation_period, deactivation_date: now, location:) } |
||||
|
||||
describe "#validate" do |
||||
around do |example| |
||||
Timecop.freeze(now) do |
||||
example.run |
||||
end |
||||
end |
||||
|
||||
context "when not in a crossover period" do |
||||
let(:now) { Time.utc(2023, 3, 1) } |
||||
|
||||
context "with a deactivation date before the current collection period" do |
||||
it "adds an error" do |
||||
record.deactivation_date = now - 1.year |
||||
location.location_deactivation_periods.clear |
||||
validator.validate(record) |
||||
expect(record.errors[:deactivation_date]).to include "The date must be on or after the 1 April 2022" |
||||
end |
||||
end |
||||
|
||||
context "with a deactivation date in the current collection period" do |
||||
it "does not add an error" do |
||||
record.deactivation_date = now - 1.day |
||||
location.location_deactivation_periods.clear |
||||
validator.validate(record) |
||||
expect(record.errors).to be_empty |
||||
end |
||||
end |
||||
end |
||||
|
||||
context "when in a crossover period" do |
||||
let(:now) { Time.utc(2023, 5, 1) } |
||||
|
||||
context "with a deactivation date before the previous collection period" do |
||||
it "does not add an error" do |
||||
record.deactivation_date = now - 2.years |
||||
location.location_deactivation_periods.clear |
||||
validator.validate(record) |
||||
expect(record.errors[:deactivation_date]).to include "The date must be on or after the 1 April 2022" |
||||
end |
||||
end |
||||
|
||||
context "with a deactivation date in the previous collection period" do |
||||
it "does not add an error" do |
||||
record.deactivation_date = now - 1.year |
||||
location.location_deactivation_periods.clear |
||||
validator.validate(record) |
||||
expect(record.errors).to be_empty |
||||
end |
||||
end |
||||
|
||||
context "with a deactivation date in the current collection period" do |
||||
it "does not add an error" do |
||||
record.deactivation_date = now - 1.day |
||||
location.location_deactivation_periods.clear |
||||
validator.validate(record) |
||||
expect(record.errors).to be_empty |
||||
end |
||||
end |
||||
|
||||
context "but the location was created in the current collection period" do |
||||
let(:location) { FactoryBot.create(:location, startdate:) } |
||||
let(:startdate) { now - 2.days } |
||||
|
||||
context "with a deactivation date in the previous collection period" do |
||||
it "adds an error" do |
||||
record.deactivation_date = now - 1.year |
||||
location.location_deactivation_periods.clear |
||||
validator.validate(record) |
||||
start_date = startdate.to_formatted_s(:govuk_date) |
||||
expect(record.errors[:deactivation_date]).to include "The location cannot be deactivated before #{start_date}, the date when it was first available" |
||||
end |
||||
end |
||||
end |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,68 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe SchemeDeactivationPeriod do |
||||
let(:validator) { SchemeDeactivationPeriodValidator.new } |
||||
let(:scheme) { FactoryBot.create(:scheme, created_at: now - 2.years) } |
||||
let(:record) { FactoryBot.create(:scheme_deactivation_period, deactivation_date: now, scheme:) } |
||||
|
||||
describe "#validate" do |
||||
around do |example| |
||||
Timecop.freeze(now) do |
||||
example.run |
||||
end |
||||
end |
||||
|
||||
context "when not in a crossover period" do |
||||
let(:now) { Time.utc(2023, 3, 1) } |
||||
|
||||
context "with a deactivation date before the current collection period" do |
||||
it "adds an error" do |
||||
record.deactivation_date = now - 1.year |
||||
scheme.scheme_deactivation_periods.clear |
||||
validator.validate(record) |
||||
expect(record.errors[:deactivation_date]).to include("The date must be on or after the 1 April 2022") |
||||
end |
||||
end |
||||
|
||||
context "with a deactivation date in the current collection period" do |
||||
it "does not add an error" do |
||||
record.deactivation_date = now - 1.day |
||||
scheme.scheme_deactivation_periods.clear |
||||
validator.validate(record) |
||||
expect(record.errors[:deactivation_date]).to be_empty |
||||
end |
||||
end |
||||
end |
||||
|
||||
context "when in a crossover period" do |
||||
let(:now) { Time.utc(2023, 5, 1) } |
||||
|
||||
context "with a deactivation date before the previous collection period" do |
||||
it "does not add an error" do |
||||
record.deactivation_date = now - 2.years |
||||
scheme.scheme_deactivation_periods.clear |
||||
validator.validate(record) |
||||
expect(record.errors[:deactivation_date]).to include("The date must be on or after the 1 April 2022") |
||||
end |
||||
end |
||||
|
||||
context "with a deactivation date in the previous collection period" do |
||||
it "does not add an error" do |
||||
record.deactivation_date = now - 1.year |
||||
scheme.scheme_deactivation_periods.clear |
||||
validator.validate(record) |
||||
expect(record.errors[:deactivation_date]).to be_empty |
||||
end |
||||
end |
||||
|
||||
context "with a deactivation date in the current collection period" do |
||||
it "does not add an error" do |
||||
record.deactivation_date = now - 1.day |
||||
scheme.scheme_deactivation_periods.clear |
||||
validator.validate(record) |
||||
expect(record.errors[:deactivation_date]).to be_empty |
||||
end |
||||
end |
||||
end |
||||
end |
||||
end |
Loading…
Reference in new issue