Update November 20, 2024 (#122)

This commit is contained in:
Kirill
2024-12-27 22:01:51 +03:00
committed by GitHub
parent bc5f0e52a5
commit 7b5f44ee44
2 changed files with 108 additions and 0 deletions

View File

@@ -3186,3 +3186,51 @@ func (c FBS) SplitOrder(ctx context.Context, params *SplitOrderParams) (*SplitOr
return resp, nil
}
type ListUnpaidProductsParams struct {
// Cursor for the next data sample
Cursor string `json:"cursor"`
// Number of values in the response
Limit int32 `json:"limit,omitempty"`
}
type ListUnpaidProductsResponse struct {
core.CommonResponse
Products []UnpaidProduct `json:"products"`
// Cursor for the next data sample
Cursor string `json:"cursor"`
}
type UnpaidProduct struct {
// Product identifier
ProductId int64 `json:"product_id"`
// Product identifier in the seller's system
OfferId string `json:"offer_id"`
// Product quantity, pcs
Quantity int32 `json:"quantity"`
// Product name
Name string `json:"name"`
// Link to product image
ImageURL string `json:"image_url"`
}
func (c FBS) ListUnpaidProducts(ctx context.Context, params *ListUnpaidProductsParams) (*ListUnpaidProductsResponse, error) {
url := "/v1/posting/unpaid-legal/product/list"
resp := &ListUnpaidProductsResponse{}
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
}

View File

@@ -3252,3 +3252,63 @@ func TestSplitOrder(t *testing.T) {
}
}
}
func TestListUnpaidProducts(t *testing.T) {
t.Parallel()
tests := []struct {
statusCode int
headers map[string]string
params *ListUnpaidProductsParams
response string
}{
// Test Ok
{
http.StatusOK,
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
&ListUnpaidProductsParams{
Cursor: "hCGiPPopcBFMgMErdzaCEpzQfinuPyEhUoSmBMADuoFAhBjXeA==",
Limit: 1000,
},
`{
"products": [
{
"product_id": 145123054,
"offer_id": "10032",
"quantity": 1,
"name": "Телевизор LG",
"image_url": "https://cdn1.ozon.ru/multimedia/10741275.jpg"
}
],
"cursor": "hCGiPPopcBFMgMErdzaCEpzQfinuPyEhUoSmBMADuoFAhBjXeA=="
}`,
},
// Test No Client-Id or Api-Key
{
http.StatusUnauthorized,
map[string]string{},
&ListUnpaidProductsParams{},
`{
"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().ListUnpaidProducts(ctx, test.params)
if err != nil {
t.Error(err)
continue
}
compareJsonResponse(t, test.response, &ListUnpaidProductsResponse{})
if resp.StatusCode != test.statusCode {
t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode)
}
}
}