References edit methods

This commit is contained in:
Alex Lushpai 2018-02-06 15:27:01 +03:00
parent add6ed52b1
commit a04578926c
2 changed files with 695 additions and 3 deletions

View file

@ -799,8 +799,8 @@ func (c *Client) Couriers() (*CouriersResponse, int, ErrorResponse) {
return &resp, status, err
}
// DeliveryService method
func (c *Client) DeliveryService() (*DeliveryServiceResponse, int, ErrorResponse) {
// DeliveryServices method
func (c *Client) DeliveryServices() (*DeliveryServiceResponse, int, ErrorResponse) {
var resp DeliveryServiceResponse
data, status, err := c.GetRequest(fmt.Sprintf("%s/reference/delivery-services", versionedPrefix))
@ -980,3 +980,323 @@ func (c *Client) Stores() (*StoresResponse, int, ErrorResponse) {
return &resp, status, err
}
// CostGroupEdit method
func (c *Client) CostGroupEdit(costGroup CostGroup) (*SucessfulResponse, int, ErrorResponse) {
var resp SucessfulResponse
objJson, _ := json.Marshal(&costGroup)
p := url.Values{
"costGroup": {string(objJson[:])},
}
data, status, err := c.PostRequest(fmt.Sprintf("%s/reference/cost-groups/%s/edit", versionedPrefix, costGroup.Code), p)
if err.ErrorMsg != "" {
return &resp, status, err
}
json.Unmarshal(data, &resp)
return &resp, status, err
}
// CostItemEdit method
func (c *Client) CostItemEdit(costItem CostItem) (*SucessfulResponse, int, ErrorResponse) {
var resp SucessfulResponse
objJson, _ := json.Marshal(&costItem)
p := url.Values{
"costItem": {string(objJson[:])},
}
data, status, err := c.PostRequest(fmt.Sprintf("%s/reference/cost-items/%s/edit", versionedPrefix, costItem.Code), p)
if err.ErrorMsg != "" {
return &resp, status, err
}
json.Unmarshal(data, &resp)
return &resp, status, err
}
// CourierCreate method
func (c *Client) CourierCreate(courier Courier) (*CreateResponse, int, ErrorResponse) {
var resp CreateResponse
objJson, _ := json.Marshal(&courier)
p := url.Values{
"courier": {string(objJson[:])},
}
data, status, err := c.PostRequest(fmt.Sprintf("%s/reference/couriers/create", versionedPrefix), p)
if err.ErrorMsg != "" {
return &resp, status, err
}
json.Unmarshal(data, &resp)
return &resp, status, err
}
// CourierEdit method
func (c *Client) CourierEdit(courier Courier) (*SucessfulResponse, int, ErrorResponse) {
var resp SucessfulResponse
objJson, _ := json.Marshal(&courier)
p := url.Values{
"courier": {string(objJson[:])},
}
data, status, err := c.PostRequest(fmt.Sprintf("%s/reference/couriers/%d/edit", versionedPrefix, courier.Id), p)
if err.ErrorMsg != "" {
return &resp, status, err
}
json.Unmarshal(data, &resp)
return &resp, status, err
}
// DeliveryServiceEdit method
func (c *Client) DeliveryServiceEdit(deliveryService DeliveryService) (*SucessfulResponse, int, ErrorResponse) {
var resp SucessfulResponse
objJson, _ := json.Marshal(&deliveryService)
p := url.Values{
"deliveryService": {string(objJson[:])},
}
data, status, err := c.PostRequest(fmt.Sprintf("%s/reference/delivery-services/%s/edit", versionedPrefix, deliveryService.Code), p)
if err.ErrorMsg != "" {
return &resp, status, err
}
json.Unmarshal(data, &resp)
return &resp, status, err
}
// DeliveryTypeEdit method
func (c *Client) DeliveryTypeEdit(deliveryType DeliveryType) (*SucessfulResponse, int, ErrorResponse) {
var resp SucessfulResponse
objJson, _ := json.Marshal(&deliveryType)
p := url.Values{
"deliveryType": {string(objJson[:])},
}
data, status, err := c.PostRequest(fmt.Sprintf("%s/reference/delivery-types/%s/edit", versionedPrefix, deliveryType.Code), p)
if err.ErrorMsg != "" {
return &resp, status, err
}
json.Unmarshal(data, &resp)
return &resp, status, err
}
// LegalEntityEditorderMe method
func (c *Client) LegalEntityEdit(legalEntity LegalEntity) (*SucessfulResponse, int, ErrorResponse) {
var resp SucessfulResponse
objJson, _ := json.Marshal(&legalEntity)
p := url.Values{
"legalEntity": {string(objJson[:])},
}
data, status, err := c.PostRequest(fmt.Sprintf("%s/reference/legal-entities/%s/edit", versionedPrefix, legalEntity.Code), p)
if err.ErrorMsg != "" {
return &resp, status, err
}
json.Unmarshal(data, &resp)
return &resp, status, err
}
// OrderMethodEdit method
func (c *Client) OrderMethodEdit(orderMethod OrderMethod) (*SucessfulResponse, int, ErrorResponse) {
var resp SucessfulResponse
objJson, _ := json.Marshal(&orderMethod)
p := url.Values{
"orderMethod": {string(objJson[:])},
}
data, status, err := c.PostRequest(fmt.Sprintf("%s/reference/order-methods/%s/edit", versionedPrefix, orderMethod.Code), p)
if err.ErrorMsg != "" {
return &resp, status, err
}
json.Unmarshal(data, &resp)
return &resp, status, err
}
// OrderTypeEdit method
func (c *Client) OrderTypeEdit(orderType OrderType) (*SucessfulResponse, int, ErrorResponse) {
var resp SucessfulResponse
objJson, _ := json.Marshal(&orderType)
p := url.Values{
"orderType": {string(objJson[:])},
}
data, status, err := c.PostRequest(fmt.Sprintf("%s/reference/order-types/%s/edit", versionedPrefix, orderType.Code), p)
if err.ErrorMsg != "" {
return &resp, status, err
}
json.Unmarshal(data, &resp)
return &resp, status, err
}
// PaymentStatusEdit method
func (c *Client) PaymentStatusEdit(paymentStatus PaymentStatus) (*SucessfulResponse, int, ErrorResponse) {
var resp SucessfulResponse
objJson, _ := json.Marshal(&paymentStatus)
p := url.Values{
"paymentStatus": {string(objJson[:])},
}
data, status, err := c.PostRequest(fmt.Sprintf("%s/reference/payment-statuses/%s/edit", versionedPrefix, paymentStatus.Code), p)
if err.ErrorMsg != "" {
return &resp, status, err
}
json.Unmarshal(data, &resp)
return &resp, status, err
}
// PaymentTypeEdit method
func (c *Client) PaymentTypeEdit(paymentType PaymentType) (*SucessfulResponse, int, ErrorResponse) {
var resp SucessfulResponse
objJson, _ := json.Marshal(&paymentType)
p := url.Values{
"paymentType": {string(objJson[:])},
}
data, status, err := c.PostRequest(fmt.Sprintf("%s/reference/payment-types/%s/edit", versionedPrefix, paymentType.Code), p)
if err.ErrorMsg != "" {
return &resp, status, err
}
json.Unmarshal(data, &resp)
return &resp, status, err
}
// PriceTypeEdit method
func (c *Client) PriceTypeEdit(priceType PriceType) (*SucessfulResponse, int, ErrorResponse) {
var resp SucessfulResponse
objJson, _ := json.Marshal(&priceType)
p := url.Values{
"priceType": {string(objJson[:])},
}
data, status, err := c.PostRequest(fmt.Sprintf("%s/reference/price-types/%s/edit", versionedPrefix, priceType.Code), p)
if err.ErrorMsg != "" {
return &resp, status, err
}
json.Unmarshal(data, &resp)
return &resp, status, err
}
// ProductStatusEdit method
func (c *Client) ProductStatusEdit(productStatus ProductStatus) (*SucessfulResponse, int, ErrorResponse) {
var resp SucessfulResponse
objJson, _ := json.Marshal(&productStatus)
p := url.Values{
"productStatus": {string(objJson[:])},
}
data, status, err := c.PostRequest(fmt.Sprintf("%s/reference/product-statuses/%s/edit", versionedPrefix, productStatus.Code), p)
if err.ErrorMsg != "" {
return &resp, status, err
}
json.Unmarshal(data, &resp)
return &resp, status, err
}
// StatusEdit method
func (c *Client) StatusEdit(st Status) (*SucessfulResponse, int, ErrorResponse) {
var resp SucessfulResponse
objJson, _ := json.Marshal(&st)
p := url.Values{
"status": {string(objJson[:])},
}
data, status, err := c.PostRequest(fmt.Sprintf("%s/reference/statuses/%s/edit", versionedPrefix, st.Code), p)
if err.ErrorMsg != "" {
return &resp, status, err
}
json.Unmarshal(data, &resp)
return &resp, status, err
}
// SiteEdit method
func (c *Client) SiteEdit(site Site) (*SucessfulResponse, int, ErrorResponse) {
var resp SucessfulResponse
objJson, _ := json.Marshal(&site)
p := url.Values{
"site": {string(objJson[:])},
}
data, status, err := c.PostRequest(fmt.Sprintf("%s/reference/sites/%s/edit", versionedPrefix, site.Code), p)
if err.ErrorMsg != "" {
return &resp, status, err
}
json.Unmarshal(data, &resp)
return &resp, status, err
}
// StoreEdit method
func (c *Client) StoreEdit(store Store) (*SucessfulResponse, int, ErrorResponse) {
var resp SucessfulResponse
objJson, _ := json.Marshal(&store)
p := url.Values{
"store": {string(objJson[:])},
}
data, status, err := c.PostRequest(fmt.Sprintf("%s/reference/stores/%s/edit", versionedPrefix, store.Code), p)
if err.ErrorMsg != "" {
return &resp, status, err
}
json.Unmarshal(data, &resp)
return &resp, status, err
}

View file

@ -13,6 +13,7 @@ import (
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()))
@ -921,7 +922,7 @@ func TestClient_Couriers(t *testing.T) {
func TestClient_DeliveryService(t *testing.T) {
c := client()
data, st, err := c.DeliveryService()
data, st, err := c.DeliveryServices()
if err.ErrorMsg != "" {
t.Errorf("%v", err)
t.Fail()
@ -1177,3 +1178,374 @@ func TestClient_Stores(t *testing.T) {
t.Fail()
}
}
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),
})
if err.ErrorMsg != "" {
t.Errorf("%v", err)
t.Fail()
}
if !statuses[st] {
t.Errorf("%v", err.ErrorMsg)
t.Fail()
}
if data.Success != true {
t.Errorf("%v", err)
t.Fail()
}
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,
})
if err.ErrorMsg != "" {
t.Errorf("%v", err)
t.Fail()
}
if !statuses[st] {
t.Errorf("%v", err.ErrorMsg)
t.Fail()
}
if idata.Success != true {
t.Errorf("%v", err)
t.Fail()
}
}
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)
if err.ErrorMsg != "" {
t.Errorf("%v", err)
t.Fail()
}
if !statuses[st] {
t.Errorf("%v", err.ErrorMsg)
t.Fail()
}
if data.Success != true {
t.Errorf("%v", err)
t.Fail()
}
cur.Id = data.Id
cur.Patronymic = fmt.Sprintf("%s", RandomString(5))
idata, st, err := c.CourierEdit(cur)
if err.ErrorMsg != "" {
t.Errorf("%v", err)
t.Fail()
}
if !statuses[st] {
t.Errorf("%v", err.ErrorMsg)
t.Fail()
}
if idata.Success != true {
t.Errorf("%v", err)
t.Fail()
}
}
func TestClient_DeliveryServiceEdit(t *testing.T) {
c := client()
data, st, err := c.DeliveryServiceEdit(DeliveryService{
Active: false,
Code: RandomString(5),
Name: RandomString(5),
})
if err.ErrorMsg != "" {
t.Errorf("%v", err)
t.Fail()
}
if !statuses[st] {
t.Errorf("%v", err.ErrorMsg)
t.Fail()
}
if data.Success != true {
t.Errorf("%v", err)
t.Fail()
}
}
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,
})
if err.ErrorMsg != "" {
t.Errorf("%v", err)
t.Fail()
}
if !statuses[st] {
t.Errorf("%v", err.ErrorMsg)
t.Fail()
}
if data.Success != true {
t.Errorf("%v", err)
t.Fail()
}
}
func TestClient_OrderMethodEdit(t *testing.T) {
c := client()
data, st, err := c.OrderMethodEdit(OrderMethod{
Code: RandomString(5),
Name: RandomString(5),
Active: false,
DefaultForCrm: false,
})
if err.ErrorMsg != "" {
t.Errorf("%v", err.ErrorMsg)
t.Fail()
}
if !statuses[st] {
t.Errorf("%v", err.ErrorMsg)
t.Fail()
}
if data.Success != true {
t.Errorf("%v", err.ErrorMsg)
t.Fail()
}
}
func TestClient_OrderTypeEdit(t *testing.T) {
c := client()
data, st, err := c.OrderTypeEdit(OrderType{
Code: RandomString(5),
Name: RandomString(5),
Active: false,
DefaultForCrm: false,
})
if err.ErrorMsg != "" {
t.Errorf("%v", err.ErrorMsg)
t.Fail()
}
if !statuses[st] {
t.Errorf("%v", err.ErrorMsg)
t.Fail()
}
if data.Success != true {
t.Errorf("%v", err.ErrorMsg)
t.Fail()
}
}
func TestClient_PaymentStatusEdit(t *testing.T) {
c := client()
data, st, err := c.PaymentStatusEdit(PaymentStatus{
Code: RandomString(5),
Name: RandomString(5),
Active: false,
DefaultForCrm: false,
PaymentTypes: []string{"cash"},
PaymentComplete: false,
})
if err.ErrorMsg != "" {
t.Errorf("%v", err.ErrorMsg)
t.Fail()
}
if !statuses[st] {
t.Errorf("%v", err.ErrorMsg)
t.Fail()
}
if data.Success != true {
t.Errorf("%v", err.ErrorMsg)
t.Fail()
}
}
func TestClient_PaymentTypeEdit(t *testing.T) {
c := client()
data, st, err := c.PaymentTypeEdit(PaymentType{
Code: RandomString(5),
Name: RandomString(5),
Active: false,
DefaultForCrm: false,
})
if err.ErrorMsg != "" {
t.Errorf("%v", err.ErrorMsg)
t.Fail()
}
if !statuses[st] {
t.Errorf("%v", err.ErrorMsg)
t.Fail()
}
if data.Success != true {
t.Errorf("%v", err.ErrorMsg)
t.Fail()
}
}
func TestClient_PriceTypeEdit(t *testing.T) {
c := client()
data, st, err := c.PriceTypeEdit(PriceType{
Code: RandomString(5),
Name: RandomString(5),
Active: false,
})
if err.ErrorMsg != "" {
t.Errorf("%v", err.ErrorMsg)
t.Fail()
}
if !statuses[st] {
t.Errorf("%v", err.ErrorMsg)
t.Fail()
}
if data.Success != true {
t.Errorf("%v", err.ErrorMsg)
t.Fail()
}
}
func TestClient_ProductStatusEdit(t *testing.T) {
c := client()
data, st, err := c.ProductStatusEdit(ProductStatus{
Code: RandomString(5),
Name: RandomString(5),
Active: false,
CancelStatus: false,
})
if err.ErrorMsg != "" {
t.Errorf("%v", err.ErrorMsg)
t.Fail()
}
if !statuses[st] {
t.Errorf("%v", err.ErrorMsg)
t.Fail()
}
if data.Success != true {
t.Errorf("%v", err.ErrorMsg)
t.Fail()
}
}
func TestClient_StatusEdit(t *testing.T) {
c := client()
data, st, err := c.StatusEdit(Status{
Code: RandomString(5),
Name: RandomString(5),
Active: false,
Group: "new",
})
if err.ErrorMsg != "" {
t.Errorf("%v", err.ErrorMsg)
t.Fail()
}
if !statuses[st] {
t.Errorf("%v", err.ErrorMsg)
t.Fail()
}
if data.Success != true {
t.Errorf("%v", err.ErrorMsg)
t.Fail()
}
}
func TestClient_SiteEdit(t *testing.T) {
c := client()
data, _, err := c.SiteEdit(Site{
Code: RandomString(5),
Name: RandomString(5),
Url: fmt.Sprintf("https://%s.example.com", RandomString(4)),
LoadFromYml: false,
})
if err.ErrorMsg == "" {
t.Errorf("%v", err.ErrorMsg)
t.Fail()
}
if data.Success != false {
t.Errorf("%v", err.ErrorMsg)
t.Fail()
}
}
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",
})
if err.ErrorMsg != "" {
t.Errorf("%v", err.ErrorMsg)
t.Fail()
}
if !statuses[st] {
t.Errorf("%v", err.ErrorMsg)
t.Fail()
}
if data.Success != true {
t.Errorf("%v", err.ErrorMsg)
t.Fail()
}
}