Skip to content

Commit

Permalink
Merge pull request #247 from evanfuller/add-make-comment-private-api
Browse files Browse the repository at this point in the history
Add 'make comment private' API
  • Loading branch information
nukosuke committed Dec 9, 2022
2 parents 594d553 + 9eac912 commit 174d617
Show file tree
Hide file tree
Showing 3 changed files with 73 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.

10 changes: 10 additions & 0 deletions zendesk/ticket_comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
type TicketCommentAPI interface {
CreateTicketComment(ctx context.Context, ticketID int64, ticketComment TicketComment) (TicketComment, error)
ListTicketComments(ctx context.Context, ticketID int64) ([]TicketComment, error)
MakeCommentPrivate(ctx context.Context, ticketID int64, ticketCommentID int64) error
}

// TicketComment is a struct for ticket comment payload
Expand Down Expand Up @@ -101,3 +102,12 @@ func (z *Client) ListTicketComments(ctx context.Context, ticketID int64) ([]Tick

return result.TicketComments, err
}

// MakeCommentPrivate converts an existing ticket comment to an internal note that is not publicly viewable.
//
// ref: https://developer.zendesk.com/api-reference/ticketing/tickets/ticket_comments/#make-comment-private
func (z *Client) MakeCommentPrivate(ctx context.Context, ticketID int64, ticketCommentID int64) error {
path := fmt.Sprintf("/tickets/%d/comments/%d/make_private", ticketID, ticketCommentID)
_, err := z.put(ctx, path, nil)
return err
}
49 changes: 49 additions & 0 deletions zendesk/ticket_comment_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package zendesk

import (
"errors"
"net/http"
"net/http/httptest"
"testing"
)

Expand Down Expand Up @@ -51,3 +53,50 @@ func TestListTicketComments(t *testing.T) {
t.Fatalf("Returned ticket comments does not have the expected length %d. Ticket comments length is %d", expectedLength, len(ticketComments))
}
}

func TestMakeCommentPrivate(t *testing.T) {
t.Parallel()
tests := []struct {
name string
apiReturn error
expectedErrStr string
}{
{
name: "successfully made private",
apiReturn: nil,
expectedErrStr: "",
},
{
name: "error making private",
apiReturn: errors.New(`{"error":"Couldn't authenticate you"}`),
expectedErrStr: `401: {"error":"Couldn't authenticate you"}`,
},
}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
mockAPI := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if test.apiReturn != nil {
w.WriteHeader(http.StatusUnauthorized)
_, _ = w.Write([]byte(test.apiReturn.Error()))
} else {
w.WriteHeader(http.StatusOK)
_, _ = w.Write(nil)
}
}))
defer mockAPI.Close()

client := newTestClient(mockAPI)
err := client.MakeCommentPrivate(ctx, 2, 12841284)
if err == nil {
if test.expectedErrStr != "" {
t.Fatalf("Expected error %s, did not get one", test.expectedErrStr)
}
} else {
if test.expectedErrStr != err.Error() {
t.Fatalf("Got %s, wanted %s", err.Error(), test.expectedErrStr)
}
}
})
}
}

0 comments on commit 174d617

Please sign in to comment.