fix(activity): skip zero heat gift growth events
This commit is contained in:
parent
bea9dcf1dd
commit
0039c7f2ee
@ -260,9 +260,13 @@ func (s *Service) HandleRoomEvent(ctx context.Context, envelope *roomeventsv1.Ev
|
||||
if gift.GetIsRobotGift() {
|
||||
return 0, nil
|
||||
}
|
||||
if gift.GetSenderUserId() <= 0 || gift.GetTargetUserId() <= 0 || gift.GetGiftValue() <= 0 {
|
||||
if gift.GetSenderUserId() <= 0 || gift.GetTargetUserId() <= 0 || gift.GetGiftValue() < 0 {
|
||||
return 0, xerr.New(xerr.InvalidArgument, "room gift event is incomplete")
|
||||
}
|
||||
if gift.GetGiftValue() == 0 {
|
||||
// 低价幸运礼物按房间贡献比例折算后可能为 0;这是合法结算结果,增长服务只确认事件并跳过等级增量。
|
||||
return 0, nil
|
||||
}
|
||||
dimensions, err := roomGiftDimensions(envelope, &gift)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
|
||||
@ -138,6 +138,40 @@ func TestGrowthRoomGiftEventFeedsWealthAndCharm(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestGrowthRoomGiftEventSkipsZeroGiftValue(t *testing.T) {
|
||||
svc, _ := newGrowthService(t)
|
||||
ctx := appcode.WithContext(context.Background(), "lalu")
|
||||
|
||||
body, err := proto.Marshal(&activityevents.RoomGiftSent{
|
||||
SenderUserId: 20001,
|
||||
TargetUserId: 20002,
|
||||
GiftId: "gift-zero-heat",
|
||||
GiftCount: 1,
|
||||
GiftValue: 0,
|
||||
BillingReceiptId: "bill-zero-heat",
|
||||
VisibleRegionId: 86,
|
||||
CommandId: "cmd-gift-zero-heat",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("marshal zero heat room gift failed: %v", err)
|
||||
}
|
||||
consumed, err := svc.HandleRoomEvent(ctx, &activityevents.EventEnvelope{
|
||||
EventId: "room-gift-event-zero-heat",
|
||||
RoomId: "room-1",
|
||||
EventType: "RoomGiftSent",
|
||||
RoomVersion: 8,
|
||||
OccurredAtMs: fixedGrowthNow().UnixMilli(),
|
||||
Body: body,
|
||||
AppCode: "lalu",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("zero heat RoomGiftSent should be accepted and skipped: %v", err)
|
||||
}
|
||||
if consumed != 0 {
|
||||
t.Fatalf("zero heat RoomGiftSent should not create growth events, consumed=%d", consumed)
|
||||
}
|
||||
}
|
||||
|
||||
func TestListLevelConfigReturnsAdminRulesAndTiers(t *testing.T) {
|
||||
svc, _ := newGrowthService(t)
|
||||
ctx := appcode.WithContext(context.Background(), "lalu")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user