From 4bfaec947c0a7e9fb970a455559ec9b7563178be Mon Sep 17 00:00:00 2001 From: nukosuke Date: Sat, 19 Dec 2020 18:54:09 +0900 Subject: [PATCH] Make Via field to pointer type (#194) * Make Via field to pointer type * go fmt * Fix test --- zendesk/attachment_test.go | 2 +- zendesk/ticket.go | 19 +++++++++++-------- zendesk/ticket_audit_test.go | 2 -- zendesk/ticket_comment.go | 9 +-------- zendesk/ticket_test.go | 9 +-------- 5 files changed, 14 insertions(+), 27 deletions(-) diff --git a/zendesk/attachment_test.go b/zendesk/attachment_test.go index 812d8f47..ddd60a0c 100644 --- a/zendesk/attachment_test.go +++ b/zendesk/attachment_test.go @@ -51,7 +51,7 @@ func TestWrite(t *testing.T) { } func TestWriteCancelledContext(t *testing.T) { - mockAPI := newMockAPIWithStatus(http.MethodPost, "ticket.json", 201) + mockAPI := newMockAPIWithStatus(http.MethodPost, "ticket.json", 201) defer mockAPI.Close() client := newTestClient(mockAPI) diff --git a/zendesk/ticket.go b/zendesk/ticket.go index 92adb14f..df77a440 100644 --- a/zendesk/ticket.go +++ b/zendesk/ticket.go @@ -73,14 +73,7 @@ type Ticket struct { Tags []string `json:"tags,omitempty"` CustomFields []CustomField `json:"custom_fields,omitempty"` - 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,omitempty"` + Via *Via `json:"via,omitempty"` SatisfactionRating struct { ID int64 `json:"id"` @@ -109,6 +102,16 @@ type Ticket struct { // TODO: TicketAudit (POST only) #126 } +// Via is information about source of Ticket or TicketComment +type 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"` +} + type TicketListOptions struct { PageOptions diff --git a/zendesk/ticket_audit_test.go b/zendesk/ticket_audit_test.go index 320b8a65..8e973227 100644 --- a/zendesk/ticket_audit_test.go +++ b/zendesk/ticket_audit_test.go @@ -50,5 +50,3 @@ func TestGetTicketAudit(t *testing.T) { t.Fatalf("Returned ticket audit does not have the expected ID %d. Ticket audit id is %d", expectedID, ticketAudit.ID) } } - - diff --git a/zendesk/ticket_comment.go b/zendesk/ticket_comment.go index 4b02bc9a..d9606f33 100644 --- a/zendesk/ticket_comment.go +++ b/zendesk/ticket_comment.go @@ -29,14 +29,7 @@ type TicketComment struct { Uploads []string `json:"uploads,omitempty"` Metadata map[string]interface{} `json:"metadata,omitempty"` - 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,omitempty"` + Via *Via `json:"via,omitempty"` } // NewPublicTicketComment generates and returns a new TicketComment diff --git a/zendesk/ticket_test.go b/zendesk/ticket_test.go index ad5246d0..6663d82c 100644 --- a/zendesk/ticket_test.go +++ b/zendesk/ticket_test.go @@ -49,14 +49,7 @@ func TestGetTicket(t *testing.T) { 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"` - }{ + expectedVia := &Via{ Channel: "email", Source: struct { From map[string]interface{} `json:"from"`