Skip to content

Commit

Permalink
Add delete method for user
Browse files Browse the repository at this point in the history
  • Loading branch information
vovka667 authored and andygrunwald committed Jul 11, 2018
1 parent 13606a5 commit 8201aaa
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
18 changes: 18 additions & 0 deletions user.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,24 @@ func (s *UserService) Create(user *User) (*User, *Response, error) {
return responseUser, resp, nil
}

// Delete deletes an user from JIRA.
// Returns http.StatusNoContent on success.
//
// JIRA API docs: https://developer.atlassian.com/cloud/jira/platform/rest/#api-api-2-user-delete
func (s *UserService) Delete(username string) (*Response, error) {
apiEndpoint := fmt.Sprintf("/rest/api/2/user?username=%s", username)
req, err := s.client.NewRequest("DELETE", apiEndpoint, nil)
if err != nil {
return nil, err
}

resp, err := s.client.Do(req, nil)
if err != nil {
return resp, NewJiraError(resp, err)
}
return resp, nil
}

// GetGroups returns the groups which the user belongs to
//
// JIRA API docs: https://docs.atlassian.com/jira/REST/cloud/#api/2/user-getUserGroups
Expand Down
20 changes: 20 additions & 0 deletions user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,26 @@ func TestUserService_Create(t *testing.T) {
}
}

func TestUserService_Delete(t *testing.T) {
setup()
defer teardown()
testMux.HandleFunc("/rest/api/2/user", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "DELETE")
testRequestURL(t, r, "/rest/api/2/user?username=fred")

w.WriteHeader(http.StatusNoContent)
})

resp, err := testClient.User.Delete("fred")
if err != nil {
t.Errorf("Error given: %s", err)
}

if resp.StatusCode != http.StatusNoContent {
t.Errorf("Wrong status code: %d. Expected %d", resp.StatusCode, http.StatusNoContent)
}
}

func TestUserService_GetGroups(t *testing.T) {
setup()
defer teardown()
Expand Down

0 comments on commit 8201aaa

Please sign in to comment.