-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathshipments_test.go
154 lines (135 loc) · 2.9 KB
/
shipments_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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
package postmaster
import (
"testing"
)
func TestShipmentNew(t *testing.T) {
pm := New("apikey")
s := pm.Shipment()
if s.Id != -1 {
t.Error("new shipment should have ID = -1")
}
if s.p != pm {
t.Error("new shipment should have Postmaster instance initialized")
}
}
func TestShipmentCreate(t *testing.T) {
// Mock
c := make(chan *restMockObj, 1)
post = restMock(c, nil, 100, nil)
pm := New("apikey")
s := pm.Shipment()
s.Create()
ret := <-c
if ret.endpoint != "shipments" {
t.Error("wrong endpoint")
}
if ret.version != "v1" {
t.Error("wrong version")
}
s.Id = 1
_, err := s.Create()
if err == nil {
t.Error("it shouldn't be possible to create an existing shipment")
}
}
func TestShipmentGet(t *testing.T) {
// Mock
c := make(chan *restMockObj, 1)
get = restMockGet(c, nil, 100, nil)
pm := New("apikey")
s := pm.Shipment()
_, err := s.Get()
if err == nil {
t.Error("it shouldn't be possible to get a non-existing shipment")
}
s.Id = 1234
_, err = s.Get()
if err != nil {
t.Error("err should be nil")
}
ret := <-c
if ret.endpoint != "shipments/1234" {
t.Error("wrong endpoint")
}
if ret.version != "v1" {
t.Error("wrong version")
}
}
func TestShipmentVoid(t *testing.T) {
// Mock
c := make(chan *restMockObj, 1)
del = restMock(c, nil, 100, nil)
pm := New("apikey")
s := pm.Shipment()
_, err := s.Void()
if err == nil {
t.Error("it shouldn't be possible to void a non-existing shipment")
}
s.Id = 1234
_, err = s.Void()
if err != nil {
t.Error("err should be nil")
}
ret := <-c
if ret.endpoint != "shipments/1234/void" {
t.Error("wrong endpoint")
}
if ret.version != "v1" {
t.Error("wrong version")
}
}
func TestShipmentTrack(t *testing.T) {
// Mock
c := make(chan *restMockObj, 1)
get = restMockGet(c, nil, 100, nil)
pm := New("apikey")
s := pm.Shipment()
_, err := s.Track()
if err == nil {
t.Error("it shouldn't be possible to track a non-existing shipment")
}
s.Id = 1234
_, err = s.Track()
if err != nil {
t.Error("err should be nil")
}
ret := <-c
if ret.endpoint != "shipments/1234/track" {
t.Error("wrong endpoint")
}
if ret.version != "v1" {
t.Error("wrong version")
}
}
func TestShipmentList(t *testing.T) {
// Mock
c := make(chan *restMockObj, 1)
get = restMockGet(c, nil, 100, nil)
pm := New("apikey")
pm.ListShipments(10, "cursor", "Delivered")
ret := <-c
if ret.endpoint != "shipments" {
t.Error("wrong endpoint")
}
if ret.version != "v1" {
t.Error("wrong version")
}
}
func TestShipmentFind(t *testing.T) {
// Mock
c := make(chan *restMockObj, 1)
get = restMockGet(c, nil, 100, nil)
pm := New("apikey")
_, err := pm.FindShipments("", 10, "cursor")
if err == nil {
t.Error("you shouldn't be able to give empty search query")
}
pm.FindShipments("query", 10, "cursor")
ret := <-c
if ret.endpoint != "shipments/search" {
t.Error("wrong endpoint")
}
if ret.version != "v1" {
t.Error("wrong version")
}
}