@ -5,48 +5,6 @@ RSpec.describe Validations::Sales::SaleInformationValidations do
let ( :validator_class ) { Class . new { include Validations :: Sales :: SaleInformationValidations } }
describe " # validate_deposit_range " do
context " when within permitted bounds " do
let ( :record ) { build ( :sales_log , deposit : 0 ) }
it " does not add an error " do
sale_information_validator . validate_deposit_range ( record )
expect ( record . errors [ :deposit ] ) . not_to be_present
end
end
context " when blank " do
let ( :record ) { build ( :sales_log , deposit : nil ) }
it " does not add an error " do
sale_information_validator . validate_deposit_range ( record )
expect ( record . errors [ :deposit ] ) . not_to be_present
end
end
context " when below lower bound " do
let ( :record ) { build ( :sales_log , deposit : - 1 ) }
it " adds an error " do
sale_information_validator . validate_deposit_range ( record )
expect ( record . errors [ :deposit ] ) . to be_present
end
end
context " when higher than upper bound " do
let ( :record ) { build ( :sales_log , deposit : 1_000_000 ) }
it " adds an error " do
sale_information_validator . validate_deposit_range ( record )
expect ( record . errors [ :deposit ] ) . to be_present
end
end
end
describe " # validate_pratical_completion_date_before_saledate " do
context " when hodate blank " do
let ( :record ) { build ( :sales_log , hodate : nil ) }
@ -109,6 +67,82 @@ RSpec.describe Validations::Sales::SaleInformationValidations do
end
end
describe " # validate_exchange_date " do
context " when exdate blank " do
let ( :record ) { build ( :sales_log , exdate : nil ) }
it " does not add an error " do
sale_information_validator . validate_exchange_date ( record )
expect ( record . errors [ :exdate ] ) . not_to be_present
end
end
context " when saledate blank " do
let ( :record ) { build ( :sales_log , saledate : nil ) }
it " does not add an error " do
sale_information_validator . validate_exchange_date ( record )
expect ( record . errors [ :exdate ] ) . not_to be_present
end
end
context " when saledate and exdate blank " do
let ( :record ) { build ( :sales_log , exdate : nil , saledate : nil ) }
it " does not add an error " do
sale_information_validator . validate_exchange_date ( record )
expect ( record . errors [ :exdate ] ) . not_to be_present
end
end
context " when exdate before saledate " do
let ( :record ) { build ( :sales_log , exdate : 2 . months . ago , saledate : 1 . month . ago ) }
it " does not add the error " do
sale_information_validator . validate_exchange_date ( record )
expect ( record . errors [ :exdate ] ) . not_to be_present
end
end
context " when exdate more than 1 year before saledate " do
let ( :record ) { build ( :sales_log , exdate : 2 . years . ago , saledate : 1 . month . ago ) }
it " does not add the error " do
sale_information_validator . validate_exchange_date ( record )
expect ( record . errors [ :exdate ] ) . to eq (
[ " Contract exchange date must be less than 1 year before completion date " ] ,
)
end
end
context " when exdate after saledate " do
let ( :record ) { build ( :sales_log , exdate : 1 . month . ago , saledate : 2 . months . ago ) }
it " adds error " do
sale_information_validator . validate_exchange_date ( record )
expect ( record . errors [ :exdate ] ) . to eq (
[ " Contract exchange date must be less than 1 year before completion date " ] ,
)
end
end
context " when exdate == saledate " do
let ( :record ) { build ( :sales_log , exdate : Time . zone . parse ( " 2023-07-01 " ) , saledate : Time . zone . parse ( " 2023-07-01 " ) ) }
it " does not add an error " do
sale_information_validator . validate_exchange_date ( record )
expect ( record . errors [ :exdate ] ) . not_to be_present
end
end
end
describe " # validate_previous_property_unit_type " do
context " when number of bedrooms is <= 1 " do
let ( :record ) { FactoryBot . build ( :sales_log , frombeds : 1 , fromprop : 2 ) }