package jdapi import ( "testing" "time" "git.rosy.net.cn/baseapi" "git.rosy.net.cn/baseapi/utils" ) const ( mustExistStoreID = "11738324" mustExistStoreJXID = "100285" ) func TestGetStationsByVenderId(t *testing.T) { result, err := jdapi.GetStationsByVenderId() if err != nil { t.Fatal(err) } findStore := false for _, v := range result { if v == mustExistStoreID { findStore = true break } } if !findStore { baseapi.SugarLogger.Fatal("result have no store:%s", mustExistStoreID) } } func TestGetStoreInfoByStationNo(t *testing.T) { result, err := jdapi.GetStoreInfoByStationNo(mustExistStoreID) if err != nil { t.Fatal(err) } outSystemId := result["outSystemId"].(string) if outSystemId != "100285" { baseapi.SugarLogger.Fatal("outSystemId is not correct, its:%s", outSystemId) } } func TestUpdateStoreInfo4Open(t *testing.T) { result, err := jdapi.GetStoreInfoByStationNo(mustExistStoreID) if err != nil { t.Fatal(err) } oldAddress := result["stationAddress"].(string) testAddress := oldAddress + "T" addParams := map[string]interface{}{ "stationAddress": testAddress, } err = jdapi.UpdateStoreInfo4Open(mustExistStoreID, "test", addParams) if err != nil { t.Fatal(err) } result, err = jdapi.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, } jdapi.UpdateStoreInfo4Open(mustExistStoreID, "test", addParams) if err != nil { t.Fatal(err) } } func TestGetCommentByOrderId(t *testing.T) { testOrderID := int64(822347450000922) result, err := jdapi.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 := jdapi.UpdateStoreConfig4Open(testStationNo, desiredValue) if err != nil || !result { if err != nil { t.Fatal(err.Error()) } t.Fatal(result) } time.Sleep(2 * time.Second) result2, err := jdapi.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) } }