From d47806365402ec9373911b75927fa96a329b105c Mon Sep 17 00:00:00 2001 From: meskio <meskio@sindominio.net> Date: Mon, 22 Feb 2021 12:39:54 +0100 Subject: [PATCH] Set 2 products for tests --- api/order_test.go | 11 ----------- api/product_test.go | 28 ++++++++++++++++++++-------- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/api/order_test.go b/api/order_test.go index 2ebc3ff..b9170d8 100644 --- a/api/order_test.go +++ b/api/order_test.go @@ -499,17 +499,6 @@ func TestOrderUpdateProduct(t *testing.T) { t.Fatal("Can't create order:", resp.Status) } - testProduct2 := db.Product{ - Code: 123, - Name: "Huevos", - Price: 120, - Stock: 15, - } - resp = tapi.doAdmin("POST", "/product", testProduct2, nil) - if resp.StatusCode != http.StatusCreated { - tapi.t.Fatal("Can't create product:", resp.Status) - } - order := testOrder order.Products[0].Price = testProduct2.Price order.Products[0].ProductCode = testProduct2.Code diff --git a/api/product_test.go b/api/product_test.go index 09ccd9d..3d49c71 100644 --- a/api/product_test.go +++ b/api/product_test.go @@ -13,6 +13,12 @@ var testProduct = db.Product{ Price: 1700, Stock: 10, } +var testProduct2 = db.Product{ + Code: 123, + Name: "Huevos", + Price: 120, + Stock: 15, +} func TestProductAddList(t *testing.T) { tapi := newTestAPI(t) @@ -25,15 +31,16 @@ func TestProductAddList(t *testing.T) { t.Fatal("Can't get products:", resp.Status) } - if len(products) != 1 { - t.Fatal("Wrong number of products", len(products), products) - } - if products[0].Name != testProduct.Name { - t.Error("Wrong name:", products[0].Name) - } - if products[0].Price != testProduct.Price { - t.Error("Wrong price:", products[0].Price) + for _, product := range products { + if product.Name == testProduct.Name { + if product.Price != testProduct.Price { + t.Error("Wrong price:", products[0].Price) + } + return + } } + + t.Error("Can't find testProduct in product list:", products) } func TestProductGetDelete(t *testing.T) { @@ -92,4 +99,9 @@ func (tapi *testAPI) addTestProducts() { if resp.StatusCode != http.StatusCreated { tapi.t.Fatal("Can't create product:", resp.Status) } + + resp = tapi.doAdmin("POST", "/product", testProduct2, nil) + if resp.StatusCode != http.StatusCreated { + tapi.t.Fatal("Can't create product:", resp.Status) + } } -- GitLab