Browse Source

Spec weekly net income calculation

pull/58/head
baarkerlounger 4 years ago
parent
commit
ec9bde8cc0
  1. 4
      app/models/case_log.rb
  2. 20
      spec/models/case_log_spec.rb

4
app/models/case_log.rb

@ -111,9 +111,9 @@ class CaseLog < ApplicationRecord
when "Weekly"
net_income
when "Monthly"
net_income / 4
((net_income * 12) / 52.0).round(0)
when "Yearly"
net_income / 12
(net_income / 12.0).round(0)
else
nil
end

20
spec/models/case_log_spec.rb

@ -103,4 +103,24 @@ RSpec.describe Form, type: :model do
expect(in_progress_case_log.completed?).to be(false)
end
end
describe "weekly_net_income" do
let(:net_income) { 5000 }
let(:case_log) { FactoryBot.build(:case_log, net_income: net_income) }
it "returns input income if frequency is already weekly" do
case_log.net_income_frequency = "Weekly"
expect(case_log.weekly_net_income).to eq(net_income)
end
it "calculates the correct weekly income from monthly income" do
case_log.net_income_frequency = "Monthly"
expect(case_log.weekly_net_income).to eq(1154)
end
it "calculates the correct weekly income from yearly income" do
case_log.net_income_frequency = "Yearly"
expect(case_log.weekly_net_income).to eq(417)
end
end
end

Loading…
Cancel
Save