Skip to content

Commit 23ca98f

Browse files
authored
Update October 24, 2024 (#111)
1 parent eae6f54 commit 23ca98f

File tree

2 files changed

+131
-0
lines changed

2 files changed

+131
-0
lines changed

ozon/fbs.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3086,3 +3086,55 @@ func (c FBS) SetShippingDate(ctx context.Context, params *SetShippingDateParams)
30863086

30873087
return resp, nil
30883088
}
3089+
3090+
type SplitOrderParams struct {
3091+
// Shipment number
3092+
PostingNumber string `json:"posting_number"`
3093+
3094+
// Shipments list the order will be split into. You can split one order per one request
3095+
Postings []SplitOrderParamPosting `json:"postings"`
3096+
}
3097+
3098+
type SplitOrderParamPosting struct {
3099+
Products []SplitOrderPostingProduct `json:"products"`
3100+
}
3101+
3102+
type SplitOrderResponse struct {
3103+
core.CommonResponse
3104+
3105+
// Original shipment details
3106+
ParentPosting SplitOrderPosting `json:"parent_posting"`
3107+
3108+
// List of shipments the order was split into
3109+
Postings []SplitOrderPosting `json:"postings"`
3110+
}
3111+
3112+
type SplitOrderPosting struct {
3113+
// Shipment number
3114+
PostingNumber string `json:"posting_number"`
3115+
3116+
// List of products in the shipment
3117+
Products []SplitOrderPostingProduct `json:"products"`
3118+
}
3119+
3120+
type SplitOrderPostingProduct struct {
3121+
// FBS product identifier in the Ozon system, SKU
3122+
ProductId int64 `json:"product_id"`
3123+
3124+
// Product quantity
3125+
Quantity int64 `json:"quantity"`
3126+
}
3127+
3128+
func (c FBS) SplitOrder(ctx context.Context, params *SplitOrderParams) (*SplitOrderResponse, error) {
3129+
url := "/v1/posting/fbs/split"
3130+
3131+
resp := &SplitOrderResponse{}
3132+
3133+
response, err := c.client.Request(ctx, http.MethodPost, url, params, resp, nil)
3134+
if err != nil {
3135+
return nil, err
3136+
}
3137+
response.CopyCommonResponse(&resp.CommonResponse)
3138+
3139+
return resp, nil
3140+
}

ozon/fbs_test.go

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3130,3 +3130,82 @@ func TestSetShippingDate(t *testing.T) {
31303130
}
31313131
}
31323132
}
3133+
3134+
func TestSplitOrder(t *testing.T) {
3135+
t.Parallel()
3136+
3137+
tests := []struct {
3138+
statusCode int
3139+
headers map[string]string
3140+
params *SplitOrderParams
3141+
response string
3142+
}{
3143+
// Test Ok
3144+
{
3145+
http.StatusOK,
3146+
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
3147+
&SplitOrderParams{
3148+
PostingNumber: "string",
3149+
Postings: []SplitOrderParamPosting{
3150+
{
3151+
Products: []SplitOrderPostingProduct{
3152+
{
3153+
ProductId: 1,
3154+
Quantity: 1,
3155+
},
3156+
},
3157+
},
3158+
},
3159+
},
3160+
`{
3161+
"parent_posting": {
3162+
"posting_number": "string",
3163+
"products": [
3164+
{
3165+
"product_id": 0,
3166+
"quantity": 0
3167+
}
3168+
]
3169+
},
3170+
"postings": [
3171+
{
3172+
"posting_number": "string",
3173+
"products": [
3174+
{
3175+
"product_id": 0,
3176+
"quantity": 0
3177+
}
3178+
]
3179+
}
3180+
]
3181+
}`,
3182+
},
3183+
// Test No Client-Id or Api-Key
3184+
{
3185+
http.StatusUnauthorized,
3186+
map[string]string{},
3187+
&SplitOrderParams{},
3188+
`{
3189+
"code": 16,
3190+
"message": "Client-Id and Api-Key headers are required"
3191+
}`,
3192+
},
3193+
}
3194+
3195+
for _, test := range tests {
3196+
c := NewMockClient(core.NewMockHttpHandler(test.statusCode, test.response, test.headers))
3197+
3198+
ctx, _ := context.WithTimeout(context.Background(), testTimeout)
3199+
resp, err := c.FBS().SplitOrder(ctx, test.params)
3200+
if err != nil {
3201+
t.Error(err)
3202+
continue
3203+
}
3204+
3205+
compareJsonResponse(t, test.response, &SplitOrderResponse{})
3206+
3207+
if resp.StatusCode != test.statusCode {
3208+
t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode)
3209+
}
3210+
}
3211+
}

0 commit comments

Comments
 (0)