Skip to content

Commit

Permalink
Methods to manage Passes (Update April 1, 2024) (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
diPhantxm authored Apr 2, 2024
1 parent 97a9d2a commit 61a78b1
Show file tree
Hide file tree
Showing 7 changed files with 1,066 additions and 0 deletions.
93 changes: 93 additions & 0 deletions ozon/fbs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2902,3 +2902,96 @@ func (c FBS) CreateOrGetProductExemplar(ctx context.Context, params *CreateOrGet

return resp, nil
}

type GetCarriageParams struct {
CarriageId int64 `json:"carriage_id"`
}

type GetCarriageResponse struct {
core.CommonResponse

// Acceptance certificate type for FBS sellers
ActType string `json:"act_type"`

// Pass identifiers for the freight
ArrivalPassIds []string `json:"arrival_pass_ids"`

// List of available actions on the freight
AvailableActions []string `json:"available_actions"`

// Cancel availability
CancelAvailability GetCarriageCancelAvailability `json:"cancel_availability"`

// Freight identifier
CarriageId int64 `json:"carriage_id"`

// Company identifier
CompanyId int64 `json:"company_id"`

// Number of package units
ContainersCount int32 `json:"containers_count"`

// Date and time of freight creation
CreatedAt time.Time `json:"created_at"`

// Delivery method identifier
DeliveryMethodId int64 `json:"delivery_method_id"`

// Shipping date
DepartureDate string `json:"departure_date"`

// First mile type
FirstMileType string `json:"first_mile_type"`

// true if there are shipments subject to shipping that are not in the current freight
HasPostingsForNextCarriage bool `json:"has_postings_for_next_carriage"`

// Delivery service integration type
IntegrationType string `json:"integration_type"`

// true if you already printed shipping labels
IsContainerLabelPrinted bool `json:"is_container_label_printed"`

// true if the freight is partial
IsPartial bool `json:"is_partial"`

// Serial number of the partial freight
PartialNum int64 `json:"partial_num"`

// The number of retries to create a freight
RetryCount int32 `json:"retry_count"`

// Freight status
Status string `json:"status"`

// Delivery method identifier
TPLProviderId int64 `json:"tpl_provider_id"`

// Date and time when the freight was last updated
UpdatedAt time.Time `json:"updated_at"`

// Warehouse identifier
WarehouseId int64 `json:"warehouse_id"`
}

type GetCarriageCancelAvailability struct {
// true if the freight can be cancelled
IsCancelAvailable bool `json:"is_cancel_available"`

// Reason why freight can't be cancelled
Reason string `json:"reason"`
}

func (c FBS) GetCarriage(ctx context.Context, params *GetCarriageParams) (*GetCarriageResponse, error) {
url := "/v1/carriage/get"

resp := &GetCarriageResponse{}

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

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

tests := []struct {
statusCode int
headers map[string]string
params *GetCarriageParams
response string
}{
// Test Ok
{
http.StatusOK,
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
&GetCarriageParams{
CarriageId: 15,
},
`{
"act_type": "string",
"arrival_pass_ids": [
"string"
],
"available_actions": [
"string"
],
"cancel_availability": {
"is_cancel_available": true,
"reason": "string"
},
"carriage_id": 15,
"company_id": 0,
"containers_count": 0,
"created_at": "2019-08-24T14:15:22Z",
"delivery_method_id": 0,
"departure_date": "string",
"first_mile_type": "string",
"has_postings_for_next_carriage": true,
"integration_type": "string",
"is_container_label_printed": true,
"is_partial": true,
"partial_num": 0,
"retry_count": 0,
"status": "string",
"tpl_provider_id": 0,
"updated_at": "2019-08-24T14:15:22Z",
"warehouse_id": 0
}`,
},
// Test No Client-Id or Api-Key
{
http.StatusUnauthorized,
map[string]string{},
&GetCarriageParams{},
`{
"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().GetCarriage(ctx, test.params)
if err != nil {
t.Error(err)
continue
}

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

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

if resp.CarriageId != test.params.CarriageId {
t.Errorf("carriage id in request and response should be equal")
}
}
}
7 changes: 7 additions & 0 deletions ozon/ozon.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type Client struct {
certificates *Certificates
strategies *Strategies
barcodes *Barcodes
passes *Passes
}

func (c Client) Analytics() *Analytics {
Expand Down Expand Up @@ -119,6 +120,10 @@ func (c Client) Barcodes() *Barcodes {
return c.barcodes
}

func (c Client) Passes() *Passes {
return c.passes
}

type ClientOption func(c *ClientOptions)

func WithHttpClient(httpClient core.HttpClient) ClientOption {
Expand Down Expand Up @@ -182,6 +187,7 @@ func NewClient(opts ...ClientOption) *Client {
certificates: &Certificates{client: coreClient},
strategies: &Strategies{client: coreClient},
barcodes: &Barcodes{client: coreClient},
passes: &Passes{client: coreClient},
}
}

Expand Down Expand Up @@ -209,5 +215,6 @@ func NewMockClient(handler http.HandlerFunc) *Client {
certificates: &Certificates{client: coreClient},
strategies: &Strategies{client: coreClient},
barcodes: &Barcodes{client: coreClient},
passes: &Passes{client: coreClient},
}
}
Loading

0 comments on commit 61a78b1

Please sign in to comment.