implemented all methods for changing shipment status for fbs
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1 +1,2 @@
|
||||
*.out
|
||||
*.out
|
||||
mistakes.md
|
||||
@@ -116,13 +116,13 @@
|
||||
- [ ] Add weight for bulk products in a shipment
|
||||
- [ ] Cancel sending some products in the shipment
|
||||
- [x] List of shipment certificates
|
||||
- [ ] Sign shipment certificates
|
||||
- [x] Sign shipment certificates
|
||||
- [ ] List of shipments in the certificate
|
||||
- [x] Change the status to "Delivering"
|
||||
- [x] Add tracking numbers
|
||||
- [ ] Change the status to "Last Mile"
|
||||
- [ ] Change the status to "Delivered"
|
||||
- [ ] Change status to "Sent by seller"
|
||||
- [x] Change the status to "Last Mile"
|
||||
- [x] Change the status to "Delivered"
|
||||
- [x] Change status to "Sent by seller"
|
||||
- [ ] Dates available for delivery reschedule
|
||||
- [ ] Reschedule shipment delivery date
|
||||
- [ ] ETGB customs declarations
|
||||
|
||||
149
ozon/fbs.go
149
ozon/fbs.go
@@ -813,42 +813,6 @@ func (c FBS) GetShipmentDataByIdentifier(params *GetShipmentDataByIdentifierPara
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
type ChangeStatusToDeliveringParams struct {
|
||||
// Shipment identifier
|
||||
PostingNumber []string `json:"posting_number"`
|
||||
}
|
||||
|
||||
type ChangeStatusToDeliveringResponse struct {
|
||||
core.CommonResponse
|
||||
|
||||
// Method result
|
||||
Result []struct {
|
||||
// Error when processing the request
|
||||
Error []string `json:"error"`
|
||||
|
||||
// Shipment number
|
||||
PostingNumber string `json:"posting_number"`
|
||||
|
||||
// If the request is executed without errors — true
|
||||
Result bool `json:"result"`
|
||||
} `json:"result"`
|
||||
}
|
||||
|
||||
// Changes the shipment status to "Delivering" if a third-party delivery service is being used
|
||||
func (c FBS) ChangeStatusToDelivering(params *ChangeStatusToDeliveringParams) (*ChangeStatusToDeliveringResponse, error) {
|
||||
url := "/v2/fbs/posting/delivering"
|
||||
|
||||
resp := &ChangeStatusToDeliveringResponse{}
|
||||
|
||||
response, err := c.client.Request(http.MethodPost, url, params, resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
response.CopyCommonResponse(&resp.CommonResponse)
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
type AddTrackingNumbersParams struct {
|
||||
// An array with shipment identifier—tracking number pairs
|
||||
TrackingNumbers []FBSTrackingNumbersParams `json:"tracking_numbers"`
|
||||
@@ -1012,3 +976,116 @@ func (c FBS) ListOfShipmentCertificates(params *ListOfShipmentCertificatesParams
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
type SignShipmentCertificateParams struct {
|
||||
// Certificate identifier
|
||||
Id int64 `json:"id"`
|
||||
|
||||
// Type of shipment certificate:
|
||||
// - act_of_mismatch — discrepancy certificate,
|
||||
// - act_of_excess — surplus certificate
|
||||
DocType string `json:"doc_type"`
|
||||
}
|
||||
|
||||
type SignShipmentCertificateResponse struct {
|
||||
core.CommonResponse
|
||||
|
||||
// Request processing
|
||||
Result string `json:"result"`
|
||||
}
|
||||
|
||||
// Signs shipment certificates electronically via the electronic documents (ED) system of Ozon logistics
|
||||
func (c FBS) SignShipmentCertificate(params *SignShipmentCertificateParams) (*SignShipmentCertificateResponse, error) {
|
||||
url := "/v2/posting/fbs/digital/act/document-sign"
|
||||
|
||||
resp := &SignShipmentCertificateResponse{}
|
||||
|
||||
response, err := c.client.Request(http.MethodPost, url, params, resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
response.CopyCommonResponse(&resp.CommonResponse)
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
type ChangeStatusToParams struct {
|
||||
// Shipment identifier
|
||||
PostingNumber []string `json:"posting_number"`
|
||||
}
|
||||
|
||||
type ChangeStatusToResponse struct {
|
||||
core.CommonResponse
|
||||
|
||||
// Method result
|
||||
Result []struct {
|
||||
// Error when processing the request
|
||||
Error []string `json:"error"`
|
||||
|
||||
// Shipment number
|
||||
PostingNumber string `json:"posting_number"`
|
||||
|
||||
// If the request is executed without errors — true
|
||||
Result bool `json:"result"`
|
||||
} `json:"result"`
|
||||
}
|
||||
|
||||
// Changes the shipment status to "Delivering" if a third-party delivery service is being used
|
||||
func (c FBS) ChangeStatusToDelivering(params *ChangeStatusToParams) (*ChangeStatusToResponse, error) {
|
||||
url := "/v2/fbs/posting/delivering"
|
||||
|
||||
resp := &ChangeStatusToResponse{}
|
||||
|
||||
response, err := c.client.Request(http.MethodPost, url, params, resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
response.CopyCommonResponse(&resp.CommonResponse)
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// Changes the shipment status to "Last mile" if a third-party delivery service is being used
|
||||
func (c FBS) ChangeStatusToLastMile(params *ChangeStatusToParams) (*ChangeStatusToResponse, error) {
|
||||
url := "/v2/fbs/posting/last-mile"
|
||||
|
||||
resp := &ChangeStatusToResponse{}
|
||||
|
||||
response, err := c.client.Request(http.MethodPost, url, params, resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
response.CopyCommonResponse(&resp.CommonResponse)
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// Changes the shipment status to "Delivered" if a third-party delivery service is being used
|
||||
func (c FBS) ChangeStatusToDelivered(params *ChangeStatusToParams) (*ChangeStatusToResponse, error) {
|
||||
url := "/v2/fbs/posting/delivered"
|
||||
|
||||
resp := &ChangeStatusToResponse{}
|
||||
|
||||
response, err := c.client.Request(http.MethodPost, url, params, resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
response.CopyCommonResponse(&resp.CommonResponse)
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// Change shipment status to "Sent by seller". Status is only available to sellers with a first mile selling from abroad
|
||||
func (c FBS) ChangeStatusToSendBySeller(params *ChangeStatusToParams) (*ChangeStatusToResponse, error) {
|
||||
url := "/v2/fbs/posting/sent-by-seller"
|
||||
|
||||
resp := &ChangeStatusToResponse{}
|
||||
|
||||
response, err := c.client.Request(http.MethodPost, url, params, resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
response.CopyCommonResponse(&resp.CommonResponse)
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
201
ozon/fbs_test.go
201
ozon/fbs_test.go
@@ -668,69 +668,6 @@ func TestGetShipmentDataByIdentifier(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestChangeStatusToDelivering(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tests := []struct {
|
||||
statusCode int
|
||||
headers map[string]string
|
||||
params *ChangeStatusToDeliveringParams
|
||||
response string
|
||||
}{
|
||||
// Test Ok
|
||||
{
|
||||
http.StatusOK,
|
||||
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
|
||||
&ChangeStatusToDeliveringParams{
|
||||
PostingNumber: []string{"33920157-0018-1"},
|
||||
},
|
||||
`{
|
||||
"result": [
|
||||
{
|
||||
"error": [],
|
||||
"posting_number": "33920157-0018-1",
|
||||
"result": true
|
||||
}
|
||||
]
|
||||
}`,
|
||||
},
|
||||
// Test No Client-Id or Api-Key
|
||||
{
|
||||
http.StatusUnauthorized,
|
||||
map[string]string{},
|
||||
&ChangeStatusToDeliveringParams{},
|
||||
`{
|
||||
"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))
|
||||
|
||||
resp, err := c.FBS().ChangeStatusToDelivering(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.StatusCode == http.StatusOK {
|
||||
if len(resp.Result) != len(test.params.PostingNumber) {
|
||||
t.Errorf("Length of posting numbers in reqeust and response are not equal")
|
||||
}
|
||||
if len(resp.Result) > 0 {
|
||||
if resp.Result[0].PostingNumber != test.params.PostingNumber[0] {
|
||||
t.Errorf("Posting numbers in request and response are not equal")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestAddTrackingNumbers(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
@@ -894,3 +831,141 @@ func TestListOfShipmentCertificates(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSignShipmentCertificate(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tests := []struct {
|
||||
statusCode int
|
||||
headers map[string]string
|
||||
params *SignShipmentCertificateParams
|
||||
response string
|
||||
}{
|
||||
// Test Ok
|
||||
{
|
||||
http.StatusOK,
|
||||
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
|
||||
&SignShipmentCertificateParams{
|
||||
Id: 900000250859000,
|
||||
DocType: "act_of_mismatch",
|
||||
},
|
||||
`{
|
||||
"result": "string"
|
||||
}`,
|
||||
},
|
||||
// Test No Client-Id or Api-Key
|
||||
{
|
||||
http.StatusUnauthorized,
|
||||
map[string]string{},
|
||||
&SignShipmentCertificateParams{},
|
||||
`{
|
||||
"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))
|
||||
|
||||
resp, err := c.FBS().SignShipmentCertificate(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.StatusCode == http.StatusOK {
|
||||
if resp.Result == "" {
|
||||
t.Errorf("Result cannot be empty")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestChangeStatusTo(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
type test struct {
|
||||
statusCode int
|
||||
headers map[string]string
|
||||
params *ChangeStatusToParams
|
||||
response string
|
||||
}
|
||||
|
||||
assertResponse := func(t *testing.T, test *test, resp *ChangeStatusToResponse) {
|
||||
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) != len(test.params.PostingNumber) {
|
||||
t.Errorf("Length of posting numbers in request and response are not equal")
|
||||
}
|
||||
if len(resp.Result) > 0 {
|
||||
if resp.Result[0].PostingNumber != test.params.PostingNumber[0] {
|
||||
t.Errorf("Posting numbers in request and response are not equal")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tests := []test{
|
||||
// Test Ok
|
||||
{
|
||||
http.StatusOK,
|
||||
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
|
||||
&ChangeStatusToParams{
|
||||
PostingNumber: []string{"48173252-0033-2"},
|
||||
},
|
||||
`{
|
||||
"result": [
|
||||
{
|
||||
"error": [],
|
||||
"posting_number": "48173252-0033-2",
|
||||
"result": true
|
||||
}
|
||||
]
|
||||
}`,
|
||||
},
|
||||
// Test No Client-Id or Api-Key
|
||||
{
|
||||
http.StatusUnauthorized,
|
||||
map[string]string{},
|
||||
&ChangeStatusToParams{},
|
||||
`{
|
||||
"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))
|
||||
|
||||
deliveringResp, err := c.FBS().ChangeStatusToDelivering(test.params)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
lastMileResp, err := c.FBS().ChangeStatusToLastMile(test.params)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
deliveredResp, err := c.FBS().ChangeStatusToDelivered(test.params)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
sendBySellerResp, err := c.FBS().ChangeStatusToSendBySeller(test.params)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
assertResponse(t, &test, deliveringResp)
|
||||
assertResponse(t, &test, lastMileResp)
|
||||
assertResponse(t, &test, deliveredResp)
|
||||
assertResponse(t, &test, sendBySellerResp)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user