Files
baseapi/platformapi/jdapi/store_test.go

142 lines
3.6 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 jdapi
import (
"testing"
"time"
"git.rosy.net.cn/baseapi"
"git.rosy.net.cn/baseapi/utils"
)
const (
mustExistStoreID = "11053496"
mustExistStoreJXID = "2"
)
func TestGetAllCities(t *testing.T) {
result, err := api.GetAllCities()
if err != nil {
t.Fatal(err)
}
t.Log(utils.Format4Output(result, false))
}
func TestGetStationsByVenderId(t *testing.T) {
result, err := api.GetStationsByVenderId()
if err != nil {
t.Fatal(err)
}
findStore := false
for _, v := range result {
if v == mustExistStoreID {
findStore = true
break
}
}
if !findStore {
baseapi.SugarLogger.Fatalf("result have no store:%s", mustExistStoreID)
}
}
func TestGetStoreInfoByStationNo(t *testing.T) {
result, err := api.GetStoreInfoByStationNo(mustExistStoreID)
if err != nil {
t.Fatal(err)
}
outSystemId := result["outSystemId"].(string)
if outSystemId != "100285" {
baseapi.SugarLogger.Fatalf("outSystemId is not correct, its:%s", outSystemId)
}
}
func TestUpdateStoreInfo4Open(t *testing.T) {
result, err := api.GetStoreInfoByStationNo(mustExistStoreID)
if err != nil {
t.Fatal(err)
}
oldAddress := result["stationAddress"].(string)
testAddress := oldAddress + "T"
addParams := map[string]interface{}{
"stationAddress": testAddress,
}
err = api.UpdateStoreInfo4Open(mustExistStoreID, "test", addParams)
if err != nil {
t.Fatal(err)
}
result, err = api.GetStoreInfoByStationNo(mustExistStoreID)
newAddress := result["stationAddress"].(string)
if newAddress != testAddress {
t.Fatalf("address not match, newAddress:%s, oldAddress:%s", newAddress, oldAddress)
}
addParams = map[string]interface{}{
"stationAddress": oldAddress,
}
api.UpdateStoreInfo4Open(mustExistStoreID, "test", addParams)
if err != nil {
t.Fatal(err)
}
}
func TestGetCommentByOrderId(t *testing.T) {
testOrderID := int64(822347450000922)
result, err := api.GetCommentByOrderId(testOrderID)
if err != nil {
t.Fatal(err.Error())
}
gotOrderID := utils.MustInterface2Int64(result["orderId"])
if gotOrderID != testOrderID {
t.Fatalf("GetCommentByOrderId wrong, gotOrderID:%d", gotOrderID)
}
t.Log(utils.Format4Output(result, false))
}
func TestUpdateStoreConfig4Open(t *testing.T) {
testStationNo := "11785740"
desiredValue := true
// 马上修改了后通过GetStoreInfoByStationNo得到的数据不及时测试不能过的。。。
result, err := api.UpdateStoreConfig4Open(testStationNo, desiredValue)
if err != nil || !result {
if err != nil {
t.Fatal(err.Error())
}
t.Fatal(result)
}
time.Sleep(2 * time.Second)
result2, err := api.GetStoreInfoByStationNo(testStationNo)
if err != nil {
t.Fatal(err.Error())
}
isAutoOrder := int(utils.MustInterface2Int64(result2["isAutoOrder"]))
if isAutoOrder != 0 && desiredValue || isAutoOrder == 0 && !desiredValue {
t.Fatalf("UpdateStoreConfig4Open failed, isAutoOrder:%d", isAutoOrder)
}
}
func TestGetDeliveryRangeByStationNo(t *testing.T) {
const testStoreID = "11738152"
result, err := api.GetDeliveryRangeByStationNo(testStoreID)
if err != nil {
t.Fatal(err)
}
result2, err := api.GetStoreInfoByStationNo(testStoreID)
if err != nil {
t.Fatal(err)
}
baseapi.SugarLogger.Debug(utils.Format4Output(result, false))
baseapi.SugarLogger.Debug(utils.Format4Output(result2, false))
deliveryRange := result["deliveryRange"].(string)
params := map[string]interface{}{
"lng": result2["lng"],
"lat": result2["lat"],
"coordinateType": 3,
"deliveryRangeType": 2,
"coordinatePoints": deliveryRange,
}
err = api.UpdateStoreInfo4Open(testStoreID, "test", params)
if err != nil {
t.Fatal(err)
}
}