Skip to content

Commit

Permalink
Merge pull request #172 from abebars/handle-ticket-via
Browse files Browse the repository at this point in the history
Handle Via field in Ticket
  • Loading branch information
nukosuke authored May 29, 2020
2 parents 5b495ff + ca1b1f8 commit 7fdd67b
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
9 changes: 8 additions & 1 deletion zendesk/ticket.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,14 @@ type Ticket struct {
Tags []string `json:"tags,omitempty"`
CustomFields []CustomField `json:"custom_fields,omitempty"`

// TODO: Via #123
Via struct {
Channel string `json:"channel"`
Source struct {
From map[string]interface{} `json:"from"`
To map[string]interface{} `json:"to"`
Rel string `json:"rel"`
} `json:"source"`
} `json:"via"`

SatisfactionRating struct {
ID int64 `json:"id"`
Expand Down
32 changes: 32 additions & 0 deletions zendesk/ticket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package zendesk
import (
"context"
"encoding/json"
"fmt"
"net/http"
"reflect"
"sort"
"testing"
)
Expand Down Expand Up @@ -45,6 +47,36 @@ func TestGetTicket(t *testing.T) {
if ticket.ID != expectedID {
t.Fatalf("Returned ticket does not have the expected ID %d. Ticket id is %d", expectedID, ticket.ID)
}

expectedVia := struct {
Channel string `json:"channel"`
Source struct {
From map[string]interface{} `json:"from"`
To map[string]interface{} `json:"to"`
Rel string `json:"rel"`
} `json:"source"`
}{
Channel: "email",
Source: struct {
From map[string]interface{} `json:"from"`
To map[string]interface{} `json:"to"`
Rel string `json:"rel"`
}{
From: map[string]interface{}{
"address": "nukosuke@lavabit.com",
"name": "Yosuke Tamura",
},
To: map[string]interface{}{
"name": "Terraform Zendesk provider",
"address": "support@d3v-terraform-provider.zendesk.com",
},
Rel: "",
},
}

if !reflect.DeepEqual(ticket.Via, expectedVia) {
t.Fatal(fmt.Sprintf("Expected ticket via object to be %v but got %v", expectedVia, ticket.Via))
}
}

func TestGetTicketCanceledContext(t *testing.T) {
Expand Down

0 comments on commit 7fdd67b

Please sign in to comment.