From e1a7f4fbbdf4730fd9ea7a701c6da01d075cb733 Mon Sep 17 00:00:00 2001 From: Andrew Tomaka Date: Wed, 22 Nov 2023 21:41:03 -0500 Subject: [PATCH] Add some model tests (#9) Reviewed-on: https://git.atomaka.com/atomaka/budget/pulls/9 --- test/controllers/expenses_controller_test.rb | 2 +- test/controllers/incomes_controller_test.rb | 2 +- test/fixtures/credit_card_bills.yml | 8 ++--- test/fixtures/expenses.yml | 30 +++++++++++----- test/fixtures/incomes.yml | 26 ++++++++++---- test/models/credit_card_bill_test.rb | 8 +++-- test/models/expense_test.rb | 38 ++++++++++++++++++-- test/models/income_test.rb | 6 ++-- test/models/member_test.rb | 26 ++++++++++++-- test/system/expenses_test.rb | 2 +- test/system/incomes_test.rb | 2 +- 11 files changed, 113 insertions(+), 37 deletions(-) diff --git a/test/controllers/expenses_controller_test.rb b/test/controllers/expenses_controller_test.rb index 4f218a6..4a69bbb 100644 --- a/test/controllers/expenses_controller_test.rb +++ b/test/controllers/expenses_controller_test.rb @@ -2,7 +2,7 @@ require "test_helper" class ExpensesControllerTest < ActionDispatch::IntegrationTest setup do - @expense = expenses(:one) + @expense = expenses(:monthly_expense) end test "should get index" do diff --git a/test/controllers/incomes_controller_test.rb b/test/controllers/incomes_controller_test.rb index 361a2f4..ced234a 100644 --- a/test/controllers/incomes_controller_test.rb +++ b/test/controllers/incomes_controller_test.rb @@ -2,7 +2,7 @@ require "test_helper" class IncomesControllerTest < ActionDispatch::IntegrationTest setup do - @income = incomes(:one) + @income = incomes(:included_1) end test "should get index" do diff --git a/test/fixtures/credit_card_bills.yml b/test/fixtures/credit_card_bills.yml index ca0607b..4aa6d0c 100644 --- a/test/fixtures/credit_card_bills.yml +++ b/test/fixtures/credit_card_bills.yml @@ -1,9 +1,5 @@ # Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html one: - description: MyString - amount: 9.99 - -two: - description: MyString - amount: 9.99 + description: Credit Card Bill One + amount: 1_000.00 diff --git a/test/fixtures/expenses.yml b/test/fixtures/expenses.yml index 3c0ef47..5e267f5 100644 --- a/test/fixtures/expenses.yml +++ b/test/fixtures/expenses.yml @@ -1,15 +1,29 @@ # Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html -one: - description: MyString - payment: 9.99 - period: 1 +monthly_expense: + description: Monthly Expense + payment: 120.00 + period: monthly + credit_card: true + estimated: false + +annual_expense: + description: Annual Expense + payment: 120.00 + period: annually + credit_card: true + estimated: false + +weekly_expense: + description: Weekly Expense + payment: 120.00 + period: weekly credit_card: false estimated: false -two: - description: MyString - payment: 9.99 - period: 1 +quarterly_expense: + description: Quarterly Expense + payment: 120.00 + period: quarterly credit_card: false estimated: false diff --git a/test/fixtures/incomes.yml b/test/fixtures/incomes.yml index 7bf8b25..f6d8fb0 100644 --- a/test/fixtures/incomes.yml +++ b/test/fixtures/incomes.yml @@ -1,13 +1,25 @@ # Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html -one: - description: MyString - included: false - amount: 9.99 +included_1: + description: Salary + included: true + amount: 85_000.00 member: one -two: - description: MyString +included_2: + description: Salary + included: true + amount: 15_000.00 + member: one + +excluded: + description: Bonus included: false - amount: 9.99 + amount: 10_000 + member: one + +another_included: + description: Salary + included: true + amount: 10_000.00 member: two diff --git a/test/models/credit_card_bill_test.rb b/test/models/credit_card_bill_test.rb index f0558a5..d40a388 100644 --- a/test/models/credit_card_bill_test.rb +++ b/test/models/credit_card_bill_test.rb @@ -1,7 +1,9 @@ require "test_helper" class CreditCardBillTest < ActiveSupport::TestCase - # test "the truth" do - # assert true - # end + def test_unpaid + credit_card_bill = credit_card_bills(:one) + + assert_equal 870.00, credit_card_bill.unpaid + end end diff --git a/test/models/expense_test.rb b/test/models/expense_test.rb index 67ac22a..97e0831 100644 --- a/test/models/expense_test.rb +++ b/test/models/expense_test.rb @@ -1,7 +1,39 @@ require "test_helper" class ExpenseTest < ActiveSupport::TestCase - # test "the truth" do - # assert true - # end + def test_monthly_converts_period_for_monthly + expense = expenses(:monthly_expense) + + assert_equal 120.00, expense.monthly + end + + def test_monthly_converts_period_for_annually + expense = expenses(:annual_expense) + + assert_equal 10.00, expense.monthly + end + + def test_monthly_converts_period_for_weekly + expense = expenses(:weekly_expense) + + assert_equal 520.00, expense.monthly + end + + def test_monthly_converts_period_for_quarterly + expense = expenses(:quarterly_expense) + + assert_equal 40.00, expense.monthly + end + + def test_total_calculates_total_of_expenses + assert_equal 480.00, Expense.total + end + + def test_total_calculates_monthly_total + assert_equal 690.00, Expense.monthly_total + end + + def test_total_calculates_credit_card_monthly_total + assert_equal 130.00, Expense.credit_card_monthly_total + end end diff --git a/test/models/income_test.rb b/test/models/income_test.rb index 0b7dc86..2b682fe 100644 --- a/test/models/income_test.rb +++ b/test/models/income_test.rb @@ -1,7 +1,7 @@ require "test_helper" class IncomeTest < ActiveSupport::TestCase - # test "the truth" do - # assert true - # end + def test_total + assert_equal 110_000.00, Income.total + end end diff --git a/test/models/member_test.rb b/test/models/member_test.rb index 4fec230..d98f1f5 100644 --- a/test/models/member_test.rb +++ b/test/models/member_test.rb @@ -1,7 +1,27 @@ require "test_helper" class MemberTest < ActiveSupport::TestCase - # test "the truth" do - # assert true - # end + def member + members(:one) + end + + def test_income + assert_equal 110_000.00, member.income + end + + def test_included_income + assert_equal 100_000.00, member.included_income + end + + def test_others_included_income + assert_equal 10_000.00, member.others_included_income + end + + def test_burden_percent + assert_equal 0.91, member.burden_percent + end + + def test_burden_amount + assert_equal 627.90, member.burden_amount + end end diff --git a/test/system/expenses_test.rb b/test/system/expenses_test.rb index abb3fe9..9d162d8 100644 --- a/test/system/expenses_test.rb +++ b/test/system/expenses_test.rb @@ -2,7 +2,7 @@ require "application_system_test_case" class ExpensesTest < ApplicationSystemTestCase setup do - @expense = expenses(:one) + @expense = expenses(:monthly_expense) end test "visiting the index" do diff --git a/test/system/incomes_test.rb b/test/system/incomes_test.rb index ab77bf0..7a6863c 100644 --- a/test/system/incomes_test.rb +++ b/test/system/incomes_test.rb @@ -2,7 +2,7 @@ require "application_system_test_case" class IncomesTest < ApplicationSystemTestCase setup do - @income = incomes(:one) + @income = incomes(:included_1) end test "visiting the index" do