Skip to content

Commit

Permalink
Add support for modifying an incident status and assignees, as per ht…
Browse files Browse the repository at this point in the history
  • Loading branch information
raidancampbell committed May 1, 2020
1 parent bafde24 commit 8d5be34
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 4 deletions.
8 changes: 5 additions & 3 deletions incident.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,11 @@ type CreateIncidentOptions struct {

// ManageIncidentsOptions is the structure used when PUTing updates to incidents to the ManageIncidents func
type ManageIncidentsOptions struct {
ID string `json:"id"`
Type string `json:"type"`
Status string `json:"status"`
ID string `json:"id"`
Type string `json:"type"`
Status string `json:"status,omitempty"`
Priority *APIReference `json:"priority,omitempty"`
Assignments []Assignee `json:"assignments,omitempty"`
}

// MergeIncidentsOptions is the structure used when merging incidents with MergeIncidents func
Expand Down
112 changes: 111 additions & 1 deletion incident_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func TestIncident_Create(t *testing.T) {
testEqual(t, want, res)
}

func TestIncident_Manage(t *testing.T) {
func TestIncident_Manage_status(t *testing.T) {
setup()
defer teardown()

Expand Down Expand Up @@ -102,6 +102,116 @@ func TestIncident_Manage(t *testing.T) {
testEqual(t, want, res)
}

func TestIncident_Manage_priority(t *testing.T) {
setup()
defer teardown()

mux.HandleFunc("/incidents", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "PUT")
w.Write([]byte(`{"incidents": [{"title": "foo", "id": "1", "priority": {"id": "PRIORITY_ID_HERE", "type": "priority_reference"}}]}`))
})
var listObj = APIListObject{Limit: 0, Offset: 0, More: false, Total: 0}
var client = &Client{apiEndpoint: server.URL, authToken: "foo", HTTPClient: defaultHTTPClient}
from := "[email protected]"

input := []ManageIncidentsOptions{
{
ID: "1",
Type: "incident",
Priority: &APIReference{
ID: "PRIORITY_ID_HERE",
Type: "priority_reference",
},
},
}

want := &ListIncidentsResponse{
APIListObject: listObj,
Incidents: []Incident{
{
Id: "1",
Title: "foo",
Priority: &Priority{
APIObject: APIObject{
ID: "PRIORITY_ID_HERE",
Type: "priority_reference",
},
},
},
},
}
res, err := client.ManageIncidents(from, input)

if err != nil {
t.Fatal(err)
}
testEqual(t, want, res)
}

func TestIncident_Manage_assignments(t *testing.T) {
setup()
defer teardown()

mux.HandleFunc("/incidents", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "PUT")
w.Write([]byte(`{"incidents": [{"title": "foo", "id": "1", "assignments": [{"assignee":{"id": "ASSIGNEE_ONE", "type": "user_reference"}},{"assignee":{"id": "ASSIGNEE_TWO", "type": "user_reference"}}]}]}`))
})
var listObj = APIListObject{Limit: 0, Offset: 0, More: false, Total: 0}
var client = &Client{apiEndpoint: server.URL, authToken: "foo", HTTPClient: defaultHTTPClient}
from := "[email protected]"

input := []ManageIncidentsOptions{
{
ID: "1",
Type: "incident",
Assignments: []Assignee{
{
Assignee: APIObject{
ID: "ASSIGNEE_ONE",
Type: "user_reference",
},
},
{
Assignee: APIObject{
ID: "ASSIGNEE_TWO",
Type: "user_reference",
},
},
},
},
}

want := &ListIncidentsResponse{
APIListObject: listObj,
Incidents: []Incident{
{
Id: "1",
Title: "foo",
Assignments: []Assignment{
{
Assignee: APIObject{
ID: "ASSIGNEE_ONE",
Type: "user_reference",
},
},
{
Assignee: APIObject{
ID: "ASSIGNEE_TWO",
Type: "user_reference",
},
},
},
},
},
}
res, err := client.ManageIncidents(from, input)

if err != nil {
t.Fatal(err)
}
testEqual(t, want, res)
}

func TestIncident_Merge(t *testing.T) {
setup()
defer teardown()
Expand Down

0 comments on commit 8d5be34

Please sign in to comment.