Remove unused prop

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

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()