2016-06-01 14:13:11 +02:00
|
|
|
package jira
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
|
|
|
"net/http"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2016-07-17 12:13:08 +02:00
|
|
|
func TestProjectService_GetList(t *testing.T) {
|
2016-06-01 14:13:11 +02:00
|
|
|
setup()
|
|
|
|
defer teardown()
|
2016-06-03 23:25:18 +02:00
|
|
|
testAPIEdpoint := "/rest/api/2/project"
|
2016-06-01 14:13:11 +02:00
|
|
|
|
2016-06-03 23:16:21 +02:00
|
|
|
raw, err := ioutil.ReadFile("./mocks/all_projects.json")
|
2016-06-01 14:13:11 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err.Error())
|
|
|
|
}
|
2016-06-03 23:25:18 +02:00
|
|
|
testMux.HandleFunc(testAPIEdpoint, func(w http.ResponseWriter, r *http.Request) {
|
2016-06-01 14:13:11 +02:00
|
|
|
testMethod(t, r, "GET")
|
2016-06-03 23:25:18 +02:00
|
|
|
testRequestURL(t, r, testAPIEdpoint)
|
2016-06-01 14:13:11 +02:00
|
|
|
fmt.Fprint(w, string(raw))
|
|
|
|
})
|
|
|
|
|
|
|
|
projects, _, err := testClient.Project.GetList()
|
|
|
|
if projects == nil {
|
|
|
|
t.Error("Expected project list. Project list is nil")
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Error given: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-31 17:34:47 +02:00
|
|
|
func TestProjectService_ListWithOptions(t *testing.T) {
|
|
|
|
setup()
|
|
|
|
defer teardown()
|
|
|
|
testAPIEdpoint := "/rest/api/2/project"
|
|
|
|
|
|
|
|
raw, err := ioutil.ReadFile("./mocks/all_projects.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, "/rest/api/2/project?expand=issueTypes")
|
|
|
|
fmt.Fprint(w, string(raw))
|
|
|
|
})
|
|
|
|
|
|
|
|
projects, _, err := testClient.Project.ListWithOptions(&GetQueryOptions{Expand: "issueTypes"})
|
|
|
|
if projects == nil {
|
|
|
|
t.Error("Expected project list. Project list is nil")
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Error given: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-17 12:13:08 +02:00
|
|
|
func TestProjectService_Get(t *testing.T) {
|
2016-06-01 14:13:11 +02:00
|
|
|
setup()
|
|
|
|
defer teardown()
|
2016-06-03 23:25:18 +02:00
|
|
|
testAPIEdpoint := "/rest/api/2/project/12310505"
|
2016-06-01 14:13:11 +02:00
|
|
|
|
2016-06-03 23:16:21 +02:00
|
|
|
raw, err := ioutil.ReadFile("./mocks/project.json")
|
2016-06-01 14:13:11 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err.Error())
|
|
|
|
}
|
2016-06-03 23:25:18 +02:00
|
|
|
testMux.HandleFunc(testAPIEdpoint, func(w http.ResponseWriter, r *http.Request) {
|
2016-06-01 14:13:11 +02:00
|
|
|
testMethod(t, r, "GET")
|
2016-06-03 23:25:18 +02:00
|
|
|
testRequestURL(t, r, testAPIEdpoint)
|
2016-06-01 14:13:11 +02:00
|
|
|
fmt.Fprint(w, string(raw))
|
|
|
|
})
|
|
|
|
|
|
|
|
projects, _, err := testClient.Project.Get("12310505")
|
|
|
|
if projects == nil {
|
|
|
|
t.Error("Expected project list. Project list is nil")
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Error given: %s", err)
|
|
|
|
}
|
|
|
|
}
|
2016-06-01 20:36:11 +02:00
|
|
|
|
2016-07-17 12:13:08 +02:00
|
|
|
func TestProjectService_Get_NoProject(t *testing.T) {
|
2016-06-01 20:36:11 +02:00
|
|
|
setup()
|
|
|
|
defer teardown()
|
2016-06-03 23:25:18 +02:00
|
|
|
testAPIEdpoint := "/rest/api/2/project/99999999"
|
2016-06-01 20:36:11 +02:00
|
|
|
|
2016-06-03 23:25:18 +02:00
|
|
|
testMux.HandleFunc(testAPIEdpoint, func(w http.ResponseWriter, r *http.Request) {
|
2016-06-01 20:36:11 +02:00
|
|
|
testMethod(t, r, "GET")
|
2016-06-03 23:25:18 +02:00
|
|
|
testRequestURL(t, r, testAPIEdpoint)
|
2016-06-01 20:36:11 +02:00
|
|
|
fmt.Fprint(w, nil)
|
|
|
|
})
|
|
|
|
|
2016-06-02 14:59:40 +02:00
|
|
|
projects, resp, err := testClient.Project.Get("99999999")
|
2016-06-01 20:36:11 +02:00
|
|
|
if projects != nil {
|
2016-06-03 23:25:18 +02:00
|
|
|
t.Errorf("Expected nil. Got %+v", projects)
|
2016-06-01 20:36:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if resp.Status == "404" {
|
|
|
|
t.Errorf("Expected status 404. Got %s", resp.Status)
|
|
|
|
}
|
|
|
|
if err == nil {
|
|
|
|
t.Errorf("Error given: %s", err)
|
|
|
|
}
|
|
|
|
}
|
2018-05-12 09:28:05 +02:00
|
|
|
|
2018-05-14 21:35:03 +02:00
|
|
|
func TestProjectService_GetPermissionScheme_Failure(t *testing.T) {
|
2018-05-12 09:28:05 +02:00
|
|
|
setup()
|
|
|
|
defer teardown()
|
|
|
|
testAPIEdpoint := "/rest/api/2/project/99999999/permissionscheme"
|
|
|
|
|
|
|
|
testMux.HandleFunc(testAPIEdpoint, func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
testMethod(t, r, "GET")
|
|
|
|
testRequestURL(t, r, testAPIEdpoint)
|
|
|
|
fmt.Fprint(w, nil)
|
|
|
|
})
|
|
|
|
|
2018-05-14 21:35:03 +02:00
|
|
|
permissionScheme, resp, err := testClient.Project.GetPermissionScheme("99999999")
|
|
|
|
if permissionScheme != nil {
|
|
|
|
t.Errorf("Expected nil. Got %+v", permissionScheme)
|
2018-05-12 09:28:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if resp.Status == "404" {
|
|
|
|
t.Errorf("Expected status 404. Got %s", resp.Status)
|
|
|
|
}
|
|
|
|
if err == nil {
|
|
|
|
t.Errorf("Error given: %s", err)
|
|
|
|
}
|
|
|
|
}
|
2018-05-14 21:35:03 +02:00
|
|
|
|
|
|
|
func TestProjectService_GetPermissionScheme_Success(t *testing.T) {
|
|
|
|
setup()
|
|
|
|
defer teardown()
|
|
|
|
testAPIEdpoint := "/rest/api/2/project/99999999/permissionscheme"
|
|
|
|
|
|
|
|
testMux.HandleFunc(testAPIEdpoint, func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
testMethod(t, r, "GET")
|
|
|
|
testRequestURL(t, r, testAPIEdpoint)
|
|
|
|
fmt.Fprint(w, `{
|
|
|
|
"expand": "permissions,user,group,projectRole,field,all",
|
|
|
|
"id": 10201,
|
|
|
|
"self": "https://www.example.com/rest/api/2/permissionscheme/10201",
|
|
|
|
"name": "Project for specific-users",
|
|
|
|
"description": "Projects that can only see for people belonging to specific-users group"
|
|
|
|
}`)
|
|
|
|
})
|
|
|
|
|
|
|
|
permissionScheme, resp, err := testClient.Project.GetPermissionScheme("99999999")
|
|
|
|
if permissionScheme.ID != 10201 {
|
|
|
|
t.Errorf("Expected Permission Scheme ID. Got %+v", permissionScheme)
|
|
|
|
}
|
|
|
|
|
|
|
|
if resp.Status == "404" {
|
|
|
|
t.Errorf("Expected status 404. Got %s", resp.Status)
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Error given: %s", err)
|
|
|
|
}
|
|
|
|
}
|