Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
diPhantxm committed Oct 31, 2024
1 parent eae6f54 commit 815ee98
Show file tree
Hide file tree
Showing 2 changed files with 131 additions and 0 deletions.
52 changes: 52 additions & 0 deletions ozon/fbs.go
Original file line number Diff line number Diff line change
Expand Up @@ -3086,3 +3086,55 @@ func (c FBS) SetShippingDate(ctx context.Context, params *SetShippingDateParams)

return resp, nil
}

type SplitOrderParams struct {
// Shipment number
PostingNumber string `json:"posting_number"`

// Shipments list the order will be split into. You can split one order per one request
Postings []SplitOrderParamPosting `json:"postings"`
}

type SplitOrderParamPosting struct {
Products []SplitOrderPostingProduct `json:"products"`
}

type SplitOrderResponse struct {
core.CommonResponse

// Original shipment details
ParentPosting SplitOrderPosting `json:"parent_posting"`

// List of shipments the order was split into
Postings []SplitOrderPosting `json:"postings"`
}

type SplitOrderPosting struct {
// Shipment number
PostingNumber string `json:"posting_number"`

// List of products in the shipment
Products []SplitOrderPostingProduct `json:"products"`
}

type SplitOrderPostingProduct struct {
// FBS product identifier in the Ozon system, SKU
ProductId int64 `json:"product_id"`

// Product quantity
Quantity int64 `json:"quantity"`
}

func (c FBS) SplitOrder(ctx context.Context, params *SplitOrderParams) (*SplitOrderResponse, error) {
url := "/v1/posting/fbs/split"

resp := &SplitOrderResponse{}

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
}
79 changes: 79 additions & 0 deletions ozon/fbs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3130,3 +3130,82 @@ func TestSetShippingDate(t *testing.T) {
}
}
}

func TestSplitOrder(t *testing.T) {
t.Parallel()

tests := []struct {
statusCode int
headers map[string]string
params *SplitOrderParams
response string
}{
// Test Ok
{
http.StatusOK,
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
&SplitOrderParams{
PostingNumber: "string",
Postings: []SplitOrderParamPosting{
{
Products: []SplitOrderPostingProduct{
{
ProductId: 1,
Quantity: 1,
},
},
},
},
},
`{
"parent_posting": {
"posting_number": "string",
"products": [
{
"product_id": 0,
"quantity": 0
}
]
},
"postings": [
{
"posting_number": "string",
"products": [
{
"product_id": 0,
"quantity": 0
}
]
}
]
}`,
},
// Test No Client-Id or Api-Key
{
http.StatusUnauthorized,
map[string]string{},
&SplitOrderParams{},
`{
"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().SplitOrder(ctx, test.params)
if err != nil {
t.Error(err)
continue
}

compareJsonResponse(t, test.response, &SplitOrderResponse{})

if resp.StatusCode != test.statusCode {
t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode)
}
}
}

0 comments on commit 815ee98

Please sign in to comment.