Skip to content

Commit

Permalink
feat: add domain sdk 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 Jun 12, 2024
1 parent 27f5fb8 commit 4e92804
Show file tree
Hide file tree
Showing 5 changed files with 1,174 additions and 16 deletions.
2 changes: 1 addition & 1 deletion auth/api/http/domains/endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1056,7 +1056,7 @@ func TestAssignDomainUsers(t *testing.T) {
contentType: contentType,
token: validToken,
status: http.StatusBadRequest,
err: apiutil.ErrMalformedPolicy,
err: apiutil.ErrMissingRelation,
},
}

Expand Down
6 changes: 3 additions & 3 deletions auth/api/http/domains/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,11 @@ func (req assignUsersReq) validate() error {
}

if len(req.UserIDs) == 0 {
return apiutil.ErrMalformedPolicy
return apiutil.ErrMissingID
}

if req.Relation == "" {
return apiutil.ErrMalformedPolicy
return apiutil.ErrMissingRelation
}

return nil
Expand All @@ -202,7 +202,7 @@ func (req unassignUsersReq) validate() error {
}

if len(req.UserIDs) == 0 {
return apiutil.ErrMalformedPolicy
return apiutil.ErrMissingID
}

return nil
Expand Down
7 changes: 7 additions & 0 deletions pkg/sdk/go/domains.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"net/http"
"time"

"github.com/absmach/magistrala/internal/apiutil"
"github.com/absmach/magistrala/pkg/errors"
)

Expand Down Expand Up @@ -56,6 +57,9 @@ func (sdk mgSDK) UpdateDomain(domain Domain, token string) (Domain, errors.SDKEr
return Domain{}, errors.NewSDKError(err)
}

if domain.ID == "" {
return Domain{}, errors.NewSDKError(apiutil.ErrMissingID)
}
url := fmt.Sprintf("%s/%s/%s", sdk.domainsURL, domainsEndpoint, domain.ID)

_, body, sdkerr := sdk.processRequest(http.MethodPatch, url, token, data, nil, http.StatusOK)
Expand All @@ -71,6 +75,9 @@ func (sdk mgSDK) UpdateDomain(domain Domain, token string) (Domain, errors.SDKEr
}

func (sdk mgSDK) Domain(domainID, token string) (Domain, errors.SDKError) {
if domainID == "" {
return Domain{}, errors.NewSDKError(apiutil.ErrMissingID)
}
url := fmt.Sprintf("%s/%s/%s", sdk.domainsURL, domainsEndpoint, domainID)

_, body, sdkerr := sdk.processRequest(http.MethodGet, url, token, nil, nil, http.StatusOK)
Expand Down
Loading

0 comments on commit 4e92804

Please sign in to comment.