From 2d97bc49bdac51ec1030df66e18764578ee074bc Mon Sep 17 00:00:00 2001 From: Lynne Davis Date: Thu, 17 Mar 2016 12:36:38 +0000 Subject: [PATCH] Updating specs to explore the cases around zero turnover with fixed rate and minimum billable turnover --- spec/models/billable_period_spec.rb | 69 ++++++++++++++++++++++++++++- 1 file changed, 68 insertions(+), 1 deletion(-) diff --git a/spec/models/billable_period_spec.rb b/spec/models/billable_period_spec.rb index b2a1b4470e..e79c0a2cd2 100644 --- a/spec/models/billable_period_spec.rb +++ b/spec/models/billable_period_spec.rb @@ -27,6 +27,73 @@ describe BillablePeriod, type: :model do end end + describe "calculating monthly bills for enterprises with no turnover" do + let!(:subject) { create(:billable_period, turnover: 0) } + + context "when no tax is charged" do + before { Spree::Config.set(:account_invoices_tax_rate, 0) } + + context "when no minimum billable turnover" do + before { Spree::Config.set(:minimum_billable_turnover, -1) } + + context "when a fixed cost is included" do + before { Spree::Config.set(:account_invoices_monthly_fixed, 10) } + it { expect(subject.bill).to eq 10 } + end + + context "when no fixed cost is included" do + before { Spree::Config.set(:account_invoices_monthly_fixed, 0) } + it { expect(subject.bill).to eq 0 } + end + end + + context "when minimum billable turnover exists" do + before { Spree::Config.set(:minimum_billable_turnover, 0) } + + context "when a fixed cost is included" do + before { Spree::Config.set(:account_invoices_monthly_fixed, 10) } + it { expect(subject.bill).to eq 0 } + end + + context "when no fixed cost is included" do + before { Spree::Config.set(:account_invoices_monthly_fixed, 0) } + it { expect(subject.bill).to eq 0 } + end + end + end + + context "when tax is charged" do + before { Spree::Config.set(:account_invoices_tax_rate, 0.1) } + + context "when no minimum billable turnover" do + before { Spree::Config.set(:minimum_billable_turnover, -1) } + + context "when a fixed cost is included" do + before { Spree::Config.set(:account_invoices_monthly_fixed, 10) } + it { expect(subject.bill).to eq 11 } + end + + context "when no fixed cost is included" do + before { Spree::Config.set(:account_invoices_monthly_fixed, 0) } + it { expect(subject.bill).to eq 0 } + end + end + + context "when minimum billable turnover exists" do + before { Spree::Config.set(:minimum_billable_turnover, 0) } + + context "when a fixed cost is included" do + before { Spree::Config.set(:account_invoices_monthly_fixed, 10) } + it { expect(subject.bill).to eq 0 } + end + + context "when no fixed cost is included" do + before { Spree::Config.set(:account_invoices_monthly_fixed, 0) } + it { expect(subject.bill).to eq 0 } + end + end + end + end describe "calculating monthly bills for enterprises" do let!(:subject) { create(:billable_period, turnover: 100) } @@ -35,7 +102,7 @@ describe BillablePeriod, type: :model do before { Spree::Config.set(:account_invoices_tax_rate, 0) } context "when no minimum billable turnover" do - before { Spree::Config.set(:minimum_billable_turnover, 0) } + before { Spree::Config.set(:minimum_billable_turnover, -1) } context "when a fixed cost is included" do before { Spree::Config.set(:account_invoices_monthly_fixed, 10) }