修复(#81): 修复永久订阅回归促销误判
Co-authored-by: multica-agent <github@multica.ai>
This commit is contained in:
@@ -2,8 +2,13 @@ package common
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"gorm.io/driver/mysql"
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/logger"
|
||||
)
|
||||
|
||||
type fakePromoEligibilitySource struct {
|
||||
@@ -148,3 +153,26 @@ func TestEvaluatePromoInactiveUser(t *testing.T) {
|
||||
t.Fatal("inactive promo should require positive inactive_months")
|
||||
}
|
||||
}
|
||||
|
||||
func TestLastSubscribeExpireAtIncludesUnlimitedSubscription(t *testing.T) {
|
||||
db, err := gorm.Open(mysql.New(mysql.Config{
|
||||
DSN: "gorm:password@tcp(localhost:9910)/gorm?charset=utf8&parseTime=True&loc=Local",
|
||||
SkipInitializeWithVersion: true,
|
||||
}), &gorm.Config{
|
||||
DryRun: true,
|
||||
DisableAutomaticPing: true,
|
||||
Logger: logger.Default.LogMode(logger.Silent),
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("open gorm db: %v", err)
|
||||
}
|
||||
|
||||
stmt := lastSubscribeExpireQuery(db, 10).Take(nil).Statement
|
||||
sql := strings.ToLower(stmt.SQL.String())
|
||||
if strings.Contains(sql, "expire_time <>") || strings.Contains(sql, "expire_time !=") {
|
||||
t.Fatalf("last subscribe query should include unlimited subscription, sql: %s", stmt.SQL.String())
|
||||
}
|
||||
if !strings.Contains(sql, "case when expire_time = ? then 0 else 1 end asc") {
|
||||
t.Fatalf("last subscribe query should prioritize unlimited subscription, sql: %s", stmt.SQL.String())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user