Skip to content

Commit

Permalink
Rename SearchBasicInfo to SearchClients
Browse files Browse the repository at this point in the history
Signed-off-by: nyagamunene <[email protected]>
  • Loading branch information
nyagamunene authored and dborovcanin committed Jul 3, 2024
1 parent 68a1b0a commit 2739eaf
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 23 deletions.
4 changes: 2 additions & 2 deletions pkg/clients/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ type Repository interface {
// RetrieveAll retrieves all clients.
RetrieveAll(ctx context.Context, pm Page) (ClientsPage, error)

// SearchBasicInfo retrieves clients based on search criteria.
SearchBasicInfo(ctx context.Context, pm Page) (ClientsPage, error)
// SearchClients retrieves clients based on search criteria.
SearchClients(ctx context.Context, pm Page) (ClientsPage, error)

// RetrieveAllByIDs retrieves for given client IDs .
RetrieveAllByIDs(ctx context.Context, pm Page) (ClientsPage, error)
Expand Down
2 changes: 1 addition & 1 deletion pkg/clients/postgres/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func (repo *Repository) RetrieveAll(ctx context.Context, pm clients.Page) (clien
return page, nil
}

func (repo *Repository) SearchBasicInfo(ctx context.Context, pm clients.Page) (clients.ClientsPage, error) {
func (repo *Repository) SearchClients(ctx context.Context, pm clients.Page) (clients.ClientsPage, error) {
sq, tq := constructSearchQuery(pm)

q := fmt.Sprintf(`SELECT c.id, c.name, c.created_at, c.updated_at FROM clients c %s LIMIT :limit OFFSET :offset;`, sq)
Expand Down
4 changes: 2 additions & 2 deletions pkg/clients/postgres/clients_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -927,7 +927,7 @@ func TestRetrieveByIDs(t *testing.T) {
}
}

func TestSearchBasicInfo(t *testing.T) {
func TestSearchClients(t *testing.T) {
t.Cleanup(func() {
_, err := db.Exec("DELETE FROM clients")
require.Nil(t, err, fmt.Sprintf("clean clients unexpected error: %s", err))
Expand Down Expand Up @@ -1289,7 +1289,7 @@ func TestSearchBasicInfo(t *testing.T) {
}
for _, c := range cases {
t.Run(c.desc, func(t *testing.T) {
switch response, err := repo.SearchBasicInfo(context.Background(), c.page); {
switch response, err := repo.SearchClients(context.Background(), c.page); {
case err == nil:
if c.page.Order != "" && c.page.Dir != "" {
c.response = response
Expand Down
6 changes: 3 additions & 3 deletions pkg/sdk/go/things_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ func TestListThings(t *testing.T) {
repoCall1 = auth.On("Authorize", mock.Anything, mock.Anything).Return(&magistrala.AuthorizeRes{Authorized: false}, svcerr.ErrAuthorization)
repoCall2 = auth.On("ListAllObjects", mock.Anything, mock.Anything).Return(&magistrala.ListObjectsRes{}, svcerr.ErrAuthorization)
}
repoCall3 := cRepo.On("SearchBasicInfo", mock.Anything, mock.Anything).Return(mgclients.ClientsPage{Page: convertClientPage(pm), Clients: convertThings(tc.response...)}, tc.err)
repoCall3 := cRepo.On("SearchClients", mock.Anything, mock.Anything).Return(mgclients.ClientsPage{Page: convertClientPage(pm), Clients: convertThings(tc.response...)}, tc.err)
page, err := mgsdk.Things(pm, validToken)
assert.Equal(t, tc.err, err, fmt.Sprintf("%s: expected error %s, got %s", tc.desc, tc.err, err))
assert.Equal(t, tc.response, page.Things, fmt.Sprintf("%s: expected %v got %v\n", tc.desc, tc.response, page))
Expand Down Expand Up @@ -1042,7 +1042,7 @@ func TestEnableThing(t *testing.T) {
repoCall1 = auth.On("Authorize", mock.Anything, mock.Anything).Return(&magistrala.AuthorizeRes{Authorized: false}, svcerr.ErrAuthorization)
}
repoCall2 := auth.On("ListAllObjects", mock.Anything, mock.Anything).Return(&magistrala.ListObjectsRes{Policies: toIDs(tc.response.Things)}, nil)
repoCall3 := cRepo.On("SearchBasicInfo", mock.Anything, mock.Anything).Return(convertThingsPage(tc.response), nil)
repoCall3 := cRepo.On("SearchClients", mock.Anything, mock.Anything).Return(convertThingsPage(tc.response), nil)
clientsPage, err := mgsdk.Things(pm, validToken)
assert.Nil(t, err, fmt.Sprintf("unexpected error: %s", err))
size := uint64(len(clientsPage.Things))
Expand Down Expand Up @@ -1179,7 +1179,7 @@ func TestDisableThing(t *testing.T) {
repoCall1 = auth.On("Authorize", mock.Anything, mock.Anything).Return(&magistrala.AuthorizeRes{Authorized: false}, svcerr.ErrAuthorization)
}
repoCall2 := auth.On("ListAllObjects", mock.Anything, mock.Anything).Return(&magistrala.ListObjectsRes{Policies: toIDs(tc.response.Things)}, nil)
repoCall3 := cRepo.On("SearchBasicInfo", mock.Anything, mock.Anything).Return(convertThingsPage(tc.response), nil)
repoCall3 := cRepo.On("SearchClients", mock.Anything, mock.Anything).Return(convertThingsPage(tc.response), nil)
page, err := mgsdk.Things(pm, validToken)
assert.Nil(t, err, fmt.Sprintf("unexpected error: %s", err))
size := uint64(len(page.Things))
Expand Down
6 changes: 3 additions & 3 deletions things/mocks/repository.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion things/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func (svc service) ListClients(ctx context.Context, token, reqUserID string, pm

pm.IDs = ids

tp, err := svc.clients.SearchBasicInfo(ctx, pm)
tp, err := svc.clients.SearchClients(ctx, pm)
if err != nil {
return mgclients.ClientsPage{}, errors.Wrap(svcerr.ErrViewEntity, err)
}
Expand Down
8 changes: 4 additions & 4 deletions things/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ func TestListClients(t *testing.T) {
Object: client.ID,
}).Return(tc.authorizeResponse2, tc.authorizeErr2)
listAllObjectsCall := auth.On("ListAllObjects", mock.Anything, mock.Anything).Return(tc.listObjectsResponse, tc.listObjectsErr)
retrieveAllCall := cRepo.On("SearchBasicInfo", mock.Anything, mock.Anything).Return(tc.retrieveAllResponse, tc.retrieveAllErr)
retrieveAllCall := cRepo.On("SearchClients", mock.Anything, mock.Anything).Return(tc.retrieveAllResponse, tc.retrieveAllErr)
listPermissionsCall := auth.On("ListPermissions", mock.Anything, mock.Anything).Return(tc.listPermissionsResponse, tc.listPermissionsErr)

page, err := svc.ListClients(context.Background(), tc.token, tc.id, tc.page)
Expand Down Expand Up @@ -813,7 +813,7 @@ func TestListClients(t *testing.T) {
Permission: "",
ObjectType: authsvc.ThingType,
}).Return(tc.listObjectsResponse1, tc.listObjectsErr1)
retrieveAllCall := cRepo.On("SearchBasicInfo", mock.Anything, mock.Anything).Return(tc.retrieveAllResponse, tc.retrieveAllErr)
retrieveAllCall := cRepo.On("SearchClients", mock.Anything, mock.Anything).Return(tc.retrieveAllResponse, tc.retrieveAllErr)
listPermissionsCall := auth.On("ListPermissions", mock.Anything, mock.Anything).Return(tc.listPermissionsResponse, tc.listPermissionsErr)

page, err := svc.ListClients(context.Background(), tc.token, tc.id, tc.page)
Expand Down Expand Up @@ -1207,7 +1207,7 @@ func TestEnableClient(t *testing.T) {
repoCall := auth.On("Identify", mock.Anything, &magistrala.IdentityReq{Token: validToken}).Return(&magistrala.IdentityRes{Id: validID, DomainId: testsutil.GenerateUUID(t)}, nil)
repoCall1 := auth.On("Authorize", mock.Anything, mock.Anything).Return(&magistrala.AuthorizeRes{Authorized: true}, nil)
repoCall2 := auth.On("ListAllObjects", mock.Anything, mock.Anything).Return(&magistrala.ListObjectsRes{Policies: getIDs(tc.response.Clients)}, nil)
repoCall3 := cRepo.On("SearchBasicInfo", context.Background(), mock.Anything).Return(tc.response, nil)
repoCall3 := cRepo.On("SearchClients", context.Background(), mock.Anything).Return(tc.response, nil)
page, err := svc.ListClients(context.Background(), validToken, "", pm)
require.Nil(t, err, fmt.Sprintf("unexpected error: %s", err))
size := uint64(len(page.Clients))
Expand Down Expand Up @@ -1377,7 +1377,7 @@ func TestDisableClient(t *testing.T) {
repoCall := auth.On("Identify", mock.Anything, &magistrala.IdentityReq{Token: validToken}).Return(&magistrala.IdentityRes{Id: validID, DomainId: testsutil.GenerateUUID(t)}, nil)
repoCall1 := auth.On("Authorize", mock.Anything, mock.Anything).Return(&magistrala.AuthorizeRes{Authorized: true}, nil)
repoCall2 := auth.On("ListAllObjects", mock.Anything, mock.Anything).Return(&magistrala.ListObjectsRes{Policies: getIDs(tc.response.Clients)}, nil)
repoCall3 := cRepo.On("SearchBasicInfo", context.Background(), mock.Anything).Return(tc.response, nil)
repoCall3 := cRepo.On("SearchClients", context.Background(), mock.Anything).Return(tc.response, nil)
page, err := svc.ListClients(context.Background(), validToken, "", pm)
require.Nil(t, err, fmt.Sprintf("unexpected error: %s", err))
size := uint64(len(page.Clients))
Expand Down
6 changes: 3 additions & 3 deletions users/mocks/repository.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions users/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ func (svc service) ListClients(ctx context.Context, token string, pm mgclients.P
Identity: pm.Identity,
Role: mgclients.UserRole,
}
pg, err := svc.clients.SearchBasicInfo(ctx, p)
pg, err := svc.clients.SearchClients(ctx, p)
if err != nil {
return mgclients.ClientsPage{}, errors.Wrap(svcerr.ErrViewEntity, err)
}
Expand Down Expand Up @@ -559,7 +559,7 @@ func (svc service) SearchUsers(ctx context.Context, token string, pm mgclients.P
return mgclients.ClientsPage{}, err
}

cp, err := svc.clients.SearchBasicInfo(ctx, pm)
cp, err := svc.clients.SearchClients(ctx, pm)
if err != nil {
return mgclients.ClientsPage{}, errors.Wrap(svcerr.ErrSearch, err)
}
Expand Down
4 changes: 2 additions & 2 deletions users/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ func TestListClients(t *testing.T) {
authCall1 := auth.On("Authorize", context.Background(), mock.Anything).Return(tc.authorizeResponse, tc.authorizeErr)
repoCall := cRepo.On("CheckSuperAdmin", context.Background(), mock.Anything).Return(tc.superAdminErr)
repoCall1 := cRepo.On("RetrieveAll", context.Background(), mock.Anything).Return(tc.retrieveAllResponse, tc.retrieveAllErr)
repoCall2 := cRepo.On("SearchBasicInfo", context.Background(), mock.Anything).Return(tc.response, tc.err)
repoCall2 := cRepo.On("SearchClients", context.Background(), mock.Anything).Return(tc.response, tc.err)
page, err := svc.ListClients(context.Background(), tc.token, tc.page)
assert.True(t, errors.Contains(err, tc.err), fmt.Sprintf("%s: expected %s got %s\n", tc.desc, tc.err, err))
assert.Equal(t, tc.response, page, fmt.Sprintf("%s: expected %v got %v\n", tc.desc, tc.response, page))
Expand Down Expand Up @@ -2233,7 +2233,7 @@ func TestSearchUsers(t *testing.T) {

for _, tc := range cases {
authCall := auth.On("Identify", context.Background(), &magistrala.IdentityReq{Token: tc.token}).Return(tc.identifyResp, tc.identifyErr)
repoCall := cRepo.On("SearchBasicInfo", context.Background(), tc.page).Return(tc.response, tc.responseErr)
repoCall := cRepo.On("SearchClients", context.Background(), tc.page).Return(tc.response, tc.responseErr)
page, err := svc.SearchUsers(context.Background(), tc.token, tc.page)
assert.True(t, errors.Contains(err, tc.err), fmt.Sprintf("%s: expected %s got %s\n", tc.desc, tc.err, err))
assert.Equal(t, tc.response, page, fmt.Sprintf("%s: expected %v got %v\n", tc.desc, tc.response, page))
Expand Down

0 comments on commit 2739eaf

Please sign in to comment.