mirror of
https://github.com/interviewstreet/go-jira.git
synced 2025-02-01 13:07:50 +02:00
add board create with tests
This commit is contained in:
parent
9f8d06db41
commit
7d8addc179
58
board.go
58
board.go
@ -2,6 +2,7 @@ package jira
|
||||
|
||||
import (
|
||||
//"fmt"
|
||||
"fmt"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
@ -15,14 +16,16 @@ type BoardsList struct {
|
||||
StartAt int `json:"startAt"`
|
||||
Total int `json:"total"`
|
||||
IsLast bool `json:"isLast"`
|
||||
Values []Value `json:"values"`
|
||||
Values []Board `json:"values"`
|
||||
}
|
||||
|
||||
type Value struct {
|
||||
ID int `json:"id"`
|
||||
Self string `json:"self"`
|
||||
Name string `json:"name"`
|
||||
Type string `json:"type"`
|
||||
// Board represents a JIRA board
|
||||
type Board struct {
|
||||
ID int `json:"id",omitempty"`
|
||||
Self string `json:"self",omitempty"`
|
||||
Name string `json:"name",omitempty"`
|
||||
Type string `json:"type",omitempty"`
|
||||
FilterId int `omitempty`
|
||||
}
|
||||
|
||||
// BoardListOptions specifies the optional parameters to the BoardService.GetList
|
||||
@ -40,7 +43,6 @@ type BoardListOptions struct {
|
||||
// Pagination is used for the JIRA REST APIs to conserve server resources and limit
|
||||
// response size for resources that return potentially large collection of items.
|
||||
// A request to a pages API will result in a values array wrapped in a JSON object with some paging metadata
|
||||
// Works only for 1.0 endpoints
|
||||
// Default Pagination options
|
||||
// The starting index of the returned projects. Base index: 0.
|
||||
StartAt int `url:"startAt,omitempty"`
|
||||
@ -52,7 +54,7 @@ type BoardListOptions struct {
|
||||
//
|
||||
// JIRA API docs: https://docs.atlassian.com/jira/REST/latest/#api/2/project-getAllProjects
|
||||
func (s *BoardService) GetList(opt *BoardListOptions) (*BoardsList, *http.Response, error) {
|
||||
apiEndpoint := "/rest/agile/1.0/board"
|
||||
apiEndpoint := "rest/agile/1.0/board"
|
||||
url, err := addOptions(apiEndpoint, opt)
|
||||
req, err := s.client.NewRequest("GET", url, nil)
|
||||
if err != nil {
|
||||
@ -67,3 +69,43 @@ func (s *BoardService) GetList(opt *BoardListOptions) (*BoardsList, *http.Respon
|
||||
|
||||
return boards, resp, err
|
||||
}
|
||||
|
||||
// Returns the board for the given board Id. This board will only be returned if the user has permission to view it.
|
||||
func (s *BoardService) Get(boardID string) (*Board, *http.Response, error) {
|
||||
apiEndpoint := fmt.Sprintf("rest/agile/1.0/board/%s", boardID)
|
||||
req, err := s.client.NewRequest("GET", apiEndpoint, nil)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
board := new(Board)
|
||||
resp, err := s.client.Do(req, board)
|
||||
if err != nil {
|
||||
return nil, resp, err
|
||||
}
|
||||
return board, resp, nil
|
||||
}
|
||||
|
||||
// Creates a new board. Board name, type and filter Id is required.
|
||||
// name - Must be less than 255 characters.
|
||||
// type - Valid values: scrum, kanban
|
||||
// filterId - Id of a filter that the user has permissions to view.
|
||||
// Note, if the user does not have the 'Create shared objects' permission and tries to create a shared board, a private
|
||||
// board will be created instead (remember that board sharing depends on the filter sharing).
|
||||
|
||||
// JIRA API docs: https://docs.atlassian.com/jira-software/REST/cloud/#agile/1.0/board-createBoard
|
||||
func (s *BoardService) Create(board *Board) (*Board, *http.Response, error) {
|
||||
|
||||
apiEndpoint := "rest/agile/1.0/board"
|
||||
req, err := s.client.NewRequest("POST", apiEndpoint, board)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
responseBoard := new(Board)
|
||||
resp, err := s.client.Do(req, responseBoard)
|
||||
if err != nil {
|
||||
return nil, resp, err
|
||||
}
|
||||
return responseBoard, resp, nil
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ func TestBoardsGetFiltered(t *testing.T) {
|
||||
fmt.Fprint(w, string(raw))
|
||||
})
|
||||
|
||||
boardsListOptions := BoardListOptions{
|
||||
boardsListOptions := &BoardListOptions{
|
||||
BoardType: "scrum",
|
||||
Name: "Test",
|
||||
ProjectKeyOrId: "TE",
|
||||
@ -55,7 +55,7 @@ func TestBoardsGetFiltered(t *testing.T) {
|
||||
MaxResults: 10,
|
||||
}
|
||||
|
||||
projects, _, err := testClient.Board.GetList(&boardsListOptions)
|
||||
projects, _, err := testClient.Board.GetList(boardsListOptions)
|
||||
if projects == nil {
|
||||
t.Error("Expected boards list. Boards list is nil")
|
||||
}
|
||||
@ -63,3 +63,72 @@ func TestBoardsGetFiltered(t *testing.T) {
|
||||
t.Errorf("Error given: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBoardGet(t *testing.T) {
|
||||
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"}`)
|
||||
})
|
||||
|
||||
board, _, err := testClient.Board.Get("1")
|
||||
if board == nil {
|
||||
t.Error("Expected board list. Board list is nil")
|
||||
}
|
||||
if err != nil {
|
||||
t.Errorf("Error given: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBoardGet_NoBoard(t *testing.T) {
|
||||
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)
|
||||
})
|
||||
|
||||
board, resp, err := testClient.Board.Get("99999999")
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBoardCreate(t *testing.T) {
|
||||
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",
|
||||
FilterId: 17,
|
||||
}
|
||||
issue, _, err := testClient.Board.Create(b)
|
||||
if issue == nil {
|
||||
t.Error("Expected board. Board is nil")
|
||||
}
|
||||
if err != nil {
|
||||
t.Errorf("Error given: %s", err)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user