Get description of products (#120)
This commit is contained in:
		@@ -1558,6 +1558,92 @@ func (c Products) GetDescriptionOfProduct(ctx context.Context, params *GetDescri
 | 
			
		||||
	return resp, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type GetDescriptionOfProductsFilter struct {
 | 
			
		||||
	ProductId  []string `json:"product_id,omitempty"`
 | 
			
		||||
	OfferId    []string `json:"offer_id,omitempty"`
 | 
			
		||||
	Sku        []string `json:"sku,omitempty"`
 | 
			
		||||
	Visibility string   `json:"visibility,omitempty"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type GetDescriptionOfProductsParams struct {
 | 
			
		||||
	Filter        GetDescriptionOfProductsFilter `json:"filter"`
 | 
			
		||||
	LastId        string                         `json:"last_id,omitempty"`
 | 
			
		||||
	Limit         int64                          `json:"limit,omitempty"`
 | 
			
		||||
	SortBy        string                         `json:"sort_by,omitempty"`
 | 
			
		||||
	SortDirection string                         `json:"sort_dir,omitempty"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type GetDescriptionOfProductsResponse struct {
 | 
			
		||||
	core.CommonResponse
 | 
			
		||||
 | 
			
		||||
	Result []GetDescriptionOfProductsResult `json:"result"`
 | 
			
		||||
	Total  int32                            `json:"total"`
 | 
			
		||||
	LastId string                           `json:"last_id"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type GetDescriptionOfProductsResult struct {
 | 
			
		||||
	Id                    int64  `json:"id"`
 | 
			
		||||
	Barcode               string `json:"barcode"`
 | 
			
		||||
	Name                  string `json:"name"`
 | 
			
		||||
	OfferId               string `json:"offer_id"`
 | 
			
		||||
	Height                int32  `json:"height"`
 | 
			
		||||
	Depth                 int32  `json:"depth"`
 | 
			
		||||
	Width                 int32  `json:"width"`
 | 
			
		||||
	DimensionUnit         string `json:"dimension_unit"`
 | 
			
		||||
	Weight                int32  `json:"weight"`
 | 
			
		||||
	WeightUnit            string `json:"weight_unit"`
 | 
			
		||||
	DescriptionCategoryId int64  `json:"description_category_id"`
 | 
			
		||||
	TypeId                int64  `json:"type_id"`
 | 
			
		||||
	PrimaryImage          string `json:"primary_image"`
 | 
			
		||||
 | 
			
		||||
	// new "model_info" structure
 | 
			
		||||
	ModelInfo *ModelInfo `json:"model_info,omitempty"`
 | 
			
		||||
 | 
			
		||||
	Images  []string `json:"images"`
 | 
			
		||||
	PDFList []string `json:"pdf_list"`
 | 
			
		||||
 | 
			
		||||
	Attributes        []GetDescriptionOfProductsAttribute        `json:"attributes"`
 | 
			
		||||
	ComplexAttributes []GetDescriptionOfProductsComplexAttribute `json:"complex_attributes"`
 | 
			
		||||
	ColorImage        string                                     `json:"color_image"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type ModelInfo struct {
 | 
			
		||||
	ModelId int64 `json:"model_id"`
 | 
			
		||||
	Count   int64 `json:"count"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type GetDescriptionOfProductsAttribute struct {
 | 
			
		||||
	Id        int64                                    `json:"id"`
 | 
			
		||||
	ComplexId int64                                    `json:"complex_id"`
 | 
			
		||||
	Values    []GetDescriptionOfProductsAttributeValue `json:"values"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type GetDescriptionOfProductsAttributeValue struct {
 | 
			
		||||
	DictionaryValueId int64  `json:"dictionary_value_id"`
 | 
			
		||||
	Value             string `json:"value"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type GetDescriptionOfProductsComplexAttribute struct {
 | 
			
		||||
	Id        int64                                    `json:"id,omitempty"`
 | 
			
		||||
	ComplexId int64                                    `json:"complex_id,omitempty"`
 | 
			
		||||
	Values    []GetDescriptionOfProductsAttributeValue `json:"values,omitempty"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// /v4/product/info/attributes
 | 
			
		||||
func (c Products) GetDescriptionOfProducts(ctx context.Context, params *GetDescriptionOfProductsParams) (*GetDescriptionOfProductsResponse, error) {
 | 
			
		||||
	url := "/v4/product/info/attributes"
 | 
			
		||||
 | 
			
		||||
	resp := &GetDescriptionOfProductsResponse{}
 | 
			
		||||
 | 
			
		||||
	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 GetProductDescriptionParams struct {
 | 
			
		||||
	// Product identifier in the seller's system
 | 
			
		||||
	OfferId string `json:"offer_id"`
 | 
			
		||||
 
 | 
			
		||||
@@ -1789,6 +1789,113 @@ func TestGetDescriptionOfProduct(t *testing.T) {
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func TestGetDescriptionOfProductV4(t *testing.T) {
 | 
			
		||||
	t.Parallel()
 | 
			
		||||
 | 
			
		||||
	tests := []struct {
 | 
			
		||||
		statusCode int
 | 
			
		||||
		headers    map[string]string
 | 
			
		||||
		params     *GetDescriptionOfProductsParams
 | 
			
		||||
		response   string
 | 
			
		||||
	}{
 | 
			
		||||
		{
 | 
			
		||||
			http.StatusOK,
 | 
			
		||||
			map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
 | 
			
		||||
			&GetDescriptionOfProductsParams{
 | 
			
		||||
				Filter: GetDescriptionOfProductsFilter{
 | 
			
		||||
					ProductId:  []string{"330186294"},
 | 
			
		||||
					Visibility: "ALL",
 | 
			
		||||
				},
 | 
			
		||||
				Limit:         100,
 | 
			
		||||
				SortDirection: "ASC",
 | 
			
		||||
			},
 | 
			
		||||
			`{
 | 
			
		||||
				"result": [
 | 
			
		||||
				  {
 | 
			
		||||
					"id": 330186294,
 | 
			
		||||
					"barcode": "OZN653473453",
 | 
			
		||||
					"name": "PC ЮКОМС Ryzen 7 5700G ...",
 | 
			
		||||
					"offer_id": "ju-cas2-r5700g-bl",
 | 
			
		||||
					"height": 360,
 | 
			
		||||
					"depth": 420,
 | 
			
		||||
					"width": 220,
 | 
			
		||||
					"dimension_unit": "mm",
 | 
			
		||||
					"weight": 4500,
 | 
			
		||||
					"weight_unit": "g",
 | 
			
		||||
					"description_category_id": 17028619,
 | 
			
		||||
					"type_id": 91476,
 | 
			
		||||
					"primary_image": "https://cdn1.ozone.ru/s3/multimedia-1-3/7084786431.jpg",
 | 
			
		||||
					"model_info": {
 | 
			
		||||
					  "model_id": 379410772,
 | 
			
		||||
					  "count": 126
 | 
			
		||||
					},
 | 
			
		||||
					"images": [
 | 
			
		||||
					  "https://cdn1.ozone.ru/s3/multimedia-1-0/7084786428.jpg",
 | 
			
		||||
					  "https://cdn1.ozone.ru/s3/multimedia-1-k/7084786304.jpg"
 | 
			
		||||
					],
 | 
			
		||||
					"pdf_list": [],
 | 
			
		||||
					"attributes": [
 | 
			
		||||
					  {
 | 
			
		||||
						"id": 85,
 | 
			
		||||
						"complex_id": 0,
 | 
			
		||||
						"values": [
 | 
			
		||||
						  {
 | 
			
		||||
							"dictionary_value_id": 971195426,
 | 
			
		||||
							"value": "ЮКОМС"
 | 
			
		||||
						  }
 | 
			
		||||
						]
 | 
			
		||||
					  }
 | 
			
		||||
					],
 | 
			
		||||
					"complex_attributes": [],
 | 
			
		||||
					"color_image": ""
 | 
			
		||||
				  }
 | 
			
		||||
				],
 | 
			
		||||
				"total": 1,
 | 
			
		||||
				"last_id": ""
 | 
			
		||||
			}`,
 | 
			
		||||
		},
 | 
			
		||||
		// Test No Client-Id or Api-Key
 | 
			
		||||
		{
 | 
			
		||||
			http.StatusUnauthorized,
 | 
			
		||||
			map[string]string{},
 | 
			
		||||
			&GetDescriptionOfProductsParams{},
 | 
			
		||||
			`{
 | 
			
		||||
				"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, cancel := context.WithTimeout(context.Background(), testTimeout)
 | 
			
		||||
		defer cancel()
 | 
			
		||||
 | 
			
		||||
		resp, err := c.Products().GetDescriptionOfProducts(ctx, test.params)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			t.Errorf("unexpected error: %v", err)
 | 
			
		||||
			continue
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		compareJsonResponse(t, test.response, &GetDescriptionOfProductsResponse{})
 | 
			
		||||
 | 
			
		||||
		if resp.StatusCode != test.statusCode {
 | 
			
		||||
			t.Errorf("wrong status code: got: %d, want: %d", resp.StatusCode, test.statusCode)
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if test.statusCode == http.StatusOK {
 | 
			
		||||
			if len(resp.Result) == 0 {
 | 
			
		||||
				t.Error("expected non-empty result in success case")
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func TestGetProductDescription(t *testing.T) {
 | 
			
		||||
	t.Parallel()
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user