Fix test without available property

This commit is contained in:
Jan Bader 2022-04-07 07:53:25 +00:00
parent ed321d3895
commit a2280e50ec
2 changed files with 18 additions and 15 deletions

View File

@ -13,7 +13,7 @@ import (
type CategoryWithBalance struct { type CategoryWithBalance struct {
*postgres.GetCategoriesRow *postgres.GetCategoriesRow
Available numeric.Numeric AvailableLastMonth numeric.Numeric
Activity numeric.Numeric Activity numeric.Numeric
Assigned numeric.Numeric Assigned numeric.Numeric
} }
@ -21,7 +21,7 @@ type CategoryWithBalance struct {
func NewCategoryWithBalance(category *postgres.GetCategoriesRow) CategoryWithBalance { func NewCategoryWithBalance(category *postgres.GetCategoriesRow) CategoryWithBalance {
return CategoryWithBalance{ return CategoryWithBalance{
GetCategoriesRow: category, GetCategoriesRow: category,
Available: numeric.Zero(), AvailableLastMonth: numeric.Zero(),
Activity: numeric.Zero(), Activity: numeric.Zero(),
Assigned: numeric.Zero(), Assigned: numeric.Zero(),
} }
@ -157,16 +157,17 @@ func (h *Handler) calculateBalances(budget postgres.Budget, month Month,
} }
moneyUsed.SubI(bal.Assignments) moneyUsed.SubI(bal.Assignments)
categoryWithBalance.Available.AddI(bal.Assignments)
categoryWithBalance.Available.AddI(bal.Transactions)
if !categoryWithBalance.Available.IsPositive() && month.InPast(bal.Date) {
moneyUsed.AddI(categoryWithBalance.Available)
categoryWithBalance.Available = numeric.Zero()
}
if month.InPresent(bal.Date) { if month.InPresent(bal.Date) {
categoryWithBalance.Activity = bal.Transactions categoryWithBalance.Activity = bal.Transactions
categoryWithBalance.Assigned = bal.Assignments categoryWithBalance.Assigned = bal.Assignments
continue
}
categoryWithBalance.AvailableLastMonth.AddI(bal.Assignments)
categoryWithBalance.AvailableLastMonth.AddI(bal.Transactions)
if !categoryWithBalance.AvailableLastMonth.IsPositive() {
moneyUsed.AddI(categoryWithBalance.AvailableLastMonth)
categoryWithBalance.AvailableLastMonth = numeric.Zero()
} }
} }

View File

@ -231,9 +231,11 @@ func (h Handler) CheckAvailableBalance(ctx context.Context, t *testing.T, testCa
name := category.Group + " : " + category.Name name := category.Group + " : " + category.Name
if name == categoryName { if name == categoryName {
assertEqual(t, categoryTestData.Available, category.Available.GetFloat64(), "available for "+categoryName)
assertEqual(t, categoryTestData.Activity, category.Activity.GetFloat64(), "activity for "+categoryName) assertEqual(t, categoryTestData.Activity, category.Activity.GetFloat64(), "activity for "+categoryName)
assertEqual(t, categoryTestData.Assigned, category.Assigned.GetFloat64(), "assigned for "+categoryName) assertEqual(t, categoryTestData.Assigned, category.Assigned.GetFloat64(), "assigned for "+categoryName)
available := category.AvailableLastMonth
available.AddI(category.Activity).AddI(category.Assigned)
assertEqual(t, categoryTestData.Available, available.GetFloat64(), "available for "+categoryName)
found = true found = true
} }
} }