Browse Source

feat: add tests

pull/1400/head
natdeanlewissoftwire 3 years ago
parent
commit
b3387c5b03
  1. 88
      spec/models/validations/sales/financial_validations_spec.rb

88
spec/models/validations/sales/financial_validations_spec.rb

@ -224,4 +224,92 @@ RSpec.describe Validations::Sales::FinancialValidations do
end
end
end
describe "#validate_equity_in_range_for_year_and_type" do
let(:record) { FactoryBot.create(:sales_log) }
context "with a log in the 22/23 collection year" do
before do
Timecop.freeze(Time.zone.local(2023, 1, 1))
record.update!(saledate: Time.zone.local(2023, 1, 1))
end
after do
Timecop.unfreeze
end
it "adds an error for type 2, equity below min with the correct percentage" do
record.type = 2
record.equity = 1
financial_validator.validate_equity_in_range_for_year_and_type(record)
expect(record.errors["equity"]).to include(match I18n.t("validations.financial.equity.under_min", min_equity: 25))
expect(record.errors["type"]).to include(match I18n.t("validations.financial.equity.under_min", min_equity: 25))
end
it "adds an error for type 30, equity below min with the correct percentage" do
record.type = 30
record.equity = 1
financial_validator.validate_equity_in_range_for_year_and_type(record)
expect(record.errors["equity"]).to include(match I18n.t("validations.financial.equity.under_min", min_equity: 10))
expect(record.errors["type"]).to include(match I18n.t("validations.financial.equity.under_min", min_equity: 10))
end
it "does not add an error for equity in range with the correct percentage" do
record.type = 2
record.equity = 50
financial_validator.validate_equity_in_range_for_year_and_type(record)
expect(record.errors).to be_empty
end
it "adds an error for equity above max with the correct percentage" do
record.type = 2
record.equity = 90
financial_validator.validate_equity_in_range_for_year_and_type(record)
expect(record.errors["equity"]).to include(match I18n.t("validations.financial.equity.over_max"))
expect(record.errors["type"]).to include(match I18n.t("validations.financial.equity.over_max"))
end
end
context "with a log in 23/24 collection year" do
before do
Timecop.freeze(Time.zone.local(2024, 1, 1))
record.update!(saledate: Time.zone.local(2024, 1, 1))
end
after do
Timecop.unfreeze
end
it "adds an error for type 2, equity below min with the correct percentage" do
record.type = 2
record.equity = 1
financial_validator.validate_equity_in_range_for_year_and_type(record)
expect(record.errors["equity"]).to include(match I18n.t("validations.financial.equity.under_min", min_equity: 10))
expect(record.errors["type"]).to include(match I18n.t("validations.financial.equity.under_min", min_equity: 10))
end
it "adds an error for type 30, equity below min with the correct percentage" do
record.type = 30
record.equity = 1
financial_validator.validate_equity_in_range_for_year_and_type(record)
expect(record.errors["equity"]).to include(match I18n.t("validations.financial.equity.under_min", min_equity: 25))
expect(record.errors["type"]).to include(match I18n.t("validations.financial.equity.under_min", min_equity: 25))
end
it "does not add an error for equity in range with the correct percentage" do
record.type = 2
record.equity = 50
financial_validator.validate_equity_in_range_for_year_and_type(record)
expect(record.errors).to be_empty
end
it "adds an error for equity above max with the correct percentage" do
record.type = 2
record.equity = 90
financial_validator.validate_equity_in_range_for_year_and_type(record)
expect(record.errors["equity"]).to include(match I18n.t("validations.financial.equity.over_max"))
expect(record.errors["type"]).to include(match I18n.t("validations.financial.equity.over_max"))
end
end
end
end

Loading…
Cancel
Save