2016-06-24 10:43:32 +02:00
|
|
|
package jira
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
2016-07-29 19:45:03 +02:00
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
2016-06-24 10:43:32 +02:00
|
|
|
"net/http"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2016-07-17 11:17:29 +02:00
|
|
|
func TestSprintService_MoveIssuesToSprint(t *testing.T) {
|
2016-06-24 10:43:32 +02:00
|
|
|
setup()
|
|
|
|
defer teardown()
|
|
|
|
|
|
|
|
testAPIEndpoint := "/rest/agile/1.0/sprint/123/issue"
|
|
|
|
|
|
|
|
issuesToMove := []string{"KEY-1", "KEY-2"}
|
|
|
|
|
|
|
|
testMux.HandleFunc(testAPIEndpoint, func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
testMethod(t, r, "POST")
|
|
|
|
testRequestURL(t, r, testAPIEndpoint)
|
|
|
|
|
|
|
|
decoder := json.NewDecoder(r.Body)
|
|
|
|
var payload IssuesWrapper
|
|
|
|
err := decoder.Decode(&payload)
|
|
|
|
if err != nil {
|
2016-07-17 11:41:50 +02:00
|
|
|
t.Errorf("Got error: %v", err)
|
2016-06-24 10:43:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if payload.Issues[0] != issuesToMove[0] {
|
|
|
|
t.Errorf("Expected %s to be in payload, got %s instead", issuesToMove[0], payload.Issues[0])
|
|
|
|
}
|
|
|
|
})
|
2016-07-17 11:17:29 +02:00
|
|
|
_, err := testClient.Sprint.MoveIssuesToSprint(123, issuesToMove)
|
2016-06-24 10:43:32 +02:00
|
|
|
|
|
|
|
if err != nil {
|
2016-07-17 11:41:50 +02:00
|
|
|
t.Errorf("Got error: %v", err)
|
2016-06-24 10:43:32 +02:00
|
|
|
}
|
|
|
|
}
|
2016-07-26 22:18:58 +02:00
|
|
|
|
2016-07-29 19:43:34 +02:00
|
|
|
func TestSprintService_GetIssuesForSprint(t *testing.T) {
|
2016-07-26 22:18:58 +02:00
|
|
|
setup()
|
|
|
|
defer teardown()
|
|
|
|
testAPIEdpoint := "/rest/agile/1.0/sprint/123/issue"
|
|
|
|
|
|
|
|
raw, err := ioutil.ReadFile("./mocks/issues_in_sprint.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))
|
|
|
|
})
|
|
|
|
|
2016-07-29 19:43:34 +02:00
|
|
|
issues, _, err := testClient.Sprint.GetIssuesForSprint(123)
|
2016-07-26 22:18:58 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Error given: %v", err)
|
|
|
|
}
|
|
|
|
if issues == nil {
|
|
|
|
t.Error("Expected issues in sprint list. Issues list is nil")
|
|
|
|
}
|
|
|
|
if len(issues) != 1 {
|
|
|
|
t.Errorf("Expect there to be 1 issue in the sprint, found %v", len(issues))
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|