@@ -90,6 +90,30 @@ func (suite *TestSuiteEnv) TestBudgetCalculations() {
9090 suite .Assert ().Fail ("Resource could not be saved" , err )
9191 }
9292
93+ allocation1 := models.Allocation {
94+ AllocationCreate : models.AllocationCreate {
95+ EnvelopeID : envelope .ID ,
96+ Amount : decimal .NewFromFloat (17.42 ),
97+ Month : time .Date (2022 , 1 , 1 , 0 , 0 , 0 , 0 , time .UTC ),
98+ },
99+ }
100+ err = database .DB .Save (& allocation1 ).Error
101+ if err != nil {
102+ suite .Assert ().Fail ("Resource could not be saved" , err )
103+ }
104+
105+ allocation2 := models.Allocation {
106+ AllocationCreate : models.AllocationCreate {
107+ EnvelopeID : envelope .ID ,
108+ Amount : decimal .NewFromFloat (24.58 ),
109+ Month : time .Date (2022 , 2 , 1 , 0 , 0 , 0 , 0 , time .UTC ),
110+ },
111+ }
112+ err = database .DB .Save (& allocation2 ).Error
113+ if err != nil {
114+ suite .Assert ().Fail ("Resource could not be saved" , err )
115+ }
116+
93117 salaryTransaction := models.Transaction {
94118 TransactionCreate : models.TransactionCreate {
95119 Date : marchFifteenthTwentyTwentyTwo ,
@@ -176,6 +200,16 @@ func (suite *TestSuiteEnv) TestBudgetCalculations() {
176200 income , err = emptyBudget .TotalIncome ()
177201 assert .Nil (suite .T (), err )
178202 assert .True (suite .T (), income .IsZero (), "Income is %s, should be 0" , income )
203+
204+ // Verify total budgeted for used budget
205+ budgeted , err := budget .TotalBudgeted ()
206+ assert .Nil (suite .T (), err )
207+ assert .True (suite .T (), budgeted .Equal (decimal .NewFromFloat (42 )), "Income is %s, should be 42" , income )
208+
209+ // Verify total budgeted for empty budget
210+ budgeted , err = emptyBudget .TotalBudgeted ()
211+ assert .Nil (suite .T (), err )
212+ assert .True (suite .T (), budgeted .IsZero (), "Income is %s, should be 0" , income )
179213}
180214
181215func (suite * TestSuiteEnv ) TestMonthIncomeNoTransactions () {
@@ -201,3 +235,15 @@ func (suite *TestSuiteEnv) TestTotalIncomeNoTransactions() {
201235 assert .Nil (suite .T (), err )
202236 assert .True (suite .T (), income .IsZero (), "Income is %s, should be 0" , income )
203237}
238+
239+ func (suite * TestSuiteEnv ) TestTotalBudgetedNoTransactions () {
240+ budget := models.Budget {}
241+ err := database .DB .Save (& budget ).Error
242+ if err != nil {
243+ suite .Assert ().Fail ("Resource could not be saved" , err )
244+ }
245+
246+ budgeted , err := budget .TotalBudgeted ()
247+ assert .Nil (suite .T (), err )
248+ assert .True (suite .T (), budgeted .IsZero (), "Income is %s, should be 0" , budgeted )
249+ }
0 commit comments