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") }