add method for getting ozon warehouses workload
This commit is contained in:
49
ozon/fbo.go
49
ozon/fbo.go
@@ -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
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user