grafana/pkg/services/user/usertest/fake.go
idafurjes e3501dfa4d
Chore: Add Get User Profile to user and Get User Org List to org service (#53788)
* Remove delete suer from store interface

* Remove get signed in user with cache ctx from store interface

* Support options when setting up access control tests

* Fix broken tests

* Fix lint

* Add user fake to middleware

* Fix middleware tests, remove usertest being initialised twice

* Chore: Add Get User Profile to user and Get User Org List to org service

Co-authored-by: Karl Persson <kalle.persson@grafana.com>
2022-08-16 17:50:45 +02:00

92 lines
2.9 KiB
Go

package usertest
import (
"context"
"github.com/grafana/grafana/pkg/services/user"
)
type FakeUserService struct {
ExpectedUser *user.User
ExpectedSignedInUser *user.SignedInUser
ExpectedError error
ExpectedSetUsingOrgError error
ExpectedSearchUsers user.SearchUserQueryResult
ExpectedUSerProfileDTO user.UserProfileDTO
}
func NewUserServiceFake() *FakeUserService {
return &FakeUserService{}
}
func (f *FakeUserService) Create(ctx context.Context, cmd *user.CreateUserCommand) (*user.User, error) {
return f.ExpectedUser, f.ExpectedError
}
func (f *FakeUserService) Delete(ctx context.Context, cmd *user.DeleteUserCommand) error {
return f.ExpectedError
}
func (f *FakeUserService) GetByID(ctx context.Context, query *user.GetUserByIDQuery) (*user.User, error) {
return f.ExpectedUser, f.ExpectedError
}
func (f *FakeUserService) GetByLogin(ctx context.Context, query *user.GetUserByLoginQuery) (*user.User, error) {
return f.ExpectedUser, f.ExpectedError
}
func (f *FakeUserService) GetByEmail(ctx context.Context, query *user.GetUserByEmailQuery) (*user.User, error) {
return f.ExpectedUser, f.ExpectedError
}
func (f *FakeUserService) Update(ctx context.Context, cmd *user.UpdateUserCommand) error {
return f.ExpectedError
}
func (f *FakeUserService) ChangePassword(ctx context.Context, cmd *user.ChangeUserPasswordCommand) error {
return f.ExpectedError
}
func (f *FakeUserService) UpdateLastSeenAt(ctx context.Context, cmd *user.UpdateUserLastSeenAtCommand) error {
return f.ExpectedError
}
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) {
return f.GetSignedInUser(ctx, query)
}
func (f *FakeUserService) GetSignedInUser(ctx context.Context, query *user.GetSignedInUserQuery) (*user.SignedInUser, error) {
if f.ExpectedSignedInUser == nil {
return &user.SignedInUser{}, f.ExpectedError
}
return f.ExpectedSignedInUser, f.ExpectedError
}
func (f *FakeUserService) Search(ctx context.Context, query *user.SearchUsersQuery) (*user.SearchUserQueryResult, error) {
return &f.ExpectedSearchUsers, f.ExpectedError
}
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
}
func (f *FakeUserService) UpdatePermissions(userID int64, isAdmin bool) error {
return f.ExpectedError
}
func (f *FakeUserService) SetUserHelpFlag(ctx context.Context, cmd *user.SetUserHelpFlagCommand) error {
return f.ExpectedError
}
func (f *FakeUserService) GetUserProfile(ctx context.Context, query *user.GetUserProfileQuery) (user.UserProfileDTO, error) {
return f.ExpectedUSerProfileDTO, f.ExpectedError
}