Update October 26, 2023 (#46)
This commit is contained in:
@@ -577,3 +577,13 @@ const (
|
|||||||
ReportInfoSuccess ReportInfoStatus = "success"
|
ReportInfoSuccess ReportInfoStatus = "success"
|
||||||
ReportInfoFailed ReportInfoStatus = "failed"
|
ReportInfoFailed ReportInfoStatus = "failed"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type SKUAvailability string
|
||||||
|
|
||||||
|
const (
|
||||||
|
SKUAvailabilityHidden = "HIDDEN"
|
||||||
|
SKUAvailabilityAvailable = "AVAILABLE"
|
||||||
|
|
||||||
|
// SKU is deleted
|
||||||
|
SKUAvailabilityUnavailable = "UNAVAILABLE"
|
||||||
|
)
|
||||||
|
|||||||
@@ -2335,3 +2335,64 @@ func (c Products) UpdateCharacteristics(ctx context.Context, params *UpdateChara
|
|||||||
|
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type GetRelatedSKUsParams struct {
|
||||||
|
// List of SKUs
|
||||||
|
SKUs []string `json:"sku"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type GetRelatedSKUsResponse struct {
|
||||||
|
core.CommonResponse
|
||||||
|
|
||||||
|
// Related SKUs information
|
||||||
|
Items []GetRelatedSKUsItem `json:"items"`
|
||||||
|
|
||||||
|
// Errors
|
||||||
|
Errors []GetRelatedSKUsError `json:"errors"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type GetRelatedSKUsItem struct {
|
||||||
|
// Product availability attribute by SKU
|
||||||
|
Availability SKUAvailability `json:"availability"`
|
||||||
|
|
||||||
|
// Date and time of deletion
|
||||||
|
DeletedAt time.Time `json:"deleted_at"`
|
||||||
|
|
||||||
|
// Delivery scheme
|
||||||
|
DeliverySchema string `json:"delivery_schema"`
|
||||||
|
|
||||||
|
// Product identifier
|
||||||
|
ProductId int64 `json:"product_id"`
|
||||||
|
|
||||||
|
// Product identifier in the Ozon system, SKU
|
||||||
|
SKU int64 `json:"sku"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type GetRelatedSKUsError struct {
|
||||||
|
// Error code
|
||||||
|
Code string `json:"code"`
|
||||||
|
|
||||||
|
// SKU, in which the error occurred
|
||||||
|
SKU int `json:"sku"`
|
||||||
|
|
||||||
|
// Error text
|
||||||
|
Message string `json:"message"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// You can pass any SKU in the request, even a deleted one.
|
||||||
|
// The response will contain all SKUs related to the passed ones.
|
||||||
|
//
|
||||||
|
// In one request, you can pass up to 200 SKUs.
|
||||||
|
func (c Products) GetRelatedSKUs(ctx context.Context, params *GetRelatedSKUsParams) (*GetRelatedSKUsResponse, error) {
|
||||||
|
url := "/v1/product/related-sku/get"
|
||||||
|
|
||||||
|
resp := &GetRelatedSKUsResponse{}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|||||||
@@ -2600,3 +2600,69 @@ func TestUpdateCharacteristics(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGetRelatedSKUs(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
tests := []struct {
|
||||||
|
statusCode int
|
||||||
|
headers map[string]string
|
||||||
|
params *GetRelatedSKUsParams
|
||||||
|
response string
|
||||||
|
}{
|
||||||
|
// Test Ok
|
||||||
|
{
|
||||||
|
http.StatusOK,
|
||||||
|
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
|
||||||
|
&GetRelatedSKUsParams{
|
||||||
|
SKUs: []string{"321", "322"},
|
||||||
|
},
|
||||||
|
`{
|
||||||
|
"items": [
|
||||||
|
{
|
||||||
|
"availability": "HIDDEN",
|
||||||
|
"deleted_at": "2019-08-24T14:15:22Z",
|
||||||
|
"delivery_schema": "fbs",
|
||||||
|
"product_id": 123,
|
||||||
|
"sku": 321
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"errors": [
|
||||||
|
{
|
||||||
|
"code": "test_code",
|
||||||
|
"sku": 322,
|
||||||
|
"message": "test_message"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}`,
|
||||||
|
},
|
||||||
|
// Test No Client-Id or Api-Key
|
||||||
|
{
|
||||||
|
http.StatusUnauthorized,
|
||||||
|
map[string]string{},
|
||||||
|
&GetRelatedSKUsParams{},
|
||||||
|
`{
|
||||||
|
"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.Products().GetRelatedSKUs(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 len(resp.Errors)+len(resp.Items) != len(test.params.SKUs) {
|
||||||
|
t.Errorf("expected equal length of skus in request and response")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user