mirror of
https://github.com/retailcrm/api-client-go.git
synced 2025-04-19 17:00:55 +00:00
Compare commits
No commits in common. "master" and "v2.2.1" have entirely different histories.
5 changed files with 26 additions and 98 deletions
23
client.go
23
client.go
|
@ -1965,17 +1965,17 @@ func (c *Client) CorporateCustomerEdit(customer CorporateCustomer, by string, si
|
|||
//
|
||||
// var client = retailcrm.New("https://demo.url", "09jIJ")
|
||||
//
|
||||
// data, status, err := client.ClearCart("site_id", retailcrm.SiteFilter{SiteBy: "id"},
|
||||
// retailcrm.ClearCartRequest{
|
||||
// ClearedAt: time.Now().String(),
|
||||
// Customer: retailcrm.CartCustomer{
|
||||
// data, status, err := client.ClearCart("site_id", SiteFilter{SiteBy: "id"},
|
||||
// ClearCartRequest{
|
||||
// CreatedAt: time.Now().String(),
|
||||
// Customer: CartCustomer{
|
||||
// ID: 1,
|
||||
// ExternalID: "ext_id",
|
||||
// Site: "site",
|
||||
// BrowserID: "browser_id",
|
||||
// GaClientID: "ga_client_id",
|
||||
// },
|
||||
// Order: retailcrm.ClearCartOrder{
|
||||
// Order: ClearCartOrder{
|
||||
// ID: 1,
|
||||
// ExternalID: "ext_id",
|
||||
// Number: "abc123",
|
||||
|
@ -2027,23 +2027,23 @@ func (c *Client) ClearCart(site string, filter SiteFilter, req ClearCartRequest)
|
|||
//
|
||||
// var client = retailcrm.New("https://demo.url", "09jIJ")
|
||||
//
|
||||
// data, status, err := client.SetCart("site_id", retailcrm.SiteFilter{SiteBy: "id"},
|
||||
// retailcrm.SetCartRequest{
|
||||
// data, status, err := client.SetCart("site_id", SiteFilter{SiteBy: "id"},
|
||||
// SetCartRequest{
|
||||
// ExternalID: "ext_id",
|
||||
// DroppedAt: time.Now().String(),
|
||||
// Link: "link",
|
||||
// Customer: retailcrm.CartCustomer{
|
||||
// Customer: CartCustomer{
|
||||
// ID: 1,
|
||||
// ExternalID: "ext_id",
|
||||
// Site: "site",
|
||||
// BrowserID: "browser_id",
|
||||
// GaClientID: "ga_client_id",
|
||||
// },
|
||||
// Items: []retailcrm.SetCartItem{
|
||||
// Items: []SetCartItem{
|
||||
// {
|
||||
// Quantity: 1,
|
||||
// Price: 1.0,
|
||||
// Offer: retailcrm.SetCartOffer{
|
||||
// Offer: SetCartOffer{
|
||||
// ID: 1,
|
||||
// ExternalID: "ext_id",
|
||||
// XMLID: "xml_id",
|
||||
|
@ -2097,8 +2097,7 @@ func (c *Client) SetCart(site string, filter SiteFilter, req SetCartRequest) (
|
|||
//
|
||||
// var client = retailcrm.New("https://demo.url", "09jIJ")
|
||||
//
|
||||
// data, status, err := client.GetCart("site_id","customer_id",
|
||||
// retailcrm.GetCartFilter{ SiteBy: "code", By: "externalId"})
|
||||
// data, status, err := client.GetCart("site_id","customer_id", GetCartFilter{ SiteBy: "code", By: "externalId"})
|
||||
//
|
||||
// if err != nil {
|
||||
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
|
||||
|
|
|
@ -1,13 +1,9 @@
|
|||
package retailcrm
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/retailcrm/api-client-go/v2/constant"
|
||||
"github.com/stretchr/testify/require"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"math/rand"
|
||||
|
@ -1884,18 +1880,15 @@ func TestClient_CorporateCustomerEdit(t *testing.T) {
|
|||
func TestClient_ClearCart(t *testing.T) {
|
||||
c := client()
|
||||
|
||||
tm := "2025-04-14 15:50:00"
|
||||
clearedAt, err := time.Parse("2006-01-02 15:04:05", tm)
|
||||
require.NoError(t, err)
|
||||
|
||||
site := "site_id"
|
||||
filter := SiteFilter{SiteBy: "id"}
|
||||
request := ClearCartRequest{
|
||||
ClearedAt: clearedAt.UTC().Format(constant.DateTimeWithZoneFormat),
|
||||
CreatedAt: time.Now().String(),
|
||||
Customer: CartCustomer{
|
||||
ID: 1,
|
||||
ExternalID: "ext_id",
|
||||
Site: "site",
|
||||
BrowserID: "browser_id",
|
||||
GaClientID: "ga_client_id",
|
||||
},
|
||||
Order: ClearCartOrder{
|
||||
|
@ -1905,40 +1898,9 @@ func TestClient_ClearCart(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
expectedJSON := `{
|
||||
"clearedAt": "2025-04-14 15:50:00+00:00",
|
||||
"customer": {
|
||||
"id": 1,
|
||||
"externalId": "ext_id",
|
||||
"site": "site",
|
||||
"gaClientId": "ga_client_id"
|
||||
},
|
||||
"order": {
|
||||
"id": 1,
|
||||
"externalId": "ext_id",
|
||||
"number": "abc123"
|
||||
}
|
||||
}`
|
||||
|
||||
defer gock.Off()
|
||||
gock.New(crmURL).
|
||||
Post(fmt.Sprintf("/customer-interaction/%s/cart/clear", site)).
|
||||
AddMatcher(func(request *http.Request, _ *gock.Request) (bool, error) {
|
||||
body, err := io.ReadAll(request.Body)
|
||||
require.NoError(t, err)
|
||||
request.Body = io.NopCloser(bytes.NewBuffer(body))
|
||||
|
||||
val, err := url.ParseQuery(string(body))
|
||||
require.NoError(t, err)
|
||||
|
||||
val.Get("cart")
|
||||
|
||||
if !assert.JSONEq(t, expectedJSON, val.Get("cart")) {
|
||||
return false, errors.New("unequal values")
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}).
|
||||
MatchParam("siteBy", filter.SiteBy).
|
||||
Reply(200).
|
||||
BodyString(`{"success":true}`)
|
||||
|
@ -1964,7 +1926,7 @@ func TestClient_SetCart(t *testing.T) {
|
|||
filter := SiteFilter{SiteBy: "id"}
|
||||
request := SetCartRequest{
|
||||
ExternalID: "ext_id",
|
||||
DroppedAt: time.Now().UTC().Format(constant.DateTimeWithZoneFormat),
|
||||
DroppedAt: time.Now().String(),
|
||||
Link: "link",
|
||||
Customer: CartCustomer{
|
||||
ID: 1,
|
||||
|
@ -1989,36 +1951,6 @@ func TestClient_SetCart(t *testing.T) {
|
|||
defer gock.Off()
|
||||
gock.New(crmURL).
|
||||
Post(fmt.Sprintf("/customer-interaction/%s/cart/set", site)).
|
||||
AddMatcher(func(req *http.Request, _ *gock.Request) (bool, error) {
|
||||
body, err := io.ReadAll(req.Body)
|
||||
require.NoError(t, err)
|
||||
req.Body = io.NopCloser(bytes.NewBuffer(body))
|
||||
|
||||
val, err := url.ParseQuery(string(body))
|
||||
require.NoError(t, err)
|
||||
|
||||
cartJSON := val.Get("cart")
|
||||
var cart SetCartRequest
|
||||
require.NoError(t, json.Unmarshal([]byte(cartJSON), &cart))
|
||||
|
||||
equal := assert.Equal(t, "ext_id", cart.ExternalID) &&
|
||||
assert.NotEmpty(t, cart.DroppedAt) &&
|
||||
assert.Equal(t, 1, cart.Customer.ID) &&
|
||||
assert.Equal(t, "ext_id", cart.Customer.ExternalID) &&
|
||||
assert.Equal(t, "site", cart.Customer.Site) &&
|
||||
assert.Equal(t, "ga_client_id", cart.Customer.GaClientID) &&
|
||||
assert.Equal(t, float64(1), cart.Items[0].Quantity) &&
|
||||
assert.Equal(t, float64(1), cart.Items[0].Price) &&
|
||||
assert.Equal(t, 1, cart.Items[0].Offer.ID) &&
|
||||
assert.Equal(t, "ext_id", cart.Items[0].Offer.ExternalID) &&
|
||||
assert.Equal(t, "xml_id", cart.Items[0].Offer.XMLID)
|
||||
|
||||
if !equal {
|
||||
return false, errors.New("unequal values")
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}).
|
||||
MatchParam("siteBy", filter.SiteBy).
|
||||
Reply(200).
|
||||
BodyString(`{"success":true}`)
|
||||
|
@ -2050,8 +1982,8 @@ func TestClient_GetCart(t *testing.T) {
|
|||
expCart := Cart{
|
||||
Currency: "currency",
|
||||
ExternalID: "ext_id",
|
||||
DroppedAt: "2025-04-14 14:32:14+03:00",
|
||||
ClearedAt: "2025-04-14 14:52:14+03:00",
|
||||
DroppedAt: time.Now().String(),
|
||||
ClearedAt: time.Now().String(),
|
||||
Link: "link",
|
||||
Items: []CartItem{
|
||||
{
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
package constant
|
||||
|
||||
const DateTimeWithZoneFormat = "2006-01-02 15:04:05-07:00"
|
16
request.go
16
request.go
|
@ -196,18 +196,18 @@ type DeliveryShipmentsRequest struct {
|
|||
|
||||
// ClearCartRequest type.
|
||||
type ClearCartRequest struct {
|
||||
ClearedAt string `json:"clearedAt,omitempty"`
|
||||
Customer CartCustomer `json:"customer,omitempty"`
|
||||
Order ClearCartOrder `json:"order,omitempty"`
|
||||
CreatedAt string `url:"createdAt,omitempty"`
|
||||
Customer CartCustomer `url:"customer,omitempty"`
|
||||
Order ClearCartOrder `url:"order,omitempty"`
|
||||
}
|
||||
|
||||
// SetCartRequest type.
|
||||
type SetCartRequest struct {
|
||||
ExternalID string `json:"externalId,omitempty"`
|
||||
DroppedAt string `json:"droppedAt,omitempty"`
|
||||
Link string `json:"link,omitempty"`
|
||||
Customer CartCustomer `json:"customer,omitempty"`
|
||||
Items []SetCartItem `json:"items,omitempty"`
|
||||
ExternalID string `url:"externalId,omitempty"`
|
||||
DroppedAt string `url:"droppedAt,omitempty"`
|
||||
Link string `url:"link,omitempty"`
|
||||
Customer CartCustomer `url:"customer,omitempty"`
|
||||
Items []SetCartItem `url:"items,omitempty"`
|
||||
}
|
||||
|
||||
// CostsRequest type.
|
||||
|
|
4
types.go
4
types.go
|
@ -411,7 +411,7 @@ type SerializedOrderLink struct {
|
|||
// ClearCartOrder type.
|
||||
type ClearCartOrder struct {
|
||||
ID int `json:"id,omitempty"`
|
||||
ExternalID string `json:"externalId,omitempty"`
|
||||
ExternalID string `json:"externalID,omitempty"`
|
||||
Number string `json:"number,omitempty"`
|
||||
}
|
||||
|
||||
|
@ -495,7 +495,7 @@ type SetCartItem struct {
|
|||
// SetCartOffer type.
|
||||
type SetCartOffer struct {
|
||||
ID int `json:"id,omitempty"`
|
||||
ExternalID string `json:"externalId,omitempty"`
|
||||
ExternalID string `json:"externalID,omitempty"`
|
||||
XMLID string `json:"xmlId,omitempty"`
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue