Skip to content
Snippets Groups Projects
Commit d4780636 authored by meskio's avatar meskio :tent:
Browse files

Set 2 products for tests

parent 5b0765c2
Branches
No related tags found
No related merge requests found
...@@ -499,17 +499,6 @@ func TestOrderUpdateProduct(t *testing.T) { ...@@ -499,17 +499,6 @@ func TestOrderUpdateProduct(t *testing.T) {
t.Fatal("Can't create order:", resp.Status) 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 := testOrder
order.Products[0].Price = testProduct2.Price order.Products[0].Price = testProduct2.Price
order.Products[0].ProductCode = testProduct2.Code order.Products[0].ProductCode = testProduct2.Code
......
...@@ -13,6 +13,12 @@ var testProduct = db.Product{ ...@@ -13,6 +13,12 @@ var testProduct = db.Product{
Price: 1700, Price: 1700,
Stock: 10, Stock: 10,
} }
var testProduct2 = db.Product{
Code: 123,
Name: "Huevos",
Price: 120,
Stock: 15,
}
func TestProductAddList(t *testing.T) { func TestProductAddList(t *testing.T) {
tapi := newTestAPI(t) tapi := newTestAPI(t)
...@@ -25,15 +31,16 @@ func TestProductAddList(t *testing.T) { ...@@ -25,15 +31,16 @@ func TestProductAddList(t *testing.T) {
t.Fatal("Can't get products:", resp.Status) t.Fatal("Can't get products:", resp.Status)
} }
if len(products) != 1 { for _, product := range products {
t.Fatal("Wrong number of products", len(products), products) if product.Name == testProduct.Name {
if product.Price != testProduct.Price {
t.Error("Wrong price:", products[0].Price)
} }
if products[0].Name != testProduct.Name { return
t.Error("Wrong name:", products[0].Name)
} }
if products[0].Price != testProduct.Price {
t.Error("Wrong price:", products[0].Price)
} }
t.Error("Can't find testProduct in product list:", products)
} }
func TestProductGetDelete(t *testing.T) { func TestProductGetDelete(t *testing.T) {
...@@ -92,4 +99,9 @@ func (tapi *testAPI) addTestProducts() { ...@@ -92,4 +99,9 @@ func (tapi *testAPI) addTestProducts() {
if resp.StatusCode != http.StatusCreated { if resp.StatusCode != http.StatusCreated {
tapi.t.Fatal("Can't create product:", resp.Status) 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)
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment