4 Commits

Author SHA1 Message Date
diPhantxm
e60a3f1ca2 add method for getting ozon warehouses workload 2023-06-02 18:55:45 +03:00
diPhantxm
2f1dbd5c00 add method for updating product characteristics 2023-06-02 18:55:33 +03:00
diPhantxm
387af0e30e add pricing strategy methods 2023-04-24 01:03:24 +03:00
diPhantxm
c1e7f2b370 add optional paramter with_details to request and details to response in GetFinancial in reports 2023-04-24 01:03:24 +03:00
10 changed files with 1524 additions and 13 deletions

View File

@@ -313,3 +313,67 @@ const (
// delivery by the seller
NonIntegratedTPLType TPLIntegrationType = "non_integrated"
)
type DetailsDeliveryItemName string
const (
DirectFlowLogisticSumDetailsDeliveryItemName DetailsDeliveryItemName = "MarketplaceServiceItemDirectFlowLogisticSum"
DropoffDetailsDeliveryItemName DetailsDeliveryItemName = "MarketplaceServiceItemDropoff"
DelivToCustomerDetailsDeliveryItemName DetailsDeliveryItemName = "MarketplaceServiceItemDelivToCustomer"
)
type DetailsReturnServiceName string
const (
ReturnAfterDelivToCustomerDetailsReturnServiceName DetailsReturnServiceName = "MarketplaceServiceItemReturnAfterDelivToCustomer"
ReturnPartGoodsCustomerDetailsReturnServiceName DetailsReturnServiceName = "MarketplaceServiceItemReturnPartGoodsCustomer"
ReturnNotDelivToCustomerDetailsReturnServiceName DetailsReturnServiceName = "MarketplaceServiceItemReturnNotDelivToCustomer"
ReturnFlowLogisticDetailsReturnServiceName DetailsReturnServiceName = "MarketplaceServiceItemReturnFlowLogistic"
)
type DetailsServiceItemName string
const (
OtherMarketAndTech DetailsServiceItemName = "MarketplaceServiceItemOtherMarketAndTechService"
ReturnStorageServiceAtThePickupPointFbsItem DetailsServiceItemName = "MarketplaceReturnStorageServiceAtThePickupPointFbsItem"
SaleReviewsItem DetailsServiceItemName = "MarketplaceSaleReviewsItem"
ServicePremiumCashbackIndividualPoints DetailsServiceItemName = "MarketplaceServicePremiumCashbackIndividualPoints"
ServiceStorageItem DetailsServiceItemName = "MarketplaceServiceStorageItem"
ServiceStockDisposal DetailsServiceItemName = "MarketplaceServiceStockDisposal"
ReturnDisposalServiceFbsItem DetailsServiceItemName = "MarketplaceReturnDisposalServiceFbsItem"
ServiceItemFlexiblePaymentSchedule DetailsServiceItemName = "MarketplaceServiceItemFlexiblePaymentSchedule"
ServiceProcessingSpoilage DetailsServiceItemName = "MarketplaceServiceProcessingSpoilage"
ServiceProcessingIdentifiedSurplus DetailsServiceItemName = "MarketplaceServiceProcessingIdentifiedSurplus"
ServiceProcessingIdentifiedDiscrepancies DetailsServiceItemName = "MarketplaceServiceProcessingIdentifiedDiscrepancies"
ServiceItemInternetSiteAdvertising DetailsServiceItemName = "MarketplaceServiceItemInternetSiteAdvertising"
ServiceItemPremiumSubscribtion DetailsServiceItemName = "MarketplaceServiceItemPremiumSubscribtion"
AgencyFeeAggregator3PLGlobalItem DetailsServiceItemName = "MarketplaceAgencyFeeAggregator3PLGlobalItem"
)
type DetailsOtherItemName string
const (
RedistributionOfAcquiringOperation DetailsOtherItemName = "MarketplaceRedistributionOfAcquiringOperation"
CompensationLossOfGoodsOperation DetailsOtherItemName = "MarketplaceSellerCompensationLossOfGoodsOperation"
CorrectionOperation DetailsOtherItemName = "MarketplaceSellerCorrectionOperation"
OperationCorrectionSeller DetailsOtherItemName = "OperationCorrectionSeller"
OperationMarketplaceWithHoldingForUndeliverableGoods DetailsOtherItemName = "OperationMarketplaceWithHoldingForUndeliverableGoods"
OperationClaim DetailsOtherItemName = "OperationClaim"
)
type StrategyType string
const (
MinExtPrice StrategyType = "MIN_EXT_PRICE"
CompPrice StrategyType = "COMP_PRICE"
)
type StrategyUpdateType string
const (
StrategyEnabled StrategyUpdateType = "strategyEnabled"
StrategyDisabled StrategyUpdateType = "strategyDisabled"
StrategyChanged StrategyUpdateType = "strategyChanged"
StrategyCreated StrategyUpdateType = "strategyCreated"
StrategyItemsListChanged StrategyUpdateType = "strategyItemsListChanged"
)

