-
Notifications
You must be signed in to change notification settings - Fork 0
/
filter_test.go
126 lines (114 loc) · 3.13 KB
/
filter_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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package jira
import (
"fmt"
"io/ioutil"
"net/http"
"testing"
)
func TestFilterService_GetList(t *testing.T) {
setup()
defer teardown()
testAPIEndpoint := "/rest/api/2/filter"
raw, err := ioutil.ReadFile("./mocks/all_filters.json")
if err != nil {
t.Error(err.Error())
}
testMux.HandleFunc(testAPIEndpoint, func(writer http.ResponseWriter, request *http.Request) {
testMethod(t, request, "GET")
testRequestURL(t, request, testAPIEndpoint)
fmt.Fprint(writer, string(raw))
})
filters, _, err := testClient.Filter.GetList()
if filters == nil {
t.Error("Expected Filters list. Filters list is nil")
}
if err != nil {
t.Errorf("Error given: %s", err)
}
}
func TestFilterService_Get(t *testing.T) {
setup()
defer teardown()
testAPIEndpoint := "/rest/api/2/filter/10000"
raw, err := ioutil.ReadFile("./mocks/filter.json")
if err != nil {
t.Error(err.Error())
}
testMux.HandleFunc(testAPIEndpoint, func(writer http.ResponseWriter, request *http.Request) {
testMethod(t, request, "GET")
testRequestURL(t, request, testAPIEndpoint)
fmt.Fprint(writer, string(raw))
})
filter, _, err := testClient.Filter.Get(10000)
if filter == nil {
t.Errorf("Expected Filter, got nil")
}
if err != nil {
t.Errorf("Error given: %s", err)
}
}
func TestFilterService_GetFavouriteList(t *testing.T) {
setup()
defer teardown()
testAPIEndpoint := "/rest/api/2/filter/favourite"
raw, err := ioutil.ReadFile("./mocks/favourite_filters.json")
if err != nil {
t.Error(err.Error())
}
testMux.HandleFunc(testAPIEndpoint, func(writer http.ResponseWriter, request *http.Request) {
testMethod(t, request, "GET")
testRequestURL(t, request, testAPIEndpoint)
fmt.Fprint(writer, string(raw))
})
filters, _, err := testClient.Filter.GetFavouriteList()
if filters == nil {
t.Error("Expected Filters list. Filters list is nil")
}
if err != nil {
t.Errorf("Error given: %s", err)
}
}
func TestFilterService_GetMyFilters(t *testing.T) {
setup()
defer teardown()
testAPIEndpoint := "/rest/api/3/filter/my"
raw, err := ioutil.ReadFile("./mocks/my_filters.json")
if err != nil {
t.Error(err.Error())
}
testMux.HandleFunc(testAPIEndpoint, func(writer http.ResponseWriter, request *http.Request) {
testMethod(t, request, "GET")
testRequestURL(t, request, testAPIEndpoint)
fmt.Fprint(writer, string(raw))
})
opts := GetMyFiltersQueryOptions{}
filters, _, err := testClient.Filter.GetMyFilters(&opts)
if err != nil {
t.Errorf("Error given: %s", err)
}
if filters == nil {
t.Errorf("Expected Filters, got nil")
}
}
func TestFilterService_Search(t *testing.T) {
setup()
defer teardown()
testAPIEndpoint := "/rest/api/3/filter/search"
raw, err := ioutil.ReadFile("./mocks/search_filters.json")
if err != nil {
t.Error(err.Error())
}
testMux.HandleFunc(testAPIEndpoint, func(writer http.ResponseWriter, request *http.Request) {
testMethod(t, request, "GET")
testRequestURL(t, request, testAPIEndpoint)
fmt.Fprint(writer, string(raw))
})
opt := FilterSearchOptions{}
filters, _, err := testClient.Filter.Search(&opt)
if err != nil {
t.Errorf("Error given: %s", err)
}
if filters == nil {
t.Errorf("Expected Filters, got nil")
}
}