This repository has been archived by the owner on Jul 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
/
checkpoints_test.go
150 lines (134 loc) · 3.62 KB
/
checkpoints_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
package aftership
import (
"context"
"fmt"
"net/http"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestGetLastCheckpoint(t *testing.T) {
setup()
defer teardown()
p := SlugTrackingNumber{
Slug: "xq-express",
TrackingNumber: "LS404494276CN",
}
uri := fmt.Sprintf("/last_checkpoint/%s/%s", p.Slug, p.TrackingNumber)
mux.HandleFunc(uri, func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, http.MethodGet, r.Method)
w.Header().Set("content-type", "application/json")
w.Write([]byte(`{
"meta": {
"code": 200
},
"data": {
"id": "5b74f4958776db0e00b6f5ed",
"tracking_number": "111111111111",
"slug": "fedex",
"tag": "Delivered",
"subtag": "Delivered_001",
"subtag_message": "Delivered",
"checkpoint": {
"slug": "fedex",
"created_at": "2018-08-16T03:50:47+00:00",
"checkpoint_time": "2018-08-01T13:19:47-04:00",
"city": "Deal",
"coordinates": [],
"country_iso3": null,
"country_name": null,
"message": "Delivered - Left at front door. Signature Service not requested.",
"state": "NJ",
"tag": "Delivered",
"subtag": "Delivered_001",
"subtag_message": "Delivered",
"zip": null,
"raw_tag": "FPX_L_RPIF"
}
}
}`))
})
createdAt, _ := time.Parse(time.RFC3339, "2018-08-16T03:50:47+00:00")
exp := LastCheckpoint{
ID: "5b74f4958776db0e00b6f5ed",
TrackingNumber: "111111111111",
Slug: "fedex",
Tag: "Delivered",
Subtag: "Delivered_001",
SubtagMessage: "Delivered",
Checkpoint: Checkpoint{
Slug: "fedex",
CreatedAt: &createdAt,
CheckpointTime: "2018-08-01T13:19:47-04:00",
City: "Deal",
Coordinates: []float32{},
Message: "Delivered - Left at front door. Signature Service not requested.",
State: "NJ",
Tag: "Delivered",
Subtag: "Delivered_001",
SubtagMessage: "Delivered",
RawTag: "FPX_L_RPIF",
},
}
res, err := client.GetLastCheckpoint(context.Background(), p, GetCheckpointParams{})
assert.Equal(t, exp, res)
assert.Nil(t, err)
}
func TestGetLastCheckpointWithOptionalParams(t *testing.T) {
setup()
defer teardown()
p := SlugTrackingNumber{
Slug: "xq-express",
TrackingNumber: "LS404494276CN",
}
op := GetCheckpointParams{
Fields: "slug",
Lang: "en",
}
uri := fmt.Sprintf("/last_checkpoint/%s/%s", p.Slug, p.TrackingNumber)
mux.HandleFunc(uri, func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, http.MethodGet, r.Method)
w.Header().Set("content-type", "application/json")
w.Write([]byte(`{
"meta": {
"code": 200
},
"data": {
"id": "5b74f4958776db0e00b6f5ed",
"tracking_number": "111111111111",
"slug": "fedex",
"tag": "Delivered",
"subtag": "Delivered_001",
"subtag_message": "Delivered",
"checkpoint": {
"slug": "fedex"
}
}
}`))
})
exp := LastCheckpoint{
ID: "5b74f4958776db0e00b6f5ed",
TrackingNumber: "111111111111",
Slug: "fedex",
Tag: "Delivered",
Subtag: "Delivered_001",
SubtagMessage: "Delivered",
Checkpoint: Checkpoint{
Slug: "fedex",
},
}
res, err := client.GetLastCheckpoint(context.Background(), p, op)
assert.Equal(t, exp, res)
assert.Nil(t, err)
}
func TestError(t *testing.T) {
setup()
defer teardown()
// empty id, slug and tracking_number
p := SlugTrackingNumber{
Slug: "",
TrackingNumber: "",
}
_, err := client.GetLastCheckpoint(context.Background(), p, GetCheckpointParams{})
assert.NotNil(t, err)
}