@ -6,13 +6,99 @@ RSpec.describe Validations::SetupValidations do
let ( :setup_validator_class ) { Class . new { include Validations :: SetupValidations } }
let ( :setup_validator_class ) { Class . new { include Validations :: SetupValidations } }
let ( :record ) { FactoryBot . create ( :lettings_log ) }
let ( :record ) { FactoryBot . create ( :lettings_log ) }
before do
allow ( FeatureToggle ) . to receive ( :startdate_validation_enabled? ) . and_return ( true )
end
describe " tenancy start date " do
context " when in 22/23 collection " do
context " when in the crossover period " do
before do
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 )
expect ( record . errors [ " startdate " ] ) . to include ( match " Enter a date within the 21/22 or 22/23 financial 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 )
expect ( record . errors [ " startdate " ] ) . to include ( match " Enter a date within the 21/22 or 22/23 financial years, which is between 1st April 2021 and 31st March 2023 " )
end
end
context " when after the crossover period " do
before do
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 )
expect ( record . errors [ " startdate " ] ) . to include ( match " Enter a date within the 22/23 financial 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 )
expect ( record . errors [ " startdate " ] ) . to include ( match " Enter a date within the 22/23 financial year, which is between 1st April 2022 and 31st March 2023 " )
end
end
end
context " when in 23/24 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 )
expect ( record . errors [ " startdate " ] ) . to include ( match " Enter a date within the 22/23 or 23/24 financial years, which is between 1st April 2022 and 31st March 2024 " )
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 )
expect ( record . errors [ " startdate " ] ) . to include ( match " Enter a date within the 22/23 or 23/24 financial years, which is between 1st April 2022 and 31st March 2024 " )
end
end
context " when after the crossover period " do
before do
allow ( Time ) . to receive ( :now ) . and_return ( Time . zone . local ( 2024 , 1 , 1 ) )
record . created_at = Time . zone . local ( 2024 , 1 , 1 )
end
it " cannot be before the first collection window start date " do
record . startdate = Time . zone . local ( 2023 , 1 , 1 )
setup_validator . validate_startdate_setup ( record )
expect ( record . errors [ " startdate " ] ) . to include ( match " Enter a date within the 23/24 financial year, which is between 1st April 2023 and 31st March 2024 " )
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 )
expect ( record . errors [ " startdate " ] ) . to include ( match " Enter a date within the 23/24 financial year, which is between 1st April 2023 and 31st March 2024 " )
end
end
end
end
describe " # validate_irproduct " do
describe " # validate_irproduct " do
it " adds an error when the intermediate rent product name is not provided but the rent type was given as other intermediate rent product " do
it " adds an error when the intermediate rent product name is not provided but the rent type was given as other intermediate rent product " do
record . rent_type = 5
record . rent_type = 5
record . irproduct_other = nil
record . irproduct_other = nil
setup_validator . validate_irproduct_other ( record )
setup_validator . validate_irproduct_other ( record )
expect ( record . errors [ " irproduct_other " ] )
expect ( record . errors [ " irproduct_other " ] )
. to include ( match I18n . t ( " validations.setup.intermediate_rent_product_name.blank " ) )
. to include ( match I18n . t ( " validations.setup.intermediate_rent_product_name.blank " ) )
end
end
it " adds an error when the intermediate rent product name is blank but the rent type was given as other intermediate rent product " do
it " adds an error when the intermediate rent product name is blank but the rent type was given as other intermediate rent product " do
@ -20,7 +106,7 @@ RSpec.describe Validations::SetupValidations do
record . irproduct_other = " "
record . irproduct_other = " "
setup_validator . validate_irproduct_other ( record )
setup_validator . validate_irproduct_other ( record )
expect ( record . errors [ " irproduct_other " ] )
expect ( record . errors [ " irproduct_other " ] )
. to include ( match I18n . t ( " validations.setup.intermediate_rent_product_name.blank " ) )
. to include ( match I18n . t ( " validations.setup.intermediate_rent_product_name.blank " ) )
end
end
it " Does not add an error when the intermediate rent product name is provided and the rent type was given as other intermediate rent product " do
it " Does not add an error when the intermediate rent product name is provided and the rent type was given as other intermediate rent product " do
@ -46,7 +132,7 @@ RSpec.describe Validations::SetupValidations do
record . location = location
record . location = location
setup_validator . validate_scheme ( record )
setup_validator . validate_scheme ( record )
expect ( record . errors [ " scheme_id " ] )
expect ( record . errors [ " scheme_id " ] )
. to include ( match I18n . t ( " validations.setup.startdate.location.deactivated " , postcode : location . postcode , date : " 4 June 2022 " ) )
. to include ( match I18n . t ( " validations.setup.startdate.location.deactivated " , postcode : location . postcode , date : " 4 June 2022 " ) )
end
end
it " produces no error when tenancy start date is during an active location period " do
it " produces no error when tenancy start date is during an active location period " do
@ -71,7 +157,7 @@ RSpec.describe Validations::SetupValidations do
record . location = location
record . location = location
setup_validator . validate_scheme ( record )
setup_validator . validate_scheme ( record )
expect ( record . errors [ " scheme_id " ] )
expect ( record . errors [ " scheme_id " ] )
. to include ( match I18n . t ( " validations.setup.startdate.location.reactivating_soon " , postcode : location . postcode , date : " 4 August 2022 " ) )
. to include ( match I18n . t ( " validations.setup.startdate.location.reactivating_soon " , postcode : location . postcode , date : " 4 August 2022 " ) )
end
end
it " produces no error when tenancy start date is during an active location period " do
it " produces no error when tenancy start date is during an active location period " do
@ -98,7 +184,7 @@ RSpec.describe Validations::SetupValidations do
record . location = location
record . location = location
setup_validator . validate_scheme ( record )
setup_validator . validate_scheme ( record )
expect ( record . errors [ " scheme_id " ] )
expect ( record . errors [ " scheme_id " ] )
. to include ( match I18n . t ( " validations.setup.startdate.location.activating_soon " , postcode : location . postcode , date : " 15 September 2022 " ) )
. to include ( match I18n . t ( " validations.setup.startdate.location.activating_soon " , postcode : location . postcode , date : " 15 September 2022 " ) )
end
end
end
end
@ -115,7 +201,7 @@ RSpec.describe Validations::SetupValidations do
record . scheme = scheme
record . scheme = scheme
setup_validator . validate_scheme ( record )
setup_validator . validate_scheme ( record )
expect ( record . errors [ " scheme_id " ] )
expect ( record . errors [ " scheme_id " ] )
. to include ( match I18n . t ( " validations.setup.startdate.scheme.reactivating_soon " , name : scheme . service_name , date : " 4 August 2022 " ) )
. to include ( match I18n . t ( " validations.setup.startdate.scheme.reactivating_soon " , name : scheme . service_name , date : " 4 August 2022 " ) )
end
end
it " produces no error when tenancy start date is during an active scheme period " do
it " produces no error when tenancy start date is during an active scheme period " do
@ -141,7 +227,7 @@ RSpec.describe Validations::SetupValidations do
record . scheme = scheme
record . scheme = scheme
setup_validator . validate_scheme ( record )
setup_validator . validate_scheme ( record )
expect ( record . errors [ " scheme_id " ] )
expect ( record . errors [ " scheme_id " ] )
. to include ( match I18n . t ( " validations.setup.startdate.scheme.reactivating_soon " , name : scheme . service_name , date : " 4 September 2022 " ) )
. to include ( match I18n . t ( " validations.setup.startdate.scheme.reactivating_soon " , name : scheme . service_name , date : " 4 September 2022 " ) )
end
end
it " produces no error when tenancy start date is during an active scheme period " do
it " produces no error when tenancy start date is during an active scheme period " do
@ -168,7 +254,7 @@ RSpec.describe Validations::SetupValidations do
record . location = location
record . location = location
setup_validator . validate_location ( record )
setup_validator . validate_location ( record )
expect ( record . errors [ " location_id " ] )
expect ( record . errors [ " location_id " ] )
. to include ( match I18n . t ( " validations.setup.startdate.location.deactivated " , postcode : location . postcode , date : " 4 June 2022 " ) )
. to include ( match I18n . t ( " validations.setup.startdate.location.deactivated " , postcode : location . postcode , date : " 4 June 2022 " ) )
end
end
it " produces no error when tenancy start date is during an active location period " do
it " produces no error when tenancy start date is during an active location period " do
@ -193,7 +279,7 @@ RSpec.describe Validations::SetupValidations do
record . location = location
record . location = location
setup_validator . validate_location ( record )
setup_validator . validate_location ( record )
expect ( record . errors [ " location_id " ] )
expect ( record . errors [ " location_id " ] )
. to include ( match I18n . t ( " validations.setup.startdate.location.reactivating_soon " , postcode : location . postcode , date : " 4 August 2022 " ) )
. to include ( match I18n . t ( " validations.setup.startdate.location.reactivating_soon " , postcode : location . postcode , date : " 4 August 2022 " ) )
end
end
it " produces no error when tenancy start date is during an active location period " do
it " produces no error when tenancy start date is during an active location period " do
@ -220,7 +306,7 @@ RSpec.describe Validations::SetupValidations do
record . location = location
record . location = location
setup_validator . validate_location ( record )
setup_validator . validate_location ( record )
expect ( record . errors [ " location_id " ] )
expect ( record . errors [ " location_id " ] )
. to include ( match I18n . t ( " validations.setup.startdate.location.activating_soon " , postcode : location . postcode , date : " 15 September 2022 " ) )
. to include ( match I18n . t ( " validations.setup.startdate.location.activating_soon " , postcode : location . postcode , date : " 15 September 2022 " ) )
end
end
end
end
end
end