feat: grant badges from manager props send
This commit is contained in:
parent
c1a0049b1d
commit
31811d5cf4
@ -178,6 +178,19 @@ func (s *Service) SendProps(ctx context.Context, user AuthUser, req SendPropsReq
|
||||
}
|
||||
|
||||
days := propsGiftDays(prop.Type)
|
||||
if prop.Type == propsTypeBadge {
|
||||
if err := s.java.ActivateTemporaryBadge(ctx, req.AcceptUserID.Int64(), prop.ID, days); err != nil {
|
||||
return nil, serverError("send_badge_failed", err.Error())
|
||||
}
|
||||
return &SendPropsResponse{
|
||||
Success: true,
|
||||
AcceptUserID: req.AcceptUserID,
|
||||
PropsID: req.PropsID,
|
||||
Type: prop.Type,
|
||||
Days: days,
|
||||
}, nil
|
||||
}
|
||||
|
||||
grants := []propsGrant{{
|
||||
propsID: prop.ID,
|
||||
typ: prop.Type,
|
||||
|
||||
@ -15,16 +15,22 @@ import (
|
||||
)
|
||||
|
||||
type fakeManagerGateway struct {
|
||||
recharges map[int64][]integration.UserTotalRecharge
|
||||
rechargeErr error
|
||||
abilities map[int64]integration.PropsNobleVIPAbility
|
||||
maxAbility integration.PropsNobleVIPAbility
|
||||
giveRequests []integration.GivePropsBackpackRequest
|
||||
punishRequests []integration.PunishAccountRequest
|
||||
unblockRequests []integration.UnblockAccountRequest
|
||||
switchIDs []int64
|
||||
cacheCleared []int64
|
||||
badgeIDs []int64
|
||||
recharges map[int64][]integration.UserTotalRecharge
|
||||
rechargeErr error
|
||||
abilities map[int64]integration.PropsNobleVIPAbility
|
||||
maxAbility integration.PropsNobleVIPAbility
|
||||
giveRequests []integration.GivePropsBackpackRequest
|
||||
punishRequests []integration.PunishAccountRequest
|
||||
unblockRequests []integration.UnblockAccountRequest
|
||||
switchIDs []int64
|
||||
cacheCleared []int64
|
||||
badgeActivations []fakeBadgeActivation
|
||||
}
|
||||
|
||||
type fakeBadgeActivation struct {
|
||||
userID int64
|
||||
badgeID int64
|
||||
days int
|
||||
}
|
||||
|
||||
func (f *fakeManagerGateway) GetUserProfile(context.Context, int64) (integration.UserProfile, error) {
|
||||
@ -64,8 +70,8 @@ func (f *fakeManagerGateway) SwitchUseProps(_ context.Context, _ int64, propsID
|
||||
return nil
|
||||
}
|
||||
|
||||
func (f *fakeManagerGateway) ActivateTemporaryBadge(_ context.Context, _ int64, badgeID int64, _ int) error {
|
||||
f.badgeIDs = append(f.badgeIDs, badgeID)
|
||||
func (f *fakeManagerGateway) ActivateTemporaryBadge(_ context.Context, userID int64, badgeID int64, days int) error {
|
||||
f.badgeActivations = append(f.badgeActivations, fakeBadgeActivation{userID: userID, badgeID: badgeID, days: days})
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -220,6 +226,34 @@ func TestSendNobleVIPGivesAccessoriesAndSwitchesMax(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestSendBadgeActivatesBadgeBackpack(t *testing.T) {
|
||||
service, fake := newManagerCenterTestService(t)
|
||||
db := service.db.(*gorm.DB)
|
||||
seedManager(t, db, 1)
|
||||
seedUsers(t, db, userBaseInfoRow{ID: 2, Account: "2"})
|
||||
seedProps(t, db, propsSourceRecordRow{ID: 501, Type: propsTypeBadge, Name: "Activity badge", AdminFree: true})
|
||||
|
||||
resp, err := service.SendProps(context.Background(), AuthUser{UserID: 1}, SendPropsRequest{
|
||||
AcceptUserID: ID(2),
|
||||
PropsID: ID(501),
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("SendProps() error = %v", err)
|
||||
}
|
||||
if !resp.Success || resp.Type != propsTypeBadge || resp.Days != defaultGiftDays {
|
||||
t.Fatalf("resp = %+v, want badge success with default days", resp)
|
||||
}
|
||||
if len(fake.badgeActivations) != 1 {
|
||||
t.Fatalf("badge activations = %+v, want one", fake.badgeActivations)
|
||||
}
|
||||
if got := fake.badgeActivations[0]; got.userID != 2 || got.badgeID != 501 || got.days != defaultGiftDays {
|
||||
t.Fatalf("badge activation = %+v, want user 2 badge 501 days %d", got, defaultGiftDays)
|
||||
}
|
||||
if len(fake.giveRequests) != 0 {
|
||||
t.Fatalf("give requests = %+v, want no props backpack grant", fake.giveRequests)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSendVIPUsesVIPLevelConfig(t *testing.T) {
|
||||
service, _ := newManagerCenterTestService(t)
|
||||
db := service.db.(*gorm.DB)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user