Refactor employee management
This commit is contained in:
@@ -53,7 +53,7 @@ func TestAuthService_ValidateUser_Success(t *testing.T) {
|
||||
Password: string(password),
|
||||
Name: "测试用户",
|
||||
Email: "test@example.com",
|
||||
Role: "user",
|
||||
Role: "technician",
|
||||
}
|
||||
database.DB.Create(&user)
|
||||
|
||||
@@ -75,7 +75,7 @@ func TestAuthService_ValidateUser_WrongPassword(t *testing.T) {
|
||||
Password: string(password),
|
||||
Name: "测试用户2",
|
||||
Email: "test2@example.com",
|
||||
Role: "user",
|
||||
Role: "technician",
|
||||
}
|
||||
database.DB.Create(&user)
|
||||
|
||||
@@ -87,6 +87,25 @@ func TestAuthService_ValidateUser_WrongPassword(t *testing.T) {
|
||||
database.DB.Unscoped().Delete(&user)
|
||||
}
|
||||
|
||||
func TestAuthService_ValidateUser_EmployeeCannotLogin(t *testing.T) {
|
||||
password, _ := bcrypt.GenerateFromPassword([]byte("password123"), bcrypt.DefaultCost)
|
||||
user := models.User{
|
||||
Username: "employee_no_login",
|
||||
Password: string(password),
|
||||
Name: "普通员工",
|
||||
Role: "employee",
|
||||
}
|
||||
database.DB.Create(&user)
|
||||
|
||||
authService := AuthService{}
|
||||
_, err := authService.ValidateUser("employee_no_login", "password123")
|
||||
|
||||
assert.Error(t, err)
|
||||
assert.Contains(t, err.Error(), "用户名或密码不正确")
|
||||
|
||||
database.DB.Unscoped().Delete(&user)
|
||||
}
|
||||
|
||||
func TestAuthService_ValidateUser_UserNotFound(t *testing.T) {
|
||||
authService := AuthService{}
|
||||
_, err := authService.ValidateUser("nonexistent", "password")
|
||||
@@ -98,7 +117,7 @@ func TestAuthService_GenerateToken_Success(t *testing.T) {
|
||||
user := &models.User{
|
||||
ID: 1,
|
||||
Username: "testuser",
|
||||
Role: "user",
|
||||
Role: "technician",
|
||||
}
|
||||
|
||||
authService := AuthService{}
|
||||
@@ -117,7 +136,7 @@ func TestAuthService_GetProfile_Success(t *testing.T) {
|
||||
Password: string(password),
|
||||
Name: "测试用户3",
|
||||
Email: "test3@example.com",
|
||||
Role: "user",
|
||||
Role: "technician",
|
||||
}
|
||||
database.DB.Create(&user)
|
||||
|
||||
@@ -140,7 +159,7 @@ func TestAuthService_ChangePassword_Success(t *testing.T) {
|
||||
Password: string(password),
|
||||
Name: "测试用户4",
|
||||
Email: "test4@example.com",
|
||||
Role: "user",
|
||||
Role: "technician",
|
||||
}
|
||||
database.DB.Create(&user)
|
||||
|
||||
@@ -165,7 +184,7 @@ func TestAuthService_ChangePassword_WrongCurrentPassword(t *testing.T) {
|
||||
Password: string(password),
|
||||
Name: "测试用户5",
|
||||
Email: "test5@example.com",
|
||||
Role: "user",
|
||||
Role: "technician",
|
||||
}
|
||||
database.DB.Create(&user)
|
||||
|
||||
@@ -185,7 +204,7 @@ func TestAuthService_UpdateProfile_Success(t *testing.T) {
|
||||
Password: string(password),
|
||||
Name: "测试用户6",
|
||||
Email: "test6@example.com",
|
||||
Role: "user",
|
||||
Role: "technician",
|
||||
}
|
||||
database.DB.Create(&user)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user