|
|
|
|
@ -339,4 +339,244 @@ RSpec.describe Validations::Sales::FinancialValidations do
|
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
describe "#validate_discounted_ownership_value" do |
|
|
|
|
let(:record) { FactoryBot.build(:sales_log, mortgage: 10_000, deposit: 5_000, value: 30_000, ownershipsch: 2, type: 8, saledate: now) } |
|
|
|
|
|
|
|
|
|
around do |example| |
|
|
|
|
Timecop.freeze(now) do |
|
|
|
|
example.run |
|
|
|
|
end |
|
|
|
|
Timecop.return |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context "with a log in the 24/25 collection year" do |
|
|
|
|
let(:now) { Time.zone.local(2024, 4, 1) } |
|
|
|
|
|
|
|
|
|
context "when grant is routed to" do |
|
|
|
|
context "and not provided" do |
|
|
|
|
before do |
|
|
|
|
record.grant = nil |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "returns false" do |
|
|
|
|
financial_validator.validate_discounted_ownership_value(record) |
|
|
|
|
expect(record.errors["mortgageused"]).to be_empty |
|
|
|
|
expect(record.errors["mortgage"]).to be_empty |
|
|
|
|
expect(record.errors["value"]).to be_empty |
|
|
|
|
expect(record.errors["deposit"]).to be_empty |
|
|
|
|
expect(record.errors["ownershipsch"]).to be_empty |
|
|
|
|
expect(record.errors["discount"]).to be_empty |
|
|
|
|
expect(record.errors["grant"]).to be_empty |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context "and is provided" do |
|
|
|
|
it "returns true if mortgage, deposit and grant total does not equal market value" do |
|
|
|
|
record.grant = 3_000 |
|
|
|
|
financial_validator.validate_discounted_ownership_value(record) |
|
|
|
|
expect(record.errors["mortgageused"]).to include("Mortgage, deposit, and grant total must equal £30,000.00") |
|
|
|
|
expect(record.errors["mortgage"]).to include("Mortgage, deposit, and grant total must equal £30,000.00") |
|
|
|
|
expect(record.errors["value"]).to include("Mortgage, deposit, and grant total must equal £30,000.00") |
|
|
|
|
expect(record.errors["deposit"]).to include("Mortgage, deposit, and grant total must equal £30,000.00") |
|
|
|
|
expect(record.errors["ownershipsch"]).to include("Mortgage, deposit, and grant total must equal £30,000.00") |
|
|
|
|
expect(record.errors["discount"]).to include("Mortgage, deposit, and grant total must equal £30,000.00") |
|
|
|
|
expect(record.errors["grant"]).to include("Mortgage, deposit, and grant total must equal £30,000.00") |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "returns false if mortgage, deposit and grant total equals market value" do |
|
|
|
|
record.grant = 15_000 |
|
|
|
|
financial_validator.validate_discounted_ownership_value(record) |
|
|
|
|
expect(record.errors["mortgageused"]).to be_empty |
|
|
|
|
expect(record.errors["mortgage"]).to be_empty |
|
|
|
|
expect(record.errors["value"]).to be_empty |
|
|
|
|
expect(record.errors["deposit"]).to be_empty |
|
|
|
|
expect(record.errors["ownershipsch"]).to be_empty |
|
|
|
|
expect(record.errors["discount"]).to be_empty |
|
|
|
|
expect(record.errors["grant"]).to be_empty |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
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, saledate: now) } |
|
|
|
|
|
|
|
|
|
context "and not provided" do |
|
|
|
|
before do |
|
|
|
|
record.discount = nil |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "returns false" do |
|
|
|
|
financial_validator.validate_discounted_ownership_value(record) |
|
|
|
|
expect(record.errors["mortgageused"]).to be_empty |
|
|
|
|
expect(record.errors["mortgage"]).to be_empty |
|
|
|
|
expect(record.errors["value"]).to be_empty |
|
|
|
|
expect(record.errors["deposit"]).to be_empty |
|
|
|
|
expect(record.errors["ownershipsch"]).to be_empty |
|
|
|
|
expect(record.errors["discount"]).to be_empty |
|
|
|
|
expect(record.errors["grant"]).to be_empty |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context "and is provided" do |
|
|
|
|
it "returns true if mortgage and deposit total does not equal market value - discount" do |
|
|
|
|
record.discount = 10 |
|
|
|
|
financial_validator.validate_discounted_ownership_value(record) |
|
|
|
|
expect(record.errors["mortgageused"]).to include("Mortgage, deposit, and grant total must equal £27,000.00") |
|
|
|
|
expect(record.errors["mortgage"]).to include("Mortgage, deposit, and grant total must equal £27,000.00") |
|
|
|
|
expect(record.errors["value"]).to include("Mortgage, deposit, and grant total must equal £27,000.00") |
|
|
|
|
expect(record.errors["deposit"]).to include("Mortgage, deposit, and grant total must equal £27,000.00") |
|
|
|
|
expect(record.errors["ownershipsch"]).to include("Mortgage, deposit, and grant total must equal £27,000.00") |
|
|
|
|
expect(record.errors["discount"]).to include("Mortgage, deposit, and grant total must equal £27,000.00") |
|
|
|
|
expect(record.errors["grant"]).to include("Mortgage, deposit, and grant total must equal £27,000.00") |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "returns false if mortgage and deposit total equals market value - discount" do |
|
|
|
|
record.discount = 50 |
|
|
|
|
financial_validator.validate_discounted_ownership_value(record) |
|
|
|
|
expect(record.errors["mortgageused"]).to be_empty |
|
|
|
|
expect(record.errors["mortgage"]).to be_empty |
|
|
|
|
expect(record.errors["value"]).to be_empty |
|
|
|
|
expect(record.errors["deposit"]).to be_empty |
|
|
|
|
expect(record.errors["ownershipsch"]).to be_empty |
|
|
|
|
expect(record.errors["discount"]).to be_empty |
|
|
|
|
expect(record.errors["grant"]).to be_empty |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
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, saledate: now) } |
|
|
|
|
|
|
|
|
|
it "returns true if mortgage and deposit total does not equal market value" do |
|
|
|
|
record.deposit = 2_000 |
|
|
|
|
financial_validator.validate_discounted_ownership_value(record) |
|
|
|
|
expect(record.errors["mortgageused"]).to include("Mortgage, deposit, and grant total must equal £30,000.00") |
|
|
|
|
expect(record.errors["mortgage"]).to include("Mortgage, deposit, and grant total must equal £30,000.00") |
|
|
|
|
expect(record.errors["value"]).to include("Mortgage, deposit, and grant total must equal £30,000.00") |
|
|
|
|
expect(record.errors["deposit"]).to include("Mortgage, deposit, and grant total must equal £30,000.00") |
|
|
|
|
expect(record.errors["ownershipsch"]).to include("Mortgage, deposit, and grant total must equal £30,000.00") |
|
|
|
|
expect(record.errors["discount"]).to include("Mortgage, deposit, and grant total must equal £30,000.00") |
|
|
|
|
expect(record.errors["grant"]).to include("Mortgage, deposit, and grant total must equal £30,000.00") |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "returns false if mortgage and deposit total equals market value" do |
|
|
|
|
record.deposit = 20_000 |
|
|
|
|
financial_validator.validate_discounted_ownership_value(record) |
|
|
|
|
expect(record.errors["mortgageused"]).to be_empty |
|
|
|
|
expect(record.errors["mortgage"]).to be_empty |
|
|
|
|
expect(record.errors["value"]).to be_empty |
|
|
|
|
expect(record.errors["deposit"]).to be_empty |
|
|
|
|
expect(record.errors["ownershipsch"]).to be_empty |
|
|
|
|
expect(record.errors["discount"]).to be_empty |
|
|
|
|
expect(record.errors["grant"]).to be_empty |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
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, saledate: now) } |
|
|
|
|
|
|
|
|
|
context "and not provided" do |
|
|
|
|
before do |
|
|
|
|
record.mortgage = nil |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "returns false" do |
|
|
|
|
financial_validator.validate_discounted_ownership_value(record) |
|
|
|
|
expect(record.errors["mortgageused"]).to be_empty |
|
|
|
|
expect(record.errors["mortgage"]).to be_empty |
|
|
|
|
expect(record.errors["value"]).to be_empty |
|
|
|
|
expect(record.errors["deposit"]).to be_empty |
|
|
|
|
expect(record.errors["ownershipsch"]).to be_empty |
|
|
|
|
expect(record.errors["discount"]).to be_empty |
|
|
|
|
expect(record.errors["grant"]).to be_empty |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context "and is provided" do |
|
|
|
|
it "returns true if mortgage, grant and deposit total does not equal market value - discount" do |
|
|
|
|
record.mortgage = 10 |
|
|
|
|
financial_validator.validate_discounted_ownership_value(record) |
|
|
|
|
expect(record.errors["mortgageused"]).to include("Mortgage, deposit, and grant total must equal £18,000.00") |
|
|
|
|
expect(record.errors["mortgage"]).to include("Mortgage, deposit, and grant total must equal £18,000.00") |
|
|
|
|
expect(record.errors["value"]).to include("Mortgage, deposit, and grant total must equal £18,000.00") |
|
|
|
|
expect(record.errors["deposit"]).to include("Mortgage, deposit, and grant total must equal £18,000.00") |
|
|
|
|
expect(record.errors["ownershipsch"]).to include("Mortgage, deposit, and grant total must equal £18,000.00") |
|
|
|
|
expect(record.errors["discount"]).to include("Mortgage, deposit, and grant total must equal £18,000.00") |
|
|
|
|
expect(record.errors["grant"]).to include("Mortgage, deposit, and grant total must equal £18,000.00") |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "returns false if mortgage, grant and deposit total equals market value - discount" do |
|
|
|
|
record.mortgage = 10_000 |
|
|
|
|
financial_validator.validate_discounted_ownership_value(record) |
|
|
|
|
expect(record.errors["mortgageused"]).to be_empty |
|
|
|
|
expect(record.errors["mortgage"]).to be_empty |
|
|
|
|
expect(record.errors["value"]).to be_empty |
|
|
|
|
expect(record.errors["deposit"]).to be_empty |
|
|
|
|
expect(record.errors["ownershipsch"]).to be_empty |
|
|
|
|
expect(record.errors["discount"]).to be_empty |
|
|
|
|
expect(record.errors["grant"]).to be_empty |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
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, saledate: now) } |
|
|
|
|
|
|
|
|
|
it "returns true if grant and deposit total does not equal market value - discount" do |
|
|
|
|
financial_validator.validate_discounted_ownership_value(record) |
|
|
|
|
expect(record.errors["mortgageused"]).to include("Mortgage, deposit, and grant total must equal £18,000.00") |
|
|
|
|
expect(record.errors["mortgage"]).to include("Mortgage, deposit, and grant total must equal £18,000.00") |
|
|
|
|
expect(record.errors["value"]).to include("Mortgage, deposit, and grant total must equal £18,000.00") |
|
|
|
|
expect(record.errors["deposit"]).to include("Mortgage, deposit, and grant total must equal £18,000.00") |
|
|
|
|
expect(record.errors["ownershipsch"]).to include("Mortgage, deposit, and grant total must equal £18,000.00") |
|
|
|
|
expect(record.errors["discount"]).to include("Mortgage, deposit, and grant total must equal £18,000.00") |
|
|
|
|
expect(record.errors["grant"]).to include("Mortgage, deposit, and grant total must equal £18,000.00") |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "returns false if mortgage, grant and deposit total equals market value - discount" do |
|
|
|
|
record.grant = 13_000 |
|
|
|
|
financial_validator.validate_discounted_ownership_value(record) |
|
|
|
|
expect(record.errors["mortgageused"]).to be_empty |
|
|
|
|
expect(record.errors["mortgage"]).to be_empty |
|
|
|
|
expect(record.errors["value"]).to be_empty |
|
|
|
|
expect(record.errors["deposit"]).to be_empty |
|
|
|
|
expect(record.errors["ownershipsch"]).to be_empty |
|
|
|
|
expect(record.errors["discount"]).to be_empty |
|
|
|
|
expect(record.errors["grant"]).to be_empty |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
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, saledate: Time.zone.local(2023, 4, 1)) } |
|
|
|
|
|
|
|
|
|
it "returns false" do |
|
|
|
|
financial_validator.validate_discounted_ownership_value(record) |
|
|
|
|
expect(record.errors["mortgageused"]).to be_empty |
|
|
|
|
expect(record.errors["mortgage"]).to be_empty |
|
|
|
|
expect(record.errors["value"]).to be_empty |
|
|
|
|
expect(record.errors["deposit"]).to be_empty |
|
|
|
|
expect(record.errors["ownershipsch"]).to be_empty |
|
|
|
|
expect(record.errors["discount"]).to be_empty |
|
|
|
|
expect(record.errors["grant"]).to be_empty |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context "when it is a 2023 log" do |
|
|
|
|
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(2023, 4, 1)) } |
|
|
|
|
|
|
|
|
|
it "returns false" do |
|
|
|
|
record.mortgage = 10 |
|
|
|
|
financial_validator.validate_discounted_ownership_value(record) |
|
|
|
|
expect(record.errors["mortgageused"]).to be_empty |
|
|
|
|
expect(record.errors["mortgage"]).to be_empty |
|
|
|
|
expect(record.errors["value"]).to be_empty |
|
|
|
|
expect(record.errors["deposit"]).to be_empty |
|
|
|
|
expect(record.errors["ownershipsch"]).to be_empty |
|
|
|
|
expect(record.errors["discount"]).to be_empty |
|
|
|
|
expect(record.errors["grant"]).to be_empty |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|