From 7b5f44ee44dab95578fa37df57536f3439c1c236 Mon Sep 17 00:00:00 2001 From: Kirill Date: Fri, 27 Dec 2024 22:01:51 +0300 Subject: [PATCH] Update November 20, 2024 (#122) --- ozon/fbs.go | 48 ++++++++++++++++++++++++++++++++++++++ ozon/fbs_test.go | 60 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 108 insertions(+) diff --git a/ozon/fbs.go b/ozon/fbs.go index 8bd7833..19d5dfe 100644 --- a/ozon/fbs.go +++ b/ozon/fbs.go @@ -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 +} diff --git a/ozon/fbs_test.go b/ozon/fbs_test.go index 928dec9..df0f18a 100644 --- a/ozon/fbs_test.go +++ b/ozon/fbs_test.go @@ -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) + } + } +}