package user import ( "testing" "yunyan/pb" ) // 守住单位口径:翻译/会议是**秒**,智能体是**次**。 // 三个桶不同构,照抄隔壁桶的写法就会送错量级(比如给 AI 送 6000 次)。 func TestApplyNewUserGift(t *testing.T) { const now int64 = 1_700_000_000 u := &pb.DBUser{} applyNewUserGift(u, now) if got, want := u.Vipexptime, now+30*24*60*60; got != want { t.Errorf("Vipexptime = %d, want %d(30 天)", got, want) } if got, want := u.Tradeintegral, int64(6000); got != want { t.Errorf("Tradeintegral = %d, want %d(100 分钟 = 6000 秒)", got, want) } if got, want := u.Meetintegral, int64(6000); got != want { t.Errorf("Meetintegral = %d, want %d(100 分钟 = 6000 秒)", got, want) } if got, want := u.Aichatintegral, int64(100); got != want { t.Errorf("Aichatintegral = %d, want %d(100 **次**,不是秒)", got, want) } // total 系列是「累计获得」,前端拿它算进度条,必须同步给上 if u.Tradetotalintegral != u.Tradeintegral || u.Meettotalintegral != u.Meetintegral || u.Aichattotalintegral != u.Aichatintegral { t.Error("total 系列未与余额同步,前端进度条会算错") } } // 老用户不该被碰:applyNewUserGift 只在「新建用户」分支调用, // 这里顺带守住它是直接赋值而非累加(新对象都是零值,累加与赋值等价; // 万一将来有人挪去老用户路径,这个测试会提醒他先想清楚语义)。 func TestApplyNewUserGiftIsAssignNotAccumulate(t *testing.T) { const now int64 = 1_700_000_000 u := &pb.DBUser{Tradeintegral: 999, Aichatintegral: 7, Vipexptime: now + 12345} applyNewUserGift(u, now) if u.Tradeintegral != 6000 || u.Aichatintegral != 100 { t.Errorf("应为赋值语义,得到 Trade=%d Ai=%d", u.Tradeintegral, u.Aichatintegral) } if u.Vipexptime != now+30*24*60*60 { t.Errorf("VIP 应为赋值语义,得到 %d", u.Vipexptime) } }