From 60091ec56f1fadacd0b32e765c5310d72e2e83ff Mon Sep 17 00:00:00 2001 From: James Burke Date: Tue, 16 Nov 2021 11:04:55 +0100 Subject: [PATCH] fix: Accept strings as serviceDeskID see the issue for details on the reason for change closes issue #418 --- servicedesk.go | 18 ++++----- servicedesk_test.go | 93 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 102 insertions(+), 9 deletions(-) diff --git a/servicedesk.go b/servicedesk.go index c6c91473..2d942682 100644 --- a/servicedesk.go +++ b/servicedesk.go @@ -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) } @@ -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) } @@ -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, @@ -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) } @@ -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, @@ -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) } diff --git a/servicedesk_test.go b/servicedesk_test.go index 9e763740..2590f7cc 100644 --- a/servicedesk_test.go +++ b/servicedesk_test.go @@ -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) + } +}