From 13ec136ef09ea40141b1c7de70bfd34334bda61b Mon Sep 17 00:00:00 2001 From: Daniel Weiser Date: Mon, 3 Aug 2020 12:56:15 +0300 Subject: [PATCH] closes #38; OrderPaymentEdit test --- v5/client.go | 2 +- v5/client_test.go | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/v5/client.go b/v5/client.go index 0fb463e..33ac384 100644 --- a/v5/client.go +++ b/v5/client.go @@ -2489,7 +2489,7 @@ func (c *Client) OrderPaymentEdit(payment Payment, by string, site ...string) (S paymentJSON, _ := json.Marshal(&payment) p := url.Values{ - "by": context, + "by": {context}, "payment": {string(paymentJSON[:])}, } diff --git a/v5/client_test.go b/v5/client_test.go index 73282fd..80c8de8 100644 --- a/v5/client_test.go +++ b/v5/client_test.go @@ -3238,6 +3238,41 @@ func TestClient_OrderMethods(t *testing.T) { } } +func TestClient_OrderPaymentEdit(t *testing.T) { + c := client() + payment := Payment{ + ExternalID: RandomString(8), + } + + defer gock.Off() + + jr, _ := json.Marshal(&payment) + p := url.Values{ + "by": {"externalId"}, + "payment": {string(jr[:])}, + } + + gock.New(crmURL). + Post(fmt.Sprintf("/orders/payments/%s/edit", payment.ExternalID)). + MatchType("url"). + BodyString(p.Encode()). + Reply(200). + BodyString(`{"success": true}`) + + data, status, err := c.OrderPaymentEdit(payment, "externalId") + if err.Error() != "" { + t.Errorf("%v", err.Error()) + } + + if status >= http.StatusBadRequest { + t.Errorf("%v", err.ApiError()) + } + + if data.Success != true { + t.Errorf("%v", err.ApiError()) + } +} + func TestClient_OrderTypes(t *testing.T) { c := client()