Skip to content

Commit

Permalink
Merge pull request #176 from yufy/master
Browse files Browse the repository at this point in the history
Add DeleteTicket endpoint
  • Loading branch information
nukosuke committed Jul 17, 2020
2 parents fec4755 + 53844a6 commit 9cbcf5e
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
14 changes: 14 additions & 0 deletions zendesk/mock/client.go

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

13 changes: 13 additions & 0 deletions zendesk/ticket.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ type TicketAPI interface {
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)
DeleteTicket(ctx context.Context, ticketID int64) error
}

// GetTickets get ticket list
Expand Down Expand Up @@ -257,3 +258,15 @@ func (z *Client) UpdateTicket(ctx context.Context, ticketID int64, ticket Ticket

return result.Ticket, nil
}

// DeleteTicket deletes the specified ticket
// ref: https://developer.zendesk.com/rest_api/docs/support/tickets#delete-ticket
func (z *Client) DeleteTicket(ctx context.Context, ticketID int64) error {
err := z.delete(ctx, fmt.Sprintf("/tickets/%d.json", ticketID))

if err != nil {
return err
}

return nil
}
14 changes: 14 additions & 0 deletions zendesk/ticket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"net/http"
"net/http/httptest"
"reflect"
"sort"
"testing"
Expand Down Expand Up @@ -222,3 +223,16 @@ func TestUpdateTicketFailure(t *testing.T) {
t.Fatal("Client did not return error when api failed")
}
}

func TestDeleteTicket(t *testing.T) {
mockAPI := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusNoContent)
w.Write(nil)
}))

c := newTestClient(mockAPI)
err := c.DeleteTicket(ctx, 437)
if err != nil {
t.Fatalf("Failed to delete ticket field: %s", err)
}
}

0 comments on commit 9cbcf5e

Please sign in to comment.