expect(record.errors["startdate"]).toinclude(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
expect(record.errors["startdate"]).toinclude(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")
expect(record.errors["startdate"]).toinclude(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
expect(record.errors["startdate"]).toinclude(match"Enter a date within the 2022 to 2023 collection year, which is between 1st April 2022 and 31st March 2023")
expect(record.errors["startdate"]).toinclude(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
expect(record.errors["startdate"]).toinclude(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"]).toinclude(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}/))
expect(record.errors["startdate"]).toinclude(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"]).toinclude(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
expect(record.errors["startdate"]).toinclude(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
expect(record.errors["startdate"]).toinclude(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"]).toinclude(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
expect(record.errors["startdate"]).toinclude(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"]).toinclude(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
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).tobe>=2
expect(record.errors["startdate"].length).tobe>=2
expect(record.errors["startdate"][0]).toeq("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]).tomatch(/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"]).toinclude(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"]).toinclude(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
expect(record.errors["startdate"]).toinclude(match"Enter a date when the owning organisation was active. Absorbing org became active on 1 February 2023.")
expect(record.errors["startdate"]).toinclude(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
expect(record.errors["startdate"]).toinclude(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"]).toinclude(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
expect(record.errors["startdate"]).toinclude(match"Enter a date when the managing organisation was active. Absorbing org became active on 1 February 2023.")
expect(record.errors["startdate"]).toinclude(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
expect(record.errors["startdate"]).toinclude(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"]).toinclude(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
expect(record.errors["startdate"]).toinclude(match"Enter a date when the owning and managing organisation was active. Absorbing org became active on 1 February 2023.")
expect(record.errors["startdate"]).toinclude(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
expect(record.errors["startdate"]).toinclude(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"]).toinclude(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
expect(record.errors["startdate"]).toinclude(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"]).toinclude(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
expect(record.errors["startdate"]).toinclude(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"]).toinclude(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