86 lines
3.0 KiB
Go
86 lines
3.0 KiB
Go
package insight
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"git.amiirkhl.ir/starcoach-hackathon/zarinpal-analytics-backend/internal/peercomparison"
|
|
)
|
|
|
|
func TestDeterministicTransactionCopyDistinguishesPaymentStatesWithoutCausalClaims(t *testing.T) {
|
|
copy := deterministicTransactionCopy(
|
|
PeriodScope{JalaliLabelFA: "مرداد ۱۴۰۵"},
|
|
"تیر ۱۴۰۵",
|
|
aggregate{Sessions: 10, Paid: 7, Verified: 5, Unverified: 2, Failed: 2, Reversed: 1},
|
|
aggregate{Sessions: 8, Paid: 6},
|
|
true,
|
|
TimeContext{},
|
|
ConfidenceHigh,
|
|
)
|
|
|
|
body := copy.LatestObserved.Body
|
|
for _, expected := range []string{"پرداختشده و در انتظار تأیید", "تأیید نهایی", "ناموفق"} {
|
|
if !strings.Contains(body, expected) {
|
|
t.Fatalf("expected transaction copy to contain %q: %s", expected, body)
|
|
}
|
|
}
|
|
if !strings.Contains(copy.Past.Body, "علت آن را مشخص نمیکند") {
|
|
t.Fatalf("expected non-causal comparison language: %s", copy.Past.Body)
|
|
}
|
|
}
|
|
|
|
func TestDeterministicPeerCopyNamesStrongestWeakestAndAction(t *testing.T) {
|
|
result := peercomparison.Result{State: peercomparison.StateReady, Metrics: []peercomparison.Metric{
|
|
{MetricID: "payment_success_rate", MerchantPerformancePercentile: "85.00"},
|
|
{MetricID: "verification_completion_rate", MerchantPerformancePercentile: "40.00"},
|
|
}}
|
|
copy := deterministicPeerCopy(&result, "مرداد ۱۴۰۵")
|
|
for _, expected := range []string{"مرداد ۱۴۰۵", "موفقیت پرداخت", "صدک 85.00", "تکمیل تأیید", "صدک 40.00"} {
|
|
if !strings.Contains(copy.LatestObserved.Body, expected) {
|
|
t.Fatalf("peer summary missing %q: %s", expected, copy.LatestObserved.Body)
|
|
}
|
|
}
|
|
if !strings.Contains(copy.Options[0].Description, "تکمیل تأیید") {
|
|
t.Fatalf("peer action did not target weakest category: %+v", copy.Options)
|
|
}
|
|
}
|
|
|
|
func TestDeterministicTransactionCopyHandlesEmptyPeriod(t *testing.T) {
|
|
copy := deterministicTransactionCopy(
|
|
PeriodScope{JalaliLabelFA: "امروز"},
|
|
"دیروز",
|
|
aggregate{},
|
|
aggregate{},
|
|
false,
|
|
TimeContext{},
|
|
ConfidenceInsufficientData,
|
|
)
|
|
|
|
if strings.Contains(copy.LatestObserved.Body, "<nil>") {
|
|
t.Fatalf("empty-period copy exposed an implementation value: %s", copy.LatestObserved.Body)
|
|
}
|
|
if !strings.Contains(copy.LatestObserved.Body, "ناموجود") {
|
|
t.Fatalf("expected unavailable rates in empty-period copy: %s", copy.LatestObserved.Body)
|
|
}
|
|
}
|
|
|
|
func TestDeterministicPeriodCopyUsesSelectedPeriodForOverview(t *testing.T) {
|
|
copy := deterministicPeriodCopy(
|
|
ModuleOverview,
|
|
PeriodScope{JalaliLabelFA: "مرداد ۱۴۰۵"},
|
|
"تیر ۱۴۰۵",
|
|
aggregate{Sessions: 10, Paid: 7},
|
|
aggregate{Sessions: 8, Paid: 6},
|
|
true,
|
|
TimeContext{},
|
|
ConfidenceHigh,
|
|
)
|
|
|
|
if !strings.Contains(copy.LatestObserved.Body, "مرداد ۱۴۰۵") {
|
|
t.Fatalf("selected period missing from summary: %s", copy.LatestObserved.Body)
|
|
}
|
|
if !strings.Contains(copy.Past.Body, "تیر ۱۴۰۵") {
|
|
t.Fatalf("exact preceding period missing from comparison: %s", copy.Past.Body)
|
|
}
|
|
}
|