2018-02-27 11:37:15 +03:00
|
|
|
package v5
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"math/rand"
|
|
|
|
"net/http"
|
|
|
|
"net/url"
|
|
|
|
"os"
|
|
|
|
"strconv"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
var r *rand.Rand // Rand for this package.
|
|
|
|
var user, _ = strconv.Atoi(os.Getenv("RETAILCRM_USER"))
|
|
|
|
var statuses = map[int]bool{http.StatusOK: true, http.StatusCreated: true}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
r = rand.New(rand.NewSource(time.Now().UnixNano()))
|
|
|
|
}
|
|
|
|
|
|
|
|
func RandomString(strlen int) string {
|
|
|
|
const chars = "abcdefghijklmnopqrstuvwxyz0123456789"
|
|
|
|
result := make([]byte, strlen)
|
|
|
|
|
|
|
|
for i := range result {
|
|
|
|
result[i] = chars[r.Intn(len(chars))]
|
|
|
|
}
|
|
|
|
|
|
|
|
return string(result)
|
|
|
|
}
|
|
|
|
|
|
|
|
func client() *Client {
|
|
|
|
return New(os.Getenv("RETAILCRM_URL"), os.Getenv("RETAILCRM_KEY"))
|
|
|
|
}
|
|
|
|
|
2018-04-22 20:39:22 +03:00
|
|
|
func badurlclient() *Client {
|
|
|
|
return New("https://qwertypoiu.retailcrm.ru", os.Getenv("RETAILCRM_KEY"))
|
|
|
|
}
|
|
|
|
|
|
|
|
func badkeyclient() *Client {
|
|
|
|
return New(os.Getenv("RETAILCRM_URL"), "1234567890")
|
|
|
|
}
|
|
|
|
|
2018-02-27 11:37:15 +03:00
|
|
|
func TestGetRequest(t *testing.T) {
|
|
|
|
c := client()
|
|
|
|
_, status, _ := c.GetRequest("/fake-method")
|
|
|
|
|
|
|
|
if status != http.StatusNotFound {
|
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPostRequest(t *testing.T) {
|
|
|
|
c := client()
|
|
|
|
_, status, _ := c.PostRequest("/fake-method", url.Values{})
|
|
|
|
|
|
|
|
if status != http.StatusNotFound {
|
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClient_ApiVersionsVersions(t *testing.T) {
|
|
|
|
c := client()
|
|
|
|
|
2018-03-19 23:18:36 +03:00
|
|
|
data, status, err := c.APIVersions()
|
2018-04-22 20:39:22 +03:00
|
|
|
if err.RuntimeErr != nil {
|
|
|
|
t.Errorf("%v", err.Error())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if status >= http.StatusBadRequest {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if data.Success != true {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClient_ApiVersionsVersionsBadUrl(t *testing.T) {
|
|
|
|
c := badurlclient()
|
|
|
|
|
|
|
|
data, status, err := c.APIVersions()
|
|
|
|
if err.RuntimeErr != nil {
|
|
|
|
t.Errorf("%v", err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
if status >= http.StatusBadRequest {
|
|
|
|
t.Errorf("%v", err.ApiError())
|
|
|
|
}
|
|
|
|
|
|
|
|
if data.Success != true {
|
|
|
|
t.Logf("%v", err.ApiError())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClient_ApiVersionsVersionsBadKey(t *testing.T) {
|
|
|
|
c := badkeyclient()
|
|
|
|
|
|
|
|
data, status, err := c.APIVersions()
|
|
|
|
if err.RuntimeErr != nil {
|
|
|
|
t.Errorf("%v", err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
if status >= http.StatusBadRequest {
|
|
|
|
t.Logf("%v", err.ApiError())
|
|
|
|
}
|
|
|
|
|
|
|
|
if data.Success != true {
|
|
|
|
t.Logf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClient_ApiCredentialsCredentials(t *testing.T) {
|
|
|
|
c := client()
|
|
|
|
|
2018-03-19 23:18:36 +03:00
|
|
|
data, status, err := c.APICredentials()
|
2018-04-22 20:39:22 +03:00
|
|
|
if err.RuntimeErr != nil {
|
2018-02-27 11:37:15 +03:00
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
|
|
|
|
if status >= http.StatusBadRequest {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if data.Success != true {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClient_CustomersCustomers(t *testing.T) {
|
|
|
|
c := client()
|
|
|
|
|
|
|
|
data, status, err := c.Customers(CustomersRequest{
|
|
|
|
Filter: CustomersFilter{
|
|
|
|
City: "Москва",
|
|
|
|
},
|
|
|
|
Page: 3,
|
|
|
|
})
|
|
|
|
|
2018-04-22 20:39:22 +03:00
|
|
|
if err.RuntimeErr != nil {
|
|
|
|
t.Errorf("%v", err.Error())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if status >= http.StatusBadRequest {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if data.Success != true {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClient_CustomerChange(t *testing.T) {
|
|
|
|
c := client()
|
|
|
|
|
|
|
|
f := Customer{
|
|
|
|
FirstName: "Понтелей",
|
|
|
|
LastName: "Турбин",
|
|
|
|
Patronymic: "Аристархович",
|
2018-03-19 23:18:36 +03:00
|
|
|
ExternalID: RandomString(8),
|
2018-02-27 11:37:15 +03:00
|
|
|
Email: fmt.Sprintf("%s@example.com", RandomString(8)),
|
|
|
|
Address: &Address{
|
|
|
|
City: "Москва",
|
|
|
|
Street: "Кутузовский",
|
|
|
|
Building: "14",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
cr, sc, err := c.CustomerCreate(f)
|
2018-04-22 20:39:22 +03:00
|
|
|
if err.RuntimeErr != nil {
|
|
|
|
t.Errorf("%v", err.Error())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if sc != http.StatusCreated {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if cr.Success != true {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-19 23:18:36 +03:00
|
|
|
f.ID = cr.ID
|
2018-02-27 11:37:15 +03:00
|
|
|
f.Vip = true
|
|
|
|
|
|
|
|
ed, se, err := c.CustomerEdit(f, "id")
|
2018-04-22 20:39:22 +03:00
|
|
|
if err.RuntimeErr != nil {
|
|
|
|
t.Errorf("%v", err.Error())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if se != http.StatusOK {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if ed.Success != true {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-19 23:18:36 +03:00
|
|
|
data, status, err := c.Customer(f.ExternalID, "externalId", "")
|
2018-04-22 20:39:22 +03:00
|
|
|
if err.RuntimeErr != nil {
|
|
|
|
t.Errorf("%v", err.Error())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if status >= http.StatusBadRequest {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if data.Success != true {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-19 23:18:36 +03:00
|
|
|
if data.Customer.ExternalID != f.ExternalID {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClient_CustomersUpload(t *testing.T) {
|
|
|
|
c := client()
|
|
|
|
customers := make([]Customer, 3)
|
|
|
|
|
|
|
|
for i := range customers {
|
|
|
|
customers[i] = Customer{
|
|
|
|
FirstName: fmt.Sprintf("Name_%s", RandomString(8)),
|
|
|
|
LastName: fmt.Sprintf("Test_%s", RandomString(8)),
|
2018-03-19 23:18:36 +03:00
|
|
|
ExternalID: RandomString(8),
|
2018-02-27 11:37:15 +03:00
|
|
|
Email: fmt.Sprintf("%s@example.com", RandomString(8)),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
data, status, err := c.CustomersUpload(customers)
|
2018-04-22 20:39:22 +03:00
|
|
|
if err.RuntimeErr != nil {
|
|
|
|
t.Errorf("%v", err.Error())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if status >= http.StatusBadRequest {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if data.Success != true {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClient_CustomersCombine(t *testing.T) {
|
|
|
|
c := client()
|
|
|
|
|
|
|
|
dataFirst, status, err := c.CustomerCreate(Customer{
|
|
|
|
FirstName: fmt.Sprintf("Name_%s", RandomString(8)),
|
|
|
|
LastName: fmt.Sprintf("Test_%s", RandomString(8)),
|
2018-03-19 23:18:36 +03:00
|
|
|
ExternalID: RandomString(8),
|
2018-02-27 11:37:15 +03:00
|
|
|
Email: fmt.Sprintf("%s@example.com", RandomString(8)),
|
|
|
|
})
|
2018-04-22 20:39:22 +03:00
|
|
|
if err.RuntimeErr != nil {
|
|
|
|
t.Errorf("%v", err.Error())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if status >= http.StatusBadRequest {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if dataFirst.Success != true {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
dataSecond, status, err := c.CustomerCreate(Customer{
|
|
|
|
FirstName: fmt.Sprintf("Name_%s", RandomString(8)),
|
|
|
|
LastName: fmt.Sprintf("Test_%s", RandomString(8)),
|
2018-03-19 23:18:36 +03:00
|
|
|
ExternalID: RandomString(8),
|
2018-02-27 11:37:15 +03:00
|
|
|
Email: fmt.Sprintf("%s@example.com", RandomString(8)),
|
|
|
|
})
|
2018-04-22 20:39:22 +03:00
|
|
|
if err.RuntimeErr != nil {
|
|
|
|
t.Errorf("%v", err.Error())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if status >= http.StatusBadRequest {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if dataSecond.Success != true {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
dataThird, status, err := c.CustomerCreate(Customer{
|
|
|
|
FirstName: fmt.Sprintf("Name_%s", RandomString(8)),
|
|
|
|
LastName: fmt.Sprintf("Test_%s", RandomString(8)),
|
2018-03-19 23:18:36 +03:00
|
|
|
ExternalID: RandomString(8),
|
2018-02-27 11:37:15 +03:00
|
|
|
Email: fmt.Sprintf("%s@example.com", RandomString(8)),
|
|
|
|
})
|
2018-04-22 20:39:22 +03:00
|
|
|
if err.RuntimeErr != nil {
|
|
|
|
t.Errorf("%v", err.Error())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if status >= http.StatusBadRequest {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if dataThird.Success != true {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-19 23:18:36 +03:00
|
|
|
data, status, err := c.CustomersCombine([]Customer{{ID: dataFirst.ID}, {ID: dataSecond.ID}}, Customer{ID: dataThird.ID})
|
2018-04-22 20:39:22 +03:00
|
|
|
if err.RuntimeErr != nil {
|
|
|
|
t.Errorf("%v", err.Error())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if status >= http.StatusBadRequest {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if data.Success != true {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClient_CustomersFixExternalIds(t *testing.T) {
|
|
|
|
c := client()
|
|
|
|
f := Customer{
|
|
|
|
FirstName: fmt.Sprintf("Name_%s", RandomString(8)),
|
|
|
|
LastName: fmt.Sprintf("Test_%s", RandomString(8)),
|
2018-03-19 23:18:36 +03:00
|
|
|
ExternalID: RandomString(8),
|
2018-02-27 11:37:15 +03:00
|
|
|
Email: fmt.Sprintf("%s@example.com", RandomString(8)),
|
|
|
|
}
|
|
|
|
|
|
|
|
cr, sc, err := c.CustomerCreate(f)
|
2018-04-22 20:39:22 +03:00
|
|
|
if err.RuntimeErr != nil {
|
|
|
|
t.Errorf("%v", err.Error())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if sc != http.StatusCreated {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if cr.Success != true {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
customers := []IdentifiersPair{{
|
2018-03-19 23:18:36 +03:00
|
|
|
ID: cr.ID,
|
|
|
|
ExternalID: RandomString(8),
|
2018-02-27 11:37:15 +03:00
|
|
|
}}
|
|
|
|
|
|
|
|
fx, fe, err := c.CustomersFixExternalIds(customers)
|
2018-04-22 20:39:22 +03:00
|
|
|
if err.RuntimeErr != nil {
|
|
|
|
t.Errorf("%v", err.Error())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if fe != http.StatusOK {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if fx.Success != true {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClient_CustomersHistory(t *testing.T) {
|
|
|
|
c := client()
|
|
|
|
f := CustomersHistoryRequest{
|
|
|
|
Filter: CustomersHistoryFilter{
|
2018-03-19 23:18:36 +03:00
|
|
|
SinceID: 20,
|
2018-02-27 11:37:15 +03:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
data, status, err := c.CustomersHistory(f)
|
2018-04-22 20:39:22 +03:00
|
|
|
if err.RuntimeErr != nil {
|
|
|
|
t.Errorf("%v", err.Error())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if status >= http.StatusBadRequest {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if data.Success != true {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if len(data.History) == 0 {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", "Empty history")
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClient_NotesNotes(t *testing.T) {
|
|
|
|
c := client()
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
data, status, err := c.CustomerNotes(NotesRequest{Page: 1})
|
2018-04-22 20:39:22 +03:00
|
|
|
if err.RuntimeErr != nil {
|
|
|
|
t.Errorf("%v", err.Error())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if status != http.StatusOK {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if data.Success != true {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClient_NotesCreateDelete(t *testing.T) {
|
|
|
|
c := client()
|
|
|
|
|
|
|
|
createCustomerResponse, createCustomerStatus, err := c.CustomerCreate(Customer{
|
|
|
|
FirstName: "Понтелей",
|
|
|
|
LastName: "Турбин",
|
|
|
|
Patronymic: "Аристархович",
|
2018-03-19 23:18:36 +03:00
|
|
|
ExternalID: RandomString(8),
|
2018-02-27 11:37:15 +03:00
|
|
|
Email: fmt.Sprintf("%s@example.com", RandomString(8)),
|
|
|
|
})
|
2018-04-22 20:39:22 +03:00
|
|
|
if err.RuntimeErr != nil {
|
|
|
|
t.Errorf("%v", err.Error())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if createCustomerStatus != http.StatusCreated {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if createCustomerResponse.Success != true {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
noteCreateResponse, noteCreateStatus, err := c.CustomerNoteCreate(Note{
|
2018-02-27 11:37:15 +03:00
|
|
|
Text: "some text",
|
2018-03-19 23:18:36 +03:00
|
|
|
ManagerID: user,
|
2018-02-27 11:37:15 +03:00
|
|
|
Customer: &Customer{
|
2018-03-19 23:18:36 +03:00
|
|
|
ID: createCustomerResponse.ID,
|
2018-02-27 11:37:15 +03:00
|
|
|
},
|
|
|
|
})
|
2018-04-22 20:39:22 +03:00
|
|
|
if err.RuntimeErr != nil {
|
|
|
|
t.Errorf("%v", err.Error())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if noteCreateStatus != http.StatusCreated {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if noteCreateResponse.Success != true {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
noteDeleteResponse, noteDeleteStatus, err := c.CustomerNoteDelete(noteCreateResponse.ID)
|
2018-04-22 20:39:22 +03:00
|
|
|
if err.RuntimeErr != nil {
|
|
|
|
t.Errorf("%v", err.Error())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if noteDeleteStatus != http.StatusOK {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if noteDeleteResponse.Success != true {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClient_OrdersOrders(t *testing.T) {
|
|
|
|
c := client()
|
|
|
|
|
|
|
|
data, status, err := c.Orders(OrdersRequest{Filter: OrdersFilter{City: "Москва"}, Page: 1})
|
2018-04-22 20:39:22 +03:00
|
|
|
if err.RuntimeErr != nil {
|
|
|
|
t.Errorf("%v", err.Error())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if status >= http.StatusBadRequest {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if data.Success != true {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClient_OrderChange(t *testing.T) {
|
|
|
|
c := client()
|
|
|
|
|
|
|
|
random := RandomString(8)
|
|
|
|
|
|
|
|
f := Order{
|
|
|
|
FirstName: "Понтелей",
|
|
|
|
LastName: "Турбин",
|
|
|
|
Patronymic: "Аристархович",
|
2018-03-19 23:18:36 +03:00
|
|
|
ExternalID: random,
|
2018-02-27 11:37:15 +03:00
|
|
|
Email: fmt.Sprintf("%s@example.com", random),
|
|
|
|
}
|
|
|
|
|
|
|
|
cr, sc, err := c.OrderCreate(f)
|
2018-04-22 20:39:22 +03:00
|
|
|
if err.RuntimeErr != nil {
|
|
|
|
t.Errorf("%v", err.Error())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if sc != http.StatusCreated {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if cr.Success != true {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-19 23:18:36 +03:00
|
|
|
f.ID = cr.ID
|
2018-02-27 11:37:15 +03:00
|
|
|
f.CustomerComment = "test comment"
|
|
|
|
|
|
|
|
ed, se, err := c.OrderEdit(f, "id")
|
2018-04-22 20:39:22 +03:00
|
|
|
if err.RuntimeErr != nil {
|
|
|
|
t.Errorf("%v", err.Error())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if se != http.StatusOK {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if ed.Success != true {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-19 23:18:36 +03:00
|
|
|
data, status, err := c.Order(f.ExternalID, "externalId", "")
|
2018-04-22 20:39:22 +03:00
|
|
|
if err.RuntimeErr != nil {
|
|
|
|
t.Errorf("%v", err.Error())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if status >= http.StatusBadRequest {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if data.Success != true {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-19 23:18:36 +03:00
|
|
|
if data.Order.ExternalID != f.ExternalID {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClient_OrdersUpload(t *testing.T) {
|
|
|
|
c := client()
|
|
|
|
orders := make([]Order, 3)
|
|
|
|
|
|
|
|
for i := range orders {
|
|
|
|
orders[i] = Order{
|
|
|
|
FirstName: fmt.Sprintf("Name_%s", RandomString(8)),
|
|
|
|
LastName: fmt.Sprintf("Test_%s", RandomString(8)),
|
2018-03-19 23:18:36 +03:00
|
|
|
ExternalID: RandomString(8),
|
2018-02-27 11:37:15 +03:00
|
|
|
Email: fmt.Sprintf("%s@example.com", RandomString(8)),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
data, status, err := c.OrdersUpload(orders)
|
2018-04-22 20:39:22 +03:00
|
|
|
if err.RuntimeErr != nil {
|
|
|
|
t.Errorf("%v", err.Error())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if status >= http.StatusBadRequest {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if data.Success != true {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClient_OrdersCombine(t *testing.T) {
|
|
|
|
c := client()
|
|
|
|
|
|
|
|
dataFirst, status, err := c.OrderCreate(Order{
|
|
|
|
FirstName: fmt.Sprintf("Name_%s", RandomString(8)),
|
|
|
|
LastName: fmt.Sprintf("Test_%s", RandomString(8)),
|
2018-03-19 23:18:36 +03:00
|
|
|
ExternalID: RandomString(8),
|
2018-02-27 11:37:15 +03:00
|
|
|
Email: fmt.Sprintf("%s@example.com", RandomString(8)),
|
|
|
|
})
|
2018-04-22 20:39:22 +03:00
|
|
|
if err.RuntimeErr != nil {
|
|
|
|
t.Errorf("%v", err.Error())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if status >= http.StatusBadRequest {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if dataFirst.Success != true {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
dataSecond, status, err := c.OrderCreate(Order{
|
|
|
|
FirstName: fmt.Sprintf("Name_%s", RandomString(8)),
|
|
|
|
LastName: fmt.Sprintf("Test_%s", RandomString(8)),
|
2018-03-19 23:18:36 +03:00
|
|
|
ExternalID: RandomString(8),
|
2018-02-27 11:37:15 +03:00
|
|
|
Email: fmt.Sprintf("%s@example.com", RandomString(8)),
|
|
|
|
})
|
2018-04-22 20:39:22 +03:00
|
|
|
if err.RuntimeErr != nil {
|
|
|
|
t.Errorf("%v", err.Error())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if status >= http.StatusBadRequest {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if dataSecond.Success != true {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-19 23:18:36 +03:00
|
|
|
data, status, err := c.OrdersCombine("ours", Order{ID: dataFirst.ID}, Order{ID: dataSecond.ID})
|
2018-04-22 20:39:22 +03:00
|
|
|
if err.RuntimeErr != nil {
|
|
|
|
t.Errorf("%v", err.Error())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if status >= http.StatusBadRequest {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if data.Success != true {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClient_OrdersFixExternalIds(t *testing.T) {
|
|
|
|
c := client()
|
|
|
|
f := Order{
|
|
|
|
FirstName: fmt.Sprintf("Name_%s", RandomString(8)),
|
|
|
|
LastName: fmt.Sprintf("Test_%s", RandomString(8)),
|
2018-03-19 23:18:36 +03:00
|
|
|
ExternalID: RandomString(8),
|
2018-02-27 11:37:15 +03:00
|
|
|
Email: fmt.Sprintf("%s@example.com", RandomString(8)),
|
|
|
|
}
|
|
|
|
|
|
|
|
cr, sc, err := c.OrderCreate(f)
|
2018-04-22 20:39:22 +03:00
|
|
|
if err.RuntimeErr != nil {
|
|
|
|
t.Errorf("%v", err.Error())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if sc != http.StatusCreated {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if cr.Success != true {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
orders := []IdentifiersPair{{
|
2018-03-19 23:18:36 +03:00
|
|
|
ID: cr.ID,
|
|
|
|
ExternalID: RandomString(8),
|
2018-02-27 11:37:15 +03:00
|
|
|
}}
|
|
|
|
|
|
|
|
fx, fe, err := c.OrdersFixExternalIds(orders)
|
2018-04-22 20:39:22 +03:00
|
|
|
if err.RuntimeErr != nil {
|
|
|
|
t.Errorf("%v", err.Error())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if fe != http.StatusOK {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if fx.Success != true {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClient_OrdersHistory(t *testing.T) {
|
|
|
|
c := client()
|
|
|
|
|
2018-03-19 23:18:36 +03:00
|
|
|
data, status, err := c.OrdersHistory(OrdersHistoryRequest{Filter: OrdersHistoryFilter{SinceID: 20}})
|
2018-04-22 20:39:22 +03:00
|
|
|
if err.RuntimeErr != nil {
|
|
|
|
t.Errorf("%v", err.Error())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if status >= http.StatusBadRequest {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if data.Success != true {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if len(data.History) == 0 {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClient_PaymentCreateEditDelete(t *testing.T) {
|
|
|
|
c := client()
|
|
|
|
|
|
|
|
order := Order{
|
|
|
|
FirstName: "Понтелей",
|
|
|
|
LastName: "Турбин",
|
|
|
|
Patronymic: "Аристархович",
|
2018-03-19 23:18:36 +03:00
|
|
|
ExternalID: RandomString(8),
|
2018-02-27 11:37:15 +03:00
|
|
|
Email: fmt.Sprintf("%s@example.com", RandomString(8)),
|
|
|
|
}
|
|
|
|
|
|
|
|
createOrderResponse, status, err := c.OrderCreate(order)
|
2018-04-22 20:39:22 +03:00
|
|
|
if err.RuntimeErr != nil {
|
|
|
|
t.Errorf("%v", err.Error())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if status != http.StatusCreated {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if createOrderResponse.Success != true {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
f := Payment{
|
|
|
|
Order: &Order{
|
2018-03-19 23:18:36 +03:00
|
|
|
ID: createOrderResponse.ID,
|
2018-02-27 11:37:15 +03:00
|
|
|
},
|
|
|
|
Amount: 300,
|
|
|
|
Type: "cash",
|
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
paymentCreateResponse, status, err := c.OrderPaymentCreate(f)
|
2018-04-22 20:39:22 +03:00
|
|
|
if err.RuntimeErr != nil {
|
|
|
|
t.Errorf("%v", err.Error())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if status != http.StatusCreated {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if paymentCreateResponse.Success != true {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
k := Payment{
|
2018-03-19 23:18:36 +03:00
|
|
|
ID: paymentCreateResponse.ID,
|
2018-02-27 11:37:15 +03:00
|
|
|
Amount: 500,
|
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
paymentEditResponse, status, err := c.OrderPaymentEdit(k, "id")
|
2018-04-22 20:39:22 +03:00
|
|
|
if err.RuntimeErr != nil {
|
|
|
|
t.Errorf("%v", err.Error())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if status != http.StatusOK {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if paymentEditResponse.Success != true {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
paymentDeleteResponse, status, err := c.OrderPaymentDelete(paymentCreateResponse.ID)
|
2018-04-22 20:39:22 +03:00
|
|
|
if err.RuntimeErr != nil {
|
|
|
|
t.Errorf("%v", err.Error())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if status != http.StatusOK {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if paymentDeleteResponse.Success != true {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClient_TasksTasks(t *testing.T) {
|
|
|
|
c := client()
|
|
|
|
|
|
|
|
f := TasksRequest{
|
|
|
|
Filter: TasksFilter{
|
|
|
|
Creators: []int{user},
|
|
|
|
},
|
|
|
|
Page: 1,
|
|
|
|
}
|
|
|
|
|
|
|
|
data, status, err := c.Tasks(f)
|
2018-04-22 20:39:22 +03:00
|
|
|
if err.RuntimeErr != nil {
|
|
|
|
t.Errorf("%v", err.Error())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if status != http.StatusOK {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if data.Success != true {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClient_TaskChange(t *testing.T) {
|
|
|
|
c := client()
|
|
|
|
|
|
|
|
f := Task{
|
|
|
|
Text: RandomString(15),
|
2018-03-19 23:18:36 +03:00
|
|
|
PerformerID: user,
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
cr, sc, err := c.TaskCreate(f)
|
2018-04-22 20:39:22 +03:00
|
|
|
if err.RuntimeErr != nil {
|
|
|
|
t.Errorf("%v", err.Error())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if sc != http.StatusCreated {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if cr.Success != true {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-19 23:18:36 +03:00
|
|
|
f.ID = cr.ID
|
2018-02-27 11:37:15 +03:00
|
|
|
f.Commentary = RandomString(20)
|
|
|
|
|
2018-03-19 23:18:36 +03:00
|
|
|
gt, sg, err := c.Task(f.ID)
|
2018-04-22 20:39:22 +03:00
|
|
|
if err.RuntimeErr != nil {
|
|
|
|
t.Errorf("%v", err.Error())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if sg != http.StatusOK {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if gt.Success != true {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
data, status, err := c.TaskEdit(f)
|
2018-04-22 20:39:22 +03:00
|
|
|
if err.RuntimeErr != nil {
|
|
|
|
t.Errorf("%v", err.Error())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if status != http.StatusOK {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if data.Success != true {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClient_UsersUsers(t *testing.T) {
|
|
|
|
c := client()
|
|
|
|
|
|
|
|
data, status, err := c.Users(UsersRequest{Filter: UsersFilter{Active: 1}, Page: 1})
|
2018-04-22 20:39:22 +03:00
|
|
|
if err.RuntimeErr != nil {
|
|
|
|
t.Errorf("%v", err.Error())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if status >= http.StatusBadRequest {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if data.Success != true {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClient_UsersUser(t *testing.T) {
|
|
|
|
c := client()
|
|
|
|
|
|
|
|
data, st, err := c.User(user)
|
2018-04-22 20:39:22 +03:00
|
|
|
if err.RuntimeErr != nil {
|
|
|
|
t.Errorf("%v", err.Error())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if st != http.StatusOK {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if data.Success != true {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClient_UsersGroups(t *testing.T) {
|
|
|
|
c := client()
|
|
|
|
|
|
|
|
data, status, err := c.UserGroups(UserGroupsRequest{Page: 1})
|
2018-04-22 20:39:22 +03:00
|
|
|
if err.RuntimeErr != nil {
|
|
|
|
t.Errorf("%v", err.Error())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if status >= http.StatusBadRequest {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if data.Success != true {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClient_UsersUpdate(t *testing.T) {
|
|
|
|
c := client()
|
|
|
|
|
|
|
|
data, st, err := c.UserStatus(user, "busy")
|
2018-04-22 20:39:22 +03:00
|
|
|
if err.RuntimeErr != nil {
|
|
|
|
t.Errorf("%v", err.Error())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if st != http.StatusOK {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if data.Success != true {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
func TestClient_StaticticsUpdate(t *testing.T) {
|
2018-02-27 11:37:15 +03:00
|
|
|
c := client()
|
|
|
|
|
2018-03-21 00:54:37 +03:00
|
|
|
data, st, err := c.StaticticsUpdate()
|
2018-04-22 20:39:22 +03:00
|
|
|
if err.RuntimeErr != nil {
|
|
|
|
t.Errorf("%v", err.Error())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if st != http.StatusOK {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if data.Success != true {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClient_Countries(t *testing.T) {
|
|
|
|
c := client()
|
|
|
|
|
|
|
|
data, st, err := c.Couriers()
|
2018-04-22 20:39:22 +03:00
|
|
|
if err.RuntimeErr != nil {
|
|
|
|
t.Errorf("%v", err.Error())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if st != http.StatusOK {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if data.Success != true {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClient_CostGroups(t *testing.T) {
|
|
|
|
c := client()
|
|
|
|
|
|
|
|
data, st, err := c.CostGroups()
|
2018-04-22 20:39:22 +03:00
|
|
|
if err.RuntimeErr != nil {
|
|
|
|
t.Errorf("%v", err.Error())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if st != http.StatusOK {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if data.Success != true {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClient_CostItems(t *testing.T) {
|
|
|
|
c := client()
|
|
|
|
|
|
|
|
data, st, err := c.CostItems()
|
2018-04-22 20:39:22 +03:00
|
|
|
if err.RuntimeErr != nil {
|
|
|
|
t.Errorf("%v", err.Error())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if st != http.StatusOK {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if data.Success != true {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClient_Couriers(t *testing.T) {
|
|
|
|
c := client()
|
|
|
|
|
|
|
|
data, st, err := c.Couriers()
|
2018-04-22 20:39:22 +03:00
|
|
|
if err.RuntimeErr != nil {
|
|
|
|
t.Errorf("%v", err.Error())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if st != http.StatusOK {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if data.Success != true {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClient_DeliveryService(t *testing.T) {
|
|
|
|
c := client()
|
|
|
|
|
|
|
|
data, st, err := c.DeliveryServices()
|
2018-04-22 20:39:22 +03:00
|
|
|
if err.RuntimeErr != nil {
|
|
|
|
t.Errorf("%v", err.Error())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if st != http.StatusOK {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if data.Success != true {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClient_DeliveryTypes(t *testing.T) {
|
|
|
|
c := client()
|
|
|
|
|
|
|
|
data, st, err := c.DeliveryTypes()
|
2018-04-22 20:39:22 +03:00
|
|
|
if err.RuntimeErr != nil {
|
|
|
|
t.Errorf("%v", err.Error())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if st != http.StatusOK {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if data.Success != true {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClient_LegalEntities(t *testing.T) {
|
|
|
|
c := client()
|
|
|
|
|
|
|
|
data, st, err := c.LegalEntities()
|
2018-04-22 20:39:22 +03:00
|
|
|
if err.RuntimeErr != nil {
|
|
|
|
t.Errorf("%v", err.Error())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if st != http.StatusOK {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if data.Success != true {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClient_OrderMethods(t *testing.T) {
|
|
|
|
c := client()
|
|
|
|
|
|
|
|
data, st, err := c.OrderMethods()
|
2018-04-22 20:39:22 +03:00
|
|
|
if err.RuntimeErr != nil {
|
|
|
|
t.Errorf("%v", err.Error())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if st != http.StatusOK {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if data.Success != true {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClient_OrderTypes(t *testing.T) {
|
|
|
|
c := client()
|
|
|
|
|
|
|
|
data, st, err := c.OrderTypes()
|
2018-04-22 20:39:22 +03:00
|
|
|
if err.RuntimeErr != nil {
|
|
|
|
t.Errorf("%v", err.Error())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if st != http.StatusOK {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if data.Success != true {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClient_PaymentStatuses(t *testing.T) {
|
|
|
|
c := client()
|
|
|
|
|
|
|
|
data, st, err := c.PaymentStatuses()
|
2018-04-22 20:39:22 +03:00
|
|
|
if err.RuntimeErr != nil {
|
|
|
|
t.Errorf("%v", err.Error())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if st != http.StatusOK {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if data.Success != true {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClient_PaymentTypes(t *testing.T) {
|
|
|
|
c := client()
|
|
|
|
|
|
|
|
data, st, err := c.PaymentTypes()
|
2018-04-22 20:39:22 +03:00
|
|
|
if err.RuntimeErr != nil {
|
|
|
|
t.Errorf("%v", err.Error())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if st != http.StatusOK {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if data.Success != true {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClient_PriceTypes(t *testing.T) {
|
|
|
|
c := client()
|
|
|
|
|
|
|
|
data, st, err := c.PriceTypes()
|
2018-04-22 20:39:22 +03:00
|
|
|
if err.RuntimeErr != nil {
|
|
|
|
t.Errorf("%v", err.Error())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if st != http.StatusOK {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if data.Success != true {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClient_ProductStatuses(t *testing.T) {
|
|
|
|
c := client()
|
|
|
|
|
|
|
|
data, st, err := c.ProductStatuses()
|
2018-04-22 20:39:22 +03:00
|
|
|
if err.RuntimeErr != nil {
|
|
|
|
t.Errorf("%v", err.Error())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if st != http.StatusOK {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if data.Success != true {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClient_Statuses(t *testing.T) {
|
|
|
|
c := client()
|
|
|
|
|
|
|
|
data, st, err := c.Statuses()
|
2018-04-22 20:39:22 +03:00
|
|
|
if err.RuntimeErr != nil {
|
|
|
|
t.Errorf("%v", err.Error())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if st != http.StatusOK {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if data.Success != true {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClient_StatusGroups(t *testing.T) {
|
|
|
|
c := client()
|
|
|
|
|
|
|
|
data, st, err := c.StatusGroups()
|
2018-04-22 20:39:22 +03:00
|
|
|
if err.RuntimeErr != nil {
|
|
|
|
t.Errorf("%v", err.Error())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if st != http.StatusOK {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if data.Success != true {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClient_Sites(t *testing.T) {
|
|
|
|
c := client()
|
|
|
|
|
|
|
|
data, st, err := c.Sites()
|
2018-04-22 20:39:22 +03:00
|
|
|
if err.RuntimeErr != nil {
|
|
|
|
t.Errorf("%v", err.Error())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if st != http.StatusOK {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if data.Success != true {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClient_Stores(t *testing.T) {
|
|
|
|
c := client()
|
|
|
|
|
|
|
|
data, st, err := c.Stores()
|
2018-04-22 20:39:22 +03:00
|
|
|
if err.RuntimeErr != nil {
|
|
|
|
t.Errorf("%v", err.Error())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if st != http.StatusOK {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if data.Success != true {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClient_CostGroupItemEdit(t *testing.T) {
|
|
|
|
c := client()
|
|
|
|
|
|
|
|
uid := RandomString(4)
|
|
|
|
|
|
|
|
data, st, err := c.CostGroupEdit(CostGroup{
|
|
|
|
Code: fmt.Sprintf("cost-gr-%s", uid),
|
|
|
|
Active: false,
|
|
|
|
Color: "#da5c98",
|
|
|
|
Name: fmt.Sprintf("CostGroup-%s", uid),
|
|
|
|
})
|
2018-04-22 20:39:22 +03:00
|
|
|
if err.RuntimeErr != nil {
|
|
|
|
t.Errorf("%v", err.Error())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if !statuses[st] {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if data.Success != true {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
idata, st, err := c.CostItemEdit(CostItem{
|
|
|
|
Code: fmt.Sprintf("cost-it-%s", uid),
|
|
|
|
Name: fmt.Sprintf("CostItem-%s", uid),
|
|
|
|
Group: fmt.Sprintf("cost-gr-%s", uid),
|
|
|
|
Type: "const",
|
|
|
|
AppliesToOrders: true,
|
|
|
|
Active: false,
|
|
|
|
})
|
2018-04-22 20:39:22 +03:00
|
|
|
if err.RuntimeErr != nil {
|
|
|
|
t.Errorf("%v", err.Error())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if !statuses[st] {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if idata.Success != true {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClient_Courier(t *testing.T) {
|
|
|
|
c := client()
|
|
|
|
|
|
|
|
cur := Courier{
|
|
|
|
Active: true,
|
|
|
|
Email: fmt.Sprintf("%s@example.com", RandomString(5)),
|
|
|
|
FirstName: fmt.Sprintf("%s", RandomString(5)),
|
|
|
|
LastName: fmt.Sprintf("%s", RandomString(5)),
|
|
|
|
}
|
|
|
|
|
|
|
|
data, st, err := c.CourierCreate(cur)
|
2018-04-22 20:39:22 +03:00
|
|
|
if err.RuntimeErr != nil {
|
|
|
|
t.Errorf("%v", err.Error())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if !statuses[st] {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if data.Success != true {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-19 23:18:36 +03:00
|
|
|
cur.ID = data.ID
|
2018-02-27 11:37:15 +03:00
|
|
|
cur.Patronymic = fmt.Sprintf("%s", RandomString(5))
|
|
|
|
|
|
|
|
idata, st, err := c.CourierEdit(cur)
|
2018-04-22 20:39:22 +03:00
|
|
|
if err.RuntimeErr != nil {
|
|
|
|
t.Errorf("%v", err.Error())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if !statuses[st] {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if idata.Success != true {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClient_DeliveryServiceEdit(t *testing.T) {
|
|
|
|
c := client()
|
|
|
|
|
|
|
|
data, st, err := c.DeliveryServiceEdit(DeliveryService{
|
|
|
|
Active: false,
|
|
|
|
Code: RandomString(5),
|
|
|
|
Name: RandomString(5),
|
|
|
|
})
|
2018-04-22 20:39:22 +03:00
|
|
|
if err.RuntimeErr != nil {
|
|
|
|
t.Errorf("%v", err.Error())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if !statuses[st] {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if data.Success != true {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClient_DeliveryTypeEdit(t *testing.T) {
|
|
|
|
c := client()
|
|
|
|
|
|
|
|
x := []string{"cash", "bank-card"}
|
|
|
|
|
|
|
|
data, st, err := c.DeliveryTypeEdit(DeliveryType{
|
|
|
|
Active: false,
|
|
|
|
Code: RandomString(5),
|
|
|
|
Name: RandomString(5),
|
|
|
|
DefaultCost: 300,
|
|
|
|
PaymentTypes: x,
|
|
|
|
DefaultForCrm: false,
|
|
|
|
})
|
2018-04-22 20:39:22 +03:00
|
|
|
if err.RuntimeErr != nil {
|
|
|
|
t.Errorf("%v", err.Error())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if !statuses[st] {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if data.Success != true {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClient_OrderMethodEdit(t *testing.T) {
|
|
|
|
c := client()
|
|
|
|
|
|
|
|
data, st, err := c.OrderMethodEdit(OrderMethod{
|
|
|
|
Code: RandomString(5),
|
|
|
|
Name: RandomString(5),
|
|
|
|
Active: false,
|
2018-03-19 23:18:36 +03:00
|
|
|
DefaultForCRM: false,
|
2018-02-27 11:37:15 +03:00
|
|
|
})
|
2018-04-22 20:39:22 +03:00
|
|
|
if err.RuntimeErr != nil {
|
|
|
|
t.Errorf("%v", err.Error())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if !statuses[st] {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if data.Success != true {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClient_OrderTypeEdit(t *testing.T) {
|
|
|
|
c := client()
|
|
|
|
|
|
|
|
data, st, err := c.OrderTypeEdit(OrderType{
|
|
|
|
Code: RandomString(5),
|
|
|
|
Name: RandomString(5),
|
|
|
|
Active: false,
|
2018-03-19 23:18:36 +03:00
|
|
|
DefaultForCRM: false,
|
2018-02-27 11:37:15 +03:00
|
|
|
})
|
2018-04-22 20:39:22 +03:00
|
|
|
if err.RuntimeErr != nil {
|
|
|
|
t.Errorf("%v", err.Error())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if !statuses[st] {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if data.Success != true {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClient_PaymentStatusEdit(t *testing.T) {
|
|
|
|
c := client()
|
|
|
|
|
|
|
|
data, st, err := c.PaymentStatusEdit(PaymentStatus{
|
|
|
|
Code: RandomString(5),
|
|
|
|
Name: RandomString(5),
|
|
|
|
Active: false,
|
2018-03-19 23:18:36 +03:00
|
|
|
DefaultForCRM: false,
|
2018-02-27 11:37:15 +03:00
|
|
|
PaymentTypes: []string{"cash"},
|
|
|
|
PaymentComplete: false,
|
|
|
|
})
|
2018-04-22 20:39:22 +03:00
|
|
|
if err.RuntimeErr != nil {
|
|
|
|
t.Errorf("%v", err.Error())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if !statuses[st] {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if data.Success != true {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClient_PaymentTypeEdit(t *testing.T) {
|
|
|
|
c := client()
|
|
|
|
|
|
|
|
data, st, err := c.PaymentTypeEdit(PaymentType{
|
|
|
|
Code: RandomString(5),
|
|
|
|
Name: RandomString(5),
|
|
|
|
Active: false,
|
2018-03-19 23:18:36 +03:00
|
|
|
DefaultForCRM: false,
|
2018-02-27 11:37:15 +03:00
|
|
|
})
|
2018-04-22 20:39:22 +03:00
|
|
|
if err.RuntimeErr != nil {
|
|
|
|
t.Errorf("%v", err.Error())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if !statuses[st] {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if data.Success != true {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClient_PriceTypeEdit(t *testing.T) {
|
|
|
|
c := client()
|
|
|
|
|
|
|
|
data, st, err := c.PriceTypeEdit(PriceType{
|
|
|
|
Code: RandomString(5),
|
|
|
|
Name: RandomString(5),
|
|
|
|
Active: false,
|
|
|
|
})
|
2018-04-22 20:39:22 +03:00
|
|
|
if err.RuntimeErr != nil {
|
|
|
|
t.Errorf("%v", err.Error())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if !statuses[st] {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if data.Success != true {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClient_ProductStatusEdit(t *testing.T) {
|
|
|
|
c := client()
|
|
|
|
|
|
|
|
data, st, err := c.ProductStatusEdit(ProductStatus{
|
|
|
|
Code: RandomString(5),
|
|
|
|
Name: RandomString(5),
|
|
|
|
Active: false,
|
|
|
|
CancelStatus: false,
|
|
|
|
})
|
2018-04-22 20:39:22 +03:00
|
|
|
if err.RuntimeErr != nil {
|
|
|
|
t.Errorf("%v", err.Error())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if !statuses[st] {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if data.Success != true {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClient_StatusEdit(t *testing.T) {
|
|
|
|
c := client()
|
|
|
|
|
|
|
|
data, st, err := c.StatusEdit(Status{
|
|
|
|
Code: RandomString(5),
|
|
|
|
Name: RandomString(5),
|
|
|
|
Active: false,
|
|
|
|
Group: "new",
|
|
|
|
})
|
2018-04-22 20:39:22 +03:00
|
|
|
if err.RuntimeErr != nil {
|
|
|
|
t.Errorf("%v", err.Error())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if !statuses[st] {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if data.Success != true {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClient_SiteEdit(t *testing.T) {
|
|
|
|
c := client()
|
|
|
|
|
|
|
|
data, _, err := c.SiteEdit(Site{
|
|
|
|
Code: RandomString(5),
|
|
|
|
Name: RandomString(5),
|
2018-03-19 23:18:36 +03:00
|
|
|
URL: fmt.Sprintf("https://%s.example.com", RandomString(4)),
|
2018-02-27 11:37:15 +03:00
|
|
|
LoadFromYml: false,
|
|
|
|
})
|
2018-04-22 20:39:22 +03:00
|
|
|
if err.RuntimeErr != nil {
|
|
|
|
t.Errorf("%v", err.Error())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if data.Success != false {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClient_StoreEdit(t *testing.T) {
|
|
|
|
c := client()
|
|
|
|
|
|
|
|
data, st, err := c.StoreEdit(Store{
|
|
|
|
Code: RandomString(5),
|
|
|
|
Name: RandomString(5),
|
|
|
|
Active: false,
|
|
|
|
Type: "store-type-warehouse",
|
|
|
|
InventoryType: "integer",
|
|
|
|
})
|
2018-04-22 20:39:22 +03:00
|
|
|
if err.RuntimeErr != nil {
|
|
|
|
t.Errorf("%v", err.Error())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if !statuses[st] {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if data.Success != true {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClient_PackChange(t *testing.T) {
|
|
|
|
c := client()
|
|
|
|
|
|
|
|
o, status, err := c.OrderCreate(Order{
|
|
|
|
FirstName: "Понтелей",
|
|
|
|
LastName: "Турбин",
|
|
|
|
Patronymic: "Аристархович",
|
2018-03-19 23:18:36 +03:00
|
|
|
ExternalID: RandomString(8),
|
2018-02-27 11:37:15 +03:00
|
|
|
Email: fmt.Sprintf("%s@example.com", RandomString(8)),
|
2018-03-19 23:18:36 +03:00
|
|
|
Items: []OrderItem{{Offer: Offer{ID: 1609}, Quantity: 5}},
|
2018-02-27 11:37:15 +03:00
|
|
|
})
|
2018-04-22 20:39:22 +03:00
|
|
|
if err.RuntimeErr != nil {
|
|
|
|
t.Errorf("%v", err.Error())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if status != http.StatusCreated {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if o.Success != true {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-19 23:18:36 +03:00
|
|
|
g, status, err := c.Order(strconv.Itoa(o.ID), "id", "")
|
2018-04-22 20:39:22 +03:00
|
|
|
if err.RuntimeErr != nil {
|
|
|
|
t.Errorf("%v", err.Error())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if status != http.StatusOK {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if o.Success != true {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
p, status, err := c.PackCreate(Pack{
|
|
|
|
Store: "test-store",
|
2018-03-19 23:18:36 +03:00
|
|
|
ItemID: g.Order.Items[0].ID,
|
2018-02-27 11:37:15 +03:00
|
|
|
Quantity: 1,
|
|
|
|
})
|
2018-04-22 20:39:22 +03:00
|
|
|
if err.RuntimeErr != nil {
|
|
|
|
t.Errorf("%v", err.Error())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if status != http.StatusCreated {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if p.Success != true {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-19 23:18:36 +03:00
|
|
|
s, status, err := c.Pack(p.ID)
|
2018-04-22 20:39:22 +03:00
|
|
|
if err.RuntimeErr != nil {
|
|
|
|
t.Errorf("%v", err.Error())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if status != http.StatusOK {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if s.Success != true {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-19 23:18:36 +03:00
|
|
|
e, status, err := c.PackEdit(Pack{ID: p.ID, Quantity: 2})
|
2018-04-22 20:39:22 +03:00
|
|
|
if err.RuntimeErr != nil {
|
|
|
|
t.Errorf("%v", err.Error())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if status != http.StatusOK {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if e.Success != true {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-19 23:18:36 +03:00
|
|
|
d, status, err := c.PackDelete(p.ID)
|
2018-04-22 20:39:22 +03:00
|
|
|
if err.RuntimeErr != nil {
|
|
|
|
t.Errorf("%v", err.Error())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if status != http.StatusOK {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if d.Success != true {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClient_PacksHistory(t *testing.T) {
|
|
|
|
c := client()
|
|
|
|
|
2018-03-19 23:18:36 +03:00
|
|
|
data, status, err := c.PacksHistory(PacksHistoryRequest{Filter: OrdersHistoryFilter{SinceID: 5}})
|
2018-04-22 20:39:22 +03:00
|
|
|
if err.RuntimeErr != nil {
|
|
|
|
t.Errorf("%v", err.Error())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if status >= http.StatusBadRequest {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if data.Success != true {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if len(data.History) == 0 {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClient_Packs(t *testing.T) {
|
|
|
|
c := client()
|
|
|
|
|
|
|
|
data, status, err := c.Packs(PacksRequest{Filter: PacksFilter{}, Page: 1})
|
2018-04-22 20:39:22 +03:00
|
|
|
if err.RuntimeErr != nil {
|
|
|
|
t.Errorf("%v", err.Error())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if status >= http.StatusBadRequest {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if data.Success != true {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClient_Inventories(t *testing.T) {
|
|
|
|
c := client()
|
|
|
|
|
|
|
|
data, status, err := c.Inventories(InventoriesRequest{Filter: InventoriesFilter{Details: 1}, Page: 1})
|
2018-04-22 20:39:22 +03:00
|
|
|
if err.RuntimeErr != nil {
|
|
|
|
t.Errorf("%v", err.Error())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if status >= http.StatusBadRequest {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if data.Success != true {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClient_Segments(t *testing.T) {
|
|
|
|
c := client()
|
|
|
|
|
|
|
|
data, status, err := c.Segments(SegmentsRequest{})
|
2018-04-22 20:39:22 +03:00
|
|
|
if err.RuntimeErr != nil {
|
|
|
|
t.Errorf("%v", err.Error())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if status >= http.StatusBadRequest {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if data.Success != true {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClient_IntegrationModule(t *testing.T) {
|
|
|
|
c := client()
|
|
|
|
|
|
|
|
name := RandomString(5)
|
|
|
|
code := RandomString(8)
|
|
|
|
|
|
|
|
m, status, err := c.IntegrationModuleEdit(IntegrationModule{
|
|
|
|
Code: code,
|
|
|
|
IntegrationCode: code,
|
|
|
|
Active: false,
|
|
|
|
Name: fmt.Sprintf("Integration module %s", name),
|
2018-03-19 23:18:36 +03:00
|
|
|
AccountURL: fmt.Sprintf("http://example.com/%s/account", name),
|
|
|
|
BaseURL: fmt.Sprintf("http://example.com/%s", name),
|
|
|
|
ClientID: RandomString(10),
|
2018-02-27 11:37:15 +03:00
|
|
|
Logo: "https://cdn.worldvectorlogo.com/logos/github-icon.svg",
|
|
|
|
})
|
2018-04-22 20:39:22 +03:00
|
|
|
if err.RuntimeErr != nil {
|
|
|
|
t.Errorf("%v", err.Error())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if status != http.StatusCreated {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if m.Success != true {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
g, status, err := c.IntegrationModule(code)
|
2018-04-22 20:39:22 +03:00
|
|
|
if err.RuntimeErr != nil {
|
|
|
|
t.Errorf("%v", err.Error())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if status != http.StatusOK {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if g.Success != true {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClient_IntegrationModuleFail(t *testing.T) {
|
|
|
|
c := client()
|
|
|
|
code := RandomString(8)
|
|
|
|
|
|
|
|
m, status, err := c.IntegrationModuleEdit(IntegrationModule{
|
|
|
|
Code: code,
|
|
|
|
})
|
2018-04-22 20:39:22 +03:00
|
|
|
if err.RuntimeErr == nil {
|
2018-02-27 11:37:15 +03:00
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
|
|
|
|
if status < http.StatusBadRequest {
|
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
|
|
|
|
if m.Success != false {
|
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
|
|
|
|
g, status, err := c.IntegrationModule(RandomString(12))
|
2018-04-22 20:39:22 +03:00
|
|
|
if err.RuntimeErr == nil {
|
2018-02-27 11:37:15 +03:00
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
|
|
|
|
if status < http.StatusBadRequest {
|
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
|
|
|
|
if g.Success != false {
|
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClient_ProductsGroup(t *testing.T) {
|
|
|
|
c := client()
|
|
|
|
|
|
|
|
g, status, err := c.ProductsGroup(ProductsGroupsRequest{
|
|
|
|
Filter: ProductsGroupsFilter{
|
|
|
|
Active: 1,
|
|
|
|
},
|
|
|
|
})
|
2018-04-22 20:39:22 +03:00
|
|
|
if err.RuntimeErr != nil {
|
|
|
|
t.Errorf("%v", err.Error())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if status != http.StatusOK {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if g.Success != true {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClient_Products(t *testing.T) {
|
|
|
|
c := client()
|
|
|
|
|
|
|
|
g, status, err := c.Products(ProductsRequest{
|
|
|
|
Filter: ProductsFilter{
|
|
|
|
Active: 1,
|
|
|
|
MinPrice: 1,
|
|
|
|
},
|
|
|
|
})
|
2018-04-22 20:39:22 +03:00
|
|
|
if err.RuntimeErr != nil {
|
|
|
|
t.Errorf("%v", err.Error())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if status != http.StatusOK {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if g.Success != true {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClient_ProductsProperties(t *testing.T) {
|
|
|
|
c := client()
|
|
|
|
|
|
|
|
sites := make([]string, 1)
|
|
|
|
sites[0] = os.Getenv("RETAILCRM_SITE")
|
|
|
|
|
|
|
|
g, status, err := c.ProductsProperties(ProductsPropertiesRequest{
|
|
|
|
Filter: ProductsPropertiesFilter{
|
|
|
|
Sites: sites,
|
|
|
|
},
|
|
|
|
})
|
2018-04-22 20:39:22 +03:00
|
|
|
if err.RuntimeErr != nil {
|
|
|
|
t.Errorf("%v", err.Error())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if status != http.StatusOK {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if g.Success != true {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClient_DeliveryShipments(t *testing.T) {
|
|
|
|
c := client()
|
|
|
|
|
|
|
|
g, status, err := c.DeliveryShipments(DeliveryShipmentsRequest{
|
|
|
|
Filter: ShipmentFilter{
|
|
|
|
DateFrom: "2017-10-10",
|
|
|
|
},
|
|
|
|
})
|
2018-04-22 20:39:22 +03:00
|
|
|
if err.RuntimeErr != nil {
|
|
|
|
t.Errorf("%v", err.Error())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if status != http.StatusOK {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if g.Success != true {
|
2018-04-22 20:39:22 +03:00
|
|
|
t.Errorf("%v", err.ApiError())
|
2018-02-27 11:37:15 +03:00
|
|
|
}
|
|
|
|
}
|