Files
baseapi/platformapi/jdapi/store_test.go
2019-10-14 14:31:45 +08:00

154 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"
// mustExistStoreID = "11734851"
// mustExistStoreJXID = "100118"
)
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.GetStoreInfoByStationNo2(mustExistStoreID)
if err != nil {
t.Fatal(err)
}
t.Log(utils.Format4Output(result, false))
if result.OutSystemID != mustExistStoreJXID {
baseapi.SugarLogger.Fatalf("outSystemId is not correct, its:%s", result.OutSystemID)
}
}
func TestUpdateStoreInfo4Open(t *testing.T) {
result, err := api.GetStoreInfoByStationNo2(mustExistStoreID)
if err != nil {
t.Fatal(err)
}
oldAddress := result.StationAddress
params := &OpStoreParams{
StationNo: mustExistStoreID,
Operator: "test",
StationAddress: oldAddress + "T",
}
err = api.UpdateStoreInfo4Open2(params, false)
if err != nil {
t.Fatal(err)
}
result, err = api.GetStoreInfoByStationNo2(mustExistStoreID)
newAddress := result.StationAddress
if newAddress != params.StationAddress {
t.Fatalf("address not match, newAddress:%s, oldAddress:%s", newAddress, oldAddress)
}
params.StationAddress = oldAddress
api.UpdateStoreInfo4Open2(params, false)
if err != nil {
t.Fatal(err)
}
}
func TestGetCommentByOrderId(t *testing.T) {
testOrderID := int64(922520919000622)
result, err := api.GetCommentByOrderId2(testOrderID)
if err != nil {
t.Fatal(err.Error())
}
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.GetStoreInfoByStationNo2(testStationNo)
if err != nil {
t.Fatal(err.Error())
}
isAutoOrder := result2.IsAutoOrder
if isAutoOrder != 0 && desiredValue || isAutoOrder == 0 && !desiredValue {
t.Fatalf("UpdateStoreConfig4Open failed, isAutoOrder:%d", isAutoOrder)
}
}
func TestGetDeliveryRangeByStationNo(t *testing.T) {
const testStoreID = "11734851"
result, err := api.GetDeliveryRangeByStationNo2(testStoreID)
if err != nil {
t.Fatal(err)
}
baseapi.SugarLogger.Debug(utils.Format4Output(result, false))
}
func TestDisableAutoOrder4AllStores(t *testing.T) {
storeIDs, err := api.GetStationsByVenderId()
if err != nil {
t.Fatal(err)
}
for _, storeID := range storeIDs {
if storeInfo, err := api.GetStoreInfoByStationNo2(storeID); err == nil {
if storeInfo.Yn == 0 && storeInfo.IsAutoOrder == 0 {
t.Log(storeID)
api.UpdateStoreConfig4Open(storeID, false)
}
t.Log(utils.Format4Output(storeInfo, false))
}
break
}
}
func TestUpdateStoreFreightConfigNew(t *testing.T) {
err := api.UpdateStoreFreightConfigNew(&UpdateStoreFreightParam{
UserPin: "test",
MerchantStationNo: "2",
OpenDistanceFreight: true,
IsFullFree: true,
StartCharge: 1890,
})
if err != nil {
t.Fatal(err)
}
}