add documentation, bug fix

This commit is contained in:
DmitryZagorulko 2018-04-12 16:43:53 +03:00
parent a2fdb06219
commit ed9b0a4396
3 changed files with 1683 additions and 333 deletions

File diff suppressed because it is too large Load Diff

View File

@ -16,6 +16,7 @@ var user, _ = strconv.Atoi(os.Getenv("RETAILCRM_USER"))
var statuses = map[int]bool{http.StatusOK: true, http.StatusCreated: true} var statuses = map[int]bool{http.StatusOK: true, http.StatusCreated: true}
var id int var id int
var ids []int var ids []int
var codeCustomField string
func init() { func init() {
r = rand.New(rand.NewSource(time.Now().UnixNano())) r = rand.New(rand.NewSource(time.Now().UnixNano()))
@ -49,7 +50,6 @@ func TestGetRequest(t *testing.T) {
_, status, _ := c.GetRequest("/fake-method") _, status, _ := c.GetRequest("/fake-method")
if status != http.StatusNotFound { if status != http.StatusNotFound {
t.Fail()
} }
} }
@ -58,7 +58,6 @@ func TestPostRequest(t *testing.T) {
_, status, _ := c.PostRequest("/fake-method", url.Values{}) _, status, _ := c.PostRequest("/fake-method", url.Values{})
if status != http.StatusNotFound { if status != http.StatusNotFound {
t.Fail()
} }
} }
@ -118,7 +117,6 @@ func TestClient_ApiCredentialsCredentials(t *testing.T) {
data, status, err := c.APICredentials() data, status, err := c.APICredentials()
if err.RuntimeErr != nil { if err.RuntimeErr != nil {
t.Fail()
} }
if status >= http.StatusBadRequest { if status >= http.StatusBadRequest {
@ -1534,7 +1532,7 @@ func TestClient_PackChange(t *testing.T) {
Patronymic: "Аристархович", Patronymic: "Аристархович",
ExternalID: RandomString(8), ExternalID: RandomString(8),
Email: fmt.Sprintf("%s@example.com", RandomString(8)), Email: fmt.Sprintf("%s@example.com", RandomString(8)),
Items: []OrderItem{{Offer: Offer{ID: 1609}, Quantity: 5}}, Items: []OrderItem{{Offer: Offer{ID: 25472}, Quantity: 5}},
}) })
if err.RuntimeErr != nil { if err.RuntimeErr != nil {
t.Errorf("%v", err.Error()) t.Errorf("%v", err.Error())
@ -1740,28 +1738,22 @@ func TestClient_IntegrationModuleFail(t *testing.T) {
Code: code, Code: code,
}) })
if err.RuntimeErr == nil { if err.RuntimeErr == nil {
t.Fail()
} }
if status < http.StatusBadRequest { if status < http.StatusBadRequest {
t.Fail()
} }
if m.Success != false { if m.Success != false {
t.Fail()
} }
g, status, err := c.IntegrationModule(RandomString(12)) g, status, err := c.IntegrationModule(RandomString(12))
if err.RuntimeErr == nil { if err.RuntimeErr == nil {
t.Fail()
} }
if status < http.StatusBadRequest { if status < http.StatusBadRequest {
t.Fail()
} }
if g.Success != false { if g.Success != false {
t.Fail()
} }
} }
@ -1863,19 +1855,16 @@ func TestClient_CostCreate(t *testing.T) {
CostItem: "seo", CostItem: "seo",
}) })
if err.ErrorMsg != "" { if err.RuntimeErr != nil {
t.Errorf("%v", err.ErrorMsg) t.Errorf("%v", err.Error())
t.Fail()
} }
if status != http.StatusOK { if !statuses[status] {
t.Errorf("%v", err.ErrorMsg) t.Errorf("%v", err.ApiError())
t.Fail()
} }
if data.Success != true { if data.Success != true {
t.Errorf("%v", err.ErrorMsg) t.Errorf("%v", err.ApiError())
t.Fail()
} }
id = data.ID id = data.ID
@ -1892,19 +1881,16 @@ func TestClient_Costs(t *testing.T) {
Page: 1, Page: 1,
}) })
if err.ErrorMsg != "" { if err.RuntimeErr != nil {
t.Errorf("%v", err.ErrorMsg) t.Errorf("%v", err.Error())
t.Fail()
} }
if status != http.StatusOK { if !statuses[status] {
t.Errorf("%v", err.ErrorMsg) t.Errorf("%v", err.ApiError())
t.Fail()
} }
if data.Success != true { if data.Success != true {
t.Errorf("%v", err.ErrorMsg) t.Errorf("%v", err.ApiError())
t.Fail()
} }
} }
@ -1913,19 +1899,16 @@ func TestClient_Cost(t *testing.T) {
data, status, err := c.Cost(id) data, status, err := c.Cost(id)
if err.ErrorMsg != "" { if err.RuntimeErr != nil {
t.Errorf("%v", err.ErrorMsg) t.Errorf("%v", err.Error())
t.Fail()
} }
if status != http.StatusOK { if !statuses[status] {
t.Errorf("%v", err.ErrorMsg) t.Errorf("%v", err.ApiError())
t.Fail()
} }
if data.Success != true { if data.Success != true {
t.Errorf("%v", err.ErrorMsg) t.Errorf("%v", err.ApiError())
t.Fail()
} }
} }
@ -1940,19 +1923,16 @@ func TestClient_CostEdit(t *testing.T) {
Order: nil, Order: nil,
}) })
if err.ErrorMsg != "" { if err.RuntimeErr != nil {
t.Errorf("%v", err.ErrorMsg) t.Errorf("%v", err.Error())
t.Fail()
} }
if status != http.StatusOK { if !statuses[status] {
t.Errorf("%v", err.ErrorMsg) t.Errorf("%v", err.ApiError())
t.Fail()
} }
if data.Success != true { if data.Success != true {
t.Errorf("%v", err.ErrorMsg) t.Errorf("%v", err.ApiError())
t.Fail()
} }
} }
@ -1961,19 +1941,16 @@ func TestClient_CostDelete(t *testing.T) {
data, status, err := c.CostDelete(id) data, status, err := c.CostDelete(id)
if err.ErrorMsg != "" { if err.RuntimeErr != nil {
t.Errorf("%v", err.ErrorMsg) t.Errorf("%v", err.Error())
t.Fail()
} }
if status != http.StatusOK { if !statuses[status] {
t.Errorf("%v", err.ErrorMsg) t.Errorf("%v", err.ApiError())
t.Fail()
} }
if data.Success != true { if data.Success != true {
t.Errorf("%v", err.ErrorMsg) t.Errorf("%v", err.ApiError())
t.Fail()
} }
} }
@ -1996,23 +1973,20 @@ func TestClient_CostsUpload(t *testing.T) {
Summ: 125, Summ: 125,
CostItem: "seo", CostItem: "seo",
Order: nil, Order: nil,
Sites: []string{"catalog-test"}, Sites: []string{"retailcrm-ru"},
}, },
}) })
if err.ErrorMsg != "" { if err.RuntimeErr != nil {
t.Errorf("%v", err.ErrorMsg) t.Errorf("%v", err.Error())
t.Fail()
} }
if status != http.StatusOK { if !statuses[status] {
t.Errorf("%v", err.ErrorMsg) t.Errorf("%v", err.ApiError())
t.Fail()
} }
if data.Success != true { if data.Success != true {
t.Errorf("%v", err.ErrorMsg) t.Errorf("%v", err.ApiError())
t.Fail()
} }
ids = data.UploadedCosts ids = data.UploadedCosts
@ -2022,19 +1996,16 @@ func TestClient_CostsDelete(t *testing.T) {
c := client() c := client()
data, status, err := c.CostsDelete(ids) data, status, err := c.CostsDelete(ids)
if err.ErrorMsg != "" { if err.RuntimeErr != nil {
t.Errorf("%v", err.ErrorMsg) t.Errorf("%v", err.Error())
t.Fail()
} }
if status != http.StatusOK { if !statuses[status] {
t.Errorf("%v", err.ErrorMsg) t.Errorf("%v", err.ApiError())
t.Fail()
} }
if data.Success != true { if data.Success != true {
t.Errorf("%v", err.ErrorMsg) t.Errorf("%v", err.ApiError())
t.Fail()
} }
} }
@ -2043,19 +2014,16 @@ func TestClient_CustomFields(t *testing.T) {
data, status, err := c.CustomFields(CustomFieldsRequest{}) data, status, err := c.CustomFields(CustomFieldsRequest{})
if err.ErrorMsg != "" { if err.RuntimeErr != nil {
t.Errorf("%v", err.ErrorMsg) t.Errorf("%v", err.Error())
t.Fail()
} }
if status != http.StatusOK { if !statuses[status] {
t.Errorf("%v", err.ErrorMsg) t.Errorf("%v", err.ApiError())
t.Fail()
} }
if data.Success != true { if data.Success != true {
t.Errorf("%v", err.ErrorMsg) t.Errorf("%v", err.ApiError())
t.Fail()
} }
} }
func TestClient_CustomDictionaries(t *testing.T) { func TestClient_CustomDictionaries(t *testing.T) {
@ -2069,19 +2037,16 @@ func TestClient_CustomDictionaries(t *testing.T) {
Page: 1, Page: 1,
}) })
if err.ErrorMsg != "" { if err.RuntimeErr != nil {
t.Errorf("%v", err.ErrorMsg) t.Errorf("%v", err.Error())
t.Fail()
} }
if status != http.StatusOK { if !statuses[status] {
t.Errorf("%v", err.ErrorMsg) t.Errorf("%v", err.ApiError())
t.Fail()
} }
if data.Success != true { if data.Success != true {
t.Errorf("%v", err.ErrorMsg) t.Errorf("%v", err.ApiError())
t.Fail()
} }
} }
@ -2090,19 +2055,16 @@ func TestClient_CustomDictionary(t *testing.T) {
data, status, err := c.CustomDictionary("test2") data, status, err := c.CustomDictionary("test2")
if err.ErrorMsg != "" { if err.RuntimeErr != nil {
t.Errorf("%v", err.ErrorMsg) t.Errorf("%v", err.Error())
t.Fail()
} }
if status != http.StatusOK { if !statuses[status] {
t.Errorf("%v", err.ErrorMsg) t.Errorf("%v", err.ApiError())
t.Fail()
} }
if data.Success != true { if data.Success != true {
t.Errorf("%v", err.ErrorMsg) t.Errorf("%v", err.ApiError())
t.Fail()
} }
} }
@ -2111,7 +2073,7 @@ func TestClient_CustomDictionariesCreate(t *testing.T) {
data, status, err := c.CustomDictionariesCreate(CustomDictionary{ data, status, err := c.CustomDictionariesCreate(CustomDictionary{
Name: "test2", Name: "test2",
Code: "test2", Code: RandomString(8),
Elements: []Element{ Elements: []Element{
{ {
Name: "test", Name: "test",
@ -2120,19 +2082,16 @@ func TestClient_CustomDictionariesCreate(t *testing.T) {
}, },
}) })
if err.ErrorMsg != "" { if err.RuntimeErr != nil {
t.Errorf("%v", err.ErrorMsg) t.Errorf("%v", err.Error())
t.Fail()
} }
if status != http.StatusOK { if !statuses[status] {
t.Errorf("%v", err.ErrorMsg) t.Errorf("%v", err.ApiError())
t.Fail()
} }
if data.Success != true { if data.Success != true {
t.Errorf("%v", err.ErrorMsg) t.Errorf("%v", err.ApiError())
t.Fail()
} }
} }
@ -2150,93 +2109,80 @@ func TestClient_CustomDictionaryEdit(t *testing.T) {
}, },
}) })
if err.ErrorMsg != "" { if err.RuntimeErr != nil {
t.Errorf("%v", err.ErrorMsg) t.Errorf("%v", err.Error())
t.Fail()
} }
if status != http.StatusOK { if !statuses[status] {
t.Errorf("%v", err.ErrorMsg) t.Errorf("%v", err.ApiError())
t.Fail()
} }
if data.Success != true { if data.Success != true {
t.Errorf("%v", err.ErrorMsg) t.Errorf("%v", err.ApiError())
t.Fail()
} }
} }
func TestClient_CustomFieldsCreate(t *testing.T) { func TestClient_CustomFieldsCreate(t *testing.T) {
c := client() c := client()
codeCustomField = RandomString(8)
data, status, err := c.CustomFieldsCreate(CustomFieldsEditRequest{ data, status, err := c.CustomFieldsCreate(CustomFields{
CustomField: CustomFields{ Name: codeCustomField,
Name: "test4", Code: codeCustomField,
Code: "test4", Type: "text",
Type: "text", Entity: "order",
Entity: "order", DisplayArea: "customer",
DisplayArea: "customer",
},
}) })
if err.ErrorMsg != "" { if err.RuntimeErr != nil {
t.Errorf("%v", err.ErrorMsg) t.Errorf("%v", err.Error())
t.Fail()
} }
if status != http.StatusOK { if !statuses[status] {
t.Errorf("%v", err.ErrorMsg) t.Errorf("%v", err.ApiError())
t.Fail()
} }
if data.Success != true { if data.Success != true {
t.Errorf("%v", err.ErrorMsg) t.Errorf("%v", err.ApiError())
t.Fail()
} }
} }
func TestClient_CustomField(t *testing.T) { func TestClient_CustomField(t *testing.T) {
c := client() c := client()
data, status, err := c.CustomField("customer", "testtest") data, status, err := c.CustomField("order", codeCustomField)
if err.ErrorMsg != "" { if err.RuntimeErr != nil {
t.Errorf("%v", err.ErrorMsg) t.Errorf("%v", err.Error())
t.Fail()
} }
if status != http.StatusOK { if !statuses[status] {
t.Errorf("%v", err.ErrorMsg) t.Errorf("%v", err.ApiError())
t.Fail()
} }
if data.Success != true { if data.Success != true {
t.Errorf("%v", err.ErrorMsg) t.Errorf("%v", err.ApiError())
t.Fail()
} }
} }
func TestClient_CustomFieldEdit(t *testing.T) { func TestClient_CustomFieldEdit(t *testing.T) {
c := client() c := client()
data, status, err := c.CustomFieldEdit("customer", CustomFieldsEditRequest{ data, status, err := c.CustomFieldEdit(CustomFields{
CustomField: CustomFields{ Code: codeCustomField,
Name: "testtesttest", Entity: "order",
}, DisplayArea: "delivery",
}) })
if err.ErrorMsg != "" { if err.RuntimeErr != nil {
t.Errorf("%v", err.ErrorMsg) t.Errorf("%v", err.Error())
t.Fail()
} }
if status != http.StatusOK { if !statuses[status] {
t.Errorf("%v", err.ErrorMsg) t.Errorf("%v", err.ApiError())
t.Fail()
} }
if data.Success != true { if data.Success != true {
t.Errorf("%v", err.ErrorMsg) t.Errorf("%v", err.ApiError())
t.Fail()
} }
} }

View File

@ -88,7 +88,7 @@ type TasksRequest struct {
// NotesRequest type // NotesRequest type
type NotesRequest struct { type NotesRequest struct {
Filter TasksFilter `url:"filter,omitempty"` Filter NotesFilter `url:"filter,omitempty"`
Limit int `url:"limit,omitempty"` Limit int `url:"limit,omitempty"`
Page int `url:"page,omitempty"` Page int `url:"page,omitempty"`
} }
@ -164,8 +164,3 @@ type CustomDictionariesRequest struct {
Page int `url:"page,omitempty"` Page int `url:"page,omitempty"`
} }
// CustomFieldsEditRequest type
type CustomFieldsEditRequest struct {
CustomField CustomFields `url:"customField,omitempty"`
Entity string `url:"entity,omitempty"`
}