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

Set 2 products for tests

parent 5b0765c2
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
......@@ -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)
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment