Files
tenant-registry/internal/erpsetup/intake_test.go
T
sharangandClaude Opus 5.5 cee669d2bd
ci / shared (push) Successful in 14s
ci / test (push) Successful in 25m31s
ci / image (push) Successful in 46s
feat(invoiceintake): invoice@ mails become draft Eingangsrechnungen (#82)
Reads the mails of ERPNext's Email Account Eingangsrechnung via the API: e-invoices become E Invoice Import drafts, other PDFs draft Purchase Invoices (supplier by sender, placeholder line, original attached), the rest ToDos. Never submits; state lives in ERPNext (unique Link intake_communication, ToDo reference). erpsetup adds the marker fields, the placeholder item EINGANGSRECHNUNG and its SKR04 6300 account.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 08:15:32 +00:00

52 lines
1.6 KiB
Go

package erpsetup
import (
"context"
"fmt"
"net/http/httptest"
"testing"
)
func TestIntakeSetup(t *testing.T) {
f := newFake()
srv := httptest.NewServer(f)
defer srv.Close()
if _, err := Run(context.Background(), cfg(srv.URL)); err != nil {
t.Fatal(err)
}
for _, name := range []string{"Purchase Invoice-intake_communication", "E Invoice Import-intake_communication"} {
cf := f.docs["Custom Field"][name]
if cf == nil || cf["unique"] != float64(1) || cf["read_only"] != float64(1) || cf["fieldtype"] != "Link" || cf["options"] != "Communication" {
t.Errorf("custom field %s: %v", name, cf)
}
}
item := f.docs["Item"][intakeItem]
if item == nil || item["is_purchase_item"] != float64(1) || item["is_stock_item"] != float64(0) || item["stock_uom"] != intakeUOM {
t.Fatalf("placeholder item: %v", item)
}
rows, _ := item["item_defaults"].([]any)
if len(rows) != 1 || fmt.Sprint(rows[0].(map[string]any)["expense_account"]) != "6300 - Sonstige betriebliche Aufwendungen - BG" {
t.Errorf("placeholder expense account: %v", rows)
}
}
func TestIntakeWithoutExpenseAccountIsReported(t *testing.T) {
f := newFake()
delete(f.docs["Account"], "6300 - Sonstige betriebliche Aufwendungen - BG")
srv := httptest.NewServer(f)
defer srv.Close()
steps, err := Run(context.Background(), cfg(srv.URL))
if err != nil {
t.Fatal(err)
}
for _, s := range steps {
if s.What == "item "+intakeItem+" expense account "+intakeAccountNum {
if s.Result != "missing (not created)" {
t.Errorf("result %q", s.Result)
}
return
}
}
t.Error("no step for the expense account")
}