143 lines
8.3 KiB
Go
143 lines
8.3 KiB
Go
package elmapi
|
|
|
|
import (
|
|
"net/http"
|
|
"testing"
|
|
|
|
"git.rosy.net.cn/baseapi"
|
|
|
|
"git.rosy.net.cn/baseapi/utils"
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
var (
|
|
elmapi *API
|
|
sugarLogger *zap.SugaredLogger
|
|
)
|
|
|
|
func init() {
|
|
logger, _ := zap.NewDevelopment()
|
|
sugarLogger = logger.Sugar()
|
|
baseapi.Init(sugarLogger)
|
|
|
|
// sandbox
|
|
elmapi = New("623c0904c0d2499e83df15b62902eb65", "RwT214gAsS", "56afff4b9ebd8a7eb532d18fa33f17be57f9b9db", false)
|
|
// prod
|
|
// elmapi = New("cf5710018b46e75145eb0f19900bcecd", "KLRDcOZGrk", "1fc221f8265506531da36fb613d5f5ad673f2e9a", true)
|
|
}
|
|
|
|
func TestTest(t *testing.T) {
|
|
sugarLogger.Debug(utils.GetCurTimeStr())
|
|
}
|
|
|
|
func TestAccessAPI(t *testing.T) {
|
|
result, err := elmapi.AccessAPI("eleme.user.getUser", nil)
|
|
if err != nil {
|
|
t.Fatalf("Error when accessing AccessJDQuery result:%v, error:%v", result, err)
|
|
} else {
|
|
mapResult := result.Result.(map[string]interface{})
|
|
userId := utils.MustInterface2Int64(mapResult["userId"])
|
|
if userId != 336072266326420104 || err != nil {
|
|
t.Fatalf("userId is not correct:%v", mapResult["userId"])
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestCallbackSign(t *testing.T) {
|
|
jsonStr := `{"requestId":"200016348669063447","type":18,"appId":78247922,"message":"{\"orderId\":\"3024923917769149510\",\"state\":\"settled\",\"shopId\":157492364,\"updateTime\":1529465510,\"role\":1}","shopId":157492364,"timestamp":1529465510255,"signature":"D65F917D93B4F599B85486C799599141","userId":336072266322770688}`
|
|
msg, response := elmapi.GetCallbackMsg([]byte(jsonStr))
|
|
if response != nil || msg == nil {
|
|
t.Fatal(response, msg)
|
|
}
|
|
}
|
|
|
|
func TestRefreshTokenIndividual(t *testing.T) {
|
|
result, err := elmapi.RefreshTokenIndividual()
|
|
if err != nil {
|
|
t.Fatal(err.Error())
|
|
}
|
|
sugarLogger.Debug(result)
|
|
}
|
|
|
|
func TestCallbackMsgPlayback(t *testing.T) {
|
|
baseURL := "http://callback.test.jxc4.com:8080/"
|
|
playbackData := [][]string{
|
|
[]string{
|
|
"{\"requestId\":\"200016744375484334\",\"type\":10,\"appId\":78247922,\"message\":\"{\\\"id\\\":\\\"3025365125607913707\\\",\\\"orderId\\\":\\\"3025365125607913707\\\",\\\"address\\\":\\\"新世纪百货(民心佳园店)民心家园45栋22-3 民心佳园45栋22-3\\\",\\\"createdAt\\\":\\\"2018-06-28T14:25:53\\\",\\\"activeAt\\\":\\\"2018-06-28T14:25:53\\\",\\\"deliverFee\\\":1.0,\\\"deliverTime\\\":null,\\\"description\\\":\\\"猪脚砍成小块 一定要砍 谢谢\\\",\\\"groups\\\":[{\\\"name\\\":\\\"1号篮子\\\",\\\"type\\\":\\\"normal\\\",\\\"items\\\":[{\\\"id\\\":1419971532,\\\"skuId\\\":200000225250841518,\\\"name\\\":\\\"前脚约450g/份\\\",\\\"categoryId\\\":1,\\\"price\\\":32.0,\\\"quantity\\\":1,\\\"total\\\":32.0,\\\"additions\\\":[],\\\"newSpecs\\\":[],\\\"attributes\\\":[],\\\"extendCode\\\":\\\"\\\",\\\"barCode\\\":\\\"1631\\\",\\\"weight\\\":450.0,\\\"userPrice\\\":0.0,\\\"shopPrice\\\":0.0,\\\"vfoodId\\\":1392153708},{\\\"id\\\":1419974600,\\\"skuId\\\":200000225254000558,\\\"name\\\":\\\"红花生米约500g/份\\\",\\\"categoryId\\\":1,\\\"price\\\":11.43,\\\"quantity\\\":1,\\\"total\\\":11.43,\\\"additions\\\":[],\\\"newSpecs\\\":[],\\\"attributes\\\":[],\\\"extendCode\\\":\\\"\\\",\\\"barCode\\\":\\\"654\\\",\\\"weight\\\":500.0,\\\"userPrice\\\":0.0,\\\"shopPrice\\\":0.0,\\\"vfoodId\\\":1392165882},{\\\"id\\\":1419958462,\\\"skuId\\\":200000225237475246,\\\"name\\\":\\\"莲藕约500g/份\\\",\\\"categoryId\\\":1,\\\"price\\\":8.0,\\\"quantity\\\":1,\\\"total\\\":8.0,\\\"additions\\\":[],\\\"newSpecs\\\":[],\\\"attributes\\\":[],\\\"extendCode\\\":\\\"\\\",\\\"barCode\\\":\\\"3171\\\",\\\"weight\\\":500.0,\\\"userPrice\\\":0.0,\\\"shopPrice\\\":0.0,\\\"vfoodId\\\":1392164749}]}],\\\"invoice\\\":null,\\\"book\\\":false,\\\"onlinePaid\\\":true,\\\"railwayAddress\\\":null,\\\"phoneList\\\":[\\\"18983425091\\\"],\\\"shopId\\\":157465482,\\\"shopName\\\":\\\"好菜鲜生(民心店)\\\",\\\"daySn\\\":3,\\\"status\\\":\\\"unprocessed\\\",\\\"refundStatus\\\":\\\"noRefund\\\",\\\"userId\\\":82003158,\\\"userIdStr\\\":\\\"82003158\\\",\\\"totalPrice\\\":37.43,\\\"originalPrice\\\":52.43,\\\"consignee\\\":\\\"代**\\\",\\\"deliveryGeo\\\":\\\"106.56272398,29.62484594\\\",\\\"deliveryPoiAddress\\\":\\\"新世纪百货(民心佳园店)民心家园45栋22-3 民心佳园45栋22-3\\\",\\\"invoiced\\\":false,\\\"income\\\":35.56,\\\"serviceRate\\\":0.05,\\\"serviceFee\\\":-1.87,\\\"hongbao\\\":0.0,\\\"packageFee\\\":0.0,\\\"activityTotal\\\":-15.0,\\\"shopPart\\\":-15.0,\\\"elemePart\\\":-0.0,\\\"downgraded\\\":false,\\\"vipDeliveryFeeDiscount\\\":0.0,\\\"openId\\\":\\\"\\\",\\\"secretPhoneExpireTime\\\":null,\\\"orderActivities\\\":[{\\\"categoryId\\\":12,\\\"name\\\":\\\"在线支付立减优惠\\\",\\\"amount\\\":-15.0,\\\"elemePart\\\":0.0,\\\"restaurantPart\\\":-15.0,\\\"familyPart\\\":0.0,\\\"id\\\":1236491610,\\\"orderAllPartiesPartList\\\":[{\\\"partName\\\":\\\"商家补贴\\\",\\\"partAmount\\\":\\\"15.0\\\"}]}],\\\"invoiceType\\\":null,\\\"taxpayerId\\\":\\\"\\\",\\\"coldBoxFee\\\":0.0,\\\"cancelOrderDescription\\\":null,\\\"cancelOrderCreatedAt\\\":null,\\\"orderCommissions\\\":[]}\",\"shopId\":157465482,\"timestamp\":1530167153482,\"signature\":\"9A1D366FE631A54390A20A2E023B41A8\",\"userId\":336072266326420104}",
|
|
baseURL + "eleme/msg",
|
|
"application/json; charset=utf-8",
|
|
},
|
|
[]string{
|
|
"{\"requestId\":\"200016744381715374\",\"type\":12,\"appId\":78247922,\"message\":\"{\\\"orderId\\\":\\\"3025365125607913707\\\",\\\"state\\\":\\\"valid\\\",\\\"shopId\\\":157465482,\\\"updateTime\\\":1530167232,\\\"role\\\":3}\",\"shopId\":157465482,\"timestamp\":1530167232500,\"signature\":\"4B491256CC0015603F12CACAE9AFA004\",\"userId\":336072266326420104}",
|
|
baseURL + "eleme/msg",
|
|
"application/json; charset=utf-8",
|
|
},
|
|
[]string{
|
|
"sign=d75dc693f00ced3ace82c46a46a57e0e61034f14×tamp=1530168075&delivery_id=423296&status=0&appkey=3c0a05d464c247c19d7ec13accc78605&order_id=3025365125607913707&mt_peisong_id=1530168075083323",
|
|
baseURL + "mtps/status",
|
|
"",
|
|
},
|
|
[]string{
|
|
"sign=f539529a0c1db827135f5ff576d581016ef9f8ef×tamp=1530168134&delivery_id=423296&status=20&appkey=3c0a05d464c247c19d7ec13accc78605&courier_phone=17783604157&courier_name=%E7%99%BD%E5%B7%9D%E8%8B%B1&order_id=3025365125607913707&mt_peisong_id=1530168075083323",
|
|
baseURL + "mtps/status",
|
|
"",
|
|
},
|
|
[]string{
|
|
"sign=552cd6f662e7117d9975d55a86313bdf7cdce964×tamp=1530169704&delivery_id=423296&status=30&appkey=3c0a05d464c247c19d7ec13accc78605&courier_phone=17783604157&courier_name=%E7%99%BD%E5%B7%9D%E8%8B%B1&order_id=3025365125607913707&mt_peisong_id=1530168075083323",
|
|
baseURL + "mtps/status",
|
|
"",
|
|
},
|
|
[]string{
|
|
"sign=eec01e70060faa86a81d9e5ee520db69594504e0×tamp=1530169998&delivery_id=423296&status=50&appkey=3c0a05d464c247c19d7ec13accc78605&courier_phone=17783604157&courier_name=%E7%99%BD%E5%B7%9D%E8%8B%B1&order_id=3025365125607913707&mt_peisong_id=1530168075083323",
|
|
baseURL + "mtps/status",
|
|
"",
|
|
},
|
|
[]string{
|
|
"{\"requestId\":\"200016744576047022\",\"type\":18,\"appId\":78247922,\"message\":\"{\\\"orderId\\\":\\\"3025365125607913707\\\",\\\"state\\\":\\\"settled\\\",\\\"shopId\\\":157465482,\\\"updateTime\\\":1530169999,\\\"role\\\":3}\",\"shopId\":157465482,\"timestamp\":1530169999773,\"signature\":\"7D0DCE6C3514B16DA97171E5CDFABE0F\",\"userId\":336072266326420104}",
|
|
baseURL + "eleme/msg",
|
|
"application/json; charset=utf-8",
|
|
},
|
|
}
|
|
for _, v := range playbackData {
|
|
_, err := utils.SendFakeRequest(http.MethodPost, v[1], v[0], v[2])
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestConfirmOrder(t *testing.T) {
|
|
err := elmapi.ConfirmOrder("3023582487561731159")
|
|
if err != nil {
|
|
t.Fatalf("Error when accessing ConfirmOrdererror:%v", err)
|
|
}
|
|
}
|
|
|
|
func TestCancelOrder(t *testing.T) {
|
|
err := elmapi.CancelOrder("3023582487561731159", CancelOrderTypeOthers, "")
|
|
if err != nil {
|
|
t.Fatalf("Error when accessing ConfirmOrdererror:%v", err)
|
|
}
|
|
}
|
|
|
|
func TestDeliveryBySelfLite(t *testing.T) {
|
|
err := elmapi.DeliveryBySelfLite("3023582487561731159")
|
|
if err != nil {
|
|
t.Fatalf("Error when accessing ConfirmOrdererror:%v", err)
|
|
}
|
|
}
|
|
|
|
func TestStartDeliveryBySelf(t *testing.T) {
|
|
err := elmapi.StartDeliveryBySelf("3023582487561731159", "13812345678")
|
|
if err != nil {
|
|
t.Fatalf("Error when accessing ConfirmOrdererror:%v", err)
|
|
}
|
|
}
|
|
|
|
func TestCompleteDeliveryBySelf(t *testing.T) {
|
|
err := elmapi.CompleteDeliveryBySelf("3023582487561731159", "13812345678")
|
|
if err != nil {
|
|
t.Fatalf("Error when accessing ConfirmOrdererror:%v", err)
|
|
}
|
|
}
|