@ -226,8 +226,9 @@ RSpec.describe Validations::Sales::SaleInformationValidations do
end
end
describe " # validate_discounted_ownership_value " do
describe " # validate_discounted_ownership_value " do
context " when sale is on or after 24/25 collection window " do
context " when grant is routed to " do
context " when grant is routed to " do
let ( :record ) { FactoryBot . build ( :sales_log , mortgage : 10_000 , deposit : 5_000 , value : 30_000 , ownershipsch : 2 , type : 8 ) }
let ( :record ) { FactoryBot . build ( :sales_log , mortgage : 10_000 , deposit : 5_000 , value : 30_000 , ownershipsch : 2 , type : 8 , saledate : Time . zone . local ( 2024 , 4 , 3 ) ) }
context " and not provided " do
context " and not provided " do
before do
before do
@ -261,7 +262,7 @@ RSpec.describe Validations::Sales::SaleInformationValidations do
end
end
context " when discount is routed to " do
context " when discount is routed to " do
let ( :record ) { FactoryBot . build ( :sales_log , mortgage : 10_000 , deposit : 5_000 , value : 30_000 , ownershipsch : 2 , type : 9 ) }
let ( :record ) { FactoryBot . build ( :sales_log , mortgage : 10_000 , deposit : 5_000 , value : 30_000 , ownershipsch : 2 , type : 9 , saledate : Time . zone . local ( 2024 , 4 , 3 ) ) }
context " and not provided " do
context " and not provided " do
before do
before do
@ -295,7 +296,7 @@ RSpec.describe Validations::Sales::SaleInformationValidations do
end
end
context " when neither discount nor grant is routed to " do
context " when neither discount nor grant is routed to " do
let ( :record ) { FactoryBot . build ( :sales_log , mortgage : 10_000 , value : 30_000 , ownershipsch : 2 , type : 29 ) }
let ( :record ) { FactoryBot . build ( :sales_log , mortgage : 10_000 , value : 30_000 , ownershipsch : 2 , type : 29 , saledate : Time . zone . local ( 2024 , 4 , 3 ) ) }
it " adds an error if mortgage and deposit total does not equal market value " do
it " adds an error if mortgage and deposit total does not equal market value " do
record . deposit = 2_000
record . deposit = 2_000
@ -315,7 +316,7 @@ RSpec.describe Validations::Sales::SaleInformationValidations do
end
end
context " when mortgage is routed to " do
context " when mortgage is routed to " do
let ( :record ) { FactoryBot . build ( :sales_log , mortgageused : 1 , deposit : 5_000 , grant : 3_000 , value : 20_000 , discount : 10 , ownershipsch : 2 ) }
let ( :record ) { FactoryBot . build ( :sales_log , mortgageused : 1 , deposit : 5_000 , grant : 3_000 , value : 20_000 , discount : 10 , ownershipsch : 2 , saledate : Time . zone . local ( 2024 , 4 , 3 ) ) }
context " and not provided " do
context " and not provided " do
before do
before do
@ -349,7 +350,7 @@ RSpec.describe Validations::Sales::SaleInformationValidations do
end
end
context " when mortgage is not routed to " do
context " when mortgage is not routed to " do
let ( :record ) { FactoryBot . build ( :sales_log , mortgageused : 2 , deposit : 5_000 , grant : 3_000 , value : 20_000 , discount : 10 , ownershipsch : 2 ) }
let ( :record ) { FactoryBot . build ( :sales_log , mortgageused : 2 , deposit : 5_000 , grant : 3_000 , value : 20_000 , discount : 10 , ownershipsch : 2 , saledate : Time . zone . local ( 2024 , 4 , 3 ) ) }
it " adds an error if grant and deposit total does not equal market value - discount " do
it " adds an error if grant and deposit total does not equal market value - discount " do
sale_information_validator . validate_discounted_ownership_value ( record )
sale_information_validator . validate_discounted_ownership_value ( record )
@ -368,7 +369,18 @@ RSpec.describe Validations::Sales::SaleInformationValidations do
end
end
context " when ownership is not discounted " do
context " when ownership is not discounted " do
let ( :record ) { FactoryBot . build ( :sales_log , mortgage : 10_000 , deposit : 5_000 , grant : 3_000 , value : 20_000 , discount : 10 , ownershipsch : 1 ) }
let ( :record ) { FactoryBot . build ( :sales_log , mortgage : 10_000 , deposit : 5_000 , grant : 3_000 , value : 20_000 , discount : 10 , ownershipsch : 1 , saledate : Time . zone . local ( 2024 , 4 , 3 ) ) }
it " does not add an error " do
sale_information_validator . validate_discounted_ownership_value ( record )
expect ( record . errors ) . to be_empty
end
end
end
context " when sale is before 24/25 collection " do
let ( :record ) { FactoryBot . build ( :sales_log , mortgageused : 2 , deposit : 5_000 , grant : 3_000 , value : 20_000 , discount : 10 , ownershipsch : 2 , saledate : Time . zone . local ( 2023 , 4 , 4 ) ) }
it " does not add an error " do
it " does not add an error " do
sale_information_validator . validate_discounted_ownership_value ( record )
sale_information_validator . validate_discounted_ownership_value ( record )