View File

@@ -470,3 +470,52 @@ func (c FBO) ListProductsInSupplyRequest(params *ListProductsInSupplyRequestPara
return resp, nil
}
type GetWarehouseWorkloadResponse struct {
core.CommonResponse
// Method result
Result []struct {
// Workload
Schedule struct {
// Data on the products quantity supplied to the warehouse
Capacity []struct {
// Period start, local time
Start time.Time `json:"start"`
// Period end, local time
End time.Time `json:"end"`
// Average number of products that the warehouse can accept per day for the period
Value int32 `json:"value"`
} `json:"capacity"`
// The closest available date for supply, local time
Date time.Time `json:"date"`
} `json:"schedule"`
// Warehouse
Warehouse struct {
// Warehouse identifier
Id string `json:"id"`
// Warehouse name
Name string `json:"name"`
} `json:"warehouse"`
} `json:"result"`
}
// Method returns a list of active Ozon warehouses with information about their average workload in the nearest future
func (c FBO) GetWarehouseWorkload() (*GetWarehouseWorkloadResponse, error) {
url := "/v1/supplier/available_warehouses"
resp := &GetWarehouseWorkloadResponse{}
response, err := c.client.Request(http.MethodGet, url, nil, resp, nil)
if err != nil {
return nil, err
}
response.CopyCommonResponse(&resp.CommonResponse)
return resp, nil
}

View File

@@ -482,3 +482,61 @@ func TestListProductsInSupplyRequest(t *testing.T) {
}
}
}
func TestGetWarehouseWorkload(t *testing.T) {
t.Parallel()
tests := []struct {
statusCode int
headers map[string]string
response string
}{
// Test Ok
{
http.StatusOK,
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
`{
"result": [
{
"schedule": {
"capacity": [
{
"start": "2019-08-24T14:15:22Z",
"end": "2019-08-24T14:15:22Z",
"value": 0
}
],
"date": "2019-08-24T14:15:22Z"
},
"warehouse": {
"id": "string",
"name": "string"
}
}
]
}`,
},
// Test No Client-Id or Api-Key
{
http.StatusUnauthorized,
map[string]string{},
`{
"code": 16,
"message": "Client-Id and Api-Key headers are required"
}`,
},
}
for _, test := range tests {
c := NewMockClient(core.NewMockHttpHandler(test.statusCode, test.response, test.headers))
resp, err := c.FBO().GetWarehouseWorkload()
if err != nil {
t.Error(err)
}
if resp.StatusCode != test.statusCode {
t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode)
}
}
}

View File

@@ -30,6 +30,7 @@ type Client struct {
brands *Brands
chats *Chats
certificates *Certificates
strategies *Strategies
}
func (c Client) Analytics() *Analytics {
@@ -100,6 +101,10 @@ func (c Client) Certificates() *Certificates {
return c.certificates
}
func (c Client) Strategies() *Strategies {
return c.strategies
}
func NewClient(clientId, apiKey string) *Client {
coreClient := core.NewClient(DefaultAPIBaseUrl, map[string]string{
"Client-Id": clientId,
@@ -125,6 +130,7 @@ func NewClient(clientId, apiKey string) *Client {
brands: &Brands{client: coreClient},
chats: &Chats{client: coreClient},
certificates: &Certificates{client: coreClient},
strategies: &Strategies{client: coreClient},
}
}
@@ -150,5 +156,6 @@ func NewMockClient(handler http.HandlerFunc) *Client {
brands: &Brands{client: coreClient},
chats: &Chats{client: coreClient},
certificates: &Certificates{client: coreClient},
strategies: &Strategies{client: coreClient},
}
}

View File

@@ -2126,3 +2126,59 @@ func (c Products) NumberOfSubsToProductAvailability(params *NumberOfSubsToProduc
return resp, nil
}
type UpdateCharacteristicsParams struct {
// Products and characteristics to be updated
Items []UpdateCharacteristicsItem `json:"items"`
}
type UpdateCharacteristicsItem struct {
// Product characteristics
Attributes []UpdateCharacteristicsItemAttribute `json:"attributes"`
// Product ID
OfferId string `json:"offer_id"`
}
type UpdateCharacteristicsItemAttribute struct {
// Identifier of the characteristic that supports nested properties.
// Each of the nested characteristics can have multiple value variants
ComplexId int64 `json:"complex_id"`
// Characteristic identifier
Id int64 `json:"id"`
// Array of nested characteristic values
Values []UpdateCharacteristicsItemValue `json:"values"`
}
type UpdateCharacteristicsItemValue struct {
// Characteristic identifier in the dictionary
DictionaryValueId int64 `json:"dictionary_value_id"`
// Product characteristic value
Value string `json:"value"`
}
type UpdateCharacteristicsResponse struct {
core.CommonResponse
// Products update task code.
//
// To check the update status, pass the received value to the `/v1/product/import/info` method
TaskId int64 `json:"task_id"`
}
func (c Products) UpdateCharacteristics(params *UpdateCharacteristicsParams) (*UpdateCharacteristicsResponse, error) {
url := "/v1/product/attributes/update"
resp := &UpdateCharacteristicsResponse{}
response, err := c.client.Request(http.MethodPost, url, params, resp, nil)
if err != nil {
return nil, err
}
response.CopyCommonResponse(&resp.CommonResponse)
return resp, nil
}

View File

@@ -2487,3 +2487,65 @@ func TestNumberOfSubsToProductAvailability(t *testing.T) {
}
}
}
func TestUpdateCharacteristics(t *testing.T) {
t.Parallel()
tests := []struct {
statusCode int
headers map[string]string
params *UpdateCharacteristicsParams
response string
}{
// Test Ok
{
http.StatusOK,
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
&UpdateCharacteristicsParams{
Items: []UpdateCharacteristicsItem{
{
Attributes: []UpdateCharacteristicsItemAttribute{
{
ComplexId: 0,
Id: 0,
Values: []UpdateCharacteristicsItemValue{
{
DictionaryValueId: 0,
Value: "string",
},
},
},
},
OfferId: "string",
},
},
},
`{
"task_id": 0
}`,
},
// Test No Client-Id or Api-Key
{
http.StatusUnauthorized,
map[string]string{},
&UpdateCharacteristicsParams{},
`{
"code": 16,
"message": "Client-Id and Api-Key headers are required"
}`,
},
}
for _, test := range tests {
c := NewMockClient(core.NewMockHttpHandler(test.statusCode, test.response, test.headers))
resp, err := c.Products().UpdateCharacteristics(test.params)
if err != nil {
t.Error(err)
}
if resp.StatusCode != test.statusCode {
t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode)
}
}
}

