Update January 30, 2025 (#142)
This commit is contained in:
		
							
								
								
									
										79
									
								
								ozon/fbo.go
									
									
									
									
									
								
							
							
						
						
									
										79
									
								
								ozon/fbo.go
									
									
									
									
									
								
							@@ -1080,3 +1080,82 @@ func (c FBO) GetDraftTimeslots(ctx context.Context, params *GetDraftTimeslotsPar
 | 
			
		||||
 | 
			
		||||
	return resp, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type CancelSuppyOrderParams struct {
 | 
			
		||||
	// Supply request identifier
 | 
			
		||||
	OrderId int64 `json:"order_id"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type CancelSuppyOrderResponse struct {
 | 
			
		||||
	core.CommonResponse
 | 
			
		||||
 | 
			
		||||
	// Operation identifier for canceling the request
 | 
			
		||||
	OperationId string `json:"operation_id"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Cancel supply request
 | 
			
		||||
func (c FBO) CancelSuppyOrder(ctx context.Context, params *CancelSuppyOrderParams) (*CancelSuppyOrderResponse, error) {
 | 
			
		||||
	url := "/v1/supply-order/cancel"
 | 
			
		||||
 | 
			
		||||
	resp := &CancelSuppyOrderResponse{}
 | 
			
		||||
 | 
			
		||||
	response, err := c.client.Request(ctx, http.MethodGet, url, params, resp, nil)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	response.CopyCommonResponse(&resp.CommonResponse)
 | 
			
		||||
 | 
			
		||||
	return resp, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type StatusCancelledSupplyOrderParams struct {
 | 
			
		||||
	// Operation identifier for canceling the supply request
 | 
			
		||||
	OperationId string `json:"operation_id"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type StatusCancelledSupplyOrderResponse struct {
 | 
			
		||||
	core.CommonResponse
 | 
			
		||||
 | 
			
		||||
	// Reason why the supply request can't be canceled
 | 
			
		||||
	ErrorReasons []string `json:"error_reasons"`
 | 
			
		||||
 | 
			
		||||
	// Details on supply request cancellation
 | 
			
		||||
	Result StatusCancelledSupplyOrderResult `json:"result"`
 | 
			
		||||
 | 
			
		||||
	// Cancellation status of the supply request
 | 
			
		||||
	Status string `json:"status"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type StatusCancelledSupplyOrderResult struct {
 | 
			
		||||
	// true, if supply request is canceled
 | 
			
		||||
	IsOrderCancelled bool `json:"is_order_cancelled"`
 | 
			
		||||
 | 
			
		||||
	// List of canceled supplies
 | 
			
		||||
	Supplies []StatusCancelledSupplyOrderSupply `json:"supplies"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type StatusCancelledSupplyOrderSupply struct {
 | 
			
		||||
	// Reason why supplies can't be canceled
 | 
			
		||||
	ErrorReasons []string `json:"error_reasons"`
 | 
			
		||||
 | 
			
		||||
	// true, if supply is canceled
 | 
			
		||||
	IsSupplyCancelled bool `json:"is_supply_cancelled"`
 | 
			
		||||
 | 
			
		||||
	// Supply identifier
 | 
			
		||||
	SupplyId int64 `json:"supply_id"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Get status of canceled supply request
 | 
			
		||||
func (c FBO) StatusCancelledSupplyOrder(ctx context.Context, params *StatusCancelledSupplyOrderParams) (*StatusCancelledSupplyOrderResponse, error) {
 | 
			
		||||
	url := "/v1/supply-order/cancel/status"
 | 
			
		||||
 | 
			
		||||
	resp := &StatusCancelledSupplyOrderResponse{}
 | 
			
		||||
 | 
			
		||||
	response, err := c.client.Request(ctx, http.MethodGet, url, params, resp, nil)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	response.CopyCommonResponse(&resp.CommonResponse)
 | 
			
		||||
 | 
			
		||||
	return resp, nil
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										115
									
								
								ozon/fbo_test.go
									
									
									
									
									
								
							
							
						
						
									
										115
									
								
								ozon/fbo_test.go
									
									
									
									
									
								
							@@ -1208,3 +1208,118 @@ func TestGetDraftTimeslots(t *testing.T) {
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func TestCancelSuppyOrder(t *testing.T) {
 | 
			
		||||
	t.Parallel()
 | 
			
		||||
 | 
			
		||||
	tests := []struct {
 | 
			
		||||
		statusCode int
 | 
			
		||||
		headers    map[string]string
 | 
			
		||||
		params     *CancelSuppyOrderParams
 | 
			
		||||
		response   string
 | 
			
		||||
	}{
 | 
			
		||||
		// Test Ok
 | 
			
		||||
		{
 | 
			
		||||
			http.StatusOK,
 | 
			
		||||
			map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
 | 
			
		||||
			&CancelSuppyOrderParams{
 | 
			
		||||
				OrderId: 11,
 | 
			
		||||
			},
 | 
			
		||||
			`{
 | 
			
		||||
				"operation_id": "string"
 | 
			
		||||
			}`,
 | 
			
		||||
		},
 | 
			
		||||
		// Test No Client-Id or Api-Key
 | 
			
		||||
		{
 | 
			
		||||
			http.StatusUnauthorized,
 | 
			
		||||
			map[string]string{},
 | 
			
		||||
			&CancelSuppyOrderParams{},
 | 
			
		||||
			`{
 | 
			
		||||
				"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.FBO().CancelSuppyOrder(ctx, test.params)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			t.Error(err)
 | 
			
		||||
			continue
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		compareJsonResponse(t, test.response, &CancelSuppyOrderResponse{})
 | 
			
		||||
 | 
			
		||||
		if resp.StatusCode != test.statusCode {
 | 
			
		||||
			t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func TestStatusCancelledSupplyOrder(t *testing.T) {
 | 
			
		||||
	t.Parallel()
 | 
			
		||||
 | 
			
		||||
	tests := []struct {
 | 
			
		||||
		statusCode int
 | 
			
		||||
		headers    map[string]string
 | 
			
		||||
		params     *StatusCancelledSupplyOrderParams
 | 
			
		||||
		response   string
 | 
			
		||||
	}{
 | 
			
		||||
		// Test Ok
 | 
			
		||||
		{
 | 
			
		||||
			http.StatusOK,
 | 
			
		||||
			map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
 | 
			
		||||
			&StatusCancelledSupplyOrderParams{
 | 
			
		||||
				OperationId: "123",
 | 
			
		||||
			},
 | 
			
		||||
			`{
 | 
			
		||||
				"error_reasons": [
 | 
			
		||||
				  "INVALID_ORDER_STATE"
 | 
			
		||||
				],
 | 
			
		||||
				"result": {
 | 
			
		||||
				  "is_order_cancelled": true,
 | 
			
		||||
				  "supplies": [
 | 
			
		||||
					{
 | 
			
		||||
					  "error_reasons": [
 | 
			
		||||
						"INVALID_SUPPLY_STATE"
 | 
			
		||||
					  ],
 | 
			
		||||
					  "is_supply_cancelled": true,
 | 
			
		||||
					  "supply_id": 0
 | 
			
		||||
					}
 | 
			
		||||
				  ]
 | 
			
		||||
				},
 | 
			
		||||
				"status": "SUCCESS"
 | 
			
		||||
			}`,
 | 
			
		||||
		},
 | 
			
		||||
		// Test No Client-Id or Api-Key
 | 
			
		||||
		{
 | 
			
		||||
			http.StatusUnauthorized,
 | 
			
		||||
			map[string]string{},
 | 
			
		||||
			&StatusCancelledSupplyOrderParams{},
 | 
			
		||||
			`{
 | 
			
		||||
				"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.FBO().StatusCancelledSupplyOrder(ctx, test.params)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			t.Error(err)
 | 
			
		||||
			continue
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		compareJsonResponse(t, test.response, &StatusCancelledSupplyOrderResponse{})
 | 
			
		||||
 | 
			
		||||
		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