Skip to content

Commit

Permalink
Update December 19, 2024 (#130)
Browse files Browse the repository at this point in the history
  • Loading branch information
diPhantxm authored Jan 22, 2025
1 parent 7654f5b commit c38e9f1
Show file tree
Hide file tree
Showing 2 changed files with 184 additions and 0 deletions.
69 changes: 69 additions & 0 deletions ozon/fbs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 115 additions & 0 deletions ozon/fbs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}

0 comments on commit c38e9f1

Please sign in to comment.