Update November 9, 2023 (#49)
This commit is contained in:
148
ozon/reports.go
148
ozon/reports.go
@@ -61,6 +61,9 @@ type GetReportsListResultReport struct {
|
|||||||
Error string `json:"error"`
|
Error string `json:"error"`
|
||||||
|
|
||||||
// Link to CSV file
|
// Link to CSV file
|
||||||
|
//
|
||||||
|
// For a report with the SELLER_RETURNS type,
|
||||||
|
// the link is available within 5 minutes after making a request.
|
||||||
File string `json:"file"`
|
File string `json:"file"`
|
||||||
|
|
||||||
// Array with the filters specified when the seller created the report
|
// Array with the filters specified when the seller created the report
|
||||||
@@ -445,86 +448,6 @@ func (c Reports) GetProducts(ctx context.Context, params *GetProductsReportParam
|
|||||||
return resp, nil
|
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 GetStocksReportResult `json:"result"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type GetStocksReportResult struct {
|
|
||||||
// Unique report identifier
|
|
||||||
Code string `json:"code"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Report with information about the number of available and reserved products in stock
|
|
||||||
func (c Reports) GetStocks(ctx context.Context, params *GetStocksReportParams) (*GetStocksReportResponse, error) {
|
|
||||||
url := "/v1/report/stock/create"
|
|
||||||
|
|
||||||
resp := &GetStocksReportResponse{}
|
|
||||||
|
|
||||||
response, err := c.client.Request(ctx, http.MethodPost, url, params, resp, nil)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
response.CopyCommonResponse(&resp.CommonResponse)
|
|
||||||
|
|
||||||
return resp, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
type GetProductsMovementReportParams struct {
|
|
||||||
// Date from which the data will be in the report
|
|
||||||
DateFrom time.Time `json:"date_from"`
|
|
||||||
|
|
||||||
// Date up to which the data will be in the report
|
|
||||||
DateTo time.Time `json:"date_to"`
|
|
||||||
|
|
||||||
// Default: "DEFAULT"
|
|
||||||
// Response language:
|
|
||||||
// - RU — Russian
|
|
||||||
// - EN — English
|
|
||||||
Language string `json:"language" default:"DEFAULT"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type GetProductsMovementReportResponse struct {
|
|
||||||
core.CommonResponse
|
|
||||||
|
|
||||||
// Method result
|
|
||||||
Result GetProductsMovementReportResult `json:"result"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type GetProductsMovementReportResult struct {
|
|
||||||
// Unique report identifier
|
|
||||||
Code string `json:"code"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Report with complete information on products, as well as the number of products with statuses:
|
|
||||||
// - products with defects or in inventory,
|
|
||||||
// - products in transit between the fulfillment centers,
|
|
||||||
// - products in delivery,
|
|
||||||
// - products to be sold
|
|
||||||
func (c Reports) GetProductsMovement(ctx context.Context, params *GetProductsMovementReportParams) (*GetProductsMovementReportResponse, error) {
|
|
||||||
url := "/v1/report/products/movement/create"
|
|
||||||
|
|
||||||
resp := &GetProductsMovementReportResponse{}
|
|
||||||
|
|
||||||
response, err := c.client.Request(ctx, http.MethodPost, url, params, resp, nil)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
response.CopyCommonResponse(&resp.CommonResponse)
|
|
||||||
|
|
||||||
return resp, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
type GetReturnsReportParams struct {
|
type GetReturnsReportParams struct {
|
||||||
// Filter
|
// Filter
|
||||||
Filter GetReturnsReportsFilter `json:"filter"`
|
Filter GetReturnsReportsFilter `json:"filter"`
|
||||||
@@ -555,7 +478,7 @@ type GetReturnsReportResponse struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type GetReturnReportResult struct {
|
type GetReturnReportResult struct {
|
||||||
// Unique report identifier
|
// Unique report identifier. The report is available for downloading within 3 days after making a request.
|
||||||
Code string `json:"code"`
|
Code string `json:"code"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -679,56 +602,29 @@ func (c Reports) IssueOnDiscountedProducts(ctx context.Context) (*IssueOnDiscoun
|
|||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type ReportOnDiscountedProductsParams struct {
|
type GetFBSStocksParams struct {
|
||||||
|
// Response language
|
||||||
|
Language string `json:"language"`
|
||||||
|
|
||||||
|
// Warehouses identifiers
|
||||||
|
WarehouseIds []int64 `json:"warehouse_id"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type GetFBSStocksResponse struct {
|
||||||
|
core.CommonResponse
|
||||||
|
|
||||||
// Unique report identifier
|
// Unique report identifier
|
||||||
Code string `json:"code"`
|
Code string `json:"code"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ReportOnDiscountedProductsResponse struct {
|
// Report with information about the number of available and reserved products in stock.
|
||||||
core.CommonResponse
|
//
|
||||||
|
// The method returns a report identifier.
|
||||||
|
// To get the report, send the identifier in the request of the `/v1/report/info` method.
|
||||||
|
func (c Reports) GetFBSStocks(ctx context.Context, params *GetFBSStocksParams) (*GetFBSStocksResponse, error) {
|
||||||
|
url := "/v1/report/warehouse/stock"
|
||||||
|
|
||||||
// Report information
|
resp := &GetFBSStocksResponse{}
|
||||||
Report ReportonDiscountedProductsReport `json:"report"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type ReportonDiscountedProductsReport struct {
|
|
||||||
// Report creation date
|
|
||||||
CreatedAt time.Time `json:"created_at"`
|
|
||||||
|
|
||||||
// Link to report file
|
|
||||||
File string `json:"file"`
|
|
||||||
|
|
||||||
// Report status:
|
|
||||||
// - success — created
|
|
||||||
// - pending — waiting to be processed
|
|
||||||
// - processing — processed
|
|
||||||
// - failed — generation error
|
|
||||||
Status string `json:"status"`
|
|
||||||
|
|
||||||
// Report generation error code
|
|
||||||
Error string `json:"error"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// By report identifier, returns information about the report generated earlier
|
|
||||||
func (c Reports) ReportOnDiscountedProducts(ctx context.Context, params *ReportOnDiscountedProductsParams) (*ReportOnDiscountedProductsResponse, error) {
|
|
||||||
url := "/v1/report/discounted/info"
|
|
||||||
|
|
||||||
resp := &ReportOnDiscountedProductsResponse{}
|
|
||||||
|
|
||||||
response, err := c.client.Request(ctx, http.MethodPost, url, nil, resp, nil)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
response.CopyCommonResponse(&resp.CommonResponse)
|
|
||||||
|
|
||||||
return resp, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// By report identifier, returns information about the report generated earlier
|
|
||||||
func (c Reports) ListReportsOnDiscountedProducts(ctx context.Context) (*ReportOnDiscountedProductsResponse, error) {
|
|
||||||
url := "/v1/report/discounted/list"
|
|
||||||
|
|
||||||
resp := &ReportOnDiscountedProductsResponse{}
|
|
||||||
|
|
||||||
response, err := c.client.Request(ctx, http.MethodPost, url, nil, resp, nil)
|
response, err := c.client.Request(ctx, http.MethodPost, url, nil, resp, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -350,115 +350,6 @@ func TestGetProductsReport(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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))
|
|
||||||
|
|
||||||
ctx, _ := context.WithTimeout(context.Background(), testTimeout)
|
|
||||||
resp, err := c.Reports().GetStocks(ctx, 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 resp.Result.Code == "" {
|
|
||||||
t.Errorf("Code cannot be empty")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestGetProductsMovementReport(t *testing.T) {
|
|
||||||
t.Parallel()
|
|
||||||
|
|
||||||
tests := []struct {
|
|
||||||
statusCode int
|
|
||||||
headers map[string]string
|
|
||||||
params *GetProductsMovementReportParams
|
|
||||||
response string
|
|
||||||
}{
|
|
||||||
// Test Ok
|
|
||||||
{
|
|
||||||
http.StatusOK,
|
|
||||||
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
|
|
||||||
&GetProductsMovementReportParams{
|
|
||||||
DateFrom: core.TimeFromString(t, "2006-01-02T15:04:05Z", "2020-08-01T14:15:22Z"),
|
|
||||||
DateTo: core.TimeFromString(t, "2006-01-02T15:04:05Z", "2020-08-01T14:15:22Z"),
|
|
||||||
},
|
|
||||||
`{
|
|
||||||
"result": {
|
|
||||||
"code": "h56f4917-1346-4e64-9d90-с6e736c1e07c"
|
|
||||||
}
|
|
||||||
}`,
|
|
||||||
},
|
|
||||||
// Test No Client-Id or Api-Key
|
|
||||||
{
|
|
||||||
http.StatusUnauthorized,
|
|
||||||
map[string]string{},
|
|
||||||
&GetProductsMovementReportParams{},
|
|
||||||
`{
|
|
||||||
"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))
|
|
||||||
|
|
||||||
ctx, _ := context.WithTimeout(context.Background(), testTimeout)
|
|
||||||
resp, err := c.Reports().GetProductsMovement(ctx, 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 resp.Result.Code == "" {
|
|
||||||
t.Errorf("Code cannot be empty")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestGetReturnsReport(t *testing.T) {
|
func TestGetReturnsReport(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
@@ -623,36 +514,32 @@ func TestIssueOnDiscountedProducts(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestReportOnDiscountedProducts(t *testing.T) {
|
func TestGetFBSStocks(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
statusCode int
|
statusCode int
|
||||||
headers map[string]string
|
headers map[string]string
|
||||||
params *ReportOnDiscountedProductsParams
|
params *GetFBSStocksParams
|
||||||
response string
|
response string
|
||||||
}{
|
}{
|
||||||
// Test Ok
|
// Test Ok
|
||||||
{
|
{
|
||||||
http.StatusOK,
|
http.StatusOK,
|
||||||
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
|
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
|
||||||
&ReportOnDiscountedProductsParams{
|
&GetFBSStocksParams{
|
||||||
Code: "d55f4517-8347-4e24-9d93-d6e736c1c07c",
|
Language: "EN",
|
||||||
|
WarehouseIds: []int64{123},
|
||||||
},
|
},
|
||||||
`{
|
`{
|
||||||
"report": {
|
"code": "d55f4517-8347-4e24-9d93-d6e736c1c07c"
|
||||||
"created_at": "2022-10-04T10:07:08.146Z",
|
|
||||||
"error": "string",
|
|
||||||
"file": "string",
|
|
||||||
"status": "string"
|
|
||||||
}
|
|
||||||
}`,
|
}`,
|
||||||
},
|
},
|
||||||
// Test No Client-Id or Api-Key
|
// Test No Client-Id or Api-Key
|
||||||
{
|
{
|
||||||
http.StatusUnauthorized,
|
http.StatusUnauthorized,
|
||||||
map[string]string{},
|
map[string]string{},
|
||||||
&ReportOnDiscountedProductsParams{},
|
&GetFBSStocksParams{},
|
||||||
`{
|
`{
|
||||||
"code": 16,
|
"code": 16,
|
||||||
"message": "Client-Id and Api-Key headers are required"
|
"message": "Client-Id and Api-Key headers are required"
|
||||||
@@ -664,56 +551,7 @@ func TestReportOnDiscountedProducts(t *testing.T) {
|
|||||||
c := NewMockClient(core.NewMockHttpHandler(test.statusCode, test.response, test.headers))
|
c := NewMockClient(core.NewMockHttpHandler(test.statusCode, test.response, test.headers))
|
||||||
|
|
||||||
ctx, _ := context.WithTimeout(context.Background(), testTimeout)
|
ctx, _ := context.WithTimeout(context.Background(), testTimeout)
|
||||||
resp, err := c.Reports().ReportOnDiscountedProducts(ctx, test.params)
|
resp, err := c.Reports().GetFBSStocks(ctx, 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 TestListReportsOnDiscountedProducts(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"},
|
|
||||||
`{
|
|
||||||
"reports": [
|
|
||||||
{
|
|
||||||
"created_at": "2022-10-04T10:07:08.146Z",
|
|
||||||
"error": "string",
|
|
||||||
"file": "string",
|
|
||||||
"status": "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))
|
|
||||||
|
|
||||||
ctx, _ := context.WithTimeout(context.Background(), testTimeout)
|
|
||||||
resp, err := c.Reports().ListReportsOnDiscountedProducts(ctx)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user