View File

@@ -159,6 +159,9 @@ type GetFinancialReportParams struct {
// Number of the page returned in the request
Page int64 `json:"page"`
// true, если нужно добавить дополнительные параметры в ответ
WithDetails bool `json:"with_details"`
// Number of items on the page
PageSize int64 `json:"page_size"`
}
@@ -209,6 +212,99 @@ type GetFinancialReportResponse struct {
CurrencyCode string `json:"currency_code"`
} `json:"cash_flows"`
// Detailed info
Details struct {
// Balance on the beginning of period
BeginBalanceAmount float64 `json:"begin_balance_amount"`
// Orders
Delivery struct {
Total float64 `json:"total"`
Amount float64 `json:"amount"`
DeliveryServices struct {
Total float64 `json:"total"`
Items []struct {
Name DetailsDeliveryItemName `json:"name"`
Price float64 `json:"price"`
} `json:"items"`
} `json:"delivery_services"`
} `json:"delivery"`
InvoiceTransfer float64 `json:"invoice_transfer"`
Loan float64 `json:"loan"`
Payments []struct {
CurrencyCode string `json:"currency_code"`
Payment float64 `json:"payment"`
} `json:"payments"`
Period struct {
Begin time.Time `json:"begin"`
End time.Time `json:"end"`
Id int64 `json:"id"`
} `json:"period"`
Return struct {
Total float64 `json:"total"`
Amount float64 `json:"amount"`
ReturnServices struct {
Total float64 `json:"total"`
Items []struct {
Name DetailsReturnServiceName `json:"name"`
Price float64 `json:"price"`
} `json:"items"`
} `json:"return_services"`
} `json:"return"`
RFBS struct {
Total float64 `json:"total"`
TransferDelivery float64 `json:"transfer_delivery"`
TransferDeliveryReturn float64 `json:"transfer_delivery_return"`
CompensationDeliveryReturn float64 `json:"compensation_delivery_return"`
PartialCompensation float64 `json:"partial_compensation"`
PartialCompensationReturn float64 `json:"partial_compensation_return"`
} `json:"rfbs"`
Services struct {
Total float64 `json:"total"`
Items []struct {
Name DetailsServiceItemName `json:"name"`
Price float64 `json:"price"`
} `json:"items"`
} `json:"services"`
Others struct {
Total float64 `json:"total"`
Items []struct {
Name DetailsOtherItemName `json:"name"`
Price float64 `json:"price"`
} `json:"items"`
} `json:"others"`
EndBalanceAmount float64 `json:"end_balance_amount"`
} `json:"details"`
// Number of pages with reports
PageCount int64 `json:"page_count"`
} `json:"result"`

View File

