add Report details
This commit is contained in:
@@ -152,7 +152,7 @@
|
||||
- [ ] Delete the proforma invoice link
|
||||
|
||||
## Reports
|
||||
- [ ] Report details
|
||||
- [x] Report details
|
||||
- [x] Reports list
|
||||
- [ ] Products report
|
||||
- [ ] Prices report
|
||||
|
||||
@@ -90,3 +90,61 @@ func (c Reports) GetList(params *GetReportsListParams) (*GetReportsListResponse,
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
type GetReportDetailsParams struct {
|
||||
// Unique report identifier
|
||||
Code string `json:"code"`
|
||||
}
|
||||
|
||||
type GetReportDetailsResponse struct {
|
||||
core.CommonResponse
|
||||
|
||||
// Report details
|
||||
Result struct {
|
||||
// Unique report identifier
|
||||
Code string `json:"code"`
|
||||
|
||||
// Report creation date
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
|
||||
// Error code when generating the report
|
||||
Error string `json:"error"`
|
||||
|
||||
// Link to CSV file
|
||||
File string `json:"file"`
|
||||
|
||||
// Array with the filters specified when the seller created the report
|
||||
Params map[string]string `json:"params"`
|
||||
|
||||
// Report type:
|
||||
// - SELLER_PRODUCTS — products report,
|
||||
// - SELLER_TRANSACTIONS — transactions report,
|
||||
// - SELLER_PRODUCT_PRICES — product prices report,
|
||||
// - SELLER_STOCK — stocks report,
|
||||
// - SELLER_PRODUCT_MOVEMENT — products movement report,
|
||||
// - SELLER_RETURNS — returns report,
|
||||
// - SELLER_POSTINGS — shipments report,
|
||||
// - SELLER_FINANCE — financial report
|
||||
ReportType string `json:"report_type"`
|
||||
|
||||
// Report generation status:
|
||||
// - success
|
||||
// - failed
|
||||
Status string `json:"status"`
|
||||
} `json:"result"`
|
||||
}
|
||||
|
||||
// Returns information about a created report by its identifier
|
||||
func (c Reports) GetReportDetails(params *GetReportDetailsParams) (*GetReportDetailsResponse, error) {
|
||||
url := "/v1/report/list"
|
||||
|
||||
resp := &GetReportDetailsResponse{}
|
||||
|
||||
response, err := c.client.Request(http.MethodPost, url, params, resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
response.CopyCommonResponse(&resp.CommonResponse)
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@@ -77,3 +77,55 @@ func TestGetList(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetReportDetails(t *testing.T) {
|
||||
tests := []struct {
|
||||
statusCode int
|
||||
headers map[string]string
|
||||
params *GetReportDetailsParams
|
||||
response string
|
||||
}{
|
||||
// Test Ok
|
||||
{
|
||||
http.StatusOK,
|
||||
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
|
||||
&GetReportDetailsParams{
|
||||
|
||||
},
|
||||
`{
|
||||
"result": {
|
||||
"code": "257bf213-ca57-405c-8edf-41d2ce22decf",
|
||||
"status": "success",
|
||||
"error": "",
|
||||
"file": "https://storage.yandexcloud.net/ozon.reports/95/c1/95c1ae93320294cb.csv",
|
||||
"report_type": "seller_products",
|
||||
"params": {},
|
||||
"created_at": "2021-11-25T14:54:55.688260Z"
|
||||
}
|
||||
}`,
|
||||
},
|
||||
// Test No Client-Id or Api-Key
|
||||
{
|
||||
http.StatusUnauthorized,
|
||||
map[string]string{},
|
||||
&GetReportDetailsParams{},
|
||||
`{
|
||||
"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().GetReportDetails(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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user