Skip to content

Commit

Permalink
test: Add unit test for priority api
Browse files Browse the repository at this point in the history
  • Loading branch information
Thiht committed Jun 12, 2018
1 parent 8491cb0 commit e3ab825
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 1 deletion.
42 changes: 42 additions & 0 deletions mocks/all_priorities.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
[
{
"self": "https://issues.apache.org/jira/rest/api/2/priority/1",
"statusColor": "#cc0000",
"description": "Blocks development and/or testing work, production could not run",
"iconUrl": "https://issues.apache.org/jira/images/icons/priorities/blocker.svg",
"name": "Blocker",
"id": "1"
},
{
"self": "https://issues.apache.org/jira/rest/api/2/priority/2",
"statusColor": "#ff0000",
"description": "Crashes, loss of data, severe memory leak.",
"iconUrl": "https://issues.apache.org/jira/images/icons/priorities/critical.svg",
"name": "Critical",
"id": "2"
},
{
"self": "https://issues.apache.org/jira/rest/api/2/priority/3",
"statusColor": "#009900",
"description": "Major loss of function.",
"iconUrl": "https://issues.apache.org/jira/images/icons/priorities/major.svg",
"name": "Major",
"id": "3"
},
{
"self": "https://issues.apache.org/jira/rest/api/2/priority/4",
"statusColor": "#006600",
"description": "Minor loss of function, or other problem where easy workaround is present.",
"iconUrl": "https://issues.apache.org/jira/images/icons/priorities/minor.svg",
"name": "Minor",
"id": "4"
},
{
"self": "https://issues.apache.org/jira/rest/api/2/priority/5",
"statusColor": "#003300",
"description": "Cosmetic problem like misspelt words or misaligned text.",
"iconUrl": "https://issues.apache.org/jira/images/icons/priorities/trivial.svg",
"name": "Trivial",
"id": "5"
}
]
2 changes: 1 addition & 1 deletion priority.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (s *PriorityService) GetList() ([]Priority, *Response, error) {
}

priorityList := []Priority{}
resp, err := s.client.Do(req, priorityList)
resp, err := s.client.Do(req, &priorityList)
if err != nil {
return nil, resp, NewJiraError(resp, err)
}
Expand Down
32 changes: 32 additions & 0 deletions priority_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package jira

import (
"fmt"
"io/ioutil"
"net/http"
"testing"
)

func TestPriorityService_GetList(t *testing.T) {
setup()
defer teardown()
testAPIEdpoint := "/rest/api/2/priority"

raw, err := ioutil.ReadFile("./mocks/all_priorities.json")
if err != nil {
t.Error(err.Error())
}
testMux.HandleFunc(testAPIEdpoint, func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testRequestURL(t, r, testAPIEdpoint)
fmt.Fprint(w, string(raw))
})

priorities, _, err := testClient.Priority.GetList()
if priorities == nil {
t.Error("Expected priority list. Priority list is nil")
}
if err != nil {
t.Errorf("Error given: %s", err)
}
}

0 comments on commit e3ab825

Please sign in to comment.