add methods for getting stocks and products reports, make tests run parallel
This commit is contained in:
@@ -154,8 +154,7 @@
|
||||
## Reports
|
||||
- [x] Report details
|
||||
- [x] Reports list
|
||||
- [ ] Products report
|
||||
- [ ] Prices report
|
||||
- [x] Products report
|
||||
- [ ] Stocks report
|
||||
- [ ] Report on products movement
|
||||
- [ ] Returns report
|
||||
|
||||
@@ -8,6 +8,8 @@ import (
|
||||
)
|
||||
|
||||
func TestGetAnalyticsData(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tests := []struct {
|
||||
statusCode int
|
||||
headers map[string]string
|
||||
@@ -69,6 +71,8 @@ func TestGetAnalyticsData(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetStocksOnWarehouses(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tests := []struct {
|
||||
statusCode int
|
||||
headers map[string]string
|
||||
|
||||
@@ -8,6 +8,8 @@ import (
|
||||
)
|
||||
|
||||
func TestGetFBOShipmentsList(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tests := []struct {
|
||||
statusCode int
|
||||
headers map[string]string
|
||||
|
||||
@@ -8,6 +8,8 @@ import (
|
||||
)
|
||||
|
||||
func TestListUnprocessedShipments(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tests := []struct {
|
||||
statusCode int
|
||||
headers map[string]string
|
||||
@@ -177,6 +179,8 @@ func TestListUnprocessedShipments(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetFBSShipmentsList(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tests := []struct {
|
||||
statusCode int
|
||||
headers map[string]string
|
||||
@@ -286,6 +290,8 @@ func TestGetFBSShipmentsList(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestPackOrder(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tests := []struct {
|
||||
statusCode int
|
||||
headers map[string]string
|
||||
@@ -345,6 +351,8 @@ func TestPackOrder(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestValidateLabelingCodes(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tests := []struct {
|
||||
statusCode int
|
||||
headers map[string]string
|
||||
|
||||
@@ -8,6 +8,8 @@ import (
|
||||
)
|
||||
|
||||
func TestReportOnSoldProducts(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tests := []struct {
|
||||
statusCode int
|
||||
headers map[string]string
|
||||
@@ -106,6 +108,8 @@ func TestReportOnSoldProducts(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetTotalTransactionsSum(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tests := []struct {
|
||||
statusCode int
|
||||
headers map[string]string
|
||||
|
||||
@@ -8,6 +8,8 @@ import (
|
||||
)
|
||||
|
||||
func TestGetStocksInfo(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tests := []struct {
|
||||
statusCode int
|
||||
headers map[string]string
|
||||
@@ -79,6 +81,8 @@ func TestGetStocksInfo(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetProductDetails(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tests := []struct {
|
||||
statusCode int
|
||||
headers map[string]string
|
||||
@@ -243,6 +247,8 @@ func TestGetProductDetails(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestUpdateStocks(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tests := []struct {
|
||||
statusCode int
|
||||
headers map[string]string
|
||||
@@ -300,6 +306,8 @@ func TestUpdateStocks(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestStocksInSellersWarehouse(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tests := []struct {
|
||||
statusCode int
|
||||
headers map[string]string
|
||||
@@ -353,6 +361,8 @@ func TestStocksInSellersWarehouse(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestUpdatePrices(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tests := []struct {
|
||||
statusCode int
|
||||
headers map[string]string
|
||||
@@ -413,6 +423,8 @@ func TestUpdatePrices(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestUpdateQuantityStockProducts(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tests := []struct {
|
||||
statusCode int
|
||||
headers map[string]string
|
||||
@@ -472,6 +484,8 @@ func TestUpdateQuantityStockProducts(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCreateOrUpdateProduct(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tests := []struct {
|
||||
statusCode int
|
||||
headers map[string]string
|
||||
@@ -587,6 +601,8 @@ func TestCreateOrUpdateProduct(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetListOfProducts(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tests := []struct {
|
||||
statusCode int
|
||||
headers map[string]string
|
||||
@@ -646,6 +662,8 @@ func TestGetListOfProducts(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetProductsRatingBySKU(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tests := []struct {
|
||||
statusCode int
|
||||
headers map[string]string
|
||||
|
||||
@@ -8,6 +8,8 @@ import (
|
||||
)
|
||||
|
||||
func TestGetAvailablePromotions(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tests := []struct {
|
||||
statusCode int
|
||||
headers map[string]string
|
||||
@@ -66,6 +68,8 @@ func TestGetAvailablePromotions(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestAddToPromotion(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tests := []struct {
|
||||
statusCode int
|
||||
headers map[string]string
|
||||
|
||||
@@ -8,6 +8,8 @@ import (
|
||||
)
|
||||
|
||||
func TestGetCurrentRatingInfo(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tests := []struct {
|
||||
statusCode int
|
||||
headers map[string]string
|
||||
@@ -68,6 +70,8 @@ func TestGetCurrentRatingInfo(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetRatingInfoForPeriod(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tests := []struct {
|
||||
statusCode int
|
||||
headers map[string]string
|
||||
|
||||
@@ -225,3 +225,82 @@ func (c Reports) GetFinancial(params *GetFinancialReportParams) (*GetFinancialRe
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
type GetProductsReportParams struct {
|
||||
// Default: "DEFAULT"
|
||||
// Response language:
|
||||
// - RU — Russian
|
||||
// - EN — English
|
||||
Language string `json:"language" default:"DEFAULT"`
|
||||
|
||||
// Product identifier in the seller's system
|
||||
OfferId []string `json:"offer_id"`
|
||||
|
||||
// Search by record content, checks for availability
|
||||
Search string `json:"search"`
|
||||
|
||||
// Product identifier in the Ozon system, SKU
|
||||
SKU []int64 `json:"sku"`
|
||||
|
||||
// Default: "ALL"
|
||||
// Filter by product visibility
|
||||
Visibility string `json:"visibility" default:"ALL"`
|
||||
}
|
||||
|
||||
type GetProductsReportResponse struct {
|
||||
core.CommonResponse
|
||||
|
||||
// Method result
|
||||
Result struct {
|
||||
// Unique report identifier
|
||||
Code string `json:"code"`
|
||||
} `json:"result"`
|
||||
}
|
||||
|
||||
// Method for getting a report with products data. For example, Ozon ID, number of products, prices, status
|
||||
func (c Reports) GetProducts(params *GetProductsReportParams) (*GetProductsReportResponse, error) {
|
||||
url := "/v1/report/products/create"
|
||||
|
||||
resp := &GetProductsReportResponse{}
|
||||
|
||||
response, err := c.client.Request(http.MethodPost, url, params, resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
response.CopyCommonResponse(&resp.CommonResponse)
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
type GetStocksReportParams struct {
|
||||
// Default: "DEFAULT"
|
||||
// Response language:
|
||||
// - RU — Russian
|
||||
// - EN — English
|
||||
Language string `json:"language" default:"DEFAULT"`
|
||||
}
|
||||
|
||||
type GetStocksReportResponse struct {
|
||||
core.CommonResponse
|
||||
|
||||
// Method result
|
||||
Result struct {
|
||||
// Unique report identifier
|
||||
Code string `json:"code"`
|
||||
} `json:"result"`
|
||||
}
|
||||
|
||||
// Report with information about the number of available and reserved products in stock
|
||||
func (c Reports) GetStocks(params *GetStocksReportParams) (*GetStocksReportResponse, error) {
|
||||
url := "/v1/report/stock/create"
|
||||
|
||||
resp := &GetStocksReportResponse{}
|
||||
|
||||
response, err := c.client.Request(http.MethodPost, url, params, resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
response.CopyCommonResponse(&resp.CommonResponse)
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@@ -8,6 +8,8 @@ import (
|
||||
)
|
||||
|
||||
func TestGetList(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tests := []struct {
|
||||
statusCode int
|
||||
headers map[string]string
|
||||
@@ -79,6 +81,8 @@ func TestGetList(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetReportDetails(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tests := []struct {
|
||||
statusCode int
|
||||
headers map[string]string
|
||||
@@ -128,7 +132,9 @@ func TestGetReportDetails(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetFinancial(t *testing.T) {
|
||||
func TestGetFinancialReport(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tests := []struct {
|
||||
statusCode int
|
||||
headers map[string]string
|
||||
@@ -193,3 +199,95 @@ func TestGetFinancial(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetProductsReport(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tests := []struct {
|
||||
statusCode int
|
||||
headers map[string]string
|
||||
params *GetProductsReportParams
|
||||
response string
|
||||
}{
|
||||
// Test Ok
|
||||
{
|
||||
http.StatusOK,
|
||||
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
|
||||
&GetProductsReportParams{},
|
||||
`{
|
||||
"result": {
|
||||
"code": "d55f4517-8347-4e24-9d93-d6e736c1c07c"
|
||||
}
|
||||
}`,
|
||||
},
|
||||
// Test No Client-Id or Api-Key
|
||||
{
|
||||
http.StatusUnauthorized,
|
||||
map[string]string{},
|
||||
&GetProductsReportParams{},
|
||||
`{
|
||||
"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.Reports().GetProducts(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 TestGetStocksReport(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tests := []struct {
|
||||
statusCode int
|
||||
headers map[string]string
|
||||
params *GetStocksReportParams
|
||||
response string
|
||||
}{
|
||||
// Test Ok
|
||||
{
|
||||
http.StatusOK,
|
||||
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
|
||||
&GetStocksReportParams{},
|
||||
`{
|
||||
"result": {
|
||||
"code": "d55f4517-8347-4e24-9d93-d6e736c1c07c"
|
||||
}
|
||||
}`,
|
||||
},
|
||||
// Test No Client-Id or Api-Key
|
||||
{
|
||||
http.StatusUnauthorized,
|
||||
map[string]string{},
|
||||
&GetStocksReportParams{},
|
||||
`{
|
||||
"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.Reports().GetStocks(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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,8 @@ import (
|
||||
)
|
||||
|
||||
func TestGetFBOReturns(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tests := []struct {
|
||||
statusCode int
|
||||
headers map[string]string
|
||||
@@ -71,6 +73,8 @@ func TestGetFBOReturns(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetFBSReturns(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tests := []struct {
|
||||
statusCode int
|
||||
headers map[string]string
|
||||
|
||||
@@ -8,6 +8,8 @@ import (
|
||||
)
|
||||
|
||||
func TestGetListOfWarehouses(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tests := []struct {
|
||||
statusCode int
|
||||
headers map[string]string
|
||||
@@ -68,6 +70,8 @@ func TestGetListOfWarehouses(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetListOfDeliveryMethods(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tests := []struct {
|
||||
statusCode int
|
||||
headers map[string]string
|
||||
|
||||
Reference in New Issue
Block a user