Added a method for getting a barcode from the /v2/posting/fbs/act/get-barcode response in text format

This commit is contained in:
diPhantxm
2023-07-12 19:10:32 +03:00
committed by Kirill
parent 2ca20d9b12
commit 1958dfb94e
2 changed files with 79 additions and 0 deletions

View File

@@ -2678,3 +2678,30 @@ func (c FBS) BarcodeFromProductShipment(params *BarcodeFromProductShipmentParams
return resp, nil
}
type BarcodeValueFromProductShipmentParams struct {
// Freight identifier
Id int64 `json:"id"`
}
type BarcodeValueFromProductShipmentResponse struct {
core.CommonResponse
// Barcode in text format
Result string `json:"result"`
}
// Use this method to get the barcode from the /v2/posting/fbs/act/get-barcode response in text format.
func (c FBS) BarcodeValueFromProductShipment(params *BarcodeValueFromProductShipmentParams) (*BarcodeValueFromProductShipmentResponse, error) {
url := "/v2/posting/fbs/act/get-barcode/text"
resp := &BarcodeValueFromProductShipmentResponse{}
response, err := c.client.Request(http.MethodPost, url, params, resp, nil)
if err != nil {
return nil, err
}
response.CopyCommonResponse(&resp.CommonResponse)
return resp, nil
}

View File

@@ -2586,3 +2586,55 @@ func TestBarcodeFromProductShipment(t *testing.T) {
}
}
}
func TestBarcodeValueFromProductShipment(t *testing.T) {
t.Parallel()
tests := []struct {
statusCode int
headers map[string]string
params *BarcodeValueFromProductShipmentParams
response string
}{
// Test Ok
{
http.StatusOK,
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
&BarcodeValueFromProductShipmentParams{
Id: 295662811,
},
`{
"result": "%303%24276481394"
}`,
},
// Test No Client-Id or Api-Key
{
http.StatusUnauthorized,
map[string]string{},
&BarcodeValueFromProductShipmentParams{},
`{
"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().BarcodeValueFromProductShipment(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")
}
}
}
}