Browse Source

update tests for the validations

pull/2470/head
Arthur Campbell 2 years ago
parent
commit
ec88fffd75
  1. 105
      spec/models/validations/sales/sale_information_validations_spec.rb

105
spec/models/validations/sales/sale_information_validations_spec.rb

@ -1344,47 +1344,100 @@ RSpec.describe Validations::Sales::SaleInformationValidations do
end end
end end
describe "#validate_mortgage_used_and_stairbought" do describe "#validate_mortgage_used_dont_know" do
let(:now) { Time.zone.local(2024, 4, 4) } let(:staircase) { nil }
let(:stairowned) { nil }
let(:saledate) { nil }
let(:sales_log) { build(:sales_log, ownershipsch:, mortgageused:, staircase:, stairowned:, saledate:) }
before do before do
Timecop.freeze(now) sale_information_validator.validate_mortgage_used_dont_know(sales_log)
Singleton.__init__(FormHandler)
end end
after do context "when mortgageused is don't know" do
Timecop.return let(:mortgageused) { 3 }
Singleton.__init__(FormHandler)
end context "and it is a discounted ownership sale" do
let(:ownershipsch) { 2 }
context "when mortgageused don't know" do it "adds an error" do
let(:record) { build(:sales_log, ownershipsch: 1, type: 9, saledate: now, mortgageused: 3) } expect(sales_log.errors[:mortgageused]).to include "Enter a valid value for was a mortgage used for the purchase of this property?"
end
end
it "does not add an error if stairowned 100" do context "and it is an outright sale" do
record.stairowned = 100 let(:ownershipsch) { 3 }
sale_information_validator.validate_mortgage_used_and_stairbought(record)
expect(record.errors).to be_empty context "with a saledate before 24/25" do
let(:saledate) { Time.zone.local(2023, 9, 9) }
it "adds errors" do
expect(sales_log.errors[:mortgageused]).to include "Enter a valid value for was a mortgage used for the purchase of this property?"
expect(sales_log.errors[:saledate]).to include "You must answer either ‘yes’ or ‘no’ to the question ‘was a mortgage used’ for the selected year."
end
end
context "with a saledate from 24/25 or after" do
let(:saledate) { Time.zone.today }
it "does not add any errors" do
expect(sales_log.errors).to be_empty
end
end
end end
it "adds an error if stairowned is not 100" do context "and it is a shared ownership scheme sale" do
record.stairowned = 90 let(:ownershipsch) { 1 }
sale_information_validator.validate_mortgage_used_and_stairbought(record)
context "and a staircasing transaction" do
let(:staircase) { 1 }
expect(record.errors[:stairowned]).to include("The percentage owned has to be 100% if the mortgage used is 'Don’t know'") context "and stairowned is nil" do
expect(record.errors[:mortgageused]).to include("The percentage owned has to be 100% if the mortgage used is 'Don’t know'") let(:stairowned) { nil }
it "does not add an error" do
expect(sales_log.errors).to be_empty
end
end
context "and stairowned is less than 100" do
let(:stairowned) { 50 }
it "adds errors" do
expect(sales_log.errors[:mortgageused]).to include "The percentage owned has to be 100% if the mortgage used is 'Don’t know'"
expect(sales_log.errors[:stairowned]).to include "The percentage owned has to be 100% if the mortgage used is 'Don’t know'"
end
end
context "and stairowned is 100" do
let(:stairowned) { 100 }
it "does not add an error" do
expect(sales_log.errors).to be_empty
end
end
end
context "and not a staircasing transaction" do
let(:staircase) { 2 }
it "adds errors" do
expect(sales_log.errors[:mortgageused]).to include "Enter a valid value for was a mortgage used for the purchase of this property?"
expect(sales_log.errors[:staircase]).to include "You must answer either ‘yes’ or ‘no’ to the question ‘was a mortgage used’ for staircasing transactions."
end
end
end end
end end
context "when the collection year is before 2024" do context "when mortgageused is not don't know" do
let(:record) { build(:sales_log, ownershipsch: 1, type: 9, saledate: now, mortgageused: 3, stairowned: 90) } let(:mortgageused) { 1 }
let(:now) { Time.zone.local(2023, 4, 4) }
it "adds an error" do context "and it is a discounted ownership sale" do
sale_information_validator.validate_mortgage_used_and_stairbought(record) let(:ownershipsch) { 2 }
expect(record.errors[:stairowned]).to include("The percentage owned has to be 100% if the mortgage used is 'Don’t know'") it "does not add an error" do
expect(record.errors[:mortgageused]).to include("The percentage owned has to be 100% if the mortgage used is 'Don’t know'") expect(sales_log.errors).to be_empty
end
end end
end end
end end

Loading…
Cancel
Save