Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for modifying an incident status and assignees #219

Merged
merged 1 commit into from
May 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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