From 52e0273679835b43d1437690b3f7ab04c7ec2d70 Mon Sep 17 00:00:00 2001 From: nukosuke Date: Tue, 12 Mar 2019 15:29:23 +0900 Subject: [PATCH 1/4] Add GetGroup --- zendesk/group.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/zendesk/group.go b/zendesk/group.go index ed1eac5b..dccbdb74 100644 --- a/zendesk/group.go +++ b/zendesk/group.go @@ -61,3 +61,24 @@ func (z *Client) CreateGroup(group Group) (Group, error) { } return result.Group, nil } + +// GetGroup gets a specified group +// ref: https://developer.zendesk.com/rest_api/docs/support/groups#show-group +func (z *Client) GetGroup(groupID int64) (Group, error) { + var result struct { + Group Group `json:"group"` + } + + body, err := z.Get(fmt.Sprintf("/groups/%d.json", groupID)) + + if err != nil { + return Group{}, err + } + + err = json.Unmarshal(body, &result) + if err != nil { + return Group{}, err + } + + return result.Group, err +} From 966cc25a16086be02a9d6e38eb2b2a715f540c37 Mon Sep 17 00:00:00 2001 From: nukosuke Date: Tue, 12 Mar 2019 15:36:04 +0900 Subject: [PATCH 2/4] Add test for GetGroup --- fixture/GET/group.json | 10 ++++++++++ zendesk/group.go | 1 + zendesk/group_test.go | 16 ++++++++++++++++ 3 files changed, 27 insertions(+) create mode 100644 fixture/GET/group.json diff --git a/fixture/GET/group.json b/fixture/GET/group.json new file mode 100644 index 00000000..5ac98a84 --- /dev/null +++ b/fixture/GET/group.json @@ -0,0 +1,10 @@ +{ + "group": { + "url": "https://terraform-provider-zendesk.zendesk.com/api/v2/groups/360002440594.json", + "id": 360002440594, + "name": "Support", + "deleted": false, + "created_at": "2018-11-23T16:05:12Z", + "updated_at": "2018-11-23T16:05:15Z" + } +} diff --git a/zendesk/group.go b/zendesk/group.go index dccbdb74..c368b6d8 100644 --- a/zendesk/group.go +++ b/zendesk/group.go @@ -2,6 +2,7 @@ package zendesk import ( "encoding/json" + "fmt" "time" ) diff --git a/zendesk/group_test.go b/zendesk/group_test.go index 2a7ee71d..f67e15fa 100644 --- a/zendesk/group_test.go +++ b/zendesk/group_test.go @@ -30,3 +30,19 @@ func TestCreateGroup(t *testing.T) { t.Fatalf("Failed to send request to create group: %s", err) } } + +func TestGetGroup(t *testing.T) { + mockAPI := newMockAPI(http.MethodGet, "group.json") + client := newTestClient(mockAPI) + defer mockAPI.Close() + + group, err := client.GetGroup(123) + if err != nil { + t.Fatalf("Failed to get group: %s", err) + } + + expectedID := int64(360002440594) + if group.ID != expectedID { + t.Fatalf("Returned group does not have the expected ID %d. Group ID is %d", expectedID, group.ID) + } +} From 57656904a92b2d8babbaa057f2480228b58700f6 Mon Sep 17 00:00:00 2001 From: nukosuke Date: Tue, 12 Mar 2019 15:44:43 +0900 Subject: [PATCH 3/4] Add interface for mock --- zendesk/group.go | 1 + 1 file changed, 1 insertion(+) diff --git a/zendesk/group.go b/zendesk/group.go index c368b6d8..b0f8ef52 100644 --- a/zendesk/group.go +++ b/zendesk/group.go @@ -20,6 +20,7 @@ type Group struct { // GroupAPI an interface containing all methods associated with zendesk groups type GroupAPI interface { GetGroups() ([]Group, Page, error) + GetGroup(groupID int64) (Group, error) CreateGroup(group Group) (Group, error) } From da68e12c7ea48c243663089dff1342487de4d8a1 Mon Sep 17 00:00:00 2001 From: nukosuke Date: Wed, 13 Mar 2019 16:52:25 +0900 Subject: [PATCH 4/4] Regenerate mock client --- zendesk/mock/client.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/zendesk/mock/client.go b/zendesk/mock/client.go index 30c384b8..6b2e893e 100644 --- a/zendesk/mock/client.go +++ b/zendesk/mock/client.go @@ -108,6 +108,21 @@ func (mr *ClientMockRecorder) CreateUser(arg0 interface{}) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateUser", reflect.TypeOf((*Client)(nil).CreateUser), arg0) } +// GetGroup mocks base method +func (m *Client) GetGroup(arg0 int64) (zendesk.Group, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetGroup", arg0) + ret0, _ := ret[0].(zendesk.Group) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetGroup indicates an expected call of GetGroup +func (mr *ClientMockRecorder) GetGroup(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetGroup", reflect.TypeOf((*Client)(nil).GetGroup), arg0) +} + // GetGroups mocks base method func (m *Client) GetGroups() ([]zendesk.Group, zendesk.Page, error) { m.ctrl.T.Helper()