package report import ( "encoding/json" "testing" "time" "github.com/yuxingu/digital-psychology/apps/api/internal/rhythm" "github.com/yuxingu/digital-psychology/apps/api/internal/star" ) func TestDayKeyCST(t *testing.T) { // 2026-08-12 23:30 UTC = 2026-08-13 07:30 CST utc := time.Date(2026, 8, 12, 23, 30, 0, 0, time.UTC) if got := dayKey(utc); got != "2026-08-13" { t.Fatalf("dayKey=%s", got) } } func TestStarOutlookChangesByDay(t *testing.T) { birth := time.Date(1990, 5, 15, 0, 0, 0, 0, time.UTC) d1 := time.Date(2026, 8, 12, 10, 0, 0, 0, cstLoc()) d2 := time.Date(2026, 8, 13, 10, 0, 0, 0, cstLoc()) a, err := star.BuildWith(star.BuildOpts{Birth: birth, Name: "测", AsOf: d1}) if err != nil { t.Fatal(err) } b, err := star.BuildWith(star.BuildOpts{Birth: birth, Name: "测", AsOf: d2}) if err != nil { t.Fatal(err) } if a.Summary["as_of"] != "2026-08-12" || b.Summary["as_of"] != "2026-08-13" { t.Fatalf("as_of a=%v b=%v", a.Summary["as_of"], b.Summary["as_of"]) } oa, _ := a.Summary["outlook"].(map[string]any) ob, _ := b.Summary["outlook"].(map[string]any) da, _ := oa["daily"].(map[string]any) db, _ := ob["daily"].(map[string]any) if da["score"] == db["score"] && da["tip"] == db["tip"] { t.Fatalf("expected daily outlook to differ across days") } if a.Summary["valid_until"] == nil || b.Summary["valid_until"] == nil { t.Fatal("missing valid_until") } } func TestRhythmTipsChangeByDay(t *testing.T) { birth := time.Date(1992, 6, 8, 0, 0, 0, 0, time.UTC) d1 := time.Date(2026, 8, 10, 12, 0, 0, 0, cstLoc()) // Mon d2 := time.Date(2026, 8, 11, 12, 0, 0, 0, cstLoc()) // Tue a := rhythm.BuildWith(birth, "测", d1) b := rhythm.BuildWith(birth, "测", d2) if a.Summary["as_of"] != "2026-08-10" || b.Summary["as_of"] != "2026-08-11" { t.Fatalf("as_of a=%v b=%v", a.Summary["as_of"], b.Summary["as_of"]) } if a.Summary["week_focus"] == b.Summary["week_focus"] && a.Summary["today_tip"] == b.Summary["today_tip"] { t.Fatalf("expected tips to differ") } } func TestSummaryDay(t *testing.T) { raw, _ := json.Marshal(map[string]any{"as_of": "2026-08-12"}) if summaryDay(raw) != "2026-08-12" { t.Fatal(summaryDay(raw)) } if summaryDay(json.RawMessage(`{}`)) != "" { t.Fatal("empty") } }