diff --git a/zendesk/ticket.go b/zendesk/ticket.go index cba28965..b79c9d11 100644 --- a/zendesk/ticket.go +++ b/zendesk/ticket.go @@ -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"` diff --git a/zendesk/ticket_test.go b/zendesk/ticket_test.go index ac9e907c..0544a2e8 100644 --- a/zendesk/ticket_test.go +++ b/zendesk/ticket_test.go @@ -3,7 +3,9 @@ package zendesk import ( "context" "encoding/json" + "fmt" "net/http" + "reflect" "sort" "testing" ) @@ -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) {