@@ -165,28 +165,98 @@ func TestGetFinancialReport(t *testing.T) {
From: core.TimeFromString(t, "2006-01-02T15:04:05Z", "2022-01-01T00:00:00.000Z"),
To: core.TimeFromString(t, "2006-01-02T15:04:05Z", "2022-12-31T00:00:00.000Z"),
},
Page: 1,
PageSize: 1,
WithDetails: true,
Page: 1,
PageSize: 1,
},
`{
"result": {
"cash_flows": [
{
"period": {
"id": 11567022278500,
"begin": "2022-08-01T00:00:00Z",
"end": "2022-08-15T00:00:00Z"
},
"orders_amount": 1000,
"returns_amount": -3000,
"commission_amount": 1437,
"services_amount": 8471.28,
"currency_code": "string",
"item_delivery_and_return_amount": 1991,
"currency_code": "RUB"
"orders_amount": 1000,
"period": {
"begin": "2023-04-03T09:12:10.239Z",
"end": "2023-04-03T09:12:10.239Z",
"id": 11567022278500
},
"returns_amount": -3000,
"services_amount": 8471.28
}
],
"page_count": 15
}
"details": {
"period": {
"begin": "2023-04-03T09:12:10.239Z",
"end": "2023-04-03T09:12:10.239Z",
"id": 11567022278500
},
"payments": [
{
"payment": 0,
"currency_code": "string"
}
],
"begin_balance_amount": 0,
"delivery": {
"total": 0,
"amount": 0,
"delivery_services": {
"total": 0,
"items": [
{
"name": "string",
"price": 0
}
]
}
},
"return": {
"total": 0,
"amount": 0,
"return_services": {
"total": 0,
"items": [
{
"name": "string",
"price": 0
}
]
}
},
"loan": 0,
"invoice_transfer": 0,
"rfbs": {
"total": 0,
"transfer_delivery": 0,
"transfer_delivery_return": 0,
"compensation_delivery_return": 0,
"partial_compensation": 0,
"partial_compensation_return": 0
},
"services": {
"total": 0,
"items": [
{
"name": "string",
"price": 0
}
]
},
"others": {
"total": 0,
"items": [
{
"name": "string",
"price": 0
}
]
},
"end_balance_amount": 0
}
},
"page_count": 15
}`,
},
// Test No Client-Id or Api-Key

381
ozon/strategies.go Normal file
View File

