Skip to content

Commit

Permalink
Handle UpdateTicket Endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
abebars committed May 12, 2020
1 parent 46a12a2 commit db4cda2
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 0 deletions.
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20190425150028-36563e24a262 h1:qsl9y/CJx34tuA7QCPNp86JNJe4spst6Ff8MjvPUdPg=
golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
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.

21 changes: 21 additions & 0 deletions zendesk/ticket.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ type TicketAPI interface {
GetTicket(ctx context.Context, id int64) (Ticket, error)
GetMultipleTickets(ctx context.Context, ticketIDs []int64) ([]Ticket, error)
CreateTicket(ctx context.Context, ticket Ticket) (Ticket, error)
UpdateTicket(ctx context.Context, ticketId int64, ticket Ticket) (Ticket, error)
}

// GetTickets get ticket list
Expand Down Expand Up @@ -227,3 +228,23 @@ func (z *Client) CreateTicket(ctx context.Context, ticket Ticket) (Ticket, error
}
return result.Ticket, nil
}

// UpdateTicket update an existing ticket
// ref: https://developer.zendesk.com/rest_api/docs/support/tickets#update-ticket
func (z *Client) UpdateTicket(ctx context.Context, ticketId int64, ticket Ticket) (Ticket, error) {
var data, result struct {
Ticket Ticket `json:"ticket"`
}
data.Ticket = ticket

body, err := z.put(ctx, fmt.Sprintf("/tickets/%d.json", ticketId), data)
if err != nil {
return Ticket{}, err
}

err = json.Unmarshal(body, &result)
if err != nil {
return Ticket{}, err
}
return result.Ticket, nil
}
16 changes: 16 additions & 0 deletions zendesk/ticket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,19 @@ func TestCreateTicket(t *testing.T) {
t.Fatalf("Returned ticket does not have the expected ID %d. Ticket id is %d", expectedID, ticket.ID)
}
}

func TestUpdateTicket(t *testing.T) {
mockAPI := newMockAPIWithStatus(http.MethodPut, "ticket.json", http.StatusOK)
client := newTestClient(mockAPI)
defer mockAPI.Close()

ticket, err := client.UpdateTicket(ctx, 2, Ticket{})
if err != nil {
t.Fatalf("Failed to update ticket: %s", err)
}

expectedID := int64(2)
if ticket.ID != expectedID {
t.Fatalf("Returned ticket does not have the expected ID %d. Ticket id is %d", expectedID, ticket.ID)
}
}

0 comments on commit db4cda2

Please sign in to comment.