Skip to content

Commit

Permalink
Update November 20, 2024 (#122)
Browse files Browse the repository at this point in the history
  • Loading branch information
diPhantxm authored Dec 27, 2024
1 parent bc5f0e5 commit 7b5f44e
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 0 deletions.
48 changes: 48 additions & 0 deletions ozon/fbs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
60 changes: 60 additions & 0 deletions ozon/fbs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}

0 comments on commit 7b5f44e

Please sign in to comment.