Update December 19, 2024 (#130)
This commit is contained in:
69
ozon/fbs.go
69
ozon/fbs.go
@@ -3234,3 +3234,72 @@ func (c FBS) ListUnpaidProducts(ctx context.Context, params *ListUnpaidProductsP
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
type ChangeShipmentCompositionParams struct {
|
||||
// Freight identifier
|
||||
CarriageId int64 `json:"carriage_id"`
|
||||
|
||||
// Current list of shipments
|
||||
PostingNumbers []string `json:"posting_numbers"`
|
||||
}
|
||||
|
||||
type ChangeShipmentCompositionResponse struct {
|
||||
core.CommonResponse
|
||||
|
||||
Result []ChangeShipmentCompositionResult `json:"result"`
|
||||
}
|
||||
|
||||
type ChangeShipmentCompositionResult struct {
|
||||
// Error message
|
||||
Error string `json:"error"`
|
||||
|
||||
// Shipment number
|
||||
PostingNumber string `json:"posting_number"`
|
||||
|
||||
// Request processing result. true if the request was executed successfully
|
||||
Result bool `json:"result"`
|
||||
}
|
||||
|
||||
// Method overwrites the list of orders in the shipment. Pass only orders in the awaiting_deliver status and ones which are ready for shipping.
|
||||
func (c FBS) ChangeShipmentComposition(ctx context.Context, params *ChangeShipmentCompositionParams) (*ChangeShipmentCompositionResponse, error) {
|
||||
url := "/v1/carriage/set-postings"
|
||||
|
||||
resp := &ChangeShipmentCompositionResponse{}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
type DeleteShipmentParams struct {
|
||||
// Freight identifier
|
||||
CarriageId int64 `json:"carriage_id"`
|
||||
}
|
||||
|
||||
type DeleteShipmentResponse struct {
|
||||
core.CommonResponse
|
||||
|
||||
// Error message
|
||||
Error string `json:"error"`
|
||||
|
||||
// Carriage status
|
||||
Status string `json:"carriage_status"`
|
||||
}
|
||||
|
||||
func (c FBS) DeleteShipment(ctx context.Context, params *DeleteShipmentParams) (*DeleteShipmentResponse, error) {
|
||||
url := "/v1/carriage/cancel"
|
||||
|
||||
resp := &DeleteShipmentResponse{}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
115
ozon/fbs_test.go
115
ozon/fbs_test.go
@@ -3312,3 +3312,118 @@ func TestListUnpaidProducts(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestChangeShipmentComposition(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tests := []struct {
|
||||
statusCode int
|
||||
headers map[string]string
|
||||
params *ChangeShipmentCompositionParams
|
||||
response string
|
||||
}{
|
||||
// Test Ok
|
||||
{
|
||||
http.StatusOK,
|
||||
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
|
||||
&ChangeShipmentCompositionParams{
|
||||
CarriageId: 10,
|
||||
PostingNumbers: []string{"something"},
|
||||
},
|
||||
`{
|
||||
"result": [
|
||||
{
|
||||
"error": "string",
|
||||
"posting_number": "something",
|
||||
"result": true
|
||||
}
|
||||
]
|
||||
}`,
|
||||
},
|
||||
// Test No Client-Id or Api-Key
|
||||
{
|
||||
http.StatusUnauthorized,
|
||||
map[string]string{},
|
||||
&ChangeShipmentCompositionParams{},
|
||||
`{
|
||||
"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().ChangeShipmentComposition(ctx, test.params)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
continue
|
||||
}
|
||||
|
||||
compareJsonResponse(t, test.response, &ChangeShipmentCompositionResponse{})
|
||||
|
||||
if resp.StatusCode != test.statusCode {
|
||||
t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode)
|
||||
}
|
||||
if resp.StatusCode == http.StatusOK {
|
||||
if len(resp.Result) > 0 {
|
||||
if resp.Result[0].PostingNumber != test.params.PostingNumbers[0] {
|
||||
t.Errorf("posting numbers are different. Expected: %s, got: %s", test.params.PostingNumbers[0], resp.Result[0].PostingNumber)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestDeleteShipment(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tests := []struct {
|
||||
statusCode int
|
||||
headers map[string]string
|
||||
params *DeleteShipmentParams
|
||||
response string
|
||||
}{
|
||||
// Test Ok
|
||||
{
|
||||
http.StatusOK,
|
||||
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
|
||||
&DeleteShipmentParams{
|
||||
CarriageId: 10,
|
||||
},
|
||||
`{
|
||||
"error": "string",
|
||||
"carriage_status": "string"
|
||||
}`,
|
||||
},
|
||||
// Test No Client-Id or Api-Key
|
||||
{
|
||||
http.StatusUnauthorized,
|
||||
map[string]string{},
|
||||
&DeleteShipmentParams{},
|
||||
`{
|
||||
"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().DeleteShipment(ctx, test.params)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
continue
|
||||
}
|
||||
|
||||
compareJsonResponse(t, test.response, &DeleteShipmentResponse{})
|
||||
|
||||
if resp.StatusCode != test.statusCode {
|
||||
t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user