mirror of
https://github.com/retailcrm/api-client-go.git
synced 2024-11-25 14:26:04 +03:00
corporate customers history
This commit is contained in:
parent
f808c50da8
commit
680fcf117c
@ -943,7 +943,6 @@ func (c *Client) CorporateCustomersFixExternalIds(customers []IdentifiersPair) (
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CorporateCustomersHistory returns corporate customer's history
|
// CorporateCustomersHistory returns corporate customer's history
|
||||||
// TODO: Check implementation when history becomes available
|
|
||||||
//
|
//
|
||||||
// For more information see http://help.retailcrm.pro/Developers/ApiVersion5#post--api-v5-customers-corporate-fix-external-ids
|
// For more information see http://help.retailcrm.pro/Developers/ApiVersion5#post--api-v5-customers-corporate-fix-external-ids
|
||||||
//
|
//
|
||||||
@ -951,8 +950,8 @@ func (c *Client) CorporateCustomersFixExternalIds(customers []IdentifiersPair) (
|
|||||||
//
|
//
|
||||||
// var client = v5.New("https://demo.url", "09jIJ")
|
// var client = v5.New("https://demo.url", "09jIJ")
|
||||||
//
|
//
|
||||||
// data, status, err := client.CorporateCustomersHistory(v5.CustomersHistoryRequest{
|
// data, status, err := client.CorporateCustomersHistory(v5.CorporateCustomersHistoryRequest{
|
||||||
// Filter: v5.CustomersHistoryFilter{
|
// Filter: v5.CorporateCustomersHistoryFilter{
|
||||||
// SinceID: 20,
|
// SinceID: 20,
|
||||||
// },
|
// },
|
||||||
// })
|
// })
|
||||||
@ -968,7 +967,7 @@ func (c *Client) CorporateCustomersFixExternalIds(customers []IdentifiersPair) (
|
|||||||
// for _, value := range data.History {
|
// for _, value := range data.History {
|
||||||
// fmt.Printf("%v\n", value)
|
// fmt.Printf("%v\n", value)
|
||||||
// }
|
// }
|
||||||
func (c *Client) CorporateCustomersHistory(parameters CustomersHistoryRequest) (CorporateCustomersHistoryResponse, int, *errs.Failure) {
|
func (c *Client) CorporateCustomersHistory(parameters CorporateCustomersHistoryRequest) (CorporateCustomersHistoryResponse, int, *errs.Failure) {
|
||||||
var resp CorporateCustomersHistoryResponse
|
var resp CorporateCustomersHistoryResponse
|
||||||
|
|
||||||
params, _ := query.Values(parameters)
|
params, _ := query.Values(parameters)
|
||||||
|
@ -920,6 +920,69 @@ func TestClient_CorporateCustomersFixExternalIds_Fail(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestClient_CorporateCustomersHistory(t *testing.T) {
|
||||||
|
c := client()
|
||||||
|
f := CorporateCustomersHistoryRequest{
|
||||||
|
Filter: CorporateCustomersHistoryFilter{
|
||||||
|
SinceID: 20,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
defer gock.Off()
|
||||||
|
|
||||||
|
gock.New(crmURL).
|
||||||
|
Get("/customers-corporate/history").
|
||||||
|
MatchParam("filter[sinceId]", "20").
|
||||||
|
Reply(200).
|
||||||
|
BodyString(`{"success": true, "history": [{"id": 1}]}`)
|
||||||
|
|
||||||
|
data, status, err := c.CorporateCustomersHistory(f)
|
||||||
|
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())
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(data.History) == 0 {
|
||||||
|
t.Errorf("%v", "Empty history")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestClient_CorporateCustomersHistory_Fail(t *testing.T) {
|
||||||
|
c := client()
|
||||||
|
f := CorporateCustomersHistoryRequest{
|
||||||
|
Filter: CorporateCustomersHistoryFilter{
|
||||||
|
StartDate: "2020-13-12",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
defer gock.Off()
|
||||||
|
|
||||||
|
gock.New(crmURL).
|
||||||
|
Get("/customers-corporate/history").
|
||||||
|
MatchParam("filter[startDate]", "2020-13-12").
|
||||||
|
Reply(400).
|
||||||
|
BodyString(`{"success": false, "errorMsg": "Errors in the input parameters", "errors": {"children[startDate]": "Значение недопустимо."}}`)
|
||||||
|
|
||||||
|
data, status, err := c.CorporateCustomersHistory(f)
|
||||||
|
if err.Error() != "" {
|
||||||
|
t.Errorf("%v", err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
if status < http.StatusBadRequest {
|
||||||
|
t.Error(statusFail)
|
||||||
|
}
|
||||||
|
|
||||||
|
if data.Success != false {
|
||||||
|
t.Error(successFail)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestClient_CorporateCustomersNotes(t *testing.T) {
|
func TestClient_CorporateCustomersNotes(t *testing.T) {
|
||||||
defer gock.Off()
|
defer gock.Off()
|
||||||
|
|
||||||
|
@ -133,6 +133,16 @@ type CustomersHistoryFilter struct {
|
|||||||
EndDate string `url:"endDate,omitempty"`
|
EndDate string `url:"endDate,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CorporateCustomersHistoryFilter type
|
||||||
|
type CorporateCustomersHistoryFilter struct {
|
||||||
|
CustomerID int `url:"customerId,omitempty"`
|
||||||
|
SinceID int `url:"sinceId,omitempty"`
|
||||||
|
CustomerExternalID string `url:"customerExternalId,omitempty"`
|
||||||
|
ContactIds []string `url:"contactIds,omitempty,brackets"`
|
||||||
|
StartDate string `url:"startDate,omitempty"`
|
||||||
|
EndDate string `url:"endDate,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
// OrdersFilter type
|
// OrdersFilter type
|
||||||
type OrdersFilter struct {
|
type OrdersFilter struct {
|
||||||
Ids []int `url:"ids,omitempty,brackets"`
|
Ids []int `url:"ids,omitempty,brackets"`
|
||||||
|
@ -58,6 +58,13 @@ type CustomersHistoryRequest struct {
|
|||||||
Page int `url:"page,omitempty"`
|
Page int `url:"page,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CorporateCustomersHistoryRequest type
|
||||||
|
type CorporateCustomersHistoryRequest struct {
|
||||||
|
Filter CorporateCustomersHistoryFilter `url:"filter,omitempty"`
|
||||||
|
Limit int `url:"limit,omitempty"`
|
||||||
|
Page int `url:"page,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
// OrderRequest type
|
// OrderRequest type
|
||||||
type OrderRequest struct {
|
type OrderRequest struct {
|
||||||
By string `url:"by,omitempty"`
|
By string `url:"by,omitempty"`
|
||||||
|
@ -110,7 +110,6 @@ type CustomersHistoryResponse struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CorporateCustomersHistoryResponse type
|
// CorporateCustomersHistoryResponse type
|
||||||
// TODO: Update history format in case of changes
|
|
||||||
type CorporateCustomersHistoryResponse struct {
|
type CorporateCustomersHistoryResponse struct {
|
||||||
Success bool `json:"success,omitempty"`
|
Success bool `json:"success,omitempty"`
|
||||||
GeneratedAt string `json:"generatedAt,omitempty"`
|
GeneratedAt string `json:"generatedAt,omitempty"`
|
||||||
|
Loading…
Reference in New Issue
Block a user