From 9560940220646db300b6a0b68a63eec640dc45de Mon Sep 17 00:00:00 2001 From: Sam Seed Date: Thu, 9 Mar 2023 17:04:19 +0000 Subject: [PATCH] test: add tests for stairbought threshold validation --- .../sales/financial_validations_spec.rb | 87 +++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/spec/models/validations/sales/financial_validations_spec.rb b/spec/models/validations/sales/financial_validations_spec.rb index fae0e4536..59ce6daea 100644 --- a/spec/models/validations/sales/financial_validations_spec.rb +++ b/spec/models/validations/sales/financial_validations_spec.rb @@ -160,6 +160,93 @@ RSpec.describe Validations::Sales::FinancialValidations do end end + describe "#validate_percentage_bought_at_least_threshold" do + let(:record) { FactoryBot.create(:sales_log) } + + it "adds an error to stairbought if the percentage bought is less than the threshold (which depends on the shared ownership type)" do + record.stairbought = 9 + + record.type = 2 + financial_validator.validate_percentage_bought_at_least_threshold(record) + expect(record.errors["stairbought"]).to eq(["The minimum increase in equity while staircasing is 10%"]) + record.errors.clear + + record.type = 16 + financial_validator.validate_percentage_bought_at_least_threshold(record) + expect(record.errors["stairbought"]).to eq(["The minimum increase in equity while staircasing is 10%"]) + record.errors.clear + + record.type = 18 + financial_validator.validate_percentage_bought_at_least_threshold(record) + expect(record.errors["stairbought"]).to eq(["The minimum increase in equity while staircasing is 10%"]) + record.errors.clear + + record.type = 24 + financial_validator.validate_percentage_bought_at_least_threshold(record) + expect(record.errors["stairbought"]).to eq(["The minimum increase in equity while staircasing is 10%"]) + record.errors.clear + + + record.stairbought = 0 + + record.type = 30 + financial_validator.validate_percentage_bought_at_least_threshold(record) + expect(record.errors["stairbought"]).to eq(["The minimum increase in equity while staircasing is 1%"]) + record.errors.clear + end + + it "doesn't add an error to stairbought if the percentage bought is greater than or equal to the threshold (which depends on the shared ownership type)" do + record.stairbought = 10 + + record.type = 2 + financial_validator.validate_percentage_bought_at_least_threshold(record) + expect(record.errors["stairbought"]).to be_empty + record.errors.clear + + record.type = 16 + financial_validator.validate_percentage_bought_at_least_threshold(record) + expect(record.errors["stairbought"]).to be_empty + record.errors.clear + + record.type = 18 + financial_validator.validate_percentage_bought_at_least_threshold(record) + expect(record.errors["stairbought"]).to be_empty + record.errors.clear + + record.type = 24 + financial_validator.validate_percentage_bought_at_least_threshold(record) + expect(record.errors["stairbought"]).to be_empty + record.errors.clear + + + record.stairbought = 1 + + record.type = 30 + financial_validator.validate_percentage_bought_at_least_threshold(record) + expect(record.errors["stairbought"]).to be_empty + record.errors.clear + end + + it "doesn't add an error to stairbought if the percentage bought is less than the smallest possible threshold and the shared ownership type is not one which should have a threshold associated with it" do + record.stairbought = 0 + + record.type = 28 + financial_validator.validate_percentage_bought_at_least_threshold(record) + expect(record.errors["stairbought"]).to be_empty + record.errors.clear + + record.type = 31 + financial_validator.validate_percentage_bought_at_least_threshold(record) + expect(record.errors["stairbought"]).to be_empty + record.errors.clear + + record.type = 32 + financial_validator.validate_percentage_bought_at_least_threshold(record) + expect(record.errors["stairbought"]).to be_empty + record.errors.clear + end + end + describe "#validate_percentage_owned_not_too_much_if_older_person" do let(:record) { FactoryBot.create(:sales_log) }