package wheel import ( "context" "testing" "chatapp3-golang/internal/integration" "chatapp3-golang/internal/model" ) type fakeWheelGateway struct { giftCalls []fakeGiftBackpackCall propsCalls []integration.GivePropsBackpackRequest switches int } type fakeGiftBackpackCall struct { userID int64 giftID int64 quantity int } func (g *fakeWheelGateway) ChangeGoldBalance(context.Context, integration.GoldReceiptCommand) error { return nil } func (g *fakeWheelGateway) GivePropsBackpack(_ context.Context, req integration.GivePropsBackpackRequest) error { g.propsCalls = append(g.propsCalls, req) return nil } func (g *fakeWheelGateway) IncrGiftBackpack(_ context.Context, userID int64, giftID int64, quantity int) error { g.giftCalls = append(g.giftCalls, fakeGiftBackpackCall{ userID: userID, giftID: giftID, quantity: quantity, }) return nil } func (g *fakeWheelGateway) SwitchUseProps(context.Context, int64, int64) error { g.switches++ return nil } func (g *fakeWheelGateway) ActivateTemporaryBadge(context.Context, int64, int64, int) error { return nil } func (g *fakeWheelGateway) RemoveUserProfileCacheAll(context.Context, int64) error { return nil } func (g *fakeWheelGateway) MapGoldBalance(context.Context, []int64) (map[int64]int64, error) { return map[int64]int64{}, nil } func (g *fakeWheelGateway) GetRoomProfileByUserID(context.Context, int64) (integration.RoomProfile, error) { return integration.RoomProfile{}, nil } func TestGrantResourceRewardRoutesGiftToGiftBackpack(t *testing.T) { gateway := &fakeWheelGateway{} service := &Service{java: gateway} giftID := int64(2044086730826510337) if err := service.grantResourceReward(context.Background(), &model.WheelDrawRecord{ UserID: 2042274349343506434, ResourceID: &giftID, ResourceType: resourceTypeGift, DurationDays: 7, }); err != nil { t.Fatalf("grantResourceReward() error = %v", err) } if len(gateway.giftCalls) != 1 { t.Fatalf("gift backpack calls = %d, want 1", len(gateway.giftCalls)) } if got := gateway.giftCalls[0]; got.userID != 2042274349343506434 || got.giftID != giftID || got.quantity != 1 { t.Fatalf("gift backpack call = %+v", got) } if len(gateway.propsCalls) != 0 { t.Fatalf("props backpack calls = %d, want 0", len(gateway.propsCalls)) } if gateway.switches != 0 { t.Fatalf("switch use props calls = %d, want 0", gateway.switches) } }