2016-06-15 11:20:37 +02:00
|
|
|
package jira
|
2016-06-15 19:08:15 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
|
|
|
"net/http"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2016-07-17 11:17:29 +02:00
|
|
|
func TestBoardService_GetAllBoards(t *testing.T) {
|
2016-06-15 19:08:15 +02:00
|
|
|
setup()
|
|
|
|
defer teardown()
|
|
|
|
testAPIEdpoint := "/rest/agile/1.0/board"
|
|
|
|
|
|
|
|
raw, err := ioutil.ReadFile("./mocks/all_boards.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-17 11:08:07 +02:00
|
|
|
projects, _, err := testClient.Board.GetAllBoards(nil)
|
2016-06-15 19:08:15 +02:00
|
|
|
if projects == nil {
|
|
|
|
t.Error("Expected boards list. Boards list is nil")
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Error given: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test with params
|
2016-07-17 11:17:29 +02:00
|
|
|
func TestBoardService_GetAllBoards_WithFilter(t *testing.T) {
|
2016-06-15 19:08:15 +02:00
|
|
|
setup()
|
|
|
|
defer teardown()
|
|
|
|
testAPIEdpoint := "/rest/agile/1.0/board"
|
|
|
|
|
|
|
|
raw, err := ioutil.ReadFile("./mocks/all_boards_filtered.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-06-16 09:52:16 +02:00
|
|
|
boardsListOptions := &BoardListOptions{
|
2016-06-15 19:15:12 +02:00
|
|
|
BoardType: "scrum",
|
|
|
|
Name: "Test",
|
2016-06-19 15:08:53 +02:00
|
|
|
ProjectKeyOrID: "TE",
|
2016-06-15 19:08:15 +02:00
|
|
|
}
|
2016-06-19 15:08:53 +02:00
|
|
|
boardsListOptions.StartAt = 1
|
|
|
|
boardsListOptions.MaxResults = 10
|
2016-06-15 19:08:15 +02:00
|
|
|
|
2016-07-17 11:08:07 +02:00
|
|
|
projects, _, err := testClient.Board.GetAllBoards(boardsListOptions)
|
2016-06-15 19:08:15 +02:00
|
|
|
if projects == nil {
|
|
|
|
t.Error("Expected boards list. Boards list is nil")
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Error given: %s", err)
|
|
|
|
}
|
|
|
|
}
|
2016-06-16 09:52:16 +02:00
|
|
|
|
2016-07-17 11:17:29 +02:00
|
|
|
func TestBoardService_GetBoard(t *testing.T) {
|
2016-06-16 09:52:16 +02:00
|
|
|
setup()
|
|
|
|
defer teardown()
|
|
|
|
testAPIEdpoint := "/rest/agile/1.0/board/1"
|
|
|
|
|
|
|
|
testMux.HandleFunc(testAPIEdpoint, func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
testMethod(t, r, "GET")
|
|
|
|
testRequestURL(t, r, testAPIEdpoint)
|
|
|
|
fmt.Fprint(w, `{"id":4,"self":"https://test.jira.org/rest/agile/1.0/board/1","name":"Test Weekly","type":"scrum"}`)
|
|
|
|
})
|
|
|
|
|
2016-07-17 11:08:07 +02:00
|
|
|
board, _, err := testClient.Board.GetBoard(1)
|
2016-06-16 09:52:16 +02:00
|
|
|
if board == nil {
|
|
|
|
t.Error("Expected board list. Board list is nil")
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Error given: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-17 11:17:29 +02:00
|
|
|
func TestBoardService_GetBoard_WrongID(t *testing.T) {
|
2016-06-16 09:52:16 +02:00
|
|
|
setup()
|
|
|
|
defer teardown()
|
|
|
|
testAPIEndpoint := "/rest/api/2/board/99999999"
|
|
|
|
|
|
|
|
testMux.HandleFunc(testAPIEndpoint, func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
testMethod(t, r, "GET")
|
|
|
|
testRequestURL(t, r, testAPIEndpoint)
|
|
|
|
fmt.Fprint(w, nil)
|
|
|
|
})
|
|
|
|
|
2016-07-17 11:08:07 +02:00
|
|
|
board, resp, err := testClient.Board.GetBoard(99999999)
|
2016-06-16 09:52:16 +02:00
|
|
|
if board != nil {
|
|
|
|
t.Errorf("Expected nil. Got %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if resp.Status == "404" {
|
|
|
|
t.Errorf("Expected status 404. Got %s", resp.Status)
|
|
|
|
}
|
|
|
|
if err == nil {
|
|
|
|
t.Errorf("Error given: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-17 11:17:29 +02:00
|
|
|
func TestBoardService_CreateBoard(t *testing.T) {
|
2016-06-16 09:52:16 +02:00
|
|
|
setup()
|
|
|
|
defer teardown()
|
|
|
|
testMux.HandleFunc("/rest/agile/1.0/board", func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
testMethod(t, r, "POST")
|
|
|
|
testRequestURL(t, r, "/rest/agile/1.0/board")
|
|
|
|
|
|
|
|
w.WriteHeader(http.StatusCreated)
|
|
|
|
fmt.Fprint(w, `{"id":17,"self":"https://test.jira.org/rest/agile/1.0/board/17","name":"Test","type":"kanban"}`)
|
|
|
|
})
|
|
|
|
|
|
|
|
b := &Board{
|
|
|
|
Name: "Test",
|
|
|
|
Type: "kanban",
|
2016-06-19 15:08:53 +02:00
|
|
|
FilterID: 17,
|
2016-06-16 09:52:16 +02:00
|
|
|
}
|
2016-07-17 11:08:07 +02:00
|
|
|
issue, _, err := testClient.Board.CreateBoard(b)
|
2016-06-16 09:52:16 +02:00
|
|
|
if issue == nil {
|
|
|
|
t.Error("Expected board. Board is nil")
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Error given: %s", err)
|
|
|
|
}
|
|
|
|
}
|
2016-06-16 11:20:47 +02:00
|
|
|
|
2016-07-17 11:17:29 +02:00
|
|
|
func TestBoardService_DeleteBoard(t *testing.T) {
|
2016-06-16 11:20:47 +02:00
|
|
|
setup()
|
|
|
|
defer teardown()
|
|
|
|
testMux.HandleFunc("/rest/agile/1.0/board/1", func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
testMethod(t, r, "DELETE")
|
|
|
|
testRequestURL(t, r, "/rest/agile/1.0/board/1")
|
|
|
|
|
|
|
|
w.WriteHeader(http.StatusNoContent)
|
|
|
|
fmt.Fprint(w, `{}`)
|
|
|
|
})
|
|
|
|
|
2016-07-17 11:08:07 +02:00
|
|
|
_, resp, err := testClient.Board.DeleteBoard(1)
|
2016-06-16 11:20:47 +02:00
|
|
|
if resp.StatusCode != 204 {
|
|
|
|
t.Error("Expected board not deleted.")
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Error given: %s", err)
|
|
|
|
}
|
|
|
|
}
|
2016-07-17 11:17:29 +02:00
|
|
|
|
|
|
|
func TestBoardService_GetAllSprints(t *testing.T) {
|
|
|
|
setup()
|
|
|
|
defer teardown()
|
|
|
|
|
|
|
|
testAPIEndpoint := "/rest/agile/1.0/board/123/sprint"
|
|
|
|
|
|
|
|
raw, err := ioutil.ReadFile("./mocks/sprints.json")
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
testMux.HandleFunc(testAPIEndpoint, func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
testMethod(t, r, "GET")
|
|
|
|
testRequestURL(t, r, testAPIEndpoint)
|
|
|
|
fmt.Fprint(w, string(raw))
|
|
|
|
})
|
|
|
|
|
|
|
|
sprints, _, err := testClient.Board.GetAllSprints("123")
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Got error: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if sprints == nil {
|
|
|
|
t.Error("Expected sprint list. Got nil.")
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(sprints) != 4 {
|
|
|
|
t.Errorf("Expected 4 transitions. Got %d", len(sprints))
|
|
|
|
}
|
|
|
|
}
|