mirror of
https://github.com/interviewstreet/go-jira.git
synced 2025-02-09 13:36:58 +02:00
Add tests for group apis
This commit is contained in:
parent
fbd056e79a
commit
4c154044b9
10
group.go
10
group.go
@ -54,7 +54,7 @@ type GroupMember struct {
|
||||
//
|
||||
// JIRA API docs: https://docs.atlassian.com/jira/REST/server/#api/2/group-getUsersFromGroup
|
||||
func (s *GroupService) Get(name string) ([]GroupMember, *Response, error) {
|
||||
apiEndpoint := fmt.Sprintf("rest/api/2/group/member?groupname=%s", name)
|
||||
apiEndpoint := fmt.Sprintf("/rest/api/2/group/member?groupname=%s", name)
|
||||
req, err := s.client.NewRequest("GET", apiEndpoint, nil)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
@ -73,7 +73,7 @@ func (s *GroupService) Get(name string) ([]GroupMember, *Response, error) {
|
||||
//
|
||||
// JIRA API docs: https://docs.atlassian.com/jira/REST/cloud/#api/2/group-addUserToGroup
|
||||
func (s *GroupService) Add(groupname string, username string) (*Group, *Response, error) {
|
||||
apiEndpoint := fmt.Sprintf("rest/api/2/group/user?groupname=%s", groupname)
|
||||
apiEndpoint := fmt.Sprintf("/rest/api/2/group/user?groupname=%s", groupname)
|
||||
var user struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
@ -97,11 +97,7 @@ func (s *GroupService) Add(groupname string, username string) (*Group, *Response
|
||||
//
|
||||
// JIRA API docs: https://docs.atlassian.com/jira/REST/cloud/#api/2/group-removeUserFromGroup
|
||||
func (s *GroupService) Remove(groupname string, username string) (*Response, error) {
|
||||
apiEndpoint := fmt.Sprintf("rest/api/2/group/user?groupname=%s&username=%s", groupname, username)
|
||||
// var user struct {
|
||||
// Name string `json:"name"`
|
||||
// }
|
||||
// user.Name = username
|
||||
apiEndpoint := fmt.Sprintf("/rest/api/2/group/user?groupname=%s&username=%s", groupname, username)
|
||||
req, err := s.client.NewRequest("DELETE", apiEndpoint, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
56
group_test.go
Normal file
56
group_test.go
Normal file
@ -0,0 +1,56 @@
|
||||
package jira
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestGroupService_Get(t *testing.T) {
|
||||
setup()
|
||||
defer teardown()
|
||||
testMux.HandleFunc("/rest/api/2/group/member", func(w http.ResponseWriter, r *http.Request) {
|
||||
testMethod(t, r, "GET")
|
||||
testRequestURL(t, r, "/rest/api/2/group/member?groupname=default")
|
||||
fmt.Fprint(w, `{"self":"http://www.example.com/jira/rest/api/2/group/member?includeInactiveUsers=false&maxResults=50&groupname=default&startAt=0","maxResults":50,"startAt":0,"total":2,"isLast":true,"values":[{"self":"http://www.example.com/jira/rest/api/2/user?username=michael","name":"michael","key":"michael","emailAddress":"michael@example.com","displayName":"MichaelScofield","active":true,"timeZone":"Australia/Sydney"},{"self":"http://www.example.com/jira/rest/api/2/user?username=alex","name":"alex","key":"alex","emailAddress":"alex@example.com","displayName":"AlexanderMahone","active":true,"timeZone":"Australia/Sydney"}]}`)
|
||||
})
|
||||
if members, _, err := testClient.Group.Get("default"); err != nil {
|
||||
t.Errorf("Error given: %s", err)
|
||||
} else if members == nil {
|
||||
t.Error("Expected members. Group.Members is nil")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGroupService_Add(t *testing.T) {
|
||||
setup()
|
||||
defer teardown()
|
||||
testMux.HandleFunc("/rest/api/2/group/user", func(w http.ResponseWriter, r *http.Request) {
|
||||
testMethod(t, r, "POST")
|
||||
testRequestURL(t, r, "/rest/api/2/group/user?groupname=default")
|
||||
|
||||
w.WriteHeader(http.StatusCreated)
|
||||
fmt.Fprint(w, `{"name":"default","self":"http://www.example.com/jira/rest/api/2/group?groupname=default","users":{"size":1,"items":[],"max-results":50,"start-index":0,"end-index":0},"expand":"users"}`)
|
||||
})
|
||||
|
||||
if group, _, err := testClient.Group.Add("default", "theodore"); err != nil {
|
||||
t.Errorf("Error given: %s", err)
|
||||
} else if group == nil {
|
||||
t.Error("Expected group. Group is nil")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGroupService_Remove(t *testing.T) {
|
||||
setup()
|
||||
defer teardown()
|
||||
testMux.HandleFunc("/rest/api/2/group/user", func(w http.ResponseWriter, r *http.Request) {
|
||||
testMethod(t, r, "DELETE")
|
||||
testRequestURL(t, r, "/rest/api/2/group/user?groupname=default")
|
||||
|
||||
w.WriteHeader(http.StatusOK)
|
||||
fmt.Fprint(w, `{"name":"default","self":"http://www.example.com/jira/rest/api/2/group?groupname=default","users":{"size":1,"items":[],"max-results":50,"start-index":0,"end-index":0},"expand":"users"}`)
|
||||
})
|
||||
|
||||
if _, err := testClient.Group.Remove("default", "theodore"); err != nil {
|
||||
t.Errorf("Error given: %s", err)
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user