package user import ( "testing" "yunyan/comm" "yunyan/pb" ) // 开户礼 = VIP 天数 + 算力,两个数额由后台配置(comm.OpsParams)。 func TestApplyNewUserGift(t *testing.T) { const now int64 = 1_700_000_000 p := comm.DefaultOpsParams() u := &pb.DBUser{} applyNewUserGift(u, now, p) if got, want := u.Vipexptime, now+int64(p.NewUserGiftVipDays)*24*60*60; got != want { t.Errorf("Vipexptime = %d, want %d(%d 天)", got, want, p.NewUserGiftVipDays) } if got, want := u.Computebalance, p.NewUserGiftCompute; got != want { t.Errorf("Computebalance = %d, want %d", got, want) } // 旧三桶必须保持 0:它们已不是闸门,往里写值只会让老后台页面显示出「有余额」的假象 if u.Tradeintegral != 0 || u.Meetintegral != 0 || u.Aichatintegral != 0 { t.Errorf("旧额度桶不应再发放: Trade=%d Meet=%d Ai=%d", u.Tradeintegral, u.Meetintegral, u.Aichatintegral) } } // 后台把两项都配成 0 = 注册不送任何东西。这是合法配置,不能被当成「没配」而回落到默认值。 func TestApplyNewUserGiftZeroMeansNoGift(t *testing.T) { const now int64 = 1_700_000_000 u := &pb.DBUser{} applyNewUserGift(u, now, comm.OpsParams{NewUserGiftVipDays: 0, NewUserGiftCompute: 0}) if u.Vipexptime != 0 || u.Computebalance != 0 { t.Errorf("配 0 应该什么都不送,得到 Vip=%d Compute=%d", u.Vipexptime, u.Computebalance) } } // 只送算力、不送 VIP 也是合法配置。 func TestApplyNewUserGiftComputeOnly(t *testing.T) { const now int64 = 1_700_000_000 u := &pb.DBUser{} applyNewUserGift(u, now, comm.OpsParams{NewUserGiftVipDays: 0, NewUserGiftCompute: 500}) if u.Vipexptime != 0 { t.Errorf("VIP 天数为 0 时不该设到期时间,得到 %d", u.Vipexptime) } if u.Computebalance != 500 { t.Errorf("Computebalance = %d, want 500", u.Computebalance) } } // 老用户不该被碰:applyNewUserGift 只在「新建用户」分支调用, // 这里顺带守住它是直接赋值而非累加(新对象都是零值,累加与赋值等价; // 万一将来有人挪去老用户路径,这个测试会提醒他先想清楚语义)。 func TestApplyNewUserGiftIsAssignNotAccumulate(t *testing.T) { const now int64 = 1_700_000_000 p := comm.DefaultOpsParams() u := &pb.DBUser{Computebalance: 999, Vipexptime: now + 12345} applyNewUserGift(u, now, p) if u.Computebalance != p.NewUserGiftCompute { t.Errorf("应为赋值语义,得到 Compute=%d", u.Computebalance) } if u.Vipexptime != now+int64(p.NewUserGiftVipDays)*24*60*60 { t.Errorf("VIP 应为赋值语义,得到 %d", u.Vipexptime) } }