feat: ground competitive insights in peer metrics
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
package insight
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"git.amiirkhl.ir/starcoach-hackathon/zarinpal-analytics-backend/internal/peercomparison"
|
||||
)
|
||||
|
||||
func TestGeneratedInsightTextMustBeOnePlainParagraph(t *testing.T) {
|
||||
@@ -55,3 +58,32 @@ func TestGeneratedInsightMustNameSelectedAndPrecedingPeriods(t *testing.T) {
|
||||
t.Fatal("generic period wording was accepted")
|
||||
}
|
||||
}
|
||||
|
||||
func TestPeerInsightAllowsOnlyGroundedAggregateNumbers(t *testing.T) {
|
||||
evidence, err := json.Marshal(map[string]any{
|
||||
"peerComparison": peercomparison.Result{
|
||||
State: peercomparison.StateReady,
|
||||
EligiblePeerCount: 10,
|
||||
CombinedPeerSessions: 1000,
|
||||
Metrics: []peercomparison.Metric{{
|
||||
MetricID: "payment_success_rate",
|
||||
CohortMedian: "72.50",
|
||||
MerchantPerformancePercentile: "85.00",
|
||||
Direction: "HIGHER_IS_BETTER",
|
||||
}},
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("marshal evidence: %v", err)
|
||||
}
|
||||
labels := []string{"مرداد ۱۴۰۵"}
|
||||
if containsUnexpectedPeerNumber("در مرداد ۱۴۰۵، جایگاه شما صدک ۸۵٫۰۰ است.", labels, evidence) {
|
||||
t.Fatal("grounded Persian percentile was rejected")
|
||||
}
|
||||
if containsUnexpectedPeerNumber("این مقایسه بر پایه ۱٬۰۰۰ نشست است.", labels, evidence) {
|
||||
t.Fatal("grounded Persian session count was rejected")
|
||||
}
|
||||
if !containsUnexpectedPeerNumber("جایگاه شما صدک ۹۱ است.", labels, evidence) {
|
||||
t.Fatal("invented percentile was accepted")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user