Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MG-888 - Add domians SDK tests #2272

Merged
merged 5 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -1070,7 +1070,7 @@ func TestAssignDomainUsers(t *testing.T) {
contentType: contentType,
token: validToken,
status: http.StatusBadRequest,
err: apiutil.ErrMalformedPolicy,
err: apiutil.ErrMissingRelation,
},
}

Expand Down
4 changes: 2 additions & 2 deletions auth/api/http/domains/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,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 Down
11 changes: 9 additions & 2 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/pkg/apiutil"
"github.com/absmach/magistrala/pkg/errors"
)

Expand Down Expand Up @@ -51,13 +52,16 @@ func (sdk mgSDK) CreateDomain(domain Domain, token string) (Domain, errors.SDKEr
}

func (sdk mgSDK) UpdateDomain(domain Domain, token string) (Domain, errors.SDKError) {
if domain.ID == "" {
felixgateru marked this conversation as resolved.
Show resolved Hide resolved
return Domain{}, errors.NewSDKError(apiutil.ErrMissingID)
}
arvindh123 marked this conversation as resolved.
Show resolved Hide resolved
url := fmt.Sprintf("%s/%s/%s", sdk.domainsURL, domainsEndpoint, domain.ID)

data, err := json.Marshal(domain)
if err != nil {
return Domain{}, errors.NewSDKError(err)
}

url := fmt.Sprintf("%s/%s/%s", sdk.domainsURL, domainsEndpoint, domain.ID)

_, body, sdkerr := sdk.processRequest(http.MethodPatch, url, token, data, nil, http.StatusOK)
if sdkerr != nil {
return Domain{}, sdkerr
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
Loading