Skip to content

Commit

Permalink
Added a method for getting information about return shipments
Browse files Browse the repository at this point in the history
  • Loading branch information
diPhantxm committed Dec 9, 2023
1 parent 997eb60 commit 6c63a00
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 0 deletions.
13 changes: 13 additions & 0 deletions ozon/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -653,3 +653,16 @@ const (
// Cancelled
GiveoutStatusCancelled GiveoutStatus = "GIVEOUT_STATUS_CANCELLED"
)

type GiveoutDeliverySchema string

const (
// Undefined, contact support team
GiveoutDeliverySchemaUnspecified GiveoutDeliverySchema = "GIVEOUT_DELIVERY_SCHEMA_UNSPECIFIED"

// FBO
GiveoutDeliverySchemaFBO GiveoutDeliverySchema = "GIVEOUT_DELIVERY_SCHEMA_FBO"

// FBS
GiveoutDeliverySchemaFBS GiveoutDeliverySchema = "GIVEOUT_DELIVERY_SCHEMA_FBS"
)
53 changes: 53 additions & 0 deletions ozon/returns.go
Original file line number Diff line number Diff line change
Expand Up @@ -818,3 +818,56 @@ func (c Returns) GetGiveoutList(ctx context.Context, params *GetGiveoutListParam

return resp, nil
}

type GetGiveoutInfoParams struct {
// Shipment identifier
GiveoutId int64 `json:"giveout_id"`
}

type GetGiveoutInfoResponse struct {
core.CommonResponse

// Product IDs
Articles []GetGiveoutInfoArticle `json:"articles"`

// Shipment identifier
GiveoutId int64 `json:"giveout_id"`

// Return shipment status
GiveoutStatus GiveoutStatus `json:"giveout_status"`

// Warehouse address
WarehouseAddress string `json:"warehouse_address"`

// Warehouse name
WarehouseName string `json:"warehouse_name"`
}

type GetGiveoutInfoArticle struct {
// `true` if the shipment is confirmed
Approved bool `json:"approved"`

// Delivery schema
DeliverySchema GiveoutDeliverySchema `json:"delivery_schema"`

// Product name
Name string `json:"name"`

// Seller identifier
SellerId int64 `json:"seller_id"`
}

// Information on return shipment
func (c Returns) GetGiveoutInfo(ctx context.Context, params *GetGiveoutInfoParams) (*GetGiveoutInfoResponse, error) {
url := "/v1/return/giveout/info"

resp := &GetGiveoutInfoResponse{}

response, err := c.client.Request(ctx, http.MethodPost, url, struct{}{}, resp, nil)
if err != nil {
return nil, err
}
response.CopyCommonResponse(&resp.CommonResponse)

return resp, nil
}
61 changes: 61 additions & 0 deletions ozon/returns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -878,3 +878,64 @@ func TestGetGiveoutList(t *testing.T) {
}
}
}

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

tests := []struct {
statusCode int
headers map[string]string
params *GetGiveoutInfoParams
response string
}{
// Test Ok
{
http.StatusOK,
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
&GetGiveoutInfoParams{
GiveoutId: 11,
},
`{
"articles": [
{
"approved": true,
"delivery_schema": "string",
"name": "string",
"seller_id": 0
}
],
"giveout_id": 11,
"giveout_status": "string",
"warehouse_address": "string",
"warehouse_name": "string"
}`,
},
// Test No Client-Id or Api-Key
{
http.StatusUnauthorized,
map[string]string{},
&GetGiveoutInfoParams{},
`{
"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.Returns().GetGiveoutInfo(ctx, test.params)
if err != nil {
t.Error(err)
}

if resp.StatusCode != test.statusCode {
t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode)
}
if resp.GiveoutId != test.params.GiveoutId {
t.Errorf("expected giveout id to be equal: got: %d, expected: %d", resp.GiveoutId, test.params.GiveoutId)
}
}
}

0 comments on commit 6c63a00

Please sign in to comment.