Browse Source

CLDC-3499: Remove year specific tests from lettings setup validations

CLDC-3499-remove-pre-2025-tests
samyou-softwire 2 weeks ago
parent
commit
78801b54f5
  1. 199
      spec/models/validations/setup_validations_spec.rb

199
spec/models/validations/setup_validations_spec.rb

@ -9,90 +9,32 @@ RSpec.describe Validations::SetupValidations do
let(:record) { build(:lettings_log) } let(:record) { build(:lettings_log) }
describe "tenancy start date" do describe "tenancy start date" do
context "when in 2022 to 2023 collection" do context "when in the crossover period" do
context "when in the crossover period" do before do
before do Timecop.freeze(current_collection_start_date)
allow(Time).to receive(:now).and_return(Time.zone.local(2022, 4, 1))
record.created_at = Time.zone.local(2022, 4, 1)
end
it "cannot be before the first collection window start date" do
record.startdate = Time.zone.local(2021, 1, 1)
setup_validator.validate_startdate_setup(record)
setup_validator.validate_merged_organisations_start_date(record)
expect(record.errors["startdate"]).to include(match "Enter a date within the 2021 to 2022 or 2022 to 2023 collection years, which is between 1st April 2021 and 31st March 2023")
end
it "cannot be after the second collection window end date" do
record.startdate = Time.zone.local(2023, 7, 1, 6)
setup_validator.validate_startdate_setup(record)
setup_validator.validate_merged_organisations_start_date(record)
expect(record.errors["startdate"]).to include(match "Enter a date within the 2021 to 2022 or 2022 to 2023 collection years, which is between 1st April 2021 and 31st March 2023")
end
end end
context "when after the crossover period" do after do
before do Timecop.return
allow(Time).to receive(:now).and_return(Time.zone.local(2023, 1, 1))
record.created_at = Time.zone.local(2023, 1, 1)
end
it "cannot be before the first collection window start date" do
record.startdate = Time.zone.local(2022, 1, 1)
setup_validator.validate_startdate_setup(record)
setup_validator.validate_merged_organisations_start_date(record)
expect(record.errors["startdate"]).to include(match "Enter a date within the 2022 to 2023 collection year, which is between 1st April 2022 and 31st March 2023")
end
it "cannot be after the second collection window end date" do
record.startdate = Time.zone.local(2023, 7, 1, 6)
setup_validator.validate_startdate_setup(record)
setup_validator.validate_merged_organisations_start_date(record)
expect(record.errors["startdate"]).to include(match "Enter a date within the 2022 to 2023 collection year, which is between 1st April 2022 and 31st March 2023")
end
end end
end
context "when in 2023 to 2024 collection" do
context "when in the crossover period" do
before do
allow(Time).to receive(:now).and_return(Time.zone.local(2023, 4, 1))
record.created_at = Time.zone.local(2023, 4, 1)
end
it "cannot be before the first collection window start date" do
record.startdate = Time.zone.local(2022, 1, 1)
setup_validator.validate_startdate_setup(record)
setup_validator.validate_merged_organisations_start_date(record)
expect(record.errors["startdate"]).to include(match "Enter a date within the 2022 to 2023 or 2023 to 2024 collection years, which is between 1st April 2022 and 31st March 2024")
end
it "cannot be after the second collection window end date" do it "cannot be before previous collection year start date" do
record.startdate = Time.zone.local(2024, 7, 1, 6) record.startdate = previous_collection_start_date - 1.month
setup_validator.validate_startdate_setup(record) setup_validator.validate_startdate_setup(record)
setup_validator.validate_merged_organisations_start_date(record) setup_validator.validate_merged_organisations_start_date(record)
expect(record.errors["startdate"]).to include(match "Enter a date within the 2022 to 2023 or 2023 to 2024 collection years, which is between 1st April 2022 and 31st March 2024") expect(record.errors["startdate"]).to include(match(/Enter a date within the \d{4} to \d{4} or \d{4} to \d{4} collection years, which is between 1st April \d{4} and 31st March \d{4}/))
end
end end
context "when after the crossover period" do context "when after the crossover period" do
before do before do
allow(Time).to receive(:now).and_return(Time.zone.local(2024, 1, 1)) allow(Time).to receive(:now).and_return(current_collection_after_crossover_start_date)
record.created_at = Time.zone.local(2024, 1, 1)
end end
it "cannot be before the first collection window start date" do it "cannot be before previous collection year start date" do
record.startdate = Time.zone.local(2023, 1, 1) record.startdate = previous_collection_start_date - 1.month
setup_validator.validate_startdate_setup(record) setup_validator.validate_startdate_setup(record)
setup_validator.validate_merged_organisations_start_date(record) setup_validator.validate_merged_organisations_start_date(record)
expect(record.errors["startdate"]).to include(match "Enter a date within the 2023 to 2024 collection year, which is between 1st April 2023 and 31st March 2024") expect(record.errors["startdate"]).to include(match(/Enter a date within the \d{4} to \d{4} collection year, which is between 1st April \d{4} and 31st March \d{4}/))
end
it "cannot be after the second collection window end date" do
record.startdate = Time.zone.local(2024, 7, 1, 6)
setup_validator.validate_startdate_setup(record)
setup_validator.validate_merged_organisations_start_date(record)
expect(record.errors["startdate"]).to include(match "Enter a date within the 2023 to 2024 collection year, which is between 1st April 2023 and 31st March 2024")
end end
end end
@ -125,73 +67,90 @@ RSpec.describe Validations::SetupValidations do
context "when after the new logs end date and after the edit end date for the previous period" do context "when after the new logs end date and after the edit end date for the previous period" do
before do before do
allow(Time).to receive(:now).and_return(Time.zone.local(2024, 1, 8)) Timecop.freeze(previous_collection_edit_end_date + 1.day)
end
after do
Timecop.return
end end
it "cannot create new logs for the previous collection year" do it "cannot create new logs for the previous collection year" do
record.update!(startdate: nil) record.update!(startdate: nil)
record.startdate = Time.zone.local(2023, 1, 1) record.startdate = previous_collection_start_date
setup_validator.validate_startdate_setup(record) setup_validator.validate_startdate_setup(record)
setup_validator.validate_merged_organisations_start_date(record) setup_validator.validate_merged_organisations_start_date(record)
expect(record.errors["startdate"]).to include(match "Enter a date within the 2023 to 2024 collection year, which is between 1st April 2023 and 31st March 2024") expect(record.errors["startdate"]).to include(match(/Enter a date within the \d{4} to \d{4} collection year, which is between 1st April \d{4} and 31st March \d{4}/))
end end
it "cannot edit already created logs for the previous collection year" do it "cannot edit already created logs for the previous collection year" do
record.startdate = Time.zone.local(2023, 1, 2) record.startdate = previous_collection_start_date + 1.day
record.save!(validate: false) record.save!(validate: false)
record.startdate = Time.zone.local(2023, 1, 1) record.startdate = previous_collection_start_date
setup_validator.validate_startdate_setup(record) setup_validator.validate_startdate_setup(record)
setup_validator.validate_merged_organisations_start_date(record) setup_validator.validate_merged_organisations_start_date(record)
expect(record.errors["startdate"]).to include(match "Enter a date within the 2023 to 2024 collection year, which is between 1st April 2023 and 31st March 2024") expect(record.errors["startdate"]).to include(match(/Enter a date within the \d{4} to \d{4} collection year, which is between 1st April \d{4} and 31st March \d{4}/))
end end
end end
end end
context "when attempted startdate is more than 14 days from the current date" do context "when attempted startdate is more than 14 days from the current date" do
before do before do
allow(Time).to receive(:now).and_return(Time.zone.local(2024, 3, 1)) Timecop.freeze(current_collection_start_date - 1.month)
end
after do
Timecop.return
end end
it "adds an error to startdate" do it "adds an error to startdate" do
record.startdate = Time.zone.local(2024, 3, 31) record.startdate = Time.now + 15.days
setup_validator.validate_startdate_setup(record) setup_validator.validate_startdate_setup(record)
expect(record.errors["startdate"]).to include(match I18n.t("validations.lettings.setup.startdate.not_within.next_two_weeks")) expect(record.errors["startdate"]).to include(match I18n.t("validations.lettings.setup.startdate.not_within.next_two_weeks"))
end end
context "and the attempted startdate is in a future collection year" do context "and the attempted startdate is in a future collection year" do
it "adds both errors to startdate, with the collection year error first" do it "adds both errors to startdate, with the collection year error first" do
record.startdate = Time.zone.local(2024, 4, 1) record.startdate = next_collection_start_date
setup_validator.validate_startdate_setup(record) setup_validator.validate_startdate_setup(record)
expect(record.errors["startdate"].length).to be >= 2 expect(record.errors["startdate"].length).to be >= 2
expect(record.errors["startdate"][0]).to eq("Enter a date within the 2023 to 2024 collection year, which is between 1st April 2023 and 31st March 2024.") expect(record.errors["startdate"][0]).to match(/Enter a date within the \d{4} to \d{4} collection year, which is between 1st April \d{4} and 31st March \d{4}/)
expect(record.errors["startdate"][1]).to eq(I18n.t("validations.lettings.setup.startdate.not_within.next_two_weeks")) expect(record.errors["startdate"][1]).to eq(I18n.t("validations.lettings.setup.startdate.not_within.next_two_weeks"))
end end
end end
end end
context "when organisations were merged" do context "when organisations were merged" do
let(:absorbing_organisation) { create(:organisation, created_at: Time.zone.local(2023, 1, 30, 4, 5, 6), available_from: Time.zone.local(2023, 2, 1, 4, 5, 6), name: "Absorbing org") } let(:org_available_from) { current_collection_start_date - 2.months }
let(:absorbing_organisation_2) { create(:organisation, created_at: Time.zone.local(2023, 1, 30), available_from: Time.zone.local(2023, 2, 1), name: "Absorbing org 2") } let(:org_created_at) { org_available_from - 2.days }
let(:org_merge_date) { org_available_from + 1.day }
let(:merge_date_formatted) { org_merge_date.strftime("%-d %B %Y") }
let(:available_from_formatted) { org_available_from.strftime("%-d %B %Y") }
let(:absorbing_organisation) { create(:organisation, created_at: org_created_at, available_from: org_available_from, name: "Absorbing org") }
let(:absorbing_organisation_2) { create(:organisation, created_at: org_created_at, available_from: org_available_from, name: "Absorbing org 2") }
let(:merged_organisation) { create(:organisation, name: "Merged org") } let(:merged_organisation) { create(:organisation, name: "Merged org") }
let(:merged_organisation_2) { create(:organisation, name: "Merged org 2") } let(:merged_organisation_2) { create(:organisation, name: "Merged org 2") }
before do before do
allow(Time).to receive(:now).and_return(Time.zone.local(2023, 5, 1)) Timecop.freeze(current_collection_start_date + 1.month)
merged_organisation.update!(absorbing_organisation:, merge_date: Time.zone.local(2023, 2, 2)) merged_organisation.update!(absorbing_organisation:, merge_date: org_merge_date)
merged_organisation_2.update!(absorbing_organisation:, merge_date: Time.zone.local(2023, 2, 2)) merged_organisation_2.update!(absorbing_organisation:, merge_date: org_merge_date)
end
after do
Timecop.return
end end
context "and owning organisation is no longer active" do context "and owning organisation is no longer active" do
it "does not allow startdate after organisation has been merged" do it "does not allow startdate after organisation has been merged" do
record.startdate = Time.zone.local(2023, 3, 1) record.startdate = org_merge_date + 1.month
record.owning_organisation_id = merged_organisation.id record.owning_organisation_id = merged_organisation.id
setup_validator.validate_startdate_setup(record) setup_validator.validate_startdate_setup(record)
setup_validator.validate_merged_organisations_start_date(record) setup_validator.validate_merged_organisations_start_date(record)
expect(record.errors["startdate"]).to include(match "Enter a date when the owning organisation was active. Merged org became inactive on 2 February 2023 and was replaced by Absorbing org.") expect(record.errors["startdate"]).to include(match "Enter a date when the owning organisation was active. Merged org became inactive on #{merge_date_formatted} and was replaced by Absorbing org.")
end end
it "allows startdate before organisation has been merged" do it "allows startdate before organisation has been merged" do
record.startdate = Time.zone.local(2023, 1, 1) record.startdate = org_merge_date - 1.month
record.owning_organisation_id = merged_organisation.id record.owning_organisation_id = merged_organisation.id
setup_validator.validate_startdate_setup(record) setup_validator.validate_startdate_setup(record)
setup_validator.validate_merged_organisations_start_date(record) setup_validator.validate_merged_organisations_start_date(record)
@ -201,15 +160,15 @@ RSpec.describe Validations::SetupValidations do
context "and owning organisation is not yet active during the startdate" do context "and owning organisation is not yet active during the startdate" do
it "does not allow startdate before absorbing organisation has become available" do it "does not allow startdate before absorbing organisation has become available" do
record.startdate = Time.zone.local(2023, 1, 1) record.startdate = org_available_from - 1.month
record.owning_organisation_id = absorbing_organisation.id record.owning_organisation_id = absorbing_organisation.id
setup_validator.validate_startdate_setup(record) setup_validator.validate_startdate_setup(record)
setup_validator.validate_merged_organisations_start_date(record) setup_validator.validate_merged_organisations_start_date(record)
expect(record.errors["startdate"]).to include(match "Enter a date when the owning organisation was active. Absorbing org became active on 1 February 2023.") expect(record.errors["startdate"]).to include(match "Enter a date when the owning organisation was active. Absorbing org became active on #{available_from_formatted}.")
end end
it "allows startdate after absorbing organisation has become available" do it "allows startdate after absorbing organisation has become available" do
record.startdate = Time.zone.local(2023, 2, 2) record.startdate = org_available_from + 1.month
record.owning_organisation_id = absorbing_organisation.id record.owning_organisation_id = absorbing_organisation.id
setup_validator.validate_startdate_setup(record) setup_validator.validate_startdate_setup(record)
setup_validator.validate_merged_organisations_start_date(record) setup_validator.validate_merged_organisations_start_date(record)
@ -217,7 +176,7 @@ RSpec.describe Validations::SetupValidations do
end end
it "allows startdate if organisation does not have available from date" do it "allows startdate if organisation does not have available from date" do
record.startdate = Time.zone.local(2023, 1, 1) record.startdate = org_available_from - 1.month
absorbing_organisation.update!(available_from: nil) absorbing_organisation.update!(available_from: nil)
record.owning_organisation_id = absorbing_organisation.id record.owning_organisation_id = absorbing_organisation.id
setup_validator.validate_startdate_setup(record) setup_validator.validate_startdate_setup(record)
@ -228,15 +187,15 @@ RSpec.describe Validations::SetupValidations do
context "and managing organisation is no longer active during the startdate" do context "and managing organisation is no longer active during the startdate" do
it "does not allow startdate after organisation has been merged" do it "does not allow startdate after organisation has been merged" do
record.startdate = Time.zone.local(2023, 3, 1) record.startdate = org_merge_date + 1.month
record.managing_organisation_id = merged_organisation.id record.managing_organisation_id = merged_organisation.id
setup_validator.validate_startdate_setup(record) setup_validator.validate_startdate_setup(record)
setup_validator.validate_merged_organisations_start_date(record) setup_validator.validate_merged_organisations_start_date(record)
expect(record.errors["startdate"]).to include(match "Enter a date when the managing organisation was active. Merged org became inactive on 2 February 2023 and was replaced by Absorbing org.") expect(record.errors["startdate"]).to include(match "Enter a date when the managing organisation was active. Merged org became inactive on #{merge_date_formatted} and was replaced by Absorbing org.")
end end
it "allows startdate before organisation has been merged" do it "allows startdate before organisation has been merged" do
record.startdate = Time.zone.local(2023, 1, 1) record.startdate = org_merge_date - 1.month
record.managing_organisation_id = merged_organisation.id record.managing_organisation_id = merged_organisation.id
setup_validator.validate_startdate_setup(record) setup_validator.validate_startdate_setup(record)
setup_validator.validate_merged_organisations_start_date(record) setup_validator.validate_merged_organisations_start_date(record)
@ -246,15 +205,15 @@ RSpec.describe Validations::SetupValidations do
context "and managing organisation is not yet active during the startdate" do context "and managing organisation is not yet active during the startdate" do
it "does not allow startdate before absorbing organisation has become available'" do it "does not allow startdate before absorbing organisation has become available'" do
record.startdate = Time.zone.local(2023, 1, 1) record.startdate = org_available_from - 1.month
record.managing_organisation_id = absorbing_organisation.id record.managing_organisation_id = absorbing_organisation.id
setup_validator.validate_startdate_setup(record) setup_validator.validate_startdate_setup(record)
setup_validator.validate_merged_organisations_start_date(record) setup_validator.validate_merged_organisations_start_date(record)
expect(record.errors["startdate"]).to include(match "Enter a date when the managing organisation was active. Absorbing org became active on 1 February 2023.") expect(record.errors["startdate"]).to include(match "Enter a date when the managing organisation was active. Absorbing org became active on #{available_from_formatted}.")
end end
it "allows startdate after absorbing organisation has become available" do it "allows startdate after absorbing organisation has become available" do
record.startdate = Time.zone.local(2023, 2, 2) record.startdate = org_available_from + 1.month
record.managing_organisation_id = absorbing_organisation.id record.managing_organisation_id = absorbing_organisation.id
setup_validator.validate_startdate_setup(record) setup_validator.validate_startdate_setup(record)
setup_validator.validate_merged_organisations_start_date(record) setup_validator.validate_merged_organisations_start_date(record)
@ -262,7 +221,7 @@ RSpec.describe Validations::SetupValidations do
end end
it "allows startdate if organisation does not have available from date" do it "allows startdate if organisation does not have available from date" do
record.startdate = Time.zone.local(2023, 1, 1) record.startdate = org_available_from - 1.month
absorbing_organisation.update!(available_from: nil) absorbing_organisation.update!(available_from: nil)
record.managing_organisation_id = absorbing_organisation.id record.managing_organisation_id = absorbing_organisation.id
setup_validator.validate_startdate_setup(record) setup_validator.validate_startdate_setup(record)
@ -273,16 +232,16 @@ RSpec.describe Validations::SetupValidations do
context "and owning and managing organisation is no longer active during the startdate" do context "and owning and managing organisation is no longer active during the startdate" do
it "does not allow startdate after organisation has been merged" do it "does not allow startdate after organisation has been merged" do
record.startdate = Time.zone.local(2023, 3, 1) record.startdate = org_merge_date + 1.month
record.managing_organisation_id = merged_organisation.id record.managing_organisation_id = merged_organisation.id
record.owning_organisation_id = merged_organisation.id record.owning_organisation_id = merged_organisation.id
setup_validator.validate_startdate_setup(record) setup_validator.validate_startdate_setup(record)
setup_validator.validate_merged_organisations_start_date(record) setup_validator.validate_merged_organisations_start_date(record)
expect(record.errors["startdate"]).to include(match "Enter a date when the owning and managing organisation was active. Merged org became inactive on 2 February 2023 and was replaced by Absorbing org.") expect(record.errors["startdate"]).to include(match "Enter a date when the owning and managing organisation was active. Merged org became inactive on #{merge_date_formatted} and was replaced by Absorbing org.")
end end
it "allows startdate before organisation has been merged" do it "allows startdate before organisation has been merged" do
record.startdate = Time.zone.local(2023, 1, 1) record.startdate = org_merge_date - 1.month
record.managing_organisation_id = merged_organisation.id record.managing_organisation_id = merged_organisation.id
record.owning_organisation_id = merged_organisation.id record.owning_organisation_id = merged_organisation.id
setup_validator.validate_startdate_setup(record) setup_validator.validate_startdate_setup(record)
@ -293,16 +252,16 @@ RSpec.describe Validations::SetupValidations do
context "and owning and managing organisation is not yet active during the startdate" do context "and owning and managing organisation is not yet active during the startdate" do
it "does not allow startdate before absorbing organisation has become available" do it "does not allow startdate before absorbing organisation has become available" do
record.startdate = Time.zone.local(2023, 1, 1) record.startdate = org_available_from - 1.month
record.managing_organisation_id = absorbing_organisation.id record.managing_organisation_id = absorbing_organisation.id
record.owning_organisation_id = absorbing_organisation.id record.owning_organisation_id = absorbing_organisation.id
setup_validator.validate_startdate_setup(record) setup_validator.validate_startdate_setup(record)
setup_validator.validate_merged_organisations_start_date(record) setup_validator.validate_merged_organisations_start_date(record)
expect(record.errors["startdate"]).to include(match "Enter a date when the owning and managing organisation was active. Absorbing org became active on 1 February 2023.") expect(record.errors["startdate"]).to include(match "Enter a date when the owning and managing organisation was active. Absorbing org became active on #{available_from_formatted}.")
end end
it "allows startdate after absorbing organisation has become available" do it "allows startdate after absorbing organisation has become available" do
record.startdate = Time.zone.local(2023, 2, 1) record.startdate = org_available_from + 1.month
record.managing_organisation_id = absorbing_organisation.id record.managing_organisation_id = absorbing_organisation.id
record.owning_organisation_id = absorbing_organisation.id record.owning_organisation_id = absorbing_organisation.id
setup_validator.validate_startdate_setup(record) setup_validator.validate_startdate_setup(record)
@ -311,7 +270,7 @@ RSpec.describe Validations::SetupValidations do
end end
it "allows startdate if organisation does not have available from date" do it "allows startdate if organisation does not have available from date" do
record.startdate = Time.zone.local(2023, 1, 1) record.startdate = org_available_from - 1.month
absorbing_organisation.update!(available_from: nil) absorbing_organisation.update!(available_from: nil)
record.managing_organisation_id = absorbing_organisation.id record.managing_organisation_id = absorbing_organisation.id
record.owning_organisation_id = absorbing_organisation.id record.owning_organisation_id = absorbing_organisation.id
@ -323,16 +282,16 @@ RSpec.describe Validations::SetupValidations do
context "and owning and managing organisations are no longer active during the startdate" do context "and owning and managing organisations are no longer active during the startdate" do
it "does not allow startdate after organisation have been merged" do it "does not allow startdate after organisation have been merged" do
record.startdate = Time.zone.local(2023, 2, 2) record.startdate = org_merge_date + 1.month
record.managing_organisation_id = merged_organisation.id record.managing_organisation_id = merged_organisation.id
record.owning_organisation_id = merged_organisation_2.id record.owning_organisation_id = merged_organisation_2.id
setup_validator.validate_startdate_setup(record) setup_validator.validate_startdate_setup(record)
setup_validator.validate_merged_organisations_start_date(record) setup_validator.validate_merged_organisations_start_date(record)
expect(record.errors["startdate"]).to include(match "Enter a date when the owning and managing organisations were active. Merged org 2 and Merged org became inactive on 2 February 2023 and were replaced by Absorbing org.") expect(record.errors["startdate"]).to include(match "Enter a date when the owning and managing organisations were active. Merged org 2 and Merged org became inactive on #{merge_date_formatted} and were replaced by Absorbing org.")
end end
it "allows startdate before organisations have been merged" do it "allows startdate before organisations have been merged" do
record.startdate = Time.zone.local(2023, 1, 1) record.startdate = org_merge_date - 1.month
record.managing_organisation_id = merged_organisation.id record.managing_organisation_id = merged_organisation.id
record.owning_organisation_id = merged_organisation_2.id record.owning_organisation_id = merged_organisation_2.id
setup_validator.validate_startdate_setup(record) setup_validator.validate_startdate_setup(record)
@ -343,20 +302,20 @@ RSpec.describe Validations::SetupValidations do
context "and owning and managing organisations are from different merges and no longer active during the startdate" do context "and owning and managing organisations are from different merges and no longer active during the startdate" do
before do before do
merged_organisation_2.update!(absorbing_organisation: absorbing_organisation_2, merge_date: Time.zone.local(2023, 2, 2)) merged_organisation_2.update!(absorbing_organisation: absorbing_organisation_2, merge_date: org_merge_date)
end end
it "does not allow startdate after organisations have been merged" do it "does not allow startdate after organisations have been merged" do
record.startdate = Time.zone.local(2023, 3, 1) record.startdate = org_merge_date + 1.month
record.managing_organisation_id = merged_organisation.id record.managing_organisation_id = merged_organisation.id
record.owning_organisation_id = merged_organisation_2.id record.owning_organisation_id = merged_organisation_2.id
setup_validator.validate_startdate_setup(record) setup_validator.validate_startdate_setup(record)
setup_validator.validate_merged_organisations_start_date(record) setup_validator.validate_merged_organisations_start_date(record)
expect(record.errors["startdate"]).to include(match "Enter a date when the owning and managing organisations were active. Merged org 2 became inactive on 2 February 2023 and was replaced by Absorbing org 2. Merged org became inactive on 2 February 2023 and was replaced by Absorbing org.") expect(record.errors["startdate"]).to include(match "Enter a date when the owning and managing organisations were active. Merged org 2 became inactive on #{merge_date_formatted} and was replaced by Absorbing org 2. Merged org became inactive on #{merge_date_formatted} and was replaced by Absorbing org.")
end end
it "allows startdate before organisations have been merged" do it "allows startdate before organisations have been merged" do
record.startdate = Time.zone.local(2023, 1, 1) record.startdate = org_merge_date - 1.month
record.managing_organisation_id = merged_organisation.id record.managing_organisation_id = merged_organisation.id
record.owning_organisation_id = merged_organisation_2.id record.owning_organisation_id = merged_organisation_2.id
setup_validator.validate_startdate_setup(record) setup_validator.validate_startdate_setup(record)
@ -367,20 +326,20 @@ RSpec.describe Validations::SetupValidations do
context "and owning and managing organisation have different merges and are not yet active during the startdate" do context "and owning and managing organisation have different merges and are not yet active during the startdate" do
before do before do
merged_organisation_2.update!(absorbing_organisation: absorbing_organisation_2, merge_date: Time.zone.local(2023, 2, 2)) merged_organisation_2.update!(absorbing_organisation: absorbing_organisation_2, merge_date: org_merge_date)
end end
it "does not allow startdate before absorbing organisation has become available" do it "does not allow startdate before absorbing organisation has become available" do
record.startdate = Time.zone.local(2023, 1, 1) record.startdate = org_available_from - 1.month
record.managing_organisation_id = absorbing_organisation.id record.managing_organisation_id = absorbing_organisation.id
record.owning_organisation_id = absorbing_organisation_2.id record.owning_organisation_id = absorbing_organisation_2.id
setup_validator.validate_startdate_setup(record) setup_validator.validate_startdate_setup(record)
setup_validator.validate_merged_organisations_start_date(record) setup_validator.validate_merged_organisations_start_date(record)
expect(record.errors["startdate"]).to include(match "Enter a date when the owning and managing organisations were active. Absorbing org 2 became active on 1 February 2023, and Absorbing org became active on 1 February 2023.") expect(record.errors["startdate"]).to include(match "Enter a date when the owning and managing organisations were active. Absorbing org 2 became active on #{available_from_formatted}, and Absorbing org became active on #{available_from_formatted}.")
end end
it "allows startdate after absorbing organisation has become available" do it "allows startdate after absorbing organisation has become available" do
record.startdate = Time.zone.local(2023, 2, 2) record.startdate = org_available_from + 1.month
record.managing_organisation_id = absorbing_organisation.id record.managing_organisation_id = absorbing_organisation.id
record.owning_organisation_id = absorbing_organisation.id record.owning_organisation_id = absorbing_organisation.id
setup_validator.validate_startdate_setup(record) setup_validator.validate_startdate_setup(record)
@ -390,7 +349,7 @@ RSpec.describe Validations::SetupValidations do
it "allows startdate if organisation does not have available from date" do it "allows startdate if organisation does not have available from date" do
absorbing_organisation.update!(available_from: nil) absorbing_organisation.update!(available_from: nil)
record.startdate = Time.zone.local(2023, 1, 1) record.startdate = org_available_from - 1.month
record.managing_organisation_id = absorbing_organisation.id record.managing_organisation_id = absorbing_organisation.id
record.owning_organisation_id = absorbing_organisation.id record.owning_organisation_id = absorbing_organisation.id
setup_validator.validate_startdate_setup(record) setup_validator.validate_startdate_setup(record)

Loading…
Cancel
Save