Skip to content

Commit

Permalink
Merge pull request #56 from tamccall/mock-client
Browse files Browse the repository at this point in the history
Mock client
  • Loading branch information
nukosuke authored Mar 11, 2019
2 parents 159575c + 72313a9 commit 5626570
Show file tree
Hide file tree
Showing 10 changed files with 277 additions and 3 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
language: go

go:
- 1.8
- 1.9
- 1.10.x
- 1.11.x
- 1.12.x
- master

before_install:
Expand All @@ -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
8 changes: 7 additions & 1 deletion Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions zendesk/api.go
Original file line number Diff line number Diff line change
@@ -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
}
6 changes: 6 additions & 0 deletions zendesk/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 5 additions & 0 deletions zendesk/locale.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
219 changes: 219 additions & 0 deletions zendesk/mock/client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions zendesk/ticket_field.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 6 additions & 0 deletions zendesk/ticket_form.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 6 additions & 0 deletions zendesk/trigger.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 6 additions & 0 deletions zendesk/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 5626570

Please sign in to comment.