Skip to content

Commit

Permalink
fix: fix tests
Browse files Browse the repository at this point in the history
Signed-off-by: 1998-felix <felix.gateru@gmail.com>
  • Loading branch information
felixgateru committed Aug 27, 2024
1 parent 46669f6 commit 2aaa9cc
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 43 deletions.
37 changes: 0 additions & 37 deletions api/openapi/things.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,43 +105,6 @@ paths:
"500":
$ref: "#/components/responses/ServiceError"

/things/members:
get:
operationId: listThingMembers
tags:
- Things
summary: Retrieves things members
description: |
Retrieves a list of things members. Due to performance concerns, data
is retrieved in subsets. The API things must ensure that the entire
dataset is consumed either by making subsequent requests, or by
increasing the subset size of the initial request.
parameters:
- $ref: "#/components/parameters/Limit"
- $ref: "#/components/parameters/Offset"
- $ref: "#/components/parameters/Metadata"
- $ref: "#/components/parameters/Status"
- $ref: "#/components/parameters/ThingName"
- $ref: "#/components/parameters/Tags"
- $ref: "#/components/parameters/Channel"
security:
- bearerAuth: []
responses:
"200":
$ref: "#/components/responses/ThingPageRes"
"400":
description: Failed due to malformed query parameters.
"401":
description: |
Missing or invalid access token provided.
"403":
description: Failed to perform authorization over the entity.
"404":
description: A non-existent entity request.
"422":
description: Database can't process request.
"500":
$ref: "#/components/responses/ServiceError"
/things/bulk:
post:
operationId: bulkCreateThings
Expand Down
5 changes: 3 additions & 2 deletions pkg/clients/postgres/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,11 @@ func (repo *Repository) RetrieveAllByIDs(ctx context.Context, pm clients.Page) (
if err != nil {
return clients.ClientsPage{}, errors.Wrap(repoerr.ErrViewEntity, err)
}
tq := query
query = applyOrdering(query, pm)

q := fmt.Sprintf(`SELECT c.id, c.name, c.tags, c.identity, c.metadata, COALESCE(c.domain_id, '') AS domain_id, c.status,
c.created_at, c.updated_at, COALESCE(c.updated_by, '') AS updated_by FROM clients c %s ORDER BY c.created_at LIMIT :limit OFFSET :offset;`, query)
c.created_at, c.updated_at, COALESCE(c.updated_by, '') AS updated_by FROM clients c %s LIMIT :limit OFFSET :offset;`, query)

dbPage, err := ToDBClientsPage(pm)
if err != nil {
Expand All @@ -286,7 +287,7 @@ func (repo *Repository) RetrieveAllByIDs(ctx context.Context, pm clients.Page) (

items = append(items, c)
}
cq := fmt.Sprintf(`SELECT COUNT(*) FROM clients c %s;`, query)
cq := fmt.Sprintf(`SELECT COUNT(*) FROM clients c %s;`, tq)

total, err := postgres.Total(ctx, repo.DB, cq, dbPage)
if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions users/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,6 @@ func (svc service) ListClients(ctx context.Context, token string, pm mgclients.P
}
return svc.listUsers(ctx, res.GetDomainId(), isSuperAdmin, pm)
}

}

func (svc service) listEntityUsers(ctx context.Context, domainID, userID string, isSuperAdmin bool, pm mgclients.Page) (mgclients.ClientsPage, error) {
Expand Down Expand Up @@ -247,8 +246,8 @@ func (svc service) listUsers(ctx context.Context, domainID string, isSuperAdmin
}
return usersPage, nil
}
func (svc service) listUserIDs(ctx context.Context, domainID, reqUserSubject, objectType, objectID, permission string) ([]string, error) {

func (svc service) listUserIDs(ctx context.Context, domainID, reqUserSubject, objectType, objectID, permission string) ([]string, error) {
res, err := svc.auth.Authorize(ctx, &magistrala.AuthorizeReq{
Domain: domainID,
SubjectType: auth.UserType,
Expand Down
4 changes: 2 additions & 2 deletions users/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ func TestListClients(t *testing.T) {
err: svcerr.ErrAuthentication,
},
{
desc: "list cleints as a superadmin with entity type and empty enty id",
desc: "list clients as a superadmin with entity type and empty enty id",
pageMeta: mgclients.Page{
EntityType: authsvc.ThingType,
EntityID: "",
Expand All @@ -733,7 +733,7 @@ func TestListClients(t *testing.T) {
err: svcerr.ErrMalformedEntity,
},
{
desc: "list cleints as non superadmin with empty entity type and id",
desc: "list clients as non superadmin with empty entity type and id",
pageMeta: mgclients.Page{},
identifyResponse: &magistrala.IdentityRes{UserId: client.ID, DomainId: validID, Id: authsvc.EncodeDomainUserID(validID, client.ID)},
platformAuthResponse: &magistrala.AuthorizeRes{Authorized: false},
Expand Down

0 comments on commit 2aaa9cc

Please sign in to comment.