-
Notifications
You must be signed in to change notification settings - Fork 6
/
client_test.go
119 lines (84 loc) · 2.69 KB
/
client_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
package invoiced
import (
"strconv"
"testing"
)
func TestParseRawRelation(t *testing.T) {
s := " rel=\" self \" "
parsed := parseRelValue(s)
if parsed != "self" {
t.Fatal("Error: Parsing of relation is not self")
}
}
func TestParseRawURL(t *testing.T) {
s := " < https://api.invoiced.com/invoices?page=1 > "
parsed := parseLinkUrl(s)
if parsed != "https://api.invoiced.com/invoices?page=1" {
t.Fatal("Error: Parsing of URL", " parsed => ", parsed)
}
}
func TestAddFilterSortToEndpointWithBothValues(t *testing.T) {
f := NewFilter()
err := f.Set("id", 121123)
if err != nil {
t.Fatal(err)
}
err = f.Set("address", 121123)
if err != nil {
t.Fatal(err)
}
s := NewSort()
s.Set("name", ASC)
s.Set("age", DESC)
endpoint := "https://www.do.com"
value := AddFilterAndSort(endpoint, f, s)
correctValue := "https://www.do.com?filter%5Baddress%5D=121123&filter%5Bid%5D=121123&sort=age+DESC%2Cname+ASC"
if value != correctValue {
t.Fatal("Error: resulting URL is incorrect it should be ", correctValue, " but instead got ", value)
}
// endpoint2 := "https://www.do.com?"
}
func TestAddFilterSortToEndpointWithOnlySort(t *testing.T) {
s := NewSort()
s.Set("name", ASC)
s.Set("age", DESC)
endpoint := "https://www.do.com"
value := AddFilterAndSort(endpoint, nil, s)
correctValue := "https://www.do.com?sort=age+DESC%2Cname+ASC"
if value != correctValue {
t.Fatal("Error: resulting URL is incorrect it should be ", correctValue, " but instead got ", value)
}
}
func TestAddFilterSortToEndpointWithOnlyFilter(t *testing.T) {
f := NewFilter()
err := f.Set("id", 121123)
if err != nil {
t.Fatal(err)
}
err = f.Set("address", 121123)
if err != nil {
t.Fatal(err)
}
endpoint := "https://www.do.com"
value := AddFilterAndSort(endpoint, f, nil)
correctValue := "https://www.do.com?filter%5Baddress%5D=121123&filter%5Bid%5D=121123"
if value != correctValue {
t.Fatal("Error: resulting URL is incorrect it should be ", correctValue, " but instead got ", value)
}
}
func TestAddFilterSortToEndpointWithNothing(t *testing.T) {
endpoint := "https://www.do.com"
value := AddFilterAndSort(endpoint, nil, nil)
correctValue := "https://www.do.com"
if value != correctValue {
t.Fatal("Error: resulting URL is incorrect it should be ", correctValue, " but instead got ", value)
}
}
func TestMakeEndpointSingular(t *testing.T) {
endpoint := "https://www.do.com/customer"
singularEndpoint := endpoint + "/" + strconv.FormatInt(5, 10)
correctSingularEndpoint := "https://www.do.com/customer/5"
if singularEndpoint != correctSingularEndpoint {
t.Fatal("Expect =>", singularEndpoint, " Got =>", correctSingularEndpoint)
}
}