Skip to content

Commit

Permalink
add method for getting ozon warehouses workload
Browse files Browse the repository at this point in the history
  • Loading branch information
diPhantxm committed Jun 2, 2023
1 parent 2f1dbd5 commit e60a3f1
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 0 deletions.
49 changes: 49 additions & 0 deletions ozon/fbo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
58 changes: 58 additions & 0 deletions ozon/fbo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}

0 comments on commit e60a3f1

Please sign in to comment.