diff --git a/api/order_test.go b/api/order_test.go index 2ebc3ff3ad1e4e162bea97fb61d43fd0ca8ddac1..b9170d805fe12ad60636f54789ba3a97dd3dcd89 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 09ccd9d5196f9215df5c5f3351a6fe36b108d45e..3d49c711257b044a203d22d8e26de661af74a676 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) + } }