fixes DeliveryTracking method

This commit is contained in:
Akolzin Dmitry 2021-01-29 13:07:04 +03:00
parent 3d71115827
commit 986ddba2a4
3 changed files with 51 additions and 13 deletions

View file

@ -1806,30 +1806,31 @@ func (c *Client) CorporateCustomerEdit(customer CorporateCustomer, by string, si
// Example:
//
// var client = v5.New("https://demo.url", "09jIJ")
// t, _ := time.Parse("2006-01-02 15:04:05", "2012-12-12 12:12:12")
//
// data, status, err := client.DeliveryTracking(
// v5.DeliveryTrackingRequest{
// []v5.DeliveryTrackingRequest{{
// DeliveryID: "1",
// TrackNumber "123",
// History: []DeliveryHistoryRecord{
// TrackNumber: "123",
// History: []v5.DeliveryHistoryRecord{
// {
// Code: "cancel",
// UpdatedAt: "2012-12-12 12:12:12"
// UpdatedAt: t.Format(time.RFC3339),
// },
// }
// },
// },
// }},
// "delivery-1",
// )
//
// if err.Error() != "" {
// fmt.Printf("%v", err.RuntimeErr)
// fmt.Printf("%v", err.Error())
// }
//
// if status >= http.StatusBadRequest {
// fmt.Printf("%v", err.ApiErr())
// fmt.Printf("%v", err.Error())
// }
//
func (c *Client) DeliveryTracking(parameters DeliveryTrackingRequest, subcode string) (SuccessfulResponse, int, *errs.Failure) {
func (c *Client) DeliveryTracking(parameters []DeliveryTrackingRequest, subcode string) (SuccessfulResponse, int, *errs.Failure) {
var resp SuccessfulResponse
updateJSON, _ := json.Marshal(&parameters)

View file

@ -5473,6 +5473,43 @@ func TestClient_ProductsProperties(t *testing.T) {
}
}
func TestClient_DeliveryTracking(t *testing.T) {
c := client()
defer gock.Off()
p := url.Values{
"statusUpdate": {`[{"deliveryId":"123","history":[{"code":"1","updatedAt":"2020-01-01T00:00:00:000"}]}]`},
}
gock.New(crmURL).
Post("/delivery/generic/subcode/tracking").
MatchType("url").
BodyString(p.Encode()).
Reply(200).
BodyString(`{"success": true}`)
g, status, err := c.DeliveryTracking([]DeliveryTrackingRequest{{
DeliveryID: "123",
History: []DeliveryHistoryRecord{{
Code: "1",
UpdatedAt: "2020-01-01T00:00:00:000",
}},
}}, "subcode")
if err.Error() != "" {
t.Errorf("%v", err.Error())
}
if status != http.StatusOK {
t.Errorf("%v", err.ApiError())
}
if g.Success != true {
t.Errorf("%v", err.ApiError())
}
}
func TestClient_DeliveryShipments(t *testing.T) {
c := client()

View file

@ -175,10 +175,10 @@ type ProductsPropertiesRequest struct {
// DeliveryTrackingRequest type
type DeliveryTrackingRequest struct {
DeliveryID string `url:"deliveryId,omitempty"`
TrackNumber string `url:"trackNumber,omitempty"`
History []DeliveryHistoryRecord `url:"history,omitempty,brackets"`
ExtraData map[string]string `url:"extraData,omitempty,brackets"`
DeliveryID string `json:"deliveryId,omitempty"`
TrackNumber string `json:"trackNumber,omitempty"`
History []DeliveryHistoryRecord `json:"history,omitempty,brackets"`
ExtraData map[string]string `json:"extraData,omitempty,brackets"`
}
// DeliveryShipmentsRequest type