Implement integration-test based on YNAB-Export #46
| @@ -81,15 +81,7 @@ func (h *Handler) prepareBudgeting(ctx context.Context, budget postgres.Budget, | ||||
|  | ||||
| 	categoriesWithBalance, moneyUsed := h.calculateBalances( | ||||
| 		budget, firstOfNextMonth, firstOfMonth, categories, cumultativeBalances) | ||||
| 	availableBalance := h.getAvailableBalance(budget, moneyUsed, cumultativeBalances, firstOfNextMonth) | ||||
| 	for i := range categoriesWithBalance { | ||||
| 		cat := &categoriesWithBalance[i] | ||||
| 		if cat.ID != budget.IncomeCategoryID { | ||||
| 			continue | ||||
| 		} | ||||
|  | ||||
| 		cat.Available = availableBalance | ||||
| 	} | ||||
| 	availableBalance := h.getAvailableBalance(budget, moneyUsed, cumultativeBalances, categoriesWithBalance, firstOfNextMonth) | ||||
|  | ||||
| 	data := BudgetingForMonthResponse{categoriesWithBalance, availableBalance} | ||||
| 	return data, nil | ||||
| @@ -102,7 +94,7 @@ type BudgetingForMonthResponse struct { | ||||
|  | ||||
| func (*Handler) getAvailableBalance(budget postgres.Budget, | ||||
| 	moneyUsed numeric.Numeric, cumultativeBalances []postgres.GetCumultativeBalancesRow, | ||||
| 	firstOfNextMonth time.Time, | ||||
| 	categoriesWithBalance []CategoryWithBalance, firstOfNextMonth time.Time, | ||||
| ) numeric.Numeric { | ||||
| 	availableBalance := moneyUsed | ||||
|  | ||||
| @@ -118,6 +110,15 @@ func (*Handler) getAvailableBalance(budget postgres.Budget, | ||||
| 		availableBalance.AddI(bal.Transactions) | ||||
| 		availableBalance.AddI(bal.Assignments) | ||||
| 	} | ||||
|  | ||||
| 	for i := range categoriesWithBalance { | ||||
| 		cat := &categoriesWithBalance[i] | ||||
| 		if cat.ID != budget.IncomeCategoryID { | ||||
| 			continue | ||||
| 		} | ||||
|  | ||||
| 		cat.Available = availableBalance | ||||
| 	} | ||||
| 	return availableBalance | ||||
| } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user