Remove unused prop
This commit is contained in:
parent
4332a1537b
commit
5f6bea4ee2
@ -25,19 +25,17 @@ func getFirstOfMonthTime(date time.Time) time.Time {
|
|||||||
|
|
||||||
type CategoryWithBalance struct {
|
type CategoryWithBalance struct {
|
||||||
*postgres.GetCategoriesRow
|
*postgres.GetCategoriesRow
|
||||||
Available numeric.Numeric
|
Available numeric.Numeric
|
||||||
AvailableLastMonth numeric.Numeric
|
Activity numeric.Numeric
|
||||||
Activity numeric.Numeric
|
Assigned numeric.Numeric
|
||||||
Assigned numeric.Numeric
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewCategoryWithBalance(category *postgres.GetCategoriesRow) CategoryWithBalance {
|
func NewCategoryWithBalance(category *postgres.GetCategoriesRow) CategoryWithBalance {
|
||||||
return CategoryWithBalance{
|
return CategoryWithBalance{
|
||||||
GetCategoriesRow: category,
|
GetCategoriesRow: category,
|
||||||
Available: numeric.Zero(),
|
Available: numeric.Zero(),
|
||||||
AvailableLastMonth: numeric.Zero(),
|
Activity: numeric.Zero(),
|
||||||
Activity: numeric.Zero(),
|
Assigned: numeric.Zero(),
|
||||||
Assigned: numeric.Zero(),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,7 +89,6 @@ func (h *Handler) prepareBudgeting(ctx context.Context, budget postgres.Budget,
|
|||||||
}
|
}
|
||||||
|
|
||||||
cat.Available = availableBalance
|
cat.Available = availableBalance
|
||||||
cat.AvailableLastMonth = availableBalance
|
|
||||||
}
|
}
|
||||||
|
|
||||||
data := BudgetingForMonthResponse{categoriesWithBalance, availableBalance}
|
data := BudgetingForMonthResponse{categoriesWithBalance, availableBalance}
|
||||||
@ -201,9 +198,7 @@ func (*Handler) CalculateCategoryBalances(cat *postgres.GetCategoriesRow,
|
|||||||
categoryWithBalance.Available = numeric.Zero()
|
categoryWithBalance.Available = numeric.Zero()
|
||||||
}
|
}
|
||||||
|
|
||||||
if bal.Date.Before(firstOfMonth) {
|
if bal.Date.Before(firstOfNextMonth) {
|
||||||
categoryWithBalance.AvailableLastMonth = categoryWithBalance.Available
|
|
||||||
} else if bal.Date.Before(firstOfNextMonth) {
|
|
||||||
categoryWithBalance.Activity = bal.Transactions
|
categoryWithBalance.Activity = bal.Transactions
|
||||||
categoryWithBalance.Assigned = bal.Assignments
|
categoryWithBalance.Assigned = bal.Assignments
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package server
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"log"
|
"log"
|
||||||
@ -69,15 +70,22 @@ func TestMain(t *testing.T) {
|
|||||||
|
|
||||||
handler.DoYNABImport(ctx, t, budget)
|
handler.DoYNABImport(ctx, t, budget)
|
||||||
|
|
||||||
|
// check available balance for more dates
|
||||||
handler.CheckAvailableBalance(ctx, t, budget)
|
handler.CheckAvailableBalance(ctx, t, budget)
|
||||||
// check available balance
|
|
||||||
|
|
||||||
// check categories
|
// check categories
|
||||||
|
|
||||||
// check accounts
|
// check accounts
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type CategoryTestData struct {
|
||||||
|
Available float64
|
||||||
|
Activity float64
|
||||||
|
Assigned float64
|
||||||
|
}
|
||||||
|
|
||||||
func (h Handler) CheckAvailableBalance(ctx context.Context, t *testing.T, budget *postgres.Budget) {
|
func (h Handler) CheckAvailableBalance(ctx context.Context, t *testing.T, budget *postgres.Budget) {
|
||||||
|
t.Helper()
|
||||||
loc := time.Now().Location()
|
loc := time.Now().Location()
|
||||||
first := time.Date(2022, 1, 1, 0, 0, 0, 0, loc)
|
first := time.Date(2022, 1, 1, 0, 0, 0, 0, loc)
|
||||||
firstOfNextMonth := time.Date(2022, 2, 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")
|
t.Errorf("available balance is wrong")
|
||||||
return
|
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) {
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
transactions, err := os.Open("../.vscode/Register.tsv")
|
transactions, err := os.Open("../testdata/production-export/Register.tsv")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
t.Fail()
|
t.Fail()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
assignments, err := os.Open("../.vscode/Budget.tsv")
|
assignments, err := os.Open("../testdata/production-export/Budget.tsv")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
t.Fail()
|
t.Fail()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user