diff --git a/.travis.yml b/.travis.yml index e818916f..9558bb43 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,10 @@ language: go go: - - 1.8 - 1.9 - 1.10.x - 1.11.x + - 1.12.x - master before_install: @@ -16,7 +16,7 @@ install: script: - go test -v ./... - - goveralls -service=travis-ci + - goveralls -service=travis-ci -ignore=zendesk/mock/client.go notifications: email: false diff --git a/Gopkg.lock b/Gopkg.lock index 10ef8111..47f62d72 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -1,9 +1,15 @@ # This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. +[[projects]] + name = "github.com/golang/mock" + packages = ["gomock"] + revision = "51421b967af1f557f93a59e0057aaf15ca02e29c" + version = "v1.2.0" + [solve-meta] analyzer-name = "dep" analyzer-version = 1 - input-imports = [] + inputs-digest = "926eb2ebfa68b0b0c883ec5a7f201ddd3c013e7e16ba99fc3710d9ed1a57e1b3" solver-name = "gps-cdcl" solver-version = 1 diff --git a/zendesk/api.go b/zendesk/api.go new file mode 100644 index 00000000..afd56976 --- /dev/null +++ b/zendesk/api.go @@ -0,0 +1,13 @@ +package zendesk + +//go:generate mockgen -destination=mock/client.go -package=mock -mock_names=API=Client github.com/nukosuke/go-zendesk/zendesk API + +// API an interface containing all of the zendesk client methods +type API interface { + GroupAPI + LocaleAPI + TicketFieldAPI + TicketFormAPI + TriggerAPI + UserAPI +} diff --git a/zendesk/group.go b/zendesk/group.go index 9a8c0424..596f080d 100644 --- a/zendesk/group.go +++ b/zendesk/group.go @@ -16,6 +16,12 @@ type Group struct { UpdatedAt time.Time `json:"updated_at,omitempty"` } +// GroupAPI an interface containing all methods associated with zendesk groups +type GroupAPI interface { + GetGroups() ([]Group, Page, error) + CreateGroup(group Group) (Group, error) +} + // GetGroups fetches group list // https://developer.zendesk.com/rest_api/docs/support/groups#list-groups func (z *Client) GetGroups() ([]Group, Page, error) { diff --git a/zendesk/locale.go b/zendesk/locale.go index fd09b061..b0343dec 100644 --- a/zendesk/locale.go +++ b/zendesk/locale.go @@ -16,6 +16,11 @@ type Locale struct { UpdatedAt time.Time `json:"updated_at"` } +// LocaleAPI an interface containing all of the local related zendesk methods +type LocaleAPI interface { + GetLocales() ([]Locale, error) +} + // GetLocales lists the translation locales available for the account. // https://developer.zendesk.com/rest_api/docs/support/locales#list-locales func (z *Client) GetLocales() ([]Locale, error) { diff --git a/zendesk/mock/client.go b/zendesk/mock/client.go new file mode 100644 index 00000000..30c384b8 --- /dev/null +++ b/zendesk/mock/client.go @@ -0,0 +1,219 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: github.com/nukosuke/go-zendesk/zendesk (interfaces: API) + +// Package mock is a generated GoMock package. +package mock + +import ( + gomock "github.com/golang/mock/gomock" + zendesk "github.com/nukosuke/go-zendesk/zendesk" + reflect "reflect" +) + +// Client is a mock of API interface +type Client struct { + ctrl *gomock.Controller + recorder *ClientMockRecorder +} + +// ClientMockRecorder is the mock recorder for Client +type ClientMockRecorder struct { + mock *Client +} + +// NewClient creates a new mock instance +func NewClient(ctrl *gomock.Controller) *Client { + mock := &Client{ctrl: ctrl} + mock.recorder = &ClientMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use +func (m *Client) EXPECT() *ClientMockRecorder { + return m.recorder +} + +// CreateGroup mocks base method +func (m *Client) CreateGroup(arg0 zendesk.Group) (zendesk.Group, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "CreateGroup", arg0) + ret0, _ := ret[0].(zendesk.Group) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// CreateGroup indicates an expected call of CreateGroup +func (mr *ClientMockRecorder) CreateGroup(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateGroup", reflect.TypeOf((*Client)(nil).CreateGroup), arg0) +} + +// CreateTicketField mocks base method +func (m *Client) CreateTicketField(arg0 zendesk.TicketField) (zendesk.TicketField, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "CreateTicketField", arg0) + ret0, _ := ret[0].(zendesk.TicketField) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// CreateTicketField indicates an expected call of CreateTicketField +func (mr *ClientMockRecorder) CreateTicketField(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateTicketField", reflect.TypeOf((*Client)(nil).CreateTicketField), arg0) +} + +// CreateTicketForm mocks base method +func (m *Client) CreateTicketForm(arg0 zendesk.TicketForm) (zendesk.TicketForm, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "CreateTicketForm", arg0) + ret0, _ := ret[0].(zendesk.TicketForm) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// CreateTicketForm indicates an expected call of CreateTicketForm +func (mr *ClientMockRecorder) CreateTicketForm(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateTicketForm", reflect.TypeOf((*Client)(nil).CreateTicketForm), arg0) +} + +// CreateTrigger mocks base method +func (m *Client) CreateTrigger(arg0 zendesk.Trigger) (zendesk.Trigger, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "CreateTrigger", arg0) + ret0, _ := ret[0].(zendesk.Trigger) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// CreateTrigger indicates an expected call of CreateTrigger +func (mr *ClientMockRecorder) CreateTrigger(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateTrigger", reflect.TypeOf((*Client)(nil).CreateTrigger), arg0) +} + +// CreateUser mocks base method +func (m *Client) CreateUser(arg0 zendesk.User) (zendesk.User, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "CreateUser", arg0) + ret0, _ := ret[0].(zendesk.User) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// CreateUser indicates an expected call of CreateUser +func (mr *ClientMockRecorder) CreateUser(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateUser", reflect.TypeOf((*Client)(nil).CreateUser), arg0) +} + +// GetGroups mocks base method +func (m *Client) GetGroups() ([]zendesk.Group, zendesk.Page, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetGroups") + ret0, _ := ret[0].([]zendesk.Group) + ret1, _ := ret[1].(zendesk.Page) + ret2, _ := ret[2].(error) + return ret0, ret1, ret2 +} + +// GetGroups indicates an expected call of GetGroups +func (mr *ClientMockRecorder) GetGroups() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetGroups", reflect.TypeOf((*Client)(nil).GetGroups)) +} + +// GetLocales mocks base method +func (m *Client) GetLocales() ([]zendesk.Locale, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetLocales") + ret0, _ := ret[0].([]zendesk.Locale) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetLocales indicates an expected call of GetLocales +func (mr *ClientMockRecorder) GetLocales() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetLocales", reflect.TypeOf((*Client)(nil).GetLocales)) +} + +// GetTicketField mocks base method +func (m *Client) GetTicketField(arg0 int64) (zendesk.TicketField, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetTicketField", arg0) + ret0, _ := ret[0].(zendesk.TicketField) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetTicketField indicates an expected call of GetTicketField +func (mr *ClientMockRecorder) GetTicketField(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTicketField", reflect.TypeOf((*Client)(nil).GetTicketField), arg0) +} + +// GetTicketFields mocks base method +func (m *Client) GetTicketFields() ([]zendesk.TicketField, zendesk.Page, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetTicketFields") + ret0, _ := ret[0].([]zendesk.TicketField) + ret1, _ := ret[1].(zendesk.Page) + ret2, _ := ret[2].(error) + return ret0, ret1, ret2 +} + +// GetTicketFields indicates an expected call of GetTicketFields +func (mr *ClientMockRecorder) GetTicketFields() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTicketFields", reflect.TypeOf((*Client)(nil).GetTicketFields)) +} + +// GetTicketForms mocks base method +func (m *Client) GetTicketForms() ([]zendesk.TicketForm, zendesk.Page, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetTicketForms") + ret0, _ := ret[0].([]zendesk.TicketForm) + ret1, _ := ret[1].(zendesk.Page) + ret2, _ := ret[2].(error) + return ret0, ret1, ret2 +} + +// GetTicketForms indicates an expected call of GetTicketForms +func (mr *ClientMockRecorder) GetTicketForms() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTicketForms", reflect.TypeOf((*Client)(nil).GetTicketForms)) +} + +// GetTriggers mocks base method +func (m *Client) GetTriggers() ([]zendesk.Trigger, zendesk.Page, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetTriggers") + ret0, _ := ret[0].([]zendesk.Trigger) + ret1, _ := ret[1].(zendesk.Page) + ret2, _ := ret[2].(error) + return ret0, ret1, ret2 +} + +// GetTriggers indicates an expected call of GetTriggers +func (mr *ClientMockRecorder) GetTriggers() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTriggers", reflect.TypeOf((*Client)(nil).GetTriggers)) +} + +// GetUsers mocks base method +func (m *Client) GetUsers() ([]zendesk.User, zendesk.Page, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetUsers") + ret0, _ := ret[0].([]zendesk.User) + ret1, _ := ret[1].(zendesk.Page) + ret2, _ := ret[2].(error) + return ret0, ret1, ret2 +} + +// GetUsers indicates an expected call of GetUsers +func (mr *ClientMockRecorder) GetUsers() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetUsers", reflect.TypeOf((*Client)(nil).GetUsers)) +} diff --git a/zendesk/ticket_field.go b/zendesk/ticket_field.go index ca7271f4..4e5a6b69 100644 --- a/zendesk/ticket_field.go +++ b/zendesk/ticket_field.go @@ -45,6 +45,13 @@ type TicketField struct { AgentDescription string `json:"agent_description,omitempty"` } +// TicketFieldAPI an interface containing all of the ticket field related zendesk methods +type TicketFieldAPI interface { + GetTicketFields() ([]TicketField, Page, error) + CreateTicketField(ticketField TicketField) (TicketField, error) + GetTicketField(ticketID int64) (TicketField, error) +} + // GetTicketFields fetches ticket field list // ref: https://developer.zendesk.com/rest_api/docs/core/ticket_fields#list-ticket-fields func (z Client) GetTicketFields() ([]TicketField, Page, error) { diff --git a/zendesk/ticket_form.go b/zendesk/ticket_form.go index abf0a9c9..8a460e51 100644 --- a/zendesk/ticket_form.go +++ b/zendesk/ticket_form.go @@ -20,6 +20,12 @@ type TicketForm struct { RestrictedBrandIDs []int64 `json:"restricted_brand_ids,omitempty"` } +// TicketFormAPI an interface containing all ticket form related methods +type TicketFormAPI interface { + GetTicketForms() ([]TicketForm, Page, error) + CreateTicketForm(ticketForm TicketForm) (TicketForm, error) +} + // GetTicketForms fetches ticket forms func (z Client) GetTicketForms() ([]TicketForm, Page, error) { var data struct { diff --git a/zendesk/trigger.go b/zendesk/trigger.go index 8c7bdc08..76daefb1 100644 --- a/zendesk/trigger.go +++ b/zendesk/trigger.go @@ -37,6 +37,12 @@ type Trigger struct { UpdatedAt *time.Time `json:"updated_at,omitempty"` } +// TriggerAPI an interface containing all trigger related methods +type TriggerAPI interface { + GetTriggers() ([]Trigger, Page, error) + CreateTrigger(trigger Trigger) (Trigger, error) +} + // GetTriggers fetch trigger list func (z *Client) GetTriggers() ([]Trigger, Page, error) { var data struct { diff --git a/zendesk/user.go b/zendesk/user.go index bff0e1cf..25a30962 100644 --- a/zendesk/user.go +++ b/zendesk/user.go @@ -67,6 +67,12 @@ func UserRoleText(role int) string { return userRoleText[role] } +// UserAPI an interface containing all user related methods +type UserAPI interface { + GetUsers() ([]User, Page, error) + CreateUser(user User) (User, error) +} + // GetUsers fetch user list func (z *Client) GetUsers() ([]User, Page, error) { var data struct {