add pricing strategy methods

This commit is contained in:
diPhantxm
2023-04-24 01:00:52 +03:00
committed by Kirill
parent c1e7f2b370
commit 387af0e30e
4 changed files with 1073 additions and 0 deletions

View File

@@ -360,3 +360,20 @@ const (
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

@@ -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},
}
}

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)
}
}
}