@@ -46,8 +46,8 @@ func TestEvaluatePromoRulesAtPriorityFirstMatch(t *testing.T) {
|
||||
},
|
||||
}
|
||||
prices := []subscribePromo{
|
||||
{SubscribeId: 100, PromoRuleId: 1, PromoPrice: 599},
|
||||
{SubscribeId: 100, PromoRuleId: 2, PromoPrice: 499},
|
||||
{SubscribeId: 100, Quantity: 1, PromoRuleId: 1, PromoPrice: 599},
|
||||
{SubscribeId: 100, Quantity: 1, PromoRuleId: 2, PromoPrice: 499},
|
||||
}
|
||||
|
||||
got, err := evaluatePromoRulesAt(context.Background(), rules, prices, fakePromoEligibilitySource{
|
||||
@@ -76,11 +76,11 @@ func TestEvaluatePromoRulesAtSkipsUnavailableRules(t *testing.T) {
|
||||
{Id: 5, Type: PromoRuleTypeCampaign, Enabled: true},
|
||||
}
|
||||
prices := []subscribePromo{
|
||||
{SubscribeId: 100, PromoRuleId: 1, PromoPrice: 100},
|
||||
{SubscribeId: 100, PromoRuleId: 2, PromoPrice: 100},
|
||||
{SubscribeId: 100, PromoRuleId: 3, PromoPrice: 100},
|
||||
{SubscribeId: 100, PromoRuleId: 4, PromoPrice: 100},
|
||||
{SubscribeId: 100, PromoRuleId: 5, PromoPrice: 88},
|
||||
{SubscribeId: 100, Quantity: 1, PromoRuleId: 1, PromoPrice: 100},
|
||||
{SubscribeId: 100, Quantity: 1, PromoRuleId: 2, PromoPrice: 100},
|
||||
{SubscribeId: 100, Quantity: 1, PromoRuleId: 3, PromoPrice: 100},
|
||||
{SubscribeId: 100, Quantity: 1, PromoRuleId: 4, PromoPrice: 100},
|
||||
{SubscribeId: 100, Quantity: 1, PromoRuleId: 5, PromoPrice: 88},
|
||||
}
|
||||
|
||||
got, err := evaluatePromoRulesAt(context.Background(), rules, prices, fakePromoEligibilitySource{}, 10, now)
|
||||
@@ -176,3 +176,32 @@ func TestLastSubscribeExpireAtIncludesUnlimitedSubscription(t *testing.T) {
|
||||
t.Fatalf("last subscribe query should prioritize unlimited subscription, sql: %s", stmt.SQL.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestSubscribePromoQueryMatchesQuantity(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 := subscribePromoQuery(db, 100, 3).Find(&[]subscribePromo{}).Statement
|
||||
sql := strings.ToLower(stmt.SQL.String())
|
||||
if !strings.Contains(sql, "subscribe_id = ?") {
|
||||
t.Fatalf("subscribe promo query should filter subscribe_id, sql: %s", stmt.SQL.String())
|
||||
}
|
||||
if !strings.Contains(sql, "quantity = ?") {
|
||||
t.Fatalf("subscribe promo query should filter quantity, sql: %s", stmt.SQL.String())
|
||||
}
|
||||
if got, want := len(stmt.Vars), 2; got != want {
|
||||
t.Fatalf("query vars len = %d, want %d, vars: %#v", got, want, stmt.Vars)
|
||||
}
|
||||
if stmt.Vars[0] != int64(100) || stmt.Vars[1] != int64(3) {
|
||||
t.Fatalf("query vars = %#v, want subscribe_id=100 quantity=3", stmt.Vars)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user