2022-06-28 07:32:25 -05:00
|
|
|
package orgtest
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/grafana/grafana/pkg/services/org"
|
|
|
|
)
|
|
|
|
|
2022-10-05 08:47:56 -05:00
|
|
|
type OrgListResponse []struct {
|
|
|
|
OrgID int64
|
|
|
|
Response error
|
|
|
|
}
|
|
|
|
|
2022-06-28 07:32:25 -05:00
|
|
|
type FakeOrgService struct {
|
2022-09-23 06:19:34 -05:00
|
|
|
ExpectedOrgUserID int64
|
|
|
|
ExpectedError error
|
|
|
|
ExpectedUserOrgDTO []*org.UserOrgDTO
|
|
|
|
ExpectedOrgs []*org.OrgDTO
|
|
|
|
ExpectedOrg *org.Org
|
|
|
|
ExpectedOrgUsers []*org.OrgUserDTO
|
|
|
|
ExpectedSearchOrgUsersResult *org.SearchOrgUsersQueryResult
|
2022-10-05 08:47:56 -05:00
|
|
|
ExpectedOrgListResponse OrgListResponse
|
2022-06-28 07:32:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewOrgServiceFake() *FakeOrgService {
|
|
|
|
return &FakeOrgService{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *FakeOrgService) GetIDForNewUser(ctx context.Context, cmd org.GetOrgIDForNewUserCommand) (int64, error) {
|
|
|
|
return f.ExpectedOrgUserID, f.ExpectedError
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *FakeOrgService) Insert(ctx context.Context, cmd *org.OrgUser) (int64, error) {
|
|
|
|
return f.ExpectedOrgUserID, f.ExpectedError
|
|
|
|
}
|
|
|
|
|
2022-07-15 11:06:44 -05:00
|
|
|
func (f *FakeOrgService) InsertOrgUser(ctx context.Context, cmd *org.OrgUser) (int64, error) {
|
2022-06-28 07:32:25 -05:00
|
|
|
return f.ExpectedOrgUserID, f.ExpectedError
|
|
|
|
}
|
2022-07-15 11:06:44 -05:00
|
|
|
|
|
|
|
func (f *FakeOrgService) DeleteUserFromAll(ctx context.Context, userID int64) error {
|
|
|
|
return f.ExpectedError
|
|
|
|
}
|
2022-08-16 10:50:45 -05:00
|
|
|
|
|
|
|
func (f *FakeOrgService) GetUserOrgList(ctx context.Context, query *org.GetUserOrgListQuery) ([]*org.UserOrgDTO, error) {
|
|
|
|
return f.ExpectedUserOrgDTO, f.ExpectedError
|
|
|
|
}
|
2022-08-23 12:26:21 -05:00
|
|
|
|
|
|
|
func (f *FakeOrgService) UpdateOrg(ctx context.Context, cmd *org.UpdateOrgCommand) error {
|
|
|
|
return f.ExpectedError
|
|
|
|
}
|
2022-09-20 02:55:40 -05:00
|
|
|
|
|
|
|
func (f *FakeOrgService) Search(ctx context.Context, query *org.SearchOrgsQuery) ([]*org.OrgDTO, error) {
|
|
|
|
return f.ExpectedOrgs, f.ExpectedError
|
|
|
|
}
|
2022-09-20 05:57:51 -05:00
|
|
|
|
2023-01-04 09:20:26 -06:00
|
|
|
func (f *FakeOrgService) GetByID(ctx context.Context, query *org.GetOrgByIDQuery) (*org.Org, error) {
|
2022-09-20 05:57:51 -05:00
|
|
|
return f.ExpectedOrg, f.ExpectedError
|
|
|
|
}
|
|
|
|
|
2022-09-27 09:53:45 -05:00
|
|
|
func (f *FakeOrgService) GetByName(ctx context.Context, query *org.GetOrgByNameQuery) (*org.Org, error) {
|
2022-09-20 05:57:51 -05:00
|
|
|
return f.ExpectedOrg, f.ExpectedError
|
|
|
|
}
|
|
|
|
|
2022-09-22 12:02:55 -05:00
|
|
|
func (f *FakeOrgService) CreateWithMember(ctx context.Context, cmd *org.CreateOrgCommand) (*org.Org, error) {
|
2022-09-20 05:57:51 -05:00
|
|
|
return f.ExpectedOrg, f.ExpectedError
|
|
|
|
}
|
2022-09-21 11:00:18 -05:00
|
|
|
|
|
|
|
func (f *FakeOrgService) UpdateAddress(ctx context.Context, cmd *org.UpdateOrgAddressCommand) error {
|
|
|
|
return f.ExpectedError
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *FakeOrgService) Delete(ctx context.Context, cmd *org.DeleteOrgCommand) error {
|
|
|
|
return f.ExpectedError
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *FakeOrgService) GetOrCreate(ctx context.Context, orgName string) (int64, error) {
|
2022-12-07 10:03:22 -06:00
|
|
|
return f.ExpectedOrg.ID, f.ExpectedError
|
2022-09-21 11:00:18 -05:00
|
|
|
}
|
2022-09-23 02:58:17 -05:00
|
|
|
|
|
|
|
func (f *FakeOrgService) AddOrgUser(ctx context.Context, cmd *org.AddOrgUserCommand) error {
|
|
|
|
return f.ExpectedError
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *FakeOrgService) UpdateOrgUser(ctx context.Context, cmd *org.UpdateOrgUserCommand) error {
|
|
|
|
return f.ExpectedError
|
|
|
|
}
|
|
|
|
|
2022-09-23 06:19:34 -05:00
|
|
|
func (f *FakeOrgService) GetOrgUsers(ctx context.Context, query *org.GetOrgUsersQuery) ([]*org.OrgUserDTO, error) {
|
2022-09-23 02:58:17 -05:00
|
|
|
return f.ExpectedOrgUsers, f.ExpectedError
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *FakeOrgService) RemoveOrgUser(ctx context.Context, cmd *org.RemoveOrgUserCommand) error {
|
2022-10-05 08:47:56 -05:00
|
|
|
testData := f.ExpectedOrgListResponse[0]
|
|
|
|
f.ExpectedOrgListResponse = f.ExpectedOrgListResponse[1:]
|
|
|
|
return testData.Response
|
2022-09-23 02:58:17 -05:00
|
|
|
}
|
2022-09-23 06:19:34 -05:00
|
|
|
|
|
|
|
func (f *FakeOrgService) SearchOrgUsers(ctx context.Context, query *org.SearchOrgUsersQuery) (*org.SearchOrgUsersQueryResult, error) {
|
|
|
|
return f.ExpectedSearchOrgUsersResult, f.ExpectedError
|
|
|
|
}
|