2022-06-28 07:32:25 -05:00
|
|
|
package usertest
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/grafana/grafana/pkg/services/user"
|
|
|
|
)
|
|
|
|
|
|
|
|
type FakeUserService struct {
|
2022-08-11 06:28:55 -05:00
|
|
|
ExpectedUser *user.User
|
|
|
|
ExpectedSignedInUser *user.SignedInUser
|
|
|
|
ExpectedError error
|
|
|
|
ExpectedSetUsingOrgError error
|
2022-08-16 07:24:57 -05:00
|
|
|
ExpectedSearchUsers user.SearchUserQueryResult
|
2022-10-04 07:14:32 -05:00
|
|
|
ExpectedUserProfileDTO *user.UserProfileDTO
|
2022-10-27 04:44:09 -05:00
|
|
|
ExpectedUserProfileDTOs []*user.UserProfileDTO
|
2023-08-30 10:46:47 -05:00
|
|
|
ExpectedUsageStats map[string]any
|
2022-09-27 06:58:49 -05:00
|
|
|
|
2024-03-28 10:05:33 -05:00
|
|
|
UpdateFn func(ctx context.Context, cmd *user.UpdateUserCommand) error
|
2023-08-18 04:11:44 -05:00
|
|
|
GetSignedInUserFn func(ctx context.Context, query *user.GetSignedInUserQuery) (*user.SignedInUser, error)
|
|
|
|
CreateFn func(ctx context.Context, cmd *user.CreateUserCommand) (*user.User, error)
|
|
|
|
BatchDisableUsersFn func(ctx context.Context, cmd *user.BatchDisableUsersCommand) error
|
2024-05-17 05:41:41 -05:00
|
|
|
GetByEmailFn func(ctx context.Context, query *user.GetUserByEmailQuery) (*user.User, error)
|
2022-10-27 04:44:09 -05:00
|
|
|
|
|
|
|
counter int
|
2022-06-28 07:32:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewUserServiceFake() *FakeUserService {
|
|
|
|
return &FakeUserService{}
|
|
|
|
}
|
|
|
|
|
2023-08-30 10:46:47 -05:00
|
|
|
func (f FakeUserService) GetUsageStats(ctx context.Context) map[string]any {
|
2023-04-18 08:34:40 -05:00
|
|
|
return f.ExpectedUsageStats
|
|
|
|
}
|
|
|
|
|
2022-06-28 07:32:25 -05:00
|
|
|
func (f *FakeUserService) Create(ctx context.Context, cmd *user.CreateUserCommand) (*user.User, error) {
|
2022-12-20 07:59:05 -06:00
|
|
|
if f.CreateFn != nil {
|
|
|
|
return f.CreateFn(ctx, cmd)
|
|
|
|
}
|
|
|
|
|
2022-06-28 07:32:25 -05:00
|
|
|
return f.ExpectedUser, f.ExpectedError
|
2022-12-07 10:03:22 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func (f *FakeUserService) CreateServiceAccount(ctx context.Context, cmd *user.CreateUserCommand) (*user.User, error) {
|
|
|
|
return f.ExpectedUser, f.ExpectedError
|
|
|
|
}
|
|
|
|
|
2022-07-19 09:01:05 -05:00
|
|
|
func (f *FakeUserService) Delete(ctx context.Context, cmd *user.DeleteUserCommand) error {
|
|
|
|
return f.ExpectedError
|
|
|
|
}
|
2022-08-02 09:58:05 -05:00
|
|
|
|
|
|
|
func (f *FakeUserService) GetByID(ctx context.Context, query *user.GetUserByIDQuery) (*user.User, error) {
|
|
|
|
return f.ExpectedUser, f.ExpectedError
|
|
|
|
}
|
2022-08-04 06:22:43 -05:00
|
|
|
|
|
|
|
func (f *FakeUserService) GetByLogin(ctx context.Context, query *user.GetUserByLoginQuery) (*user.User, error) {
|
|
|
|
return f.ExpectedUser, f.ExpectedError
|
|
|
|
}
|
2022-08-04 06:47:30 -05:00
|
|
|
|
|
|
|
func (f *FakeUserService) GetByEmail(ctx context.Context, query *user.GetUserByEmailQuery) (*user.User, error) {
|
2024-05-17 05:41:41 -05:00
|
|
|
if f.GetByEmailFn != nil {
|
|
|
|
return f.GetByEmailFn(ctx, query)
|
|
|
|
}
|
2022-08-04 06:47:30 -05:00
|
|
|
return f.ExpectedUser, f.ExpectedError
|
|
|
|
}
|
2022-08-04 07:22:44 -05:00
|
|
|
|
|
|
|
func (f *FakeUserService) Update(ctx context.Context, cmd *user.UpdateUserCommand) error {
|
2024-03-28 10:05:33 -05:00
|
|
|
if f.UpdateFn != nil {
|
|
|
|
return f.UpdateFn(ctx, cmd)
|
|
|
|
}
|
2022-08-04 07:22:44 -05:00
|
|
|
return f.ExpectedError
|
|
|
|
}
|
2022-08-04 08:05:05 -05:00
|
|
|
|
2022-08-04 08:44:14 -05:00
|
|
|
func (f *FakeUserService) UpdateLastSeenAt(ctx context.Context, cmd *user.UpdateUserLastSeenAtCommand) error {
|
|
|
|
return f.ExpectedError
|
|
|
|
}
|
2022-08-11 06:28:55 -05:00
|
|
|
|
2022-08-12 05:13:26 -05:00
|
|
|
func (f *FakeUserService) GetSignedInUser(ctx context.Context, query *user.GetSignedInUserQuery) (*user.SignedInUser, error) {
|
2022-09-27 06:58:49 -05:00
|
|
|
if f.GetSignedInUserFn != nil {
|
|
|
|
return f.GetSignedInUserFn(ctx, query)
|
|
|
|
}
|
2022-08-16 09:08:59 -05:00
|
|
|
if f.ExpectedSignedInUser == nil {
|
|
|
|
return &user.SignedInUser{}, f.ExpectedError
|
|
|
|
}
|
2022-08-12 05:13:26 -05:00
|
|
|
return f.ExpectedSignedInUser, f.ExpectedError
|
|
|
|
}
|
|
|
|
|
2022-11-03 08:03:29 -05:00
|
|
|
func (f *FakeUserService) NewAnonymousSignedInUser(ctx context.Context) (*user.SignedInUser, error) {
|
|
|
|
return f.ExpectedSignedInUser, f.ExpectedError
|
|
|
|
}
|
|
|
|
|
2022-08-12 05:13:26 -05:00
|
|
|
func (f *FakeUserService) Search(ctx context.Context, query *user.SearchUsersQuery) (*user.SearchUserQueryResult, error) {
|
2022-08-16 07:24:57 -05:00
|
|
|
return &f.ExpectedSearchUsers, f.ExpectedError
|
2022-08-12 05:13:26 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (f *FakeUserService) BatchDisableUsers(ctx context.Context, cmd *user.BatchDisableUsersCommand) error {
|
2023-08-18 04:11:44 -05:00
|
|
|
if f.BatchDisableUsersFn != nil {
|
|
|
|
return f.BatchDisableUsersFn(ctx, cmd)
|
|
|
|
}
|
2022-08-12 05:13:26 -05:00
|
|
|
return f.ExpectedError
|
|
|
|
}
|
|
|
|
|
2022-10-04 07:14:32 -05:00
|
|
|
func (f *FakeUserService) GetProfile(ctx context.Context, query *user.GetUserProfileQuery) (*user.UserProfileDTO, error) {
|
2022-10-27 04:44:09 -05:00
|
|
|
if f.ExpectedUserProfileDTO != nil {
|
|
|
|
return f.ExpectedUserProfileDTO, f.ExpectedError
|
|
|
|
}
|
|
|
|
|
|
|
|
if f.ExpectedUserProfileDTOs == nil {
|
|
|
|
return nil, f.ExpectedError
|
|
|
|
}
|
|
|
|
|
|
|
|
f.counter++
|
|
|
|
return f.ExpectedUserProfileDTOs[f.counter-1], f.ExpectedError
|
2022-08-16 10:50:45 -05:00
|
|
|
}
|