Files
baseapi/platformapi/mtpsapi/mtpsapi_test.go

146 lines
3.9 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package mtpsapi
import (
"strings"
"testing"
"git.rosy.net.cn/baseapi"
"git.rosy.net.cn/baseapi/utils"
"go.uber.org/zap"
)
var (
api *API
sugarLogger *zap.SugaredLogger
)
func init() {
logger, _ := zap.NewDevelopment()
sugarLogger = logger.Sugar()
baseapi.Init(sugarLogger)
// sandbox
api = New("25e816550bc9484480642f19a95f13fd", "r4$HqrKx9~=7?2Jfo,$Z~a7%~k!Au&pEdI2)oPJvSbH2ao@2N0[8wSIvtuumh_J^")
// prod
// api = New("3c0a05d464c247c19d7ec13accc78605", "b1M}9?:sTbsB[OF2gNORnN(|(iy9rB8(`7]|[wGLnbmt`evfM>E:A90DjHAW:UPE")
}
func handleError(t *testing.T, err error) {
if err != nil {
sugarLogger.Debug(err)
t.Fatal(err.Error())
}
}
func TestTest(t *testing.T) {
sugarLogger.Debug(utils.GetCurTimeStr())
tmpStr := "this is a\u00A0"
sugarLogger.Debug(strings.Trim(tmpStr, " \u00A0"))
}
func TestAccessAPI(t *testing.T) {
mtPeiSongId := "1529387562097059"
params := map[string]interface{}{
"delivery_id": 123456789,
"mt_peisong_id": mtPeiSongId,
}
result, err := api.AccessAPI("order/status/query", params)
if err != nil {
t.Fatalf("Error when accessing AccessAPI result:%v, error:%v", result, err)
} else {
getMtPsId := result.Data["mt_peisong_id"].(string)
if getMtPsId != mtPeiSongId {
t.Fatalf("mt_peisong_id is not same, %v vs %v", mtPeiSongId, getMtPsId)
}
}
}
func TestCreateOrderByShop(t *testing.T) {
basicParams := &CreateOrderByShopParam{
DeliveryID: 123456789,
OrderID: "order_123456789",
// 设置测试门店 id测试门店的坐标地址为 97235456,31065079高德坐标配送范围3km
ShopID: "test_0001",
DeliveryServiceCode: DeliveryServiceCodeIntime,
ReceiverName: "xjh",
ReceiverAddress: "九里堤",
ReceiverPhone: "18112345678",
ReceiverLng: 97235456,
ReceiverLat: 31065079,
CoordinateType: CoordinateTypeMars,
GoodsValue: 12.34,
GoodsWeight: 3.4,
OrderType: OrderTypeASAP,
}
order, err := api.CreateOrderByShop(basicParams, nil)
handleError(t, err)
if order != nil {
sugarLogger.Debugf("order:%v", order)
}
}
func TestShopQuery(t *testing.T) {
shopInfo, err := api.ShopQuery("not exist")
if err == nil {
t.Fatal("应该报错找不到门店")
}
shopInfo, err = api.ShopQuery("11726346")
if err != nil {
t.Fatal(err)
}
t.Log(utils.Format4Output(shopInfo, false))
}
func TestShopCreate(t *testing.T) {
shopInfo := &ShopInfo{
ShopID: "11726346",
ShopName: "测试门店",
Category: ShopCategoryFruit,
SecondCategory: ShopCategoryFruitFruit,
ContactName: "徐",
ContactPhone: "18180948107",
ShopAddress: "北京市通州区五所南路与玉桥西路南延交叉口北100米梨园农副产品交易中心 水果区",
ShopLng: 116672496,
ShopLat: 39879491,
CoordinateType: CoordinateTypeMars,
DeliveryServiceCodes: utils.Int2Str(DeliveryServiceCodeRapid),
BusinessHours: "[{\"beginTime\":\"09:00\",\"endTime\":\"18:00\"}]",
}
_, err := api.ShopCreate(shopInfo)
if err != nil {
t.Fatal(err)
}
}
func TestSimulateArrange(t *testing.T) {
err := api.SimulateArrange(123456789, "1529387562097059")
handleError(t, err)
}
func TestSimulatePickup(t *testing.T) {
err := api.SimulatePickup(123456789, "1529387562097059")
handleError(t, err)
}
func TestSimulateRearrange(t *testing.T) {
err := api.SimulateRearrange(123456789, "1529387562097059")
handleError(t, err)
}
func TestSimulateDeliver(t *testing.T) {
err := api.SimulateDeliver(123456789, "1529387562097059")
handleError(t, err)
}
func TestSimulateReportException(t *testing.T) {
err := api.SimulateReportException(123456789, "1529387562097059")
handleError(t, err)
}
func TestCancelOrder(t *testing.T) {
result, err := api.CancelOrder(123456789, "1529387562097059", CancelReasonMerchantOther, "just a test")
handleError(t, err)
sugarLogger.Debug(result)
}