Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
diPhantxm committed Oct 31, 2024
1 parent 3430ead commit 77b0813
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 134 deletions.
35 changes: 35 additions & 0 deletions ozon/fbs.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ type FBSPosting struct {
// Analytics data
AnalyticsData FBSPostingAnalyticsData `json:"analytics_data"`

// Available actions and shipment information
AvailableActions []string `json:"available_actions"`

// Shipment barcodes
Barcodes FBSBarcode `json:"barcodes"`

Expand Down Expand Up @@ -912,6 +915,9 @@ type GetShipmentDataByIdentifierResult struct {
// Analytics data
AnalyticsData GetShipmentDataByIdentifierResultAnalyticsData `json:"analytics_data"`

// Available actions and shipment information
AvailableActions []string `json:"available_actions"`

// Shipment barcodes
Barcodes FBSBarcode `json:"barcodes"`

Expand Down Expand Up @@ -3051,3 +3057,32 @@ func (c FBS) GetCancellationReasons(ctx context.Context) (*GetCancellationReason

return resp, nil
}

type SetShippingDateParams struct {
// New shipping date
NewCutoffDate time.Time `json:"new_cutoff_date"`

// Shipment number
PostingNumber string `json:"posting_number"`
}

type SetShippingDateResponse struct {
core.CommonResponse

// true if the new date is set
Result bool `json:"result"`
}

func (c FBS) SetShippingDate(ctx context.Context, params *SetShippingDateParams) (*SetShippingDateResponse, error) {
url := "/v1/posting/cutoff/set"

resp := &SetShippingDateResponse{}

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
}
50 changes: 50 additions & 0 deletions ozon/fbs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3080,3 +3080,53 @@ func TestGetCancellationReasons(t *testing.T) {
}
}
}

func TestSetShippingDate(t *testing.T) {
t.Parallel()

tests := []struct {
statusCode int
headers map[string]string
params *SetShippingDateParams
response string
}{
// Test Ok
{
http.StatusOK,
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
&SetShippingDateParams{
NewCutoffDate: core.TimeFromString(t, "2006-01-02T15:04:05Z", "2019-08-24T14:15:22Z"),
},
`{
"result": true
}`,
},
// Test No Client-Id or Api-Key
{
http.StatusUnauthorized,
map[string]string{},
&SetShippingDateParams{},
`{
"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.FBS().SetShippingDate(ctx, test.params)
if err != nil {
t.Error(err)
continue
}

compareJsonResponse(t, test.response, &SetShippingDateResponse{})

if resp.StatusCode != test.statusCode {
t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode)
}
}
}
61 changes: 0 additions & 61 deletions ozon/products.go
Original file line number Diff line number Diff line change
Expand Up @@ -1762,67 +1762,6 @@ func (c Products) RemoveProductWithoutSKU(ctx context.Context, params *RemovePro
return resp, nil
}

type ListGeoRestrictionsParams struct {
// Filter. To get all geo-restrictions, leave names blank and specify true in the only_visible parameter
Filter ListGeoRestrictionsFilter `json:"filter"`

// Order number of geo-restriction from which to output data in the response.
//
// If you specify 23 in this parameter, the first item in the restrictions list will output order_number = 24.
// If you want to get all geo-restrictions, pass 0 in this parameter
LastOrderNumber int64 `json:"last_order_number"`

// Number of items in the response
Limit int64 `json:"limit"`
}

type ListGeoRestrictionsFilter struct {
// List with city names
Names []string `json:"names"`

// Value visibility. We recommend always passing true in this parameter
OnlyVisible bool `json:"only_visible"`
}

type ListGeoRestrictionsResponse struct {
core.CommonResponse

// Restrictions
Restrictions []ListGeoRestrictionsRestriction `json:"restrictions"`
}

type ListGeoRestrictionsRestriction struct {
// Geo-restriction identifier
Id string `json:"id"`

// Item visibility
IsVisible bool `json:"is_visible"`

// City name
Name string `json:"name"`

// Geo-restriction order number.
//
// If you specify 23 in the last_order_number parameter in the request,
// the first item in the restrictions list will have order_number = 24
OrderNumber int64 `json:"order_number"`
}

// Deprecated: Get a list of geo-restrictions for services
func (c Products) ListGeoRestrictions(ctx context.Context, params *ListGeoRestrictionsParams) (*ListGeoRestrictionsResponse, error) {
url := "/v1/products/geo-restrictions-catalog-by-filter"

resp := &ListGeoRestrictionsResponse{}

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 UploadActivationCodesParams struct {
// Digital activation codes
DigitalCodes []string `json:"digital_codes"`
Expand Down
73 changes: 0 additions & 73 deletions ozon/products_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2140,79 +2140,6 @@ func TestRemoveProductWithoutSKU(t *testing.T) {
}
}

func TestListGeoRestrictions(t *testing.T) {
t.Parallel()

tests := []struct {
statusCode int
headers map[string]string
params *ListGeoRestrictionsParams
response string
}{
// Test Ok
{
http.StatusOK,
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
&ListGeoRestrictionsParams{
Filter: ListGeoRestrictionsFilter{
OnlyVisible: true,
},
LastOrderNumber: 0,
Limit: 3,
},
`{
"restrictions": [
{
"id": "world",
"name": "Весь Мир",
"is_visible": true,
"order_number": 1
},
{
"id": "42fb1c32-0cfe-5c96-9fb5-7f8e8449f28c",
"name": "Все города РФ",
"is_visible": true,
"order_number": 2
},
{
"id": "moscow",
"name": "Москва",
"is_visible": true,
"order_number": 3
}
]
}`,
},
// Test No Client-Id or Api-Key
{
http.StatusUnauthorized,
map[string]string{},
&ListGeoRestrictionsParams{},
`{
"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().ListGeoRestrictions(ctx, test.params)
if err != nil {
t.Error(err)
continue
}

compareJsonResponse(t, test.response, &ListGeoRestrictionsResponse{})

if resp.StatusCode != test.statusCode {
t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode)
}
}
}

func TestUploadActivationCodes(t *testing.T) {
t.Parallel()

Expand Down

0 comments on commit 77b0813

Please sign in to comment.