@@ -637,3 +637,39 @@ func (suite *TestSuiteEnv) TestSetAllocationsMonthFailures() {
637637 recorder = test .Request (suite .T (), http .MethodPost , strings .Replace (budgetAllocationsLink , "YYYY-MM" , "2022-01" , 1 ), `{ "mode": "UNKNOWN_MODE" }` )
638638 test .AssertHTTPStatus (suite .T (), http .StatusBadRequest , & recorder )
639639}
640+
641+ // TestBudgetBalanceDoubleRegression verifies that the Budget balance is only added once.
642+ func (suite * TestSuiteEnv ) TestBudgetBalanceDoubleRegression () {
643+ shouldBalance := decimal .NewFromFloat (1000 )
644+
645+ budget := createTestBudget (suite .T (), models.BudgetCreate {Name : "TestBudgetBalanceDoubleRegression" })
646+
647+ internalAccount := createTestAccount (suite .T (), models.AccountCreate {
648+ BudgetID : budget .Data .ID ,
649+ OnBudget : true ,
650+ External : false ,
651+ })
652+
653+ externalAccount := createTestAccount (suite .T (), models.AccountCreate {
654+ BudgetID : budget .Data .ID ,
655+ OnBudget : true ,
656+ External : true ,
657+ })
658+
659+ category := createTestCategory (suite .T (), models.CategoryCreate {BudgetID : budget .Data .ID })
660+ envelope := createTestEnvelope (suite .T (), models.EnvelopeCreate {CategoryID : category .Data .ID })
661+
662+ _ = createTestTransaction (suite .T (), models.TransactionCreate {
663+ BudgetID : budget .Data .ID ,
664+ Amount : shouldBalance ,
665+ SourceAccountID : externalAccount .Data .ID ,
666+ DestinationAccountID : internalAccount .Data .ID ,
667+ EnvelopeID : & envelope .Data .ID ,
668+ })
669+
670+ var budgetResponse controllers.BudgetResponse
671+ recorder := test .Request (suite .T (), http .MethodGet , budget .Data .Links .Self , "" )
672+ test .DecodeResponse (suite .T (), & recorder , & budgetResponse )
673+
674+ assert .True (suite .T (), budgetResponse .Data .Balance .Equal (shouldBalance ), "Balance is %s, should be %s" , budgetResponse .Data .Balance , shouldBalance )
675+ }
0 commit comments