@@ -0,0 +1,381 @@
package ozon
import (
"net/http"
core "github.com/diphantxm/ozon-api-client"
)
type Strategies struct {
client *core.Client
}
type ListCompetitorsParams struct {
Page int64 `json:"page"`
Limit int64 `json:"limit"`
}
type ListCompetitorsResponse struct {
core.CommonResponse
Competitors []struct {
Name string `json:"name"`
Id int64 `json:"id"`
} `json:"competitors"`
Total int32 `json:"total"`
}
func (c Strategies) ListCompetitors(params *ListCompetitorsParams) (*ListCompetitorsResponse, error) {
url := "/v1/pricing-strategy/competitors/list"
resp := &ListCompetitorsResponse{}
response, err := c.client.Request(http.MethodPost, url, params, resp, nil)
if err != nil {
return nil, err
}
response.CopyCommonResponse(&resp.CommonResponse)
return resp, nil
}
type ListStrategiesParams struct {
Page int64 `json:"page"`
Limit int64 `json:"limit"`
}
type ListStrategiesResponse struct {
core.CommonResponse
Strategies []struct {
Id string `json:"id"`
Name string `json:"name"`
Type StrategyType `json:"type"`
UpdateType StrategyUpdateType `json:"update_type"`
UpdatedAt string `json:"updated_at"`
ProductsCount int64 `json:"products_count"`
CompetitorsCount int64 `json:"competitors_count"`
Enabled bool `json:"enabled"`
} `json:"strategies"`
Total int32 `json:"total"`
}
func (c Strategies) List(params *ListStrategiesParams) (*ListStrategiesResponse, error) {
url := "/v1/pricing-strategy/list"
resp := &ListStrategiesResponse{}
response, err := c.client.Request(http.MethodPost, url, params, resp, nil)
if err != nil {
return nil, err
}
response.CopyCommonResponse(&resp.CommonResponse)
return resp, nil
}
type CreateStrategyParams struct {
Competitors []CreateStrategyCompetitor `json:"competitors"`
StrategyName string `json:"strategy_name"`
}
type CreateStrategyCompetitor struct {
Coefficient float32 `json:"coefficient"`
CompetitorId int64 `json:"competitor_id"`
}
type CreateStrategyResponse struct {
core.CommonResponse
Result struct {
StrategyId string `json:"strategy_id"`
} `json:"result"`
}
func (c Strategies) Create(params *CreateStrategyParams) (*CreateStrategyResponse, error) {
url := "/v1/pricing-strategy/create"
resp := &CreateStrategyResponse{}
response, err := c.client.Request(http.MethodPost, url, params, resp, nil)
if err != nil {
return nil, err
}
response.CopyCommonResponse(&resp.CommonResponse)
return resp, nil
}
type InfoStrategyParams struct {
StrategyId string `json:"strategy_id"`
}
type InfoStrategyResponse struct {
core.CommonResponse
Result struct {
Competitors []CreateStrategyCompetitor `json:"competitors"`
Enabled bool `json:"enabled"`
Name string `json:"name"`
Type StrategyType `json:"type"`
UpdateType StrategyUpdateType `json:"update_type"`
} `json:"result"`
}
func (c Strategies) Info(params *InfoStrategyParams) (*InfoStrategyResponse, error) {
url := "/v1/pricing-strategy/info"
resp := &InfoStrategyResponse{}
response, err := c.client.Request(http.MethodPost, url, params, resp, nil)
if err != nil {
return nil, err
}
response.CopyCommonResponse(&resp.CommonResponse)
return resp, nil
}
type UpdateStrategyParams struct {
Competitors []CreateStrategyCompetitor `json:"competitors"`
StrategyId string `json:"strategy_id"`
StrategyName string `json:"strategy_name"`
}
type UpdateStrategyResponse struct {
core.CommonResponse
}
func (c Strategies) Update(params *UpdateStrategyParams) (*UpdateStrategyResponse, error) {
url := "/v1/pricing-strategy/update"
resp := &UpdateStrategyResponse{}
response, err := c.client.Request(http.MethodPost, url, params, resp, nil)
if err != nil {
return nil, err
}
response.CopyCommonResponse(&resp.CommonResponse)
return resp, nil
}
type AddProductsToStrategyParams struct {
ProductId []int64 `json:"product_id"`
StrategyId string `json:"strategy_id"`
}
type AddProductsToStrategyResponse struct {
core.CommonResponse
Result struct {
Errors []struct {
Code string `json:"code"`
Error string `json:"error"`
ProductId int64 `json:"product_id"`
} `json:"errors"`
FailedProductCount int32 `json:"failed_product_count"`
} `json:"result"`
}
func (c Strategies) AddProducts(params *AddProductsToStrategyParams) (*AddProductsToStrategyResponse, error) {
url := "/v1/pricing-strategy/products/add"
resp := &AddProductsToStrategyResponse{}
response, err := c.client.Request(http.MethodPost, url, params, resp, nil)
if err != nil {
return nil, err
}
response.CopyCommonResponse(&resp.CommonResponse)
return resp, nil
}
type GetStrategiesByProductIdsParams struct {
ProductId []int64 `json:"product_id"`
}
type GetStrategiesByProductIdsResponse struct {
core.CommonResponse
Result struct {
ProductsInfo []struct {
ProductId int64 `json:"product_id"`
StrategyId string `json:"strategy_id"`
} `json:"products_info"`
} `json:"result"`
}
func (c Strategies) GetByProductIds(params *GetStrategiesByProductIdsParams) (*GetStrategiesByProductIdsResponse, error) {
url := "/v1/pricing-strategy/strategy-ids-by-product-ids"
resp := &GetStrategiesByProductIdsResponse{}
response, err := c.client.Request(http.MethodPost, url, params, resp, nil)
if err != nil {
return nil, err
}
response.CopyCommonResponse(&resp.CommonResponse)
return resp, nil
}
type ListProductsInStrategyParams struct {
StrategyId string `json:"strategy_id"`
}
type ListProductsInStrategyResponse struct {
core.CommonResponse
Result struct {
ProductId []string `json:"product_id"`
} `json:"result"`
}
func (c Strategies) ListProducts(params *ListProductsInStrategyParams) (*ListProductsInStrategyResponse, error) {
url := "/v1/pricing-strategy/products/list"
resp := &ListProductsInStrategyResponse{}
response, err := c.client.Request(http.MethodPost, url, params, resp, nil)
if err != nil {
return nil, err
}
response.CopyCommonResponse(&resp.CommonResponse)
return resp, nil
}
type GetCompetitorPriceParams struct {
ProductId int64 `json:"product_id"`
}
type GetCompetitorPriceResponse struct {
core.CommonResponse
Result struct {
StrategyId string `json:"strategy_id"`
IsEnabled bool `json:"is_enabled"`
StrategyProductPrice int32 `json:"strategy_product_price"`
PriceDownloadedAt string `json:"price_downloaded_at"`
StrategyCompetitorId int64 `json:"strategy_competitor_id"`
StrategyCompetitorProductURL string `json:"strategy_competitor_product_url"`
} `json:"result"`
}
func (c Strategies) GetCompetitorPrice(params *GetCompetitorPriceParams) (*GetCompetitorPriceResponse, error) {
url := "/v1/pricing-strategy/product/info"
resp := &GetCompetitorPriceResponse{}
response, err := c.client.Request(http.MethodPost, url, params, resp, nil)
if err != nil {
return nil, err
}
response.CopyCommonResponse(&resp.CommonResponse)
return resp, nil
}
type RemoveProductsFromStrategyParams struct {
ProductId []int64 `json:"product_id"`
}
type RemoveProductsFromStrategyResponse struct {
core.CommonResponse
Result struct {
FailedProductCount int32 `json:"failed_product_count"`
} `json:"result"`
}
func (c Strategies) RemoveProducts(params *RemoveProductsFromStrategyParams) (*RemoveProductsFromStrategyResponse, error) {
url := "/v1/pricing-strategy/products/delete"
resp := &RemoveProductsFromStrategyResponse{}
response, err := c.client.Request(http.MethodPost, url, params, resp, nil)
if err != nil {
return nil, err
}
response.CopyCommonResponse(&resp.CommonResponse)
return resp, nil
}
type ChangeStrategyStatusParams struct {
Enabled bool `json:"enabled"`
StrategyId string `json:"strategy_id"`
}
type ChangeStrategyStatusResponse struct {
core.CommonResponse
}
func (c Strategies) ChangeStatus(params *ChangeStrategyStatusParams) (*ChangeStrategyStatusResponse, error) {
url := "/v1/pricing-strategy/status"
resp := &ChangeStrategyStatusResponse{}
response, err := c.client.Request(http.MethodPost, url, params, resp, nil)
if err != nil {
return nil, err
}
response.CopyCommonResponse(&resp.CommonResponse)
return resp, nil
}
type RemoveStrategyParams struct {
StrategyId string `json:"strategy_id"`
}
type RemoveStrategyResponse struct {
core.CommonResponse
}
func (c Strategies) Remove(params *RemoveStrategyParams) (*RemoveStrategyResponse, error) {
url := "/v1/pricing-strategy/delete"
resp := &RemoveStrategyResponse{}
response, err := c.client.Request(http.MethodPost, url, params, resp, nil)
if err != nil {
return nil, err
}
response.CopyCommonResponse(&resp.CommonResponse)
return resp, nil
}

