corporate customers history

This commit is contained in:
Pavel 2019-11-25 10:55:06 +03:00
parent f808c50da8
commit 680fcf117c
5 changed files with 83 additions and 5 deletions

View File

@ -943,7 +943,6 @@ func (c *Client) CorporateCustomersFixExternalIds(customers []IdentifiersPair) (
}
// 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
//
@ -951,8 +950,8 @@ func (c *Client) CorporateCustomersFixExternalIds(customers []IdentifiersPair) (
//
// var client = v5.New("https://demo.url", "09jIJ")
//
// data, status, err := client.CorporateCustomersHistory(v5.CustomersHistoryRequest{
// Filter: v5.CustomersHistoryFilter{
// data, status, err := client.CorporateCustomersHistory(v5.CorporateCustomersHistoryRequest{
// Filter: v5.CorporateCustomersHistoryFilter{
// SinceID: 20,
// },
// })
@ -968,7 +967,7 @@ func (c *Client) CorporateCustomersFixExternalIds(customers []IdentifiersPair) (
// for _, value := range data.History {
// 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
params, _ := query.Values(parameters)

View File

@ -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) {
defer gock.Off()

View File

@ -133,6 +133,16 @@ type CustomersHistoryFilter struct {
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
type OrdersFilter struct {
Ids []int `url:"ids,omitempty,brackets"`

View File

@ -58,6 +58,13 @@ type CustomersHistoryRequest struct {
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
type OrderRequest struct {
By string `url:"by,omitempty"`

View File

@ -110,7 +110,6 @@ type CustomersHistoryResponse struct {
}
// CorporateCustomersHistoryResponse type
// TODO: Update history format in case of changes
type CorporateCustomersHistoryResponse struct {
Success bool `json:"success,omitempty"`
GeneratedAt string `json:"generatedAt,omitempty"`