Files

70 lines
2.3 KiB
Go

package insight
import (
"reflect"
"testing"
)
func TestParseModuleRejectsUnscopedValues(t *testing.T) {
for _, value := range []string{"overview", "payments", "fees", "peers", "transactions", "growth"} {
if _, ok := ParseModule(value); !ok {
t.Fatalf("expected %s to be valid", value)
}
}
for _, value := range []string{"", "transaction-detail", "merchant_2", "OVERVIEW"} {
if _, ok := ParseModule(value); ok {
t.Fatalf("expected %s to be invalid", value)
}
}
}
func TestParseSectionAllowsOnlySupportedModuleSections(t *testing.T) {
for _, value := range []string{"past", "latest-observed", "future-7-days", "future-30-days", "findings", "options"} {
if _, ok := ParseSection(ModulePayments, value); !ok {
t.Fatalf("expected %s to be valid", value)
}
}
if _, ok := ParseSection(ModuleGrowth, "future-90-days"); !ok {
t.Fatal("growth must support future-90-days")
}
for _, value := range []string{"", "future-90-days", "all", "PAST"} {
if _, ok := ParseSection(ModulePayments, value); ok {
t.Fatalf("expected %s to be invalid for payments", value)
}
}
}
func TestMergeSectionPreservesUnselectedCopy(t *testing.T) {
base := Copy{
Past: Narrative{Body: "old past"}, LatestObserved: Narrative{Body: "old latest"},
Future7Days: Narrative{Body: "old seven"}, Future30Days: Narrative{Body: "old thirty"},
}
generated := base
generated.Future7Days.Body = "new seven"
merged, err := MergeSection(base, generated, SectionFuture7Days)
if err != nil {
t.Fatal(err)
}
if merged.Future7Days.Body != "new seven" || merged.Past.Body != "old past" || merged.Future30Days.Body != "old thirty" {
t.Fatalf("unexpected merged copy: %+v", merged)
}
}
func TestStaleAlwaysCapsConfidence(t *testing.T) {
if got := confidenceFor(FreshnessStale); got != ConfidenceLow {
t.Fatalf("got %s", got)
}
}
func TestPageInsightSchemaRestrictsEvidenceReferences(t *testing.T) {
allowed := []string{"ev_success_rate", "ev_volume"}
schema := pageInsightSchema(allowed, allowed)
properties := schema["properties"].(map[string]any)
findings := properties["findings"].(map[string]any)
findingProperties := findings["items"].(map[string]any)["properties"].(map[string]any)
if got := findingProperties["evidenceId"].(map[string]any)["enum"]; !reflect.DeepEqual(got, allowed) {
t.Fatalf("evidence enum = %#v, want %#v", got, allowed)
}
}