fix: keep growth analysis available per terminal

This commit is contained in:
2026-08-21 02:57:46 +03:30
parent 7951664d08
commit e6afaa7a10
11 changed files with 180 additions and 45 deletions

View File

@@ -63,6 +63,26 @@ func TestBuildForecastReturnsOrderedNinetyDayIntegerRanges(t *testing.T) {
}
}
func TestBuildForecastUsesLimitedHistoryWithLowConfidence(t *testing.T) {
start := date("2026-07-01")
history := make([]DailyPoint, 0, 14)
for daysAgo := 14; daysAgo > 0; daysAgo-- {
day := start.AddDate(0, 0, -daysAgo)
value := int64(80 + int(day.Weekday())*5)
history = append(history, DailyPoint{Date: day, SessionCount: value, PaidSessionCount: value, PaidAmountRial: value * 100_000})
}
forecast := BuildForecast(history, nil, start, 90)
if forecast.Confidence != ConfidenceLow || len(forecast.Points) != 90 {
t.Fatalf("limited history should produce a low-confidence forecast: confidence=%s points=%d", forecast.Confidence, len(forecast.Points))
}
for _, point := range forecast.Points {
if point.PaidSessions.P10 > point.PaidSessions.P50 || point.PaidSessions.P50 > point.PaidSessions.P90 {
t.Fatalf("limited-history range is unordered: %+v", point.PaidSessions)
}
}
}
func TestDetectRisksRequiresTwentyPercentDropAndBaselineSize(t *testing.T) {
forecast := Forecast{Confidence: ConfidenceMedium, Points: []ForecastPoint{
{Date: date("2026-07-01"), BaselineSessions: 200, PaidSessions: Range{P50: 150}, BaselineAmountRial: 10_000_000, PaidAmountRial: Range{P50: 7_000_000}},