fix: stabilize backend tests

This commit is contained in:
2026-01-08 14:07:58 +08:00
parent 7f1d2e7cb3
commit edbb62449b
18 changed files with 281 additions and 147 deletions

View File

@@ -44,7 +44,7 @@ func (s *UserTestSuite) Test_LoginWithOTP() {
Convey("should create user and login success with correct OTP", func() {
phone := "13800138000"
resp, err := User.LoginWithOTP(ctx, phone, "123456")
resp, err := User.LoginWithOTP(ctx, phone, "1234")
So(err, ShouldBeNil)
So(resp, ShouldNotBeNil)
So(resp.Token, ShouldNotBeEmpty)
@@ -55,11 +55,11 @@ func (s *UserTestSuite) Test_LoginWithOTP() {
Convey("should login existing user", func() {
phone := "13800138001"
// Pre-create user
_, err := User.LoginWithOTP(ctx, phone, "123456")
_, err := User.LoginWithOTP(ctx, phone, "1234")
So(err, ShouldBeNil)
// Login again
resp, err := User.LoginWithOTP(ctx, phone, "123456")
resp, err := User.LoginWithOTP(ctx, phone, "1234")
So(err, ShouldBeNil)
So(resp.User.Phone, ShouldEqual, phone)
})
@@ -79,7 +79,7 @@ func (s *UserTestSuite) Test_Me() {
// Create user
phone := "13800138003"
resp, _ := User.LoginWithOTP(ctx, phone, "123456")
resp, _ := User.LoginWithOTP(ctx, phone, "1234")
userID := resp.User.ID
Convey("should return user profile", func() {
@@ -107,7 +107,7 @@ func (s *UserTestSuite) Test_Update() {
database.Truncate(ctx, s.DB, models.TableNameUser)
phone := "13800138004"
resp, _ := User.LoginWithOTP(ctx, phone, "123456")
resp, _ := User.LoginWithOTP(ctx, phone, "1234")
userID := resp.User.ID
ctx = context.WithValue(ctx, consts.CtxKeyUser, userID)
@@ -135,7 +135,7 @@ func (s *UserTestSuite) Test_RealName() {
database.Truncate(ctx, s.DB, models.TableNameUser)
phone := "13800138005"
resp, _ := User.LoginWithOTP(ctx, phone, "123456")
resp, _ := User.LoginWithOTP(ctx, phone, "1234")
userID := resp.User.ID
ctx = context.WithValue(ctx, consts.CtxKeyUser, userID)
@@ -160,7 +160,7 @@ func (s *UserTestSuite) Test_GetNotifications() {
database.Truncate(ctx, s.DB, models.TableNameUser, models.TableNameNotification)
phone := "13800138006"
resp, _ := User.LoginWithOTP(ctx, phone, "123456")
resp, _ := User.LoginWithOTP(ctx, phone, "1234")
userID := resp.User.ID
ctx = context.WithValue(ctx, consts.CtxKeyUser, userID)