Remove unused prop

This commit is contained in:
Jan Bader 2022-04-05 19:00:40 +00:00
parent 4332a1537b
commit 5f6bea4ee2
2 changed files with 45 additions and 16 deletions

View File

@ -25,19 +25,17 @@ func getFirstOfMonthTime(date time.Time) time.Time {
type CategoryWithBalance struct {
*postgres.GetCategoriesRow
Available numeric.Numeric
AvailableLastMonth numeric.Numeric
Activity numeric.Numeric
Assigned numeric.Numeric
Available numeric.Numeric
Activity numeric.Numeric
Assigned numeric.Numeric
}
func NewCategoryWithBalance(category *postgres.GetCategoriesRow) CategoryWithBalance {
return CategoryWithBalance{
GetCategoriesRow: category,
Available: numeric.Zero(),
AvailableLastMonth: numeric.Zero(),
Activity: numeric.Zero(),
Assigned: numeric.Zero(),
GetCategoriesRow: category,
Available: numeric.Zero(),
Activity: numeric.Zero(),
Assigned: numeric.Zero(),
}
}
@ -91,7 +89,6 @@ func (h *Handler) prepareBudgeting(ctx context.Context, budget postgres.Budget,
}
cat.Available = availableBalance
cat.AvailableLastMonth = availableBalance
}
data := BudgetingForMonthResponse{categoriesWithBalance, availableBalance}
@ -201,9 +198,7 @@ func (*Handler) CalculateCategoryBalances(cat *postgres.GetCategoriesRow,
categoryWithBalance.Available = numeric.Zero()
}
if bal.Date.Before(firstOfMonth) {
categoryWithBalance.AvailableLastMonth = categoryWithBalance.Available
} else if bal.Date.Before(firstOfNextMonth) {
if bal.Date.Before(firstOfNextMonth) {
categoryWithBalance.Activity = bal.Transactions
categoryWithBalance.Assigned = bal.Assignments
}

View File

@ -2,6 +2,7 @@ package server
import (
"context"
"encoding/json"
"fmt"
"io/fs"
"log"
@ -69,15 +70,22 @@ func TestMain(t *testing.T) {
handler.DoYNABImport(ctx, t, budget)
// check available balance for more dates
handler.CheckAvailableBalance(ctx, t, budget)
// check available balance
// check categories
// check accounts
}
type CategoryTestData struct {
Available float64
Activity float64
Assigned float64
}
func (h Handler) CheckAvailableBalance(ctx context.Context, t *testing.T, budget *postgres.Budget) {
t.Helper()
loc := time.Now().Location()
first := time.Date(2022, 1, 1, 0, 0, 0, 0, loc)
firstOfNextMonth := time.Date(2022, 2, 1, 0, 0, 0, 0, loc)
@ -91,6 +99,32 @@ func (h Handler) CheckAvailableBalance(ctx context.Context, t *testing.T, budget
t.Errorf("available balance is wrong")
return
}
categoryTestDataFile, err := os.Open("../testdata/production-export/results/categories-2021-12.json")
if err != nil {
t.Errorf("could not load category test data: %s", err)
return
}
var categoryTestData map[string]CategoryTestData
dec := json.NewDecoder(categoryTestDataFile)
err = dec.Decode(&categoryTestData)
if err != nil {
t.Errorf("could not decode category test data: %s", err)
return
}
for _, category := range data.Categories {
if category.Name == "Young & Home" {
if category.Available.GetFloat64() != 67.55 {
t.Errorf("available for category Young & Home is wrong")
}
if category.Activity.GetFloat64() != -107.78 {
t.Errorf("available for category Young & Home is wrong")
}
}
fmt.Printf("%s: %f %f\n", category.Name, category.Activity.GetFloat64(), category.Available.GetFloat64())
}
}
func (h Handler) DoYNABImport(ctx context.Context, t *testing.T, budget *postgres.Budget) {
@ -103,14 +137,14 @@ func (h Handler) DoYNABImport(ctx context.Context, t *testing.T, budget *postgre
return
}
transactions, err := os.Open("../.vscode/Register.tsv")
transactions, err := os.Open("../testdata/production-export/Register.tsv")
if err != nil {
fmt.Println(err)
t.Fail()
return
}
assignments, err := os.Open("../.vscode/Budget.tsv")
assignments, err := os.Open("../testdata/production-export/Budget.tsv")
if err != nil {
fmt.Println(err)
t.Fail()