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

Issue-418 accept strings as serviceDeskID #419

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
18 changes: 9 additions & 9 deletions servicedesk.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ type ServiceDeskOrganizationDTO struct {
// all organizations associated with a service desk.
//
// https://developer.atlassian.com/cloud/jira/service-desk/rest/api-group-organization/#api-rest-servicedeskapi-servicedesk-servicedeskid-organization-get
func (s *ServiceDeskService) GetOrganizationsWithContext(ctx context.Context, serviceDeskID int, start int, limit int, accountID string) (*PagedDTO, *Response, error) {
apiEndPoint := fmt.Sprintf("rest/servicedeskapi/servicedesk/%d/organization?start=%d&limit=%d", serviceDeskID, start, limit)
func (s *ServiceDeskService) GetOrganizationsWithContext(ctx context.Context, serviceDeskID interface{}, start int, limit int, accountID string) (*PagedDTO, *Response, error) {
apiEndPoint := fmt.Sprintf("rest/servicedeskapi/servicedesk/%v/organization?start=%d&limit=%d", serviceDeskID, start, limit)
if accountID != "" {
apiEndPoint += fmt.Sprintf("&accountId=%s", accountID)
}
Expand All @@ -43,7 +43,7 @@ func (s *ServiceDeskService) GetOrganizationsWithContext(ctx context.Context, se
}

// GetOrganizations wraps GetOrganizationsWithContext using the background context.
func (s *ServiceDeskService) GetOrganizations(serviceDeskID int, start int, limit int, accountID string) (*PagedDTO, *Response, error) {
func (s *ServiceDeskService) GetOrganizations(serviceDeskID interface{}, start int, limit int, accountID string) (*PagedDTO, *Response, error) {
return s.GetOrganizationsWithContext(context.Background(), serviceDeskID, start, limit, accountID)
}

Expand All @@ -53,8 +53,8 @@ func (s *ServiceDeskService) GetOrganizations(serviceDeskID int, start int, limi
// and the resource returns a 204 success code.
//
// https://developer.atlassian.com/cloud/jira/service-desk/rest/api-group-organization/#api-rest-servicedeskapi-servicedesk-servicedeskid-organization-post
func (s *ServiceDeskService) AddOrganizationWithContext(ctx context.Context, serviceDeskID int, organizationID int) (*Response, error) {
apiEndPoint := fmt.Sprintf("rest/servicedeskapi/servicedesk/%d/organization", serviceDeskID)
func (s *ServiceDeskService) AddOrganizationWithContext(ctx context.Context, serviceDeskID interface{}, organizationID int) (*Response, error) {
apiEndPoint := fmt.Sprintf("rest/servicedeskapi/servicedesk/%v/organization", serviceDeskID)

organization := ServiceDeskOrganizationDTO{
OrganizationID: organizationID,
Expand All @@ -76,7 +76,7 @@ func (s *ServiceDeskService) AddOrganizationWithContext(ctx context.Context, ser
}

// AddOrganization wraps AddOrganizationWithContext using the background context.
func (s *ServiceDeskService) AddOrganization(serviceDeskID int, organizationID int) (*Response, error) {
func (s *ServiceDeskService) AddOrganization(serviceDeskID interface{}, organizationID int) (*Response, error) {
return s.AddOrganizationWithContext(context.Background(), serviceDeskID, organizationID)
}

Expand All @@ -86,8 +86,8 @@ func (s *ServiceDeskService) AddOrganization(serviceDeskID int, organizationID i
// no change is made and the resource returns a 204 success code.
//
// https://developer.atlassian.com/cloud/jira/service-desk/rest/api-group-organization/#api-rest-servicedeskapi-servicedesk-servicedeskid-organization-delete
func (s *ServiceDeskService) RemoveOrganizationWithContext(ctx context.Context, serviceDeskID int, organizationID int) (*Response, error) {
apiEndPoint := fmt.Sprintf("rest/servicedeskapi/servicedesk/%d/organization", serviceDeskID)
func (s *ServiceDeskService) RemoveOrganizationWithContext(ctx context.Context, serviceDeskID interface{}, organizationID int) (*Response, error) {
apiEndPoint := fmt.Sprintf("rest/servicedeskapi/servicedesk/%v/organization", serviceDeskID)

organization := ServiceDeskOrganizationDTO{
OrganizationID: organizationID,
Expand All @@ -109,6 +109,6 @@ func (s *ServiceDeskService) RemoveOrganizationWithContext(ctx context.Context,
}

// RemoveOrganization wraps RemoveOrganizationWithContext using the background context.
func (s *ServiceDeskService) RemoveOrganization(serviceDeskID int, organizationID int) (*Response, error) {
func (s *ServiceDeskService) RemoveOrganization(serviceDeskID interface{}, organizationID int) (*Response, error) {
return s.RemoveOrganizationWithContext(context.Background(), serviceDeskID, organizationID)
}
93 changes: 93 additions & 0 deletions servicedesk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,96 @@ func TestServiceDeskService_RemoveOrganizations(t *testing.T) {
t.Errorf("Error given: %s", err)
}
}

func TestServiceDeskServiceStringServiceDeskID_GetOrganizations(t *testing.T) {
setup()
defer teardown()
testMux.HandleFunc("/rest/servicedeskapi/servicedesk/TEST/organization", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testRequestURL(t, r, "/rest/servicedeskapi/servicedesk/TEST/organization")

w.WriteHeader(http.StatusOK)
fmt.Fprint(w, `{
"_expands": [],
"size": 3,
"start": 3,
"limit": 3,
"isLastPage": false,
"_links": {
"base": "https://your-domain.atlassian.net/rest/servicedeskapi",
"context": "context",
"next": "https://your-domain.atlassian.net/rest/servicedeskapi/servicedesk/TEST/organization?start=6&limit=3",
"prev": "https://your-domain.atlassian.net/rest/servicedeskapi/servicedesk/TEST/organization?start=0&limit=3"
},
"values": [
{
"id": "1",
"name": "Charlie Cakes Franchises",
"_links": {
"self": "https://your-domain.atlassian.net/rest/servicedeskapi/organization/1"
}
},
{
"id": "2",
"name": "Atlas Coffee Co",
"_links": {
"self": "https://your-domain.atlassian.net/rest/servicedeskapi/organization/2"
}
},
{
"id": "3",
"name": "The Adjustment Bureau",
"_links": {
"self": "https://your-domain.atlassian.net/rest/servicedeskapi/organization/3"
}
}
]
}`)
})

orgs, _, err := testClient.ServiceDesk.GetOrganizations("TEST", 3, 3, "")

if orgs == nil {
t.Error("Expected Organizations. Result is nil")
} else if orgs.Size != 3 {
t.Errorf("Expected size to be 3, but got %d", orgs.Size)
}

if err != nil {
t.Errorf("Error given: %s", err)
}
}

func TestServiceDeskServiceStringServiceDeskID_AddOrganizations(t *testing.T) {
setup()
defer teardown()
testMux.HandleFunc("/rest/servicedeskapi/servicedesk/TEST/organization", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "POST")
testRequestURL(t, r, "/rest/servicedeskapi/servicedesk/TEST/organization")

w.WriteHeader(http.StatusNoContent)
})

_, err := testClient.ServiceDesk.AddOrganization("TEST", 1)

if err != nil {
t.Errorf("Error given: %s", err)
}
}

func TestServiceDeskServiceStringServiceDeskID_RemoveOrganizations(t *testing.T) {
setup()
defer teardown()
testMux.HandleFunc("/rest/servicedeskapi/servicedesk/TEST/organization", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "DELETE")
testRequestURL(t, r, "/rest/servicedeskapi/servicedesk/TEST/organization")

w.WriteHeader(http.StatusNoContent)
})

_, err := testClient.ServiceDesk.RemoveOrganization("TEST", 1)

if err != nil {
t.Errorf("Error given: %s", err)
}
}