Files
sultan/pkg/accountant/customers_test.go
T

61 lines
2.0 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package accountant
import (
"encoding/json"
"path/filepath"
"testing"
"sultan/pkg/ledger"
)
// Ein Bericht legt für neue Mandanten automatisch Kunden an.
func TestReport_CreatesCustomers(t *testing.T) {
a := start(t, "")
key := enrolledPayee(t, a, "webproxy11")
body, _ := json.Marshal(whereReport("webdocker11", route("kunde", "webdocker11", "wp", "kunde.de")))
postReport(t, a, key, body)
l, _ := ledger.Open(ctx, filepath.Join(a.DataDir(), "accountant.db"))
defer l.Close()
for _, id := range []string{"kunde", "andere"} {
if c, err := l.GetCustomer(ctx, id); err != nil || !c.Auto || c.Cycle != ledger.CycleUnclassified {
t.Errorf("Kunde %s: %+v, %v", id, c, err)
}
}
if c, _ := l.GetCustomer(ctx, "kunde"); c.Name != "Kunde A" {
t.Errorf("Name aus dem Mandanten: %q", c.Name)
}
}
// where zeigt den Kunden – auch über eine Zuordnung.
func TestWhere_Customer(t *testing.T) {
l, _ := whereLedger(t)
l.AddCustomer(ctx, ledger.Customer{ID: "k-1001", Name: "Kunde A GmbH", Group: "extern"})
l.MapTenant(ctx, "", "kunde", "k-1001")
save(t, l, "webproxy11", whereReport("webdocker11", route("kunde", "webdocker11", "wp", "kunde.de")))
res, err := Where(ctx, l, "kunde.de")
if err != nil || len(res.Current) != 1 {
t.Fatalf("%+v, %v", res, err)
}
if c := res.Current[0].Customer; c == nil || c.ID != "k-1001" || c.Group != "extern" {
t.Errorf("Kunde: %+v", c)
}
}
func TestMoney(t *testing.T) {
for in, want := range map[string]int64{"89": 8900, "89,00": 8900, "89.5": 8950, "1.234,56": 123456, "0,99": 99, " 12,30 ": 1230} {
if got, err := ParseMoney(in); err != nil || got != want {
t.Errorf("ParseMoney(%q) = %d, %v; erwartet %d", in, got, err, want)
}
}
for _, bad := range []string{"", "abc", "1,234", "-5", "1,2,3"} {
if _, err := ParseMoney(bad); err == nil {
t.Errorf("ParseMoney(%q) ohne Fehler", bad)
}
}
for in, want := range map[int64]string{8900: "89,00", 99: "0,99", 123456: "1234,56", 0: "0,00"} {
if got := FormatMoney(in); got != want {
t.Errorf("FormatMoney(%d) = %q, erwartet %q", in, got, want)
}
}
}