Skip to content

Commit

Permalink
INTMDB-860: [GO SDK] Add missing endpoint to organization resource (#495
Browse files Browse the repository at this point in the history
)
  • Loading branch information
andreaangiolillo authored Jun 9, 2023
1 parent c3435ec commit bb20942
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
25 changes: 25 additions & 0 deletions mongodbatlas/organizations.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type OrganizationsService interface {
List(context.Context, *OrganizationsListOptions) (*Organizations, *Response, error)
Invitations(context.Context, string, *InvitationOptions) ([]*Invitation, *Response, error)
Get(context.Context, string) (*Organization, *Response, error)
Update(context.Context, string, *Organization) (*Organization, *Response, error)
Create(context.Context, *CreateOrganizationRequest) (*CreateOrganizationResponse, *Response, error)
Invitation(context.Context, string, string) (*Invitation, *Response, error)
Projects(context.Context, string, *ProjectsListOptions) (*Projects, *Response, error)
Expand Down Expand Up @@ -138,6 +139,30 @@ func (s *OrganizationsServiceOp) Get(ctx context.Context, orgID string) (*Organi
return root, resp, err
}

// Update updates a single organization.
//
// See more: https://www.mongodb.com/docs/atlas/reference/api-resources-spec/#tag/Organizations/operation/renameOrganization
func (s *OrganizationsServiceOp) Update(ctx context.Context, orgID string, org *Organization) (*Organization, *Response, error) {
if orgID == "" {
return nil, nil, NewArgError("orgID", "must be set")
}

path := fmt.Sprintf("%s/%s", orgsBasePath, orgID)

req, err := s.Client.NewRequest(ctx, http.MethodPatch, path, org)
if err != nil {
return nil, nil, err
}

root := new(Organization)
resp, err := s.Client.Do(ctx, req, root)
if err != nil {
return nil, resp, err
}

return root, resp, err
}

// Projects gets all projects for the given organization ID.
//
// See more: https://docs.atlas.mongodb.com/reference/api/organization-get-all-projects/
Expand Down
39 changes: 39 additions & 0 deletions mongodbatlas/organizations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,45 @@ func TestOrganizationsServiceOp_Get(t *testing.T) {
}
}

func TestOrganizationsServiceOp_Update(t *testing.T) {
client, mux, teardown := setup()
defer teardown()

mux.HandleFunc(fmt.Sprintf("/%s/%s", orgsBasePath, orgID), func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPatch)
_, _ = fmt.Fprint(w, `{
"id": "5a0a1e7e0f2912c554080adc",
"lastActiveAgent": "2016-03-09T18:19:37Z",
"links": [{
"href": "https://cloud.mongodb.com/api/public/v1.0/orgs/5a0a1e7e0f2912c554080adc",
"rel": "self"
}],
"name": "test"
}`)
})

body := &Organization{Name: "test"}
response, _, err := client.Organizations.Update(ctx, orgID, body)
if err != nil {
t.Fatalf("Organizations.Update returned error: %v", err)
}

expected := &Organization{
ID: "5a0a1e7e0f2912c554080adc",
Links: []*Link{
{
Href: "https://cloud.mongodb.com/api/public/v1.0/orgs/5a0a1e7e0f2912c554080adc",
Rel: "self",
},
},
Name: "test",
}

if diff := deep.Equal(response, expected); diff != nil {
t.Error(diff)
}
}

func TestOrganizationsServiceOp_Projects(t *testing.T) {
client, mux, teardown := setup()
defer teardown()
Expand Down

0 comments on commit bb20942

Please sign in to comment.