Skip to content

Commit

Permalink
Merge da68e12 into d079d87
Browse files Browse the repository at this point in the history
  • Loading branch information
nukosuke committed Mar 13, 2019
2 parents d079d87 + da68e12 commit 778ecdd
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 0 deletions.
10 changes: 10 additions & 0 deletions fixture/GET/group.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
23 changes: 23 additions & 0 deletions zendesk/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package zendesk

import (
"encoding/json"
"fmt"
"time"
)

Expand All @@ -19,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)
}

Expand Down Expand Up @@ -61,3 +63,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
}
16 changes: 16 additions & 0 deletions zendesk/group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
15 changes: 15 additions & 0 deletions zendesk/mock/client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 778ecdd

Please sign in to comment.