Skip to content

Commit

Permalink
Merge pull request #91 from Staffbase/implement_incident_resolve_api
Browse files Browse the repository at this point in the history
Implement Incident Resolve API
  • Loading branch information
trabab authored Jan 31, 2022
2 parents b14b16d + 0b3d8c3 commit 29a3262
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 0 deletions.
9 changes: 9 additions & 0 deletions incident/incident.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,15 @@ func (c *Client) List(context context.Context, request *ListRequest) (*ListResul
return result, nil
}

func (c *Client) Resolve(context context.Context, request *ResolveRequest) (*AsyncResult, error) {
result := &AsyncResult{}
err := c.client.Exec(context, request, result)
if err != nil {
return nil, err
}
return result, nil
}

func (c *Client) Close(context context.Context, request *CloseRequest) (*AsyncResult, error) {
result := &AsyncResult{}
err := c.client.Exec(context, request, result)
Expand Down
22 changes: 22 additions & 0 deletions incident/incident_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,28 @@ func TestListRequest_GetParams(t *testing.T) {
assert.Equal(t, "asc", params["order"])
}

func TestResolveRequest_Validate(t *testing.T) {
request := &ResolveRequest{
Identifier: Tiny,
}
err := request.Validate()
assert.Equal(t, err.Error(), errors.New("Incident ID cannot be blank.").Error())
request.Id = "adea9e79-5527-4e49-b345-e55ae180ae59"
err = request.Validate()
assert.Nil(t, err)
}

func TestResolveRequest_Endpoint(t *testing.T) {
request := &ResolveRequest{
Id: "adea9e79-5527-4e49-b345-e55ae180ae59",
Identifier: Tiny,
}
endpoint := request.ResourcePath()
params := request.RequestParams()
assert.Equal(t, "/v1/incidents/adea9e79-5527-4e49-b345-e55ae180ae59/resolve", endpoint)
assert.Equal(t, "tiny", params["identifierType"])
}

func TestCloseRequest_Validate(t *testing.T) {
request := &CloseRequest{
Identifier: Tiny,
Expand Down
38 changes: 38 additions & 0 deletions incident/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,44 @@ func (r *ListRequest) RequestParams() map[string]string {
return params
}

type ResolveRequest struct {
client.BaseRequest
Id string
Identifier IdentifierType
Note string `json:"note,omitempty"`
}

func (r *ResolveRequest) Validate() error {
if r.Id == "" {
return errors.New("Incident ID cannot be blank.")
}
if r.Identifier != "" && r.Identifier != Id && r.Identifier != Tiny {
return errors.New("Identifier type should be one of these: 'Id', 'Tiny' or empty.")
}
return nil
}

func (r *ResolveRequest) ResourcePath() string {
return "/v1/incidents/" + r.Id + "/resolve"
}

func (r *ResolveRequest) Method() string {
return http.MethodPost
}

func (r *ResolveRequest) RequestParams() map[string]string {

params := make(map[string]string)

if r.Identifier == Tiny {
params["identifierType"] = "tiny"
} else {
params["identifierType"] = "id"
}

return params
}

type CloseRequest struct {
client.BaseRequest
Id string
Expand Down

0 comments on commit 29a3262

Please sign in to comment.