@@ -56,6 +56,14 @@ func (suite *TestSuiteStandard) TestBudgetCalculations() {
5656 Name : "TestBudgetCalculations Cash Account" ,
5757 })
5858
59+ // Regression test for https://github.com/envelope-zero/backend/issues/1007
60+ offBudgetAccount := suite .createTestAccount (models.Account {
61+ BudgetID : budget .ID ,
62+ OnBudget : false ,
63+ External : false ,
64+ Name : "TestBudgetCalculations Off Budget AccountAccount" ,
65+ })
66+
5967 employerAccount := suite .createTestAccount (models.Account {
6068 BudgetID : budget .ID ,
6169 External : true ,
@@ -146,15 +154,23 @@ func (suite *TestSuiteStandard) TestBudgetCalculations() {
146154 Amount : decimal .NewFromFloat (20 ),
147155 })
148156
149- shouldBalance := decimal .NewFromFloat (7269.38 )
157+ // Regression test for https://github.com/envelope-zero/backend/issues/1007
158+ _ = suite .createTestTransaction (models.Transaction {
159+ Date : time .Time (marchTwentyTwentyTwo ),
160+ SourceAccountID : offBudgetAccount .ID ,
161+ DestinationAccountID : cashAccount .ID ,
162+ Amount : decimal .NewFromFloat (20 ),
163+ })
164+
165+ shouldBalance := decimal .NewFromFloat (7289.38 )
150166 isBalance , err := budget .Balance (models .DB )
151167 if err != nil {
152168 assert .FailNow (suite .T (), "Balance for budget could not be calculated" )
153169 }
154- assert .True (suite .T (), isBalance .Equal (shouldBalance ), "Balance for budget is not correct. Should be %s, is %s" , shouldBalance , budget . Balance )
170+ assert .True (suite .T (), isBalance .Equal (shouldBalance ), "Balance for budget is not correct. Should be %s, is %s" , shouldBalance , isBalance )
155171
156172 // Verify income for used budget in March
157- shouldIncome := decimal .NewFromFloat (4600 )
173+ shouldIncome := decimal .NewFromFloat (4620 ) // Income transaction from employer + income from off budget account
158174 income , err := budget .Income (models .DB , marchTwentyTwentyTwo )
159175 assert .Nil (suite .T (), err )
160176 assert .True (suite .T (), income .Equal (shouldIncome ), "Income is %s, should be %s" , income , shouldIncome )
0 commit comments