668
ozon/strategies_test.go Normal file
View File

@@ -0,0 +1,668 @@
package ozon
import (
"net/http"
"testing"
core "github.com/diphantxm/ozon-api-client"
)
func TestListCompetitors(t *testing.T) {
t.Parallel()
tests := []struct {
statusCode int
headers map[string]string
params *ListCompetitorsParams
response string
}{
// Test Ok
{
http.StatusOK,
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
&ListCompetitorsParams{
Page: 1,
Limit: 20,
},
`{
"competitor": [
{
"competitor_name": "string",
"competitor_id": 0
}
],
"total": 0
}`,
},
// Test No Client-Id or Api-Key
{
http.StatusUnauthorized,
map[string]string{},
&ListCompetitorsParams{},
`{
"code": 16,
"message": "Client-Id and Api-Key headers are required"
}`,
},
}
for _, test := range tests {
c := NewMockClient(core.NewMockHttpHandler(test.statusCode, test.response, test.headers))
resp, err := c.Strategies().ListCompetitors(test.params)
if err != nil {
t.Error(err)
}
if resp.StatusCode != test.statusCode {
t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode)
}
}
}
func TestListStrategies(t *testing.T) {
t.Parallel()
tests := []struct {
statusCode int
headers map[string]string
params *ListStrategiesParams
response string
}{
// Test Ok
{
http.StatusOK,
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
&ListStrategiesParams{
Page: 1,
Limit: 20,
},
`{
"strategies": [
{
"strategy_id": "string",
"strategy_name": "string",
"type": "string",
"update_type": "string",
"updated_at": "string",
"products_count": 0,
"competitors_count": 0,
"enabled": true
}
],
"total": 0
}`,
},
// Test No Client-Id or Api-Key
{
http.StatusUnauthorized,
map[string]string{},
&ListStrategiesParams{},
`{
"code": 16,
"message": "Client-Id and Api-Key headers are required"
}`,
},
}
for _, test := range tests {
c := NewMockClient(core.NewMockHttpHandler(test.statusCode, test.response, test.headers))
resp, err := c.Strategies().List(test.params)
if err != nil {
t.Error(err)
}
if resp.StatusCode != test.statusCode {
t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode)
}
}
}
func TestCreateStrategy(t *testing.T) {
t.Parallel()
tests := []struct {
statusCode int
headers map[string]string
params *CreateStrategyParams
response string
}{
// Test Ok
{
http.StatusOK,
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
&CreateStrategyParams{
StrategyName: "New strategy",
Competitors: []CreateStrategyCompetitor{
{
CompetitorId: 1008426,
Coefficient: 1,
},
{
CompetitorId: 204,
Coefficient: 1,
},
{
CompetitorId: 91,
Coefficient: 1,
},
{
CompetitorId: 48,
Coefficient: 1,
},
},
},
`{
"result": {
"id": "4f3a1d4c-5833-4f04-b69b-495cbc1f6f1c"
}
}`,
},
// Test No Client-Id or Api-Key
{
http.StatusUnauthorized,
map[string]string{},
&CreateStrategyParams{},
`{
"code": 16,
"message": "Client-Id and Api-Key headers are required"
}`,
},
}
for _, test := range tests {
c := NewMockClient(core.NewMockHttpHandler(test.statusCode, test.response, test.headers))
resp, err := c.Strategies().Create(test.params)
if err != nil {
t.Error(err)
}
if resp.StatusCode != test.statusCode {
t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode)
}
}
}
func TestInfoStrategy(t *testing.T) {
t.Parallel()
tests := []struct {
statusCode int
headers map[string]string
params *InfoStrategyParams
response string
}{
// Test Ok
{
http.StatusOK,
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
&InfoStrategyParams{
StrategyId: "1",
},
`{
"result": {
"strategy_name": "test1",
"enabled": true,
"update_type": "strategyItemsListChanged",
"type": "COMP_PRICE",
"competitors": [
{
"competitor_id": 204,
"coefficient": 1
},
{
"competitor_id": 1008426,
"coefficient": 1
}
]
}
}`,
},
// Test No Client-Id or Api-Key
{
http.StatusUnauthorized,
map[string]string{},
&InfoStrategyParams{},
`{
"code": 16,
"message": "Client-Id and Api-Key headers are required"
}`,
},
}
for _, test := range tests {
c := NewMockClient(core.NewMockHttpHandler(test.statusCode, test.response, test.headers))
resp, err := c.Strategies().Info(test.params)
if err != nil {
t.Error(err)
}
if resp.StatusCode != test.statusCode {
t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode)
}
}
}
func TestUpdateStrategy(t *testing.T) {
t.Parallel()
tests := []struct {
statusCode int
headers map[string]string
params *UpdateStrategyParams
response string
}{
// Test Ok
{
http.StatusOK,
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
&UpdateStrategyParams{
StrategyId: "a3de1826-9c54-40f1-bb6d-1a9e2638b058",
StrategyName: "New Strategy",
Competitors: []CreateStrategyCompetitor{
{
CompetitorId: 1008426,
Coefficient: 1,
},
{
CompetitorId: 204,
Coefficient: 1,
},
{
CompetitorId: 91,
Coefficient: 1,
},
{
CompetitorId: 48,
Coefficient: 1,
},
{
CompetitorId: 45,
Coefficient: 1,
},
},
},
`{}`,
},
// Test No Client-Id or Api-Key
{
http.StatusUnauthorized,
map[string]string{},
&UpdateStrategyParams{},
`{
"code": 16,
"message": "Client-Id and Api-Key headers are required"
}`,
},
}
for _, test := range tests {
c := NewMockClient(core.NewMockHttpHandler(test.statusCode, test.response, test.headers))
resp, err := c.Strategies().Update(test.params)
if err != nil {
t.Error(err)
}
if resp.StatusCode != test.statusCode {
t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode)
}
}
}
func TestAddProductsToStrategy(t *testing.T) {
t.Parallel()
tests := []struct {
statusCode int
headers map[string]string
params *AddProductsToStrategyParams
response string
}{
// Test Ok
{
http.StatusOK,
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
&AddProductsToStrategyParams{
ProductId: []int64{29209},
StrategyId: "e29114f0-177d-4160-8d06-2bc528470dda",
},
`{
"result": {
"failed_product_count": 0
}
}`,
},
// Test No Client-Id or Api-Key
{
http.StatusUnauthorized,
map[string]string{},
&AddProductsToStrategyParams{},
`{
"code": 16,
"message": "Client-Id and Api-Key headers are required"
}`,
},
}
for _, test := range tests {
c := NewMockClient(core.NewMockHttpHandler(test.statusCode, test.response, test.headers))
resp, err := c.Strategies().AddProducts(test.params)
if err != nil {
t.Error(err)
}
if resp.StatusCode != test.statusCode {
t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode)
}
}
}
func TestGetStrategiesByProductIds(t *testing.T) {
t.Parallel()
tests := []struct {
statusCode int
headers map[string]string
params *GetStrategiesByProductIdsParams
response string
}{
// Test Ok
{
http.StatusOK,
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
&GetStrategiesByProductIdsParams{
ProductId: []int64{29209},
},
`{
"result": {
"products_info": [
{
"product_id": 29209,
"strategy_id": "b7cd30e6-5667-424d-b105-fbec30a52477"
}
]
}
}`,
},
// Test No Client-Id or Api-Key
{
http.StatusUnauthorized,
map[string]string{},
&GetStrategiesByProductIdsParams{},
`{
"code": 16,
"message": "Client-Id and Api-Key headers are required"
}`,
},
}
for _, test := range tests {
c := NewMockClient(core.NewMockHttpHandler(test.statusCode, test.response, test.headers))
resp, err := c.Strategies().GetByProductIds(test.params)
if err != nil {
t.Error(err)
}
if resp.StatusCode != test.statusCode {
t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode)
}
if resp.StatusCode == http.StatusOK {
if len(resp.Result.ProductsInfo) != len(test.params.ProductId) {
t.Errorf("Length of product ids in request and response are not equal")
}
if len(resp.Result.ProductsInfo) > 0 {
if resp.Result.ProductsInfo[0].ProductId != test.params.ProductId[0] {
t.Errorf("Product ids in request and response are not equal")
}
}
}
}
}
func TestListProductsInStrategy(t *testing.T) {
t.Parallel()
tests := []struct {
statusCode int
headers map[string]string
params *ListProductsInStrategyParams
response string
}{
// Test Ok
{
http.StatusOK,
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
&ListProductsInStrategyParams{
StrategyId: "string",
},
`{
"result": {
"product_id": [
"string"
]
}
}`,
},
// Test No Client-Id or Api-Key
{
http.StatusUnauthorized,
map[string]string{},
&ListProductsInStrategyParams{},
`{
"code": 16,
"message": "Client-Id and Api-Key headers are required"
}`,
},
}
for _, test := range tests {
c := NewMockClient(core.NewMockHttpHandler(test.statusCode, test.response, test.headers))
resp, err := c.Strategies().ListProducts(test.params)
if err != nil {
t.Error(err)
}
if resp.StatusCode != test.statusCode {
t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode)
}
}
}
func TestGetCompetitorPrice(t *testing.T) {
t.Parallel()
tests := []struct {
statusCode int
headers map[string]string
params *GetCompetitorPriceParams
response string
}{
// Test Ok
{
http.StatusOK,
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
&GetCompetitorPriceParams{
ProductId: 0,
},
`{
"result": {
"strategy_id": "string",
"is_enabled": true,
"strategy_product_price": 0,
"price_downloaded_at": "2022-11-17T15:33:53.936Z",
"strategy_competitor_id": 0,
"strategy_competitor_product_url": "string"
}
}`,
},
// Test No Client-Id or Api-Key
{
http.StatusUnauthorized,
map[string]string{},
&GetCompetitorPriceParams{},
`{
"code": 16,
"message": "Client-Id and Api-Key headers are required"
}`,
},
}
for _, test := range tests {
c := NewMockClient(core.NewMockHttpHandler(test.statusCode, test.response, test.headers))
resp, err := c.Strategies().GetCompetitorPrice(test.params)
if err != nil {
t.Error(err)
}
if resp.StatusCode != test.statusCode {
t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode)
}
}
}
func TestRemoveProductsFromStrategy(t *testing.T) {
t.Parallel()
tests := []struct {
statusCode int
headers map[string]string
params *RemoveProductsFromStrategyParams
response string
}{
// Test Ok
{
http.StatusOK,
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
&RemoveProductsFromStrategyParams{
ProductId: []int64{0},
},
`{
"result": {
"failed_product_count": 0
}
}`,
},
// Test No Client-Id or Api-Key
{
http.StatusUnauthorized,
map[string]string{},
&RemoveProductsFromStrategyParams{},
`{
"code": 16,
"message": "Client-Id and Api-Key headers are required"
}`,
},
}
for _, test := range tests {
c := NewMockClient(core.NewMockHttpHandler(test.statusCode, test.response, test.headers))
resp, err := c.Strategies().RemoveProducts(test.params)
if err != nil {
t.Error(err)
}
if resp.StatusCode != test.statusCode {
t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode)
}
}
}
func TestChangeStrategyStatus(t *testing.T) {
t.Parallel()
tests := []struct {
statusCode int
headers map[string]string
params *ChangeStrategyStatusParams
response string
}{
// Test Ok
{
http.StatusOK,
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
&ChangeStrategyStatusParams{
Enabled: true,
StrategyId: "c7516438-7124-4e2c-85d3-ccd92b6b9b65",
},
`{}`,
},
// Test No Client-Id or Api-Key
{
http.StatusUnauthorized,
map[string]string{},
&ChangeStrategyStatusParams{},
`{
"code": 16,
"message": "Client-Id and Api-Key headers are required"
}`,
},
}
for _, test := range tests {
c := NewMockClient(core.NewMockHttpHandler(test.statusCode, test.response, test.headers))
resp, err := c.Strategies().ChangeStatus(test.params)
if err != nil {
t.Error(err)
}
if resp.StatusCode != test.statusCode {
t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode)
}
}
}
func TestRemoveStrategy(t *testing.T) {
t.Parallel()
tests := []struct {
statusCode int
headers map[string]string
params *RemoveStrategyParams
response string
}{
// Test Ok
{
http.StatusOK,
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
&RemoveStrategyParams{
StrategyId: "strategy",
},
`{}`,
},
// Test No Client-Id or Api-Key
{
http.StatusUnauthorized,
map[string]string{},
&RemoveStrategyParams{},
`{
"code": 16,
"message": "Client-Id and Api-Key headers are required"
}`,
},
}
for _, test := range tests {
c := NewMockClient(core.NewMockHttpHandler(test.statusCode, test.response, test.headers))
resp, err := c.Strategies().Remove(test.params)
if err != nil {
t.Error(err)
}
if resp.StatusCode != test.statusCode {
t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode)
}
}
}