From b460ae31cf0bbbf9cefd49c06f222207fab455f0 Mon Sep 17 00:00:00 2001 From: Andrew Tomaka Date: Wed, 22 Nov 2023 18:51:53 -0500 Subject: [PATCH] Add model tests for Expense --- test/models/expense_test.rb | 59 +++++++++++++++++++++++++++++++++++-- 1 file changed, 56 insertions(+), 3 deletions(-) diff --git a/test/models/expense_test.rb b/test/models/expense_test.rb index 67ac22a..1b3389a 100644 --- a/test/models/expense_test.rb +++ b/test/models/expense_test.rb @@ -1,7 +1,60 @@ require "test_helper" class ExpenseTest < ActiveSupport::TestCase - # test "the truth" do - # assert true - # end + def test_monthly_converts_period_for_monthly + expense = Expense.new(period: :monthly, payment: 120.00) + + assert_equal 120.00, expense.monthly + end + + def test_monthly_converts_period_for_annually + expense = Expense.new(period: :annually, payment: 120.00) + + assert_equal 10.00, expense.monthly + end + + def test_monthly_converts_period_for_weekly + expense = Expense.new(period: :weekly, payment: 120.00) + + assert_equal 520.00, expense.monthly + end + + def test_monthly_converts_period_for_quarterly + expense = Expense.new(period: :quarterly, payment: 120.00) + + assert_equal 40.00, expense.monthly + end + + def test_total_calculates_total_of_expenses + Expense.destroy_all + + Expense.create!(period: :monthly, payment: 120.00) + Expense.create!(period: :annually, payment: 120.00) + Expense.create!(period: :weekly, payment: 120.00) + Expense.create!(period: :quarterly, payment: 120.00) + + assert_equal 480.00, Expense.total + end + + def test_total_calculates_monthly_total + Expense.destroy_all + + Expense.create!(period: :monthly, payment: 120.00) + Expense.create!(period: :annually, payment: 120.00) + Expense.create!(period: :weekly, payment: 120.00) + Expense.create!(period: :quarterly, payment: 120.00) + + assert_equal 690.00, Expense.monthly_total + end + + def test_total_calculates_credit_card_monthly_total + Expense.destroy_all + + Expense.create!(period: :monthly, payment: 120.00, credit_card: true) + Expense.create!(period: :annually, payment: 120.00, credit_card: true) + Expense.create!(period: :weekly, payment: 120.00) + Expense.create!(period: :quarterly, payment: 120.00) + + assert_equal 130.00, Expense.credit_card_monthly_total + end end