From 466cbc6379417e783a70e52b317039d95bc22f5f Mon Sep 17 00:00:00 2001 From: diPhantxm Date: Sat, 18 Mar 2023 03:05:06 +0300 Subject: [PATCH] extend tests --- ozon/analytics_test.go | 6 ++ ozon/fbs_test.go | 15 +++++ ozon/products_test.go | 119 +++++++++++++++++++++++++++++++++++++++- ozon/promotions_test.go | 17 ++++++ ozon/rating_test.go | 16 ++++++ ozon/reports.go | 61 ++++++++++---------- ozon/reports_test.go | 53 ++++++++++++++++++ ozon/returns_test.go | 40 +++++++++++++- ozon/warehouses_test.go | 28 ++++++++++ 9 files changed, 322 insertions(+), 33 deletions(-) diff --git a/ozon/analytics_test.go b/ozon/analytics_test.go index a5c253f..ef88a76 100644 --- a/ozon/analytics_test.go +++ b/ozon/analytics_test.go @@ -127,5 +127,11 @@ func TestGetStocksOnWarehouses(t *testing.T) { 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.Rows) > int(test.params.Limit) { + t.Errorf("Length of rows is bigger than limit") + } + } } } diff --git a/ozon/fbs_test.go b/ozon/fbs_test.go index 799ab9d..804bf67 100644 --- a/ozon/fbs_test.go +++ b/ozon/fbs_test.go @@ -347,6 +347,10 @@ func TestPackOrder(t *testing.T) { if resp.StatusCode != test.statusCode { t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode) } + + if len(resp.Result) != len(test.params.Packages) { + t.Errorf("Length of packages in request and response are not equal") + } } } @@ -420,5 +424,16 @@ func TestValidateLabelingCodes(t *testing.T) { 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.Products) != len(test.params.Products) { + t.Errorf("Length of products in request and response are not equal") + } + if len(resp.Result.Products) > 0 { + if resp.Result.Products[0].ProductId != test.params.Products[0].ProductId { + t.Errorf("Product ids in request and response are not equal") + } + } + } } } diff --git a/ozon/products_test.go b/ozon/products_test.go index c6b95d6..512ce69 100644 --- a/ozon/products_test.go +++ b/ozon/products_test.go @@ -1,6 +1,7 @@ package ozon import ( + "fmt" "net/http" "testing" @@ -77,6 +78,20 @@ func TestGetStocksInfo(t *testing.T) { 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.Items) > int(test.params.Limit) { + t.Errorf("Amount of items in response cannot be bigger than limit") + } + if len(resp.Result.Items) > 0 { + if resp.Result.Items[0].ProductId == 0 { + t.Errorf("Product id cannot be 0") + } + if resp.Result.Items[0].OfferId == "" { + t.Errorf("Offer id cannot be empty") + } + } + } } } @@ -243,6 +258,21 @@ func TestGetProductDetails(t *testing.T) { 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.Id != test.params.ProductId { + t.Errorf("Id of product in response is not equal product_id in request") + } + if resp.Result.OfferId == "" { + t.Errorf("Offer id cannot be empty") + } + if resp.Result.CategoryId == 0 { + t.Errorf("Category id cannot be 0") + } + if resp.Result.CurrencyCode == "" { + t.Errorf("Currency code cannot be empty") + } + } } } @@ -302,6 +332,20 @@ func TestUpdateStocks(t *testing.T) { 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.Stocks) { + t.Errorf("Length of stocks in request and response are not equal") + } + if len(resp.Result) > 0 { + if resp.Result[0].OfferId != test.params.Stocks[0].OfferId { + t.Errorf("Offer ids in request and response are not equal") + } + if resp.Result[0].ProductId != test.params.Stocks[0].ProductId { + t.Errorf("Product ids in request and response are not equal") + } + } + } } } @@ -357,6 +401,17 @@ func TestStocksInSellersWarehouse(t *testing.T) { 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.FBSSKU) { + t.Errorf("Length of skus in request and response must be equal") + } + if len(resp.Result) > 0 { + if fmt.Sprint(resp.Result[0].FBSSKU) == test.params.FBSSKU[0] { + t.Errorf("fbs sku in request and response are not equal") + } + } + } } } @@ -419,6 +474,17 @@ func TestUpdatePrices(t *testing.T) { 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.Prices) { + t.Errorf("Length of prices in request and response are not equal") + } + if len(resp.Result) > 0 { + if resp.Result[0].ProductId != test.params.Prices[0].ProductId { + t.Errorf("Product ids in request and response are not equal") + } + } + } } } @@ -439,7 +505,7 @@ func TestUpdateQuantityStockProducts(t *testing.T) { Stocks: []UpdateQuantityStockProductsStock{ { OfferId: "PH11042", - ProductId: 313455276, + ProductId: 118597312, Stock: 100, WarehouseId: 22142605386000, }, @@ -480,6 +546,23 @@ func TestUpdateQuantityStockProducts(t *testing.T) { 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.Stocks) { + t.Errorf("Length of stocks in request and response are not equal") + } + if len(resp.Result) > 0 { + if resp.Result[0].Offerid != test.params.Stocks[0].OfferId { + t.Errorf("Offer ids in request and response are not equal") + } + if resp.Result[0].ProductId != test.params.Stocks[0].ProductId { + t.Errorf("Product ids in request and response are not equal") + } + if resp.Result[0].WarehouseId != test.params.Stocks[0].WarehouseId { + t.Errorf("Warehouse ids in request and response are not equal") + } + } + } } } @@ -597,6 +680,12 @@ func TestCreateOrUpdateProduct(t *testing.T) { 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.TaskId == 0 { + t.Errorf("Task id cannot be 0") + } + } } } @@ -658,6 +747,23 @@ func TestGetListOfProducts(t *testing.T) { 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.Items) != int(resp.Result.Total) { + t.Errorf("Length of items is not equal total") + } + if resp.Result.Total > int32(test.params.Limit) { + t.Errorf("Length of items is bigger than limit") + } + if len(resp.Result.Items) > 0 { + if resp.Result.Items[0].OfferId == "" { + t.Errorf("Offer id cannot be empty") + } + if resp.Result.Items[0].ProductId == 0 { + t.Errorf("Product id cannot be 0") + } + } + } } } @@ -887,5 +993,16 @@ func TestGetProductsRatingBySKU(t *testing.T) { 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.Products) != len(test.params.SKUs) { + t.Errorf("Length of products in response is not equal length of skus in request") + } + if len(resp.Products) > 0 { + if resp.Products[0].SKU != test.params.SKUs[0] { + t.Errorf("SKU in request and response are not equal") + } + } + } } } diff --git a/ozon/promotions_test.go b/ozon/promotions_test.go index 4101d61..46ce911 100644 --- a/ozon/promotions_test.go +++ b/ozon/promotions_test.go @@ -64,6 +64,17 @@ func TestGetAvailablePromotions(t *testing.T) { 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) > 0 { + if resp.Result[0].Id == 0 { + t.Errorf("Id cannot be 0") + } + if resp.Result[0].ActionType == "" { + t.Errorf("Action type cannot be empty") + } + } + } } } @@ -122,5 +133,11 @@ func TestAddToPromotion(t *testing.T) { 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.ProductIds) != len(test.params.Products) { + t.Errorf("Length of products in response and request must be equal") + } + } } } diff --git a/ozon/rating_test.go b/ozon/rating_test.go index deb04e5..1bab866 100644 --- a/ozon/rating_test.go +++ b/ozon/rating_test.go @@ -66,6 +66,14 @@ func TestGetCurrentRatingInfo(t *testing.T) { 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.Groups) > 0 { + if len(resp.Groups[0].Items) == 0 { + t.Errorf("Length of items in a group cannot be 0") + } + } + } } } @@ -146,5 +154,13 @@ func TestGetRatingInfoForPeriod(t *testing.T) { 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.Ratings) > 0 { + if resp.Ratings[0].Rating == "" { + t.Errorf("Rating system cannot be empty") + } + } + } } } diff --git a/ozon/reports.go b/ozon/reports.go index b3dcdc3..4b9f30d 100644 --- a/ozon/reports.go +++ b/ozon/reports.go @@ -39,41 +39,44 @@ type GetReportsListResponse struct { // Method result Result struct { - // Unique report identifier - Code string `json:"code"` + // Array with generated reports + Reports []struct { + // Unique report identifier + Code string `json:"code"` - // Report creation date - CreatedAt time.Time `json:"created_at"` + // Report creation date + CreatedAt time.Time `json:"created_at"` - // Error code when generating the report - Error string `json:"error"` + // Error code when generating the report + Error string `json:"error"` - // Link to CSV file - File string `json:"file"` + // Link to CSV file + File string `json:"file"` - // Array with the filters specified when the seller created the report - Params struct { - } `json:"params"` + // Array with the filters specified when the seller created the report + Params struct { + } `json:"params"` - // Report type: - // - SELLER_PRODUCTS — products report, - // - SELLER_TRANSACTIONS — transactions report, - // - SELLER_PRODUCT_PRICES — product prices report, - // - SELLER_STOCK — stocks report, - // - SELLER_PRODUCT_MOVEMENT — products movement report, - // - SELLER_RETURNS — returns report, - // - SELLER_POSTINGS — shipments report, - // - SELLER_FINANCE — financial report - ReportType string `json:"report_type"` + // Report type: + // - SELLER_PRODUCTS — products report, + // - SELLER_TRANSACTIONS — transactions report, + // - SELLER_PRODUCT_PRICES — product prices report, + // - SELLER_STOCK — stocks report, + // - SELLER_PRODUCT_MOVEMENT — products movement report, + // - SELLER_RETURNS — returns report, + // - SELLER_POSTINGS — shipments report, + // - SELLER_FINANCE — financial report + ReportType string `json:"report_type"` - // Report generation status - // - `success` - // - `failed` - Status string `json:"status"` + // Report generation status + // - `success` + // - `failed` + Status string `json:"status"` + } `json:"reports"` + + // Total number of reports + Total int32 `json:"total"` } `json:"result"` - - // Total number of reports - Total int32 `json:"total"` } // Returns the list of reports that have been generated before @@ -136,7 +139,7 @@ type GetReportDetailsResponse struct { // Returns information about a created report by its identifier func (c Reports) GetReportDetails(params *GetReportDetailsParams) (*GetReportDetailsResponse, error) { - url := "/v1/report/list" + url := "/v1/report/info" resp := &GetReportDetailsResponse{} diff --git a/ozon/reports_test.go b/ozon/reports_test.go index a2100ea..8fa5f01 100644 --- a/ozon/reports_test.go +++ b/ozon/reports_test.go @@ -77,6 +77,15 @@ func TestGetList(t *testing.T) { if resp.StatusCode != test.statusCode { t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode) } + + if int(resp.Result.Total) != len(resp.Result.Reports) { + t.Errorf("Amount of reports (%d) is not equal to total (%d)", len(resp.Result.Reports), resp.Result.Total) + } + if len(resp.Result.Reports) > 0 { + if resp.Result.Reports[0].Status == "" { + t.Errorf("Status must be 'success' or 'failed'") + } + } } } @@ -129,6 +138,12 @@ func TestGetReportDetails(t *testing.T) { 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.Status == "" { + t.Errorf("Status must be 'success' or 'failed'") + } + } } } @@ -197,6 +212,14 @@ func TestGetFinancialReport(t *testing.T) { 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.CashFlows) > 0 { + if resp.Result.CashFlows[0].CurrencyCode == "" { + t.Errorf("Currency Code cannot be empty") + } + } + } } } @@ -243,6 +266,12 @@ func TestGetProductsReport(t *testing.T) { 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.Code == "" { + t.Errorf("Code cannot be empty") + } + } } } @@ -289,6 +318,12 @@ func TestGetStocksReport(t *testing.T) { 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.Code == "" { + t.Errorf("Code cannot be empty") + } + } } } @@ -338,6 +373,12 @@ func TestGetProductsMovementReport(t *testing.T) { 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.Code == "" { + t.Errorf("Code cannot be empty") + } + } } } @@ -388,6 +429,12 @@ func TestGetReturnsReport(t *testing.T) { 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.Code == "" { + t.Errorf("Code cannot be empty") + } + } } } @@ -440,5 +487,11 @@ func TestGetShipmentReport(t *testing.T) { 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.Code == "" { + t.Errorf("Code cannot be empty") + } + } } } diff --git a/ozon/returns_test.go b/ozon/returns_test.go index 0152e27..da51f7e 100644 --- a/ozon/returns_test.go +++ b/ozon/returns_test.go @@ -32,15 +32,15 @@ func TestGetFBOReturns(t *testing.T) { "returns": [ { "accepted_from_customer_moment": "2019-08-24T14:15:22Z", - "company_id": 0, + "company_id": 123456789, "current_place_name": "my-place", "dst_place_name": "that-place", - "id": 0, + "id": 123456789, "is_opened": true, "posting_number": "some number", "return_reason_name": "ripped", "returned_to_ozon_moment": "2019-08-24T14:15:22Z", - "sku": 0, + "sku": 123456789, "status_name": "delivering" } ] @@ -69,6 +69,20 @@ func TestGetFBOReturns(t *testing.T) { 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.Returns) > 0 { + if resp.Returns[0].Id == 0 { + t.Errorf("Id cannot be 0") + } + if resp.Returns[0].CompanyId == 0 { + t.Errorf("Company id cannot be 0") + } + if resp.Returns[0].SKU == 0 { + t.Errorf("SKU cannot be 0") + } + } + } } } @@ -152,5 +166,25 @@ func TestGetFBSReturns(t *testing.T) { 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 int(resp.Result.Count) != len(resp.Result.Returns) { + t.Errorf("Count must equal to length of returns") + } + if len(resp.Result.Returns) > 0 { + if resp.Result.Returns[0].Id == 0 { + t.Errorf("Id cannot be 0") + } + if resp.Result.Returns[0].ProductId == 0 { + t.Errorf("Product id cannot be 0") + } + if resp.Result.Returns[0].SKU == 0 { + t.Errorf("SKU cannot be 0") + } + if resp.Result.Returns[0].Status == "" { + t.Errorf("Status cannot be empty") + } + } + } } } diff --git a/ozon/warehouses_test.go b/ozon/warehouses_test.go index 9db6402..43df202 100644 --- a/ozon/warehouses_test.go +++ b/ozon/warehouses_test.go @@ -66,6 +66,17 @@ func TestGetListOfWarehouses(t *testing.T) { 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) > 0 { + if resp.Result[0].WarehouseId == 0 { + t.Errorf("Warehouse id cannot be 0") + } + if resp.Result[0].Name == "" { + t.Errorf("Name cannot be empty") + } + } + } } } @@ -130,5 +141,22 @@ func TestGetListOfDeliveryMethods(t *testing.T) { 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) > 0 { + if resp.Result[0].Id == 0 { + t.Errorf("Id cannot be 0") + } + if resp.Result[0].Name == "" { + t.Errorf("Name cannot be empty") + } + if resp.Result[0].Status == "" { + t.Errorf("Status cannot be empty") + } + if resp.Result[0].WarehouseId == 0 { + t.Errorf("Warehouse id cannot be 0") + } + } + } } }