forked from LouisAldorio/go-shopee-v2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logistics_test.go
77 lines (59 loc) · 2.33 KB
/
logistics_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
package goshopee
import (
"fmt"
"testing"
"github.com/jarcoal/httpmock"
)
func Test_GetChannelList(t *testing.T) {
setup()
defer teardown()
httpmock.RegisterResponder("GET", fmt.Sprintf("%s/api/v2/logistics/get_channel_list",app.APIURL),
httpmock.NewBytesResponder(200, loadFixture("channel_list.json")))
res,err:=client.Logistics.GetChannelList(shopID,accessToken)
if err!=nil {
t.Errorf("Logistics.GetChannelList error: %s",err)
}
t.Logf("Logistics.GetChannelList: %#v",res)
if len(res.Response.LogisticsChannelList)!=5 {
t.Errorf("LogisticsChannelList len return %v, expected 5",len(res.Response.LogisticsChannelList))
}
var expectedID uint64 = 5116
if res.Response.LogisticsChannelList[4].LogisticsChannelID != expectedID {
t.Errorf("LogisticsChannelList[4].LogisticsChannelID returned %+v, expected %+v",res.Response.LogisticsChannelList[4].LogisticsChannelID , expectedID)
}
}
func Test_GetShippingParameter(t *testing.T) {
setup()
defer teardown()
httpmock.RegisterResponder("GET", fmt.Sprintf("%s/api/v2/logistics/get_shipping_parameter",app.APIURL),
httpmock.NewBytesResponder(200, loadFixture("get_shipping_parameter_resp.json")))
res,err:=client.Logistics.GetShippingParameter(shopID,"SN123",accessToken)
if err!=nil {
t.Errorf("Logistics.GetShippingParameter error: %s",err)
}
t.Logf("Logistics.GetShippingParameter: %#v",res)
if len(res.Response.InfoNeeded.Pickup)!=2 {
t.Errorf("LogisticsChannelList len return %v, expected 2",len(res.Response.InfoNeeded.Pickup))
}
var expected string = "hhh, #34"
if res.Response.Pickup.AddressList[1].Address != expected {
t.Errorf("Pickup.AddressList[1].Address returned %+v, expected %+v",res.Response.Pickup.AddressList[1].Address , expected)
}
}
func Test_ShipOrder(t *testing.T) {
setup()
defer teardown()
httpmock.RegisterResponder("POST", fmt.Sprintf("%s/api/v2/logistics/ship_order",app.APIURL),
httpmock.NewBytesResponder(200, loadFixture("response.json")))
var req ShipOrderRequest
loadMockData("ship_order_req.json",&req)
res,err:=client.Logistics.ShipOrder(shopID,req,accessToken)
if err!=nil {
t.Errorf("Logistics.ShipOrder error: %s",err)
}
t.Logf("Logistics.ShipOrder: %#v",res)
var expected string = "f634ea27eff8461b8f6f9ffa1d7ddab2"
if res.RequestID != expected {
t.Errorf("RequestID returned %+v, expected %+v",res.RequestID , expected)
}
}