|
|
|
|
@ -649,6 +649,85 @@ RSpec.describe Validations::SetupValidations do
|
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
describe "validate_tenancy" do |
|
|
|
|
context "with a scheme with no locations active on the start date & no location set" do |
|
|
|
|
let(:scheme) { create(:scheme) } |
|
|
|
|
let(:location) { create(:location, scheme:) } |
|
|
|
|
|
|
|
|
|
before do |
|
|
|
|
location_deactivation_period = build(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 4), location:) |
|
|
|
|
location_deactivation_period.save!(validate: false) |
|
|
|
|
location.reload |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "produces error when scheme does not have any active locations on the tenancy start date" do |
|
|
|
|
record.startdate = Time.zone.local(2022, 7, 5) |
|
|
|
|
record.scheme = scheme |
|
|
|
|
setup_validator.validate_tenancy(record) |
|
|
|
|
expect(record.errors["startdate"]).to include(match I18n.t("validations.setup.startdate.scheme.locations_inactive.startdate", name: scheme.service_name)) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "produces no error when scheme has active locations on the tenancy start date" do |
|
|
|
|
record.startdate = Time.zone.local(2022, 6, 1) |
|
|
|
|
record.scheme = scheme |
|
|
|
|
setup_validator.validate_tenancy(record) |
|
|
|
|
expect(record.errors["startdate"]).to be_empty |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context "with a scheme with no locations active on the start date & location also set" do |
|
|
|
|
let(:scheme) { create(:scheme) } |
|
|
|
|
let(:location) { create(:location, scheme:) } |
|
|
|
|
|
|
|
|
|
before do |
|
|
|
|
location_deactivation_period = build(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 4), location:) |
|
|
|
|
location_deactivation_period.save!(validate: false) |
|
|
|
|
location.reload |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "produces error when scheme does not have any active locations on the tenancy start date" do |
|
|
|
|
record.startdate = Time.zone.local(2022, 7, 5) |
|
|
|
|
record.scheme = scheme |
|
|
|
|
record.location = location |
|
|
|
|
setup_validator.validate_tenancy(record) |
|
|
|
|
expect(record.errors["startdate"]).to include(match I18n.t("validations.setup.startdate.scheme.locations_inactive.startdate", name: scheme.service_name)) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "produces no error when scheme has active locations on the tenancy start date" do |
|
|
|
|
record.startdate = Time.zone.local(2022, 6, 1) |
|
|
|
|
record.scheme = scheme |
|
|
|
|
record.location = location |
|
|
|
|
setup_validator.validate_tenancy(record) |
|
|
|
|
expect(record.errors["startdate"]).to be_empty |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context "with the chosen location inactive on the start date" do |
|
|
|
|
let(:scheme) { create(:scheme) } |
|
|
|
|
let(:location) { create(:location, scheme:) } |
|
|
|
|
|
|
|
|
|
before do |
|
|
|
|
location_deactivation_period = build(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 4), location:) |
|
|
|
|
location_deactivation_period.save!(validate: false) |
|
|
|
|
location.reload |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "produces the location error when the chosen location is inactive on the tenancy start date" do |
|
|
|
|
record.startdate = Time.zone.local(2022, 7, 5) |
|
|
|
|
record.location = location |
|
|
|
|
setup_validator.validate_tenancy(record) |
|
|
|
|
expect(record.errors["startdate"]).to include(match I18n.t("validations.setup.startdate.location.deactivated.startdate", postcode: location.postcode)) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "produces no error when the chosen location is active on the tenancy start date" do |
|
|
|
|
record.startdate = Time.zone.local(2022, 6, 1) |
|
|
|
|
record.location = location |
|
|
|
|
setup_validator.validate_tenancy(record) |
|
|
|
|
expect(record.errors["startdate"]).to be_empty |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
describe "#validate_organisation" do |
|
|
|
|
let(:user) { create(:user) } |
|
|
|
|
let(:other_organisation) { create(:organisation, name: "other org") } |
|
|
|
|
|