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
|
2022-09-27 06:58:49 -05:00
|
|
|
|
|
|
|
GetSignedInUserFn func(ctx context.Context, query *user.GetSignedInUserQuery) (*user.SignedInUser, error)
|
2022-10-27 04:44:09 -05:00
|
|
|
|
|
|
|
counter int
|
2022-06-28 07:32:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewUserServiceFake() *FakeUserService {
|
|
|
|
return &FakeUserService{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *FakeUserService) Create(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) {
|
|
|
|
return f.ExpectedUser, f.ExpectedError
|
|
|
|
}
|
2022-08-04 07:22:44 -05:00
|
|
|
|
|
|
|
func (f *FakeUserService) Update(ctx context.Context, cmd *user.UpdateUserCommand) error {
|
|
|
|
return f.ExpectedError
|
|
|
|
}
|
2022-08-04 08:05:05 -05:00
|
|
|
|
|
|
|
func (f *FakeUserService) ChangePassword(ctx context.Context, cmd *user.ChangeUserPasswordCommand) error {
|
|
|
|
return f.ExpectedError
|
|
|
|
}
|
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
|
|
|
|
|
|
|
func (f *FakeUserService) SetUsingOrg(ctx context.Context, cmd *user.SetUsingOrgCommand) error {
|
|
|
|
return f.ExpectedSetUsingOrgError
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *FakeUserService) GetSignedInUserWithCacheCtx(ctx context.Context, query *user.GetSignedInUserQuery) (*user.SignedInUser, error) {
|
2022-08-16 09:08:59 -05:00
|
|
|
return f.GetSignedInUser(ctx, query)
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
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) Disable(ctx context.Context, cmd *user.DisableUserCommand) error {
|
|
|
|
return f.ExpectedError
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *FakeUserService) BatchDisableUsers(ctx context.Context, cmd *user.BatchDisableUsersCommand) error {
|
|
|
|
return f.ExpectedError
|
|
|
|
}
|
|
|
|
|
2022-10-04 07:14:32 -05:00
|
|
|
func (f *FakeUserService) UpdatePermissions(ctx context.Context, userID int64, isAdmin bool) error {
|
2022-08-12 05:13:26 -05:00
|
|
|
return f.ExpectedError
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *FakeUserService) SetUserHelpFlag(ctx context.Context, cmd *user.SetUserHelpFlagCommand) error {
|
|
|
|
return f.ExpectedError
|
|
|
|
}
|
2022-08-16 10:50:45 -05:00
|
|
|
|
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
|
|
|
}
|