Better tests (check that response match the structure) (#52)

Trailing zeros were removed from time in responses because of json marshaling features
This commit is contained in:
Kirill
2023-12-11 03:19:12 +03:00
committed by GitHub
parent 922e2de8b0
commit 1494ff5905
33 changed files with 744 additions and 123 deletions

View File

@@ -172,8 +172,11 @@ func TestListUnprocessedShipments(t *testing.T) {
resp, err := c.FBS().ListUnprocessedShipments(ctx, test.params)
if err != nil {
t.Error(err)
continue
}
compareJsonResponse(t, test.response, &ListUnprocessedShipmentsResponse{})
if resp.StatusCode != test.statusCode {
t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode)
}
@@ -291,8 +294,11 @@ func TestGetFBSShipmentsList(t *testing.T) {
resp, err := c.FBS().GetFBSShipmentsList(ctx, test.params)
if err != nil {
t.Error(err)
continue
}
compareJsonResponse(t, test.response, &GetFBSShipmentsListResponse{})
if resp.StatusCode != test.statusCode {
t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode)
}
@@ -353,8 +359,11 @@ func TestPackOrder(t *testing.T) {
resp, err := c.FBS().PackOrder(ctx, test.params)
if err != nil {
t.Error(err)
continue
}
compareJsonResponse(t, test.response, &PackOrderResponse{})
if resp.StatusCode != test.statusCode {
t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode)
}
@@ -431,8 +440,11 @@ func TestValidateLabelingCodes(t *testing.T) {
resp, err := c.FBS().ValidateLabelingCodes(ctx, test.params)
if err != nil {
t.Error(err)
continue
}
compareJsonResponse(t, test.response, &ValidateLabelingCodesResponse{})
if resp.StatusCode != test.statusCode {
t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode)
}
@@ -472,31 +484,8 @@ func TestGetShipmentDataByBarcode(t *testing.T) {
"order_id": 438764970,
"order_number": "57195475-0050",
"status": "awaiting_packaging",
"delivery_method": {
"id": 18114520187000,
"name": "Ozon Логистика самостоятельно, Москва",
"warehouse_id": 18114520187000,
"warehouse": "Москва основной",
"tpl_provider_id": 24,
"tpl_provider": "Ozon Логистика"
},
"tracking_number": "",
"tpl_integration_type": "ozon",
"in_process_at": "2021-11-20T09:14:16Z",
"shipment_date": "2021-11-23T10:00:00Z",
"delivering_date": null,
"provider_status": "",
"delivery_price": "",
"cancellation": {
"cancel_reason_id": 0,
"cancel_reason": "",
"cancellation_type": "",
"cancelled_after_ship": false,
"affect_cancellation_rating": false,
"cancellation_initiator": ""
},
"customer": null,
"addressee": null,
"products": [
{
"price": "279.0000",
@@ -504,25 +493,12 @@ func TestGetShipmentDataByBarcode(t *testing.T) {
"name": "Кофе ароматизированный \"Шоколадный апельсин\" 250 гр",
"sku": 180550365,
"quantity": 1,
"mandatory_mark": [],
"dimensions": {
"height": "40.00",
"length": "240.00",
"weight": "260",
"width": "140.00"
}
"mandatory_mark": []
}
],
"barcodes": null,
"analytics_data": null,
"financial_data": null,
"additional_data": [],
"is_express": false,
"requirements": {
"products_requiring_gtd": [],
"products_requiring_country": []
},
"product_exemplars": null
"financial_data": null
}
}`,
},
@@ -545,8 +521,11 @@ func TestGetShipmentDataByBarcode(t *testing.T) {
resp, err := c.FBS().GetShipmentDataByBarcode(ctx, test.params)
if err != nil {
t.Error(err)
continue
}
compareJsonResponse(t, test.response, &GetShipmentDataByBarcodeResponse{})
if resp.StatusCode != test.statusCode {
t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode)
}
@@ -659,8 +638,11 @@ func TestGetShipmentDataByIdentifier(t *testing.T) {
resp, err := c.FBS().GetShipmentDataByIdentifier(ctx, test.params)
if err != nil {
t.Error(err)
continue
}
compareJsonResponse(t, test.response, &GetShipmentDataByIdentifierResponse{})
if resp.StatusCode != test.statusCode {
t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode)
}
@@ -732,8 +714,11 @@ func TestAddTrackingNumbers(t *testing.T) {
resp, err := c.FBS().AddTrackingNumbers(ctx, test.params)
if err != nil {
t.Error(err)
continue
}
compareJsonResponse(t, test.response, &AddTrackingNumbersResponse{})
if resp.StatusCode != test.statusCode {
t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode)
}
@@ -826,8 +811,11 @@ func TestListOfShipmentCertificates(t *testing.T) {
resp, err := c.FBS().ListOfShipmentCertificates(ctx, test.params)
if err != nil {
t.Error(err)
continue
}
compareJsonResponse(t, test.response, &ListOfShipmentCertificatesResponse{})
if resp.StatusCode != test.statusCode {
t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode)
}
@@ -888,8 +876,11 @@ func TestSignShipmentCertificate(t *testing.T) {
resp, err := c.FBS().SignShipmentCertificate(ctx, test.params)
if err != nil {
t.Error(err)
continue
}
compareJsonResponse(t, test.response, &SignShipmentCertificateResponse{})
if resp.StatusCode != test.statusCode {
t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode)
}
@@ -964,24 +955,30 @@ func TestChangeStatusTo(t *testing.T) {
deliveringResp, err := c.FBS().ChangeStatusToDelivering(deliveringctx, test.params)
if err != nil {
t.Error(err)
continue
}
compareJsonResponse(t, test.response, &ChangeStatusToResponse{})
lastMilectx, _ := context.WithTimeout(context.Background(), testTimeout)
lastMileResp, err := c.FBS().ChangeStatusToLastMile(lastMilectx, test.params)
if err != nil {
t.Error(err)
continue
}
deliveredctx, _ := context.WithTimeout(context.Background(), testTimeout)
deliveredResp, err := c.FBS().ChangeStatusToDelivered(deliveredctx, test.params)
if err != nil {
t.Error(err)
continue
}
sendBySellerctx, _ := context.WithTimeout(context.Background(), testTimeout)
sendBySellerResp, err := c.FBS().ChangeStatusToSendBySeller(sendBySellerctx, test.params)
if err != nil {
t.Error(err)
continue
}
assertResponse(t, &test, deliveringResp)
@@ -1030,8 +1027,11 @@ func TestPassShipmentToShipping(t *testing.T) {
resp, err := c.FBS().PassShipmentToShipping(ctx, test.params)
if err != nil {
t.Error(err)
continue
}
compareJsonResponse(t, test.response, &PassShipmentToShippingResponse{})
if resp.StatusCode != test.statusCode {
t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode)
}
@@ -1079,8 +1079,11 @@ func TestCancelShipment(t *testing.T) {
resp, err := c.FBS().CancelShipment(ctx, test.params)
if err != nil {
t.Error(err)
continue
}
compareJsonResponse(t, test.response, &CancelShipmentResponse{})
if resp.StatusCode != test.statusCode {
t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode)
}
@@ -1130,8 +1133,11 @@ func TestCreateAct(t *testing.T) {
resp, err := c.FBS().CreateAct(ctx, test.params)
if err != nil {
t.Error(err)
continue
}
compareJsonResponse(t, test.response, &CreateActResponse{})
if resp.StatusCode != test.statusCode {
t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode)
}
@@ -1180,8 +1186,11 @@ func TestGetLabeling(t *testing.T) {
resp, err := c.FBS().GetLabeling(ctx, test.params)
if err != nil {
t.Error(err)
continue
}
compareJsonResponse(t, test.response, &GetLabelingResponse{})
if resp.StatusCode != test.statusCode {
t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode)
}
@@ -1234,8 +1243,11 @@ func TestPrintLabeling(t *testing.T) {
resp, err := c.FBS().PrintLabeling(ctx, test.params)
if err != nil {
t.Error(err)
continue
}
compareJsonResponse(t, test.response, &PrintLabelingResponse{})
if resp.StatusCode != test.statusCode {
t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode)
}
@@ -1289,8 +1301,11 @@ func TestCreateTaskForGeneratingLabel(t *testing.T) {
resp, err := c.FBS().CreateTaskForGeneratingLabel(ctx, test.params)
if err != nil {
t.Error(err)
continue
}
compareJsonResponse(t, test.response, &CreateTaskForGeneratingLabelResponse{})
if resp.StatusCode != test.statusCode {
t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode)
}
@@ -1350,8 +1365,11 @@ func TestGetDropOffPointRestrictions(t *testing.T) {
resp, err := c.FBS().GetDropOffPointRestrictions(ctx, test.params)
if err != nil {
t.Error(err)
continue
}
compareJsonResponse(t, test.response, &GetDropOffPointRestrictionsResponse{})
if resp.StatusCode != test.statusCode {
t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode)
}
@@ -1408,11 +1426,14 @@ func TestCheckProductItemsData(t *testing.T) {
c := NewMockClient(core.NewMockHttpHandler(test.statusCode, test.response, test.headers))
ctx, _ := context.WithTimeout(context.Background(), testTimeout)
resp, err := c.FBS().CheckproductItemsData(ctx, test.params)
resp, err := c.FBS().CheckProductItemsData(ctx, test.params)
if err != nil {
t.Error(err)
continue
}
compareJsonResponse(t, test.response, &CheckProductItemsDataResponse{})
if resp.StatusCode != test.statusCode {
t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode)
}
@@ -1475,8 +1496,11 @@ func TestGetProductItemsCheckStatuses(t *testing.T) {
resp, err := c.FBS().GetProductItemsCheckStatuses(ctx, test.params)
if err != nil {
t.Error(err)
continue
}
compareJsonResponse(t, test.response, &GetProductItemsCheckStatusesResponse{})
if resp.StatusCode != test.statusCode {
t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode)
}
@@ -1544,8 +1568,11 @@ func TestRescheduleShipmentDeliveryDate(t *testing.T) {
resp, err := c.FBS().RescheduleShipmentDeliveryDate(ctx, test.params)
if err != nil {
t.Error(err)
continue
}
compareJsonResponse(t, test.response, &RescheduleShipmentDeliveryDateResponse{})
if resp.StatusCode != test.statusCode {
t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode)
}
@@ -1596,8 +1623,11 @@ func TestDateAvailableForDeliverySchedule(t *testing.T) {
resp, err := c.FBS().DateAvailableForDeliverySchedule(ctx, test.params)
if err != nil {
t.Error(err)
continue
}
compareJsonResponse(t, test.response, &DateAvailableForDeliveryScheduleResponse{})
if resp.StatusCode != test.statusCode {
t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode)
}
@@ -1656,8 +1686,11 @@ func TestListManufactoruingCountries(t *testing.T) {
resp, err := c.FBS().ListManufacturingCountries(ctx, test.params)
if err != nil {
t.Error(err)
continue
}
compareJsonResponse(t, test.response, &ListManufacturingCountriesResponse{})
if resp.StatusCode != test.statusCode {
t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode)
}
@@ -1717,8 +1750,11 @@ func TestSetManufacturingCountry(t *testing.T) {
resp, err := c.FBS().SetManufacturingCountry(ctx, test.params)
if err != nil {
t.Error(err)
continue
}
compareJsonResponse(t, test.response, &SetManufacturingCountryResponse{})
if resp.StatusCode != test.statusCode {
t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode)
}
@@ -1785,8 +1821,11 @@ func TestPartialPackOrder(t *testing.T) {
resp, err := c.FBS().PartialPackOrder(ctx, test.params)
if err != nil {
t.Error(err)
continue
}
compareJsonResponse(t, test.response, &PartialPackOrderResponse{})
if resp.StatusCode != test.statusCode {
t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode)
}
@@ -1858,8 +1897,11 @@ func TestAvailableFreightsList(t *testing.T) {
resp, err := c.FBS().AvailableFreightsList(ctx, test.params)
if err != nil {
t.Error(err)
continue
}
compareJsonResponse(t, test.response, &AvailableFreightsListResponse{})
if resp.StatusCode != test.statusCode {
t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode)
}
@@ -1906,8 +1948,11 @@ func TestGenerateAct(t *testing.T) {
resp, err := c.FBS().GenerateAct(ctx, test.params)
if err != nil {
t.Error(err)
continue
}
compareJsonResponse(t, test.response, &GenerateActResponse{})
if resp.StatusCode != test.statusCode {
t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode)
}
@@ -1956,8 +2001,11 @@ func TestGetDigitalAct(t *testing.T) {
resp, err := c.FBS().GetDigitalAct(ctx, test.params)
if err != nil {
t.Error(err)
continue
}
compareJsonResponse(t, test.response, &GetDigitalActResponse{})
if resp.StatusCode != test.statusCode {
t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode)
}
@@ -2011,8 +2059,11 @@ func TestPackageUnitLabels(t *testing.T) {
resp, err := c.FBS().PackageUnitLabel(ctx, test.params)
if err != nil {
t.Error(err)
continue
}
compareJsonResponse(t, test.response, &PackageUnitLabelsResponse{})
if resp.StatusCode != test.statusCode {
t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode)
}
@@ -2064,8 +2115,11 @@ func TestOpenDisputeOverShipment(t *testing.T) {
resp, err := c.FBS().OpenDisputeOverShipment(ctx, test.params)
if err != nil {
t.Error(err)
continue
}
compareJsonResponse(t, test.response, &OpenDisputeOverShipmentResponse{})
if resp.StatusCode != test.statusCode {
t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode)
}
@@ -2132,8 +2186,11 @@ func TestShipmentCancellationReasons(t *testing.T) {
resp, err := c.FBS().ShipmentCancellationReasons(ctx, test.params)
if err != nil {
t.Error(err)
continue
}
compareJsonResponse(t, test.response, &ShipmentCancellationReasonsResponse{})
if resp.StatusCode != test.statusCode {
t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode)
}
@@ -2228,8 +2285,11 @@ func TestShipmentsCancellationReasons(t *testing.T) {
resp, err := c.FBS().ShipmentsCancellationReasons(ctx)
if err != nil {
t.Error(err)
continue
}
compareJsonResponse(t, test.response, &ShipmentsCancellationReasonsResponse{})
if resp.StatusCode != test.statusCode {
t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode)
}
@@ -2290,8 +2350,11 @@ func TestAddWeightForBulkProduct(t *testing.T) {
resp, err := c.FBS().AddWeightForBulkProduct(ctx, test.params)
if err != nil {
t.Error(err)
continue
}
compareJsonResponse(t, test.response, &AddWeightForBulkProductResponse{})
if resp.StatusCode != test.statusCode {
t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode)
}
@@ -2351,8 +2414,11 @@ func TestCancelSending(t *testing.T) {
resp, err := c.FBS().CancelSending(ctx, test.params)
if err != nil {
t.Error(err)
continue
}
compareJsonResponse(t, test.response, &CancelSendingResponse{})
if resp.StatusCode != test.statusCode {
t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode)
}
@@ -2417,8 +2483,11 @@ func TestListShipmentInCertificate(t *testing.T) {
resp, err := c.FBS().ListShipmentInCertificate(ctx, test.params)
if err != nil {
t.Error(err)
continue
}
compareJsonResponse(t, test.response, &ListShipmentInCertificateResponse{})
if resp.StatusCode != test.statusCode {
t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode)
}
@@ -2466,8 +2535,11 @@ func TestSpecifyNumberOfBoxes(t *testing.T) {
resp, err := c.FBS().SpecifyNumberOfBoxes(ctx, test.params)
if err != nil {
t.Error(err)
continue
}
compareJsonResponse(t, test.response, &SpecifyNumberOfBoxesResponse{})
if resp.StatusCode != test.statusCode {
t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode)
}
@@ -2492,7 +2564,13 @@ func TestStatusOfAct(t *testing.T) {
},
`{
"result": {
"result": true
"added_to_act": [
"true"
],
"removed_from_act": [
"false"
],
"status": "ready"
}
}`,
},
@@ -2515,8 +2593,11 @@ func TestStatusOfAct(t *testing.T) {
resp, err := c.FBS().StatusOfAct(ctx, test.params)
if err != nil {
t.Error(err)
continue
}
compareJsonResponse(t, test.response, &StatusOfActResponse{})
if resp.StatusCode != test.statusCode {
t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode)
}
@@ -2574,8 +2655,11 @@ func TestETGBCustomsDeclarations(t *testing.T) {
resp, err := c.FBS().ETGBCustomsDeclarations(ctx, test.params)
if err != nil {
t.Error(err)
continue
}
compareJsonResponse(t, test.response, &ETGBCustomsDeclarationsResponse{})
if resp.StatusCode != test.statusCode {
t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode)
}
@@ -2623,8 +2707,11 @@ func TestBarcodeFromProductShipment(t *testing.T) {
resp, err := c.FBS().BarcodeFromProductShipment(ctx, test.params)
if err != nil {
t.Error(err)
continue
}
compareJsonResponse(t, test.response, &BarcodeFromProductShipmentResponse{})
if resp.StatusCode != test.statusCode {
t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode)
}
@@ -2682,8 +2769,11 @@ func TestBarcodeValueFromProductShipment(t *testing.T) {
resp, err := c.FBS().BarcodeValueFromProductShipment(ctx, test.params)
if err != nil {
t.Error(err)
continue
}
compareJsonResponse(t, test.response, &BarcodeValueFromProductShipmentResponse{})
if resp.StatusCode != test.statusCode {
t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode)
}
@@ -2737,8 +2827,11 @@ func TestGetActPDF(t *testing.T) {
resp, err := c.FBS().GetActPDF(ctx, test.params)
if err != nil {
t.Error(err)
continue
}
compareJsonResponse(t, test.response, &GetActPDFResponse{})
if resp.StatusCode != test.statusCode {
t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode)
}