test(用户): 补齐创建用户与注册单测

覆盖管理员创建用户与注册流程的关键失败分支\n完善创建成功路径的断言
This commit is contained in:
yangjianbo
2025-12-29 15:22:50 +08:00
parent f6de36cb04
commit 305eaabb53
3 changed files with 268 additions and 2 deletions

View File

@@ -15,12 +15,24 @@ import (
type userRepoStub struct {
user *User
getErr error
createErr error
deleteErr error
exists bool
existsErr error
nextID int64
created []*User
deletedIDs []int64
}
func (s *userRepoStub) Create(ctx context.Context, user *User) error {
panic("unexpected Create call")
if s.createErr != nil {
return s.createErr
}
if s.nextID != 0 && user.ID == 0 {
user.ID = s.nextID
}
s.created = append(s.created, user)
return nil
}
func (s *userRepoStub) GetByID(ctx context.Context, id int64) (*User, error) {
@@ -71,7 +83,10 @@ func (s *userRepoStub) UpdateConcurrency(ctx context.Context, id int64, amount i
}
func (s *userRepoStub) ExistsByEmail(ctx context.Context, email string) (bool, error) {
panic("unexpected ExistsByEmail call")
if s.existsErr != nil {
return false, s.existsErr
}
return s.exists, nil
}
func (s *userRepoStub) RemoveGroupFromAllowedGroups(ctx context.Context, groupID int64) (int64, error) {