From 84a002991fa1bc32248d527f1849cb455a2056e3 Mon Sep 17 00:00:00 2001 From: Daniel Weiser Date: Tue, 4 Aug 2020 13:09:42 +0300 Subject: [PATCH 1/2] new field Tags in Customer struct --- v5/client_test.go | 27 +++++++++++++++++++++++++- v5/types.go | 49 +++++++++++++++++++++++++++-------------------- 2 files changed, 54 insertions(+), 22 deletions(-) diff --git a/v5/client_test.go b/v5/client_test.go index 73282fd..38f779a 100644 --- a/v5/client_test.go +++ b/v5/client_test.go @@ -9,6 +9,7 @@ import ( "net/http" "net/url" "os" + "reflect" "strconv" "strings" "testing" @@ -273,6 +274,10 @@ func TestClient_CustomerChange(t *testing.T) { Street: "Кутузовский", Building: "14", }, + Tags: []Tag{ + {"first", "#3e89b6", false}, + {"second", "#ffa654", false}, + }, } defer gock.Off() @@ -337,7 +342,23 @@ func TestClient_CustomerChange(t *testing.T) { Get(fmt.Sprintf("/api/v5/customers/%v", f.ExternalID)). MatchParam("by", ByExternalID). Reply(200). - BodyString(`{"success": true}`) + BodyString(`{ + "success": true, + "customer": { + "tags": [ + { + "name": "first", + "color": "#3e89b6", + "attached": false + }, + { + "name": "second", + "color": "#ffa654", + "attached": false + } + ] + } + }`) data, status, err := c.Customer(f.ExternalID, ByExternalID, "") if err.Error() != "" { @@ -351,6 +372,10 @@ func TestClient_CustomerChange(t *testing.T) { if data.Success != true { t.Errorf("%v", err.ApiError()) } + + if !reflect.DeepEqual(data.Customer.Tags, f.Tags) { + t.Errorf("%v", err.ApiError()) + } } func TestClient_CustomerChange_Fail(t *testing.T) { diff --git a/v5/types.go b/v5/types.go index b7e198b..f33c7bf 100644 --- a/v5/types.go +++ b/v5/types.go @@ -26,24 +26,24 @@ type Pagination struct { // Address type type Address struct { - Index string `json:"index,omitempty"` - CountryIso string `json:"countryIso,omitempty"` - Region string `json:"region,omitempty"` - RegionID int `json:"regionId,omitempty"` - City string `json:"city,omitempty"` - CityID int `json:"cityId,omitempty"` - CityType string `json:"cityType,omitempty"` - Street string `json:"street,omitempty"` - StreetID int `json:"streetId,omitempty"` - StreetType string `json:"streetType,omitempty"` - Building string `json:"building,omitempty"` - Flat string `json:"flat,omitempty"` - Floor int `json:"floor,omitempty"` - Block int `json:"block,omitempty"` - House string `json:"house,omitempty"` - Metro string `json:"metro,omitempty"` - Notes string `json:"notes,omitempty"` - Text string `json:"text,omitempty"` + Index string `json:"index,omitempty"` + CountryIso string `json:"countryIso,omitempty"` + Region string `json:"region,omitempty"` + RegionID int `json:"regionId,omitempty"` + City string `json:"city,omitempty"` + CityID int `json:"cityId,omitempty"` + CityType string `json:"cityType,omitempty"` + Street string `json:"street,omitempty"` + StreetID int `json:"streetId,omitempty"` + StreetType string `json:"streetType,omitempty"` + Building string `json:"building,omitempty"` + Flat string `json:"flat,omitempty"` + Floor int `json:"floor,omitempty"` + Block int `json:"block,omitempty"` + House string `json:"house,omitempty"` + Metro string `json:"metro,omitempty"` + Notes string `json:"notes,omitempty"` + Text string `json:"text,omitempty"` } // GeoHierarchyRow type @@ -628,15 +628,15 @@ type Segment struct { // SettingsNode represents an item in settings. All settings nodes contains only string value and update time for now. type SettingsNode struct { - Value string `json:"value"` + Value string `json:"value"` UpdatedAt string `json:"updated_at"` } // Settings type. Contains retailCRM configuration. type Settings struct { DefaultCurrency SettingsNode `json:"default_currency"` - SystemLanguage SettingsNode `json:"system_language"` - Timezone SettingsNode `json:"timezone"` + SystemLanguage SettingsNode `json:"system_language"` + Timezone SettingsNode `json:"timezone"` } /** @@ -1101,3 +1101,10 @@ type Activity struct { Active bool `json:"active"` Freeze bool `json:"freeze"` } + +// Tag struct +type Tag struct { + Name string `json:"name,omitempty"` + Color string `json:"color,omitempty"` + Attached bool `json:"attached,omitempty"` +} From 05ac38e199b83c07ae88166c6e44f20be719059e Mon Sep 17 00:00:00 2001 From: Daniel Weiser Date: Tue, 4 Aug 2020 13:13:52 +0300 Subject: [PATCH 2/2] fix Customer struct --- v5/types.go | 1 + 1 file changed, 1 insertion(+) diff --git a/v5/types.go b/v5/types.go index f33c7bf..aa491fe 100644 --- a/v5/types.go +++ b/v5/types.go @@ -149,6 +149,7 @@ type Customer struct { MgCustomerID string `json:"mgCustomerId,omitempty"` PhotoURL string `json:"photoUrl,omitempty"` CustomFields map[string]string `json:"customFields,omitempty,brackets"` + Tags []Tag `json:"tags,brackets,omitempty"` } // CorporateCustomer type