-
Notifications
You must be signed in to change notification settings - Fork 7
/
category_test.go
60 lines (53 loc) · 1.43 KB
/
category_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package openproject
import (
"fmt"
"net/http"
"os"
"testing"
)
func TestCategoryService_Get(t *testing.T) {
setup()
defer teardown()
testAPIEndpoint := "/api/v3/categories/1"
raw, err := os.ReadFile("./mocks/get/get-category.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))
})
category, _, err := testClient.Category.Get("1")
if err != nil {
t.Errorf("Error given: %s", err)
}
if category == nil {
t.Error("Expected category. Category is nil")
return
}
if category.Name != "Category 1 (to be changed in Project settings)" {
t.Errorf("Unexpected category name %s", category.Name)
}
}
func TestCategoryService_GetList(t *testing.T) {
setup()
defer teardown()
testAPIEdpoint := "/api/v3/projects/demo-project/categories/"
raw, err := os.ReadFile("./mocks/get/get-categories-from-project-no-filters.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))
})
categories, _, err := testClient.Category.GetList("demo-project", 0, 10)
if categories == nil {
t.Error("Expected category list from project, but received nil")
}
if err != nil {
t.Errorf("Error given: %s", err)
}
}