Skip to content

Commit

Permalink
Merge pull request #58 from nukosuke/fix-set-request-data
Browse files Browse the repository at this point in the history
Fix #57, Fix terrible bug
  • Loading branch information
nukosuke authored Mar 11, 2019
2 parents 5626570 + 872a983 commit c6f66ad
Show file tree
Hide file tree
Showing 11 changed files with 109 additions and 2 deletions.
26 changes: 26 additions & 0 deletions fixture/POST/ticket_fields.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"ticket_field": {
"url": "https://example.zendesk.com/api/v2/ticket_fields/360011737434.json",
"id": 360011737434,
"type": "subject",
"title": "Subject",
"raw_title": "Subject",
"description": "",
"raw_description": "",
"position": 0,
"active": true,
"required": false,
"collapsed_for_agents": false,
"regexp_for_validation": null,
"title_in_portal": "Subject",
"raw_title_in_portal": "Subject",
"visible_in_portal": true,
"editable_in_portal": true,
"required_in_portal": true,
"tag": null,
"created_at": "2018-11-23T16:05:12Z",
"updated_at": "2018-11-24T10:54:05Z",
"removable": false,
"agent_description": null
}
}
43 changes: 43 additions & 0 deletions fixture/POST/triggers.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"trigger": {
"url": "https://example.zendesk.com/api/v2/triggers/360056295714.json",
"id": 360056295714,
"title": "Notify requester of received request",
"active": true,
"updated_at": "2018-11-23T16:05:14Z",
"created_at": "2018-11-23T16:05:12Z",
"actions": [
{
"field": "notification_user",
"value": [
"requester_id",
"[Request received]",
"Your request ({{ticket.id}}) has been received and is being reviewed by our support staff.\n\nTo add additional comments, reply to this email."
]
}
],
"conditions": {
"all": [
{
"field": "update_type",
"operator": "is",
"value": "Create"
},
{
"field": "status",
"operator": "is_not",
"value": "solved"
},
{
"field": "ticket_is_public",
"operator": "is",
"value": "public"
}
],
"any": []
},
"description": null,
"position": 0,
"raw_title": "Notify requester of received request"
}
}
1 change: 1 addition & 0 deletions zendesk/dynamic_content.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ func (z *Client) CreateDynamicContentItem(item DynamicContentItem) (DynamicConte
var data, result struct {
Item DynamicContentItem `json:"item"`
}
data.Item = item

body, err := z.Post("/groups.json", data)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions zendesk/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func (z *Client) CreateGroup(group Group) (Group, error) {
var data, result struct {
Group Group `json:"group"`
}
data.Group = group

body, err := z.Post("/groups.json", data)
if err != nil {
Expand Down
11 changes: 11 additions & 0 deletions zendesk/group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,14 @@ func TestGetGroups(t *testing.T) {
t.Fatalf("expected length of groups is 1, but got %d", len(groups))
}
}

func TestCreateGroup(t *testing.T) {
mockAPI := newMockAPIWithStatus(http.MethodPost, "groups.json", http.StatusCreated)
client := newTestClient(mockAPI)
defer mockAPI.Close()

_, err := client.CreateGroup(Group{})
if err != nil {
t.Fatalf("Failed to send request to create group: %s", err)
}
}
1 change: 1 addition & 0 deletions zendesk/ticket_field.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ func (z Client) CreateTicketField(ticketField TicketField) (TicketField, error)
var data, result struct {
TicketField TicketField `json:"ticket_field"`
}
data.TicketField = ticketField

body, err := z.Post("/ticket_fields.json", data)
if err != nil {
Expand Down
11 changes: 11 additions & 0 deletions zendesk/ticket_field_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,14 @@ func TestGetTicketField(t *testing.T) {
t.Fatalf("Returned ticket field does not have the expected ID %d. Ticket id is %d", expectedID, ticketField.ID)
}
}

func TestCreateTicketField(t *testing.T) {
mockAPI := newMockAPIWithStatus(http.MethodPost, "ticket_fields.json", http.StatusCreated)
client := newTestClient(mockAPI)
defer mockAPI.Close()

_, err := client.CreateTicketField(TicketField{})
if err != nil {
t.Fatalf("Failed to send request to create ticket field: %s", err)
}
}
4 changes: 2 additions & 2 deletions zendesk/ticket_form_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ func TestGetTicketForms(t *testing.T) {
}
}

func TestCreateTicketForms(t *testing.T) {
func TestCreateTicketForm(t *testing.T) {
mockAPI := newMockAPIWithStatus(http.MethodPost, "ticket_form.json", http.StatusCreated)
client := newTestClient(mockAPI)
defer mockAPI.Close()

_, err := client.CreateTicketForm(TicketForm{})
if err != nil {
t.Fatalf("Failed to get ticket forms: %s", err)
t.Fatalf("Failed to send request to create ticket form: %s", err)
}
}
1 change: 1 addition & 0 deletions zendesk/trigger.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ func (z Client) CreateTrigger(trigger Trigger) (Trigger, error) {
var data, result struct {
Trigger Trigger `json:"trigger"`
}
data.Trigger = trigger

body, err := z.Post("/triggers.json", data)
if err != nil {
Expand Down
11 changes: 11 additions & 0 deletions zendesk/trigger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,14 @@ func TestGetTriggers(t *testing.T) {
t.Fatalf("expected length of triggers is , but got %d", len(triggers))
}
}

func TestCreateTrigger(t *testing.T) {
mockAPI := newMockAPIWithStatus(http.MethodPost, "triggers.json", http.StatusCreated)
client := newTestClient(mockAPI)
defer mockAPI.Close()

_, err := client.CreateTrigger(Trigger{})
if err != nil {
t.Fatalf("Failed to send request to create trigger: %s", err)
}
}
1 change: 1 addition & 0 deletions zendesk/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ func (z Client) CreateUser(user User) (User, error) {
var data, result struct {
User User `json:"user"`
}
data.User = user

body, err := z.Post("/users.json", data)
if err != nil {
Expand Down

0 comments on commit c6f66ad

Please sign in to comment.