This commit is contained in:
2026-09-03 16:23:29 +05:30
parent 0d17f46fcf
commit 18a0f9b34d
3 changed files with 96 additions and 0 deletions

View File

@@ -715,3 +715,55 @@ func TestFilteringChildrenDoesNotDisturbTheCallersSlice(t *testing.T) {
t.Errorf("the caller's slice was modified")
}
}
/*
A product with no price is unfinished, not free.
Import writes whatever the catalogue carries, and 159 of the 1,572 catalogue
rows carry no price — loose produce has none by design, some scraped rows never
had one. So a product can reach a shelf at ₹0 and go on sale at nothing.
Measured 2026-09-03: Kmart's entire customer-facing catalogue was five products,
every one at ₹0, all with stock.
*/
func TestAnUnpricedProductIsNotOfferedToShoppers(t *testing.T) {
groups := []models.Tenantproducts{{Products: []models.Products{
{Productid: 1, Price: 45},
{Productid: 2, Price: 0},
{Productid: 3, Price: 12.5},
}}}
got := PricedOnly(groups)
if len(got[0].Products) != 2 {
t.Fatalf("expected the two priced products, got %v", got[0].Products)
}
for _, product := range got[0].Products {
if product.Price <= 0 {
t.Errorf("product %d has no price and was still offered", product.Productid)
}
}
}
func TestANegativePriceIsNotAPrice(t *testing.T) {
got := PricedOnly([]models.Tenantproducts{{Products: []models.Products{{Productid: 1, Price: -5}}}})
if len(got[0].Products) != 0 {
t.Error("a negative price was treated as sellable")
}
}
func TestAShopWithNothingPricedStillExists(t *testing.T) {
// The shop is open; it has nothing ready to sell. Dropping the group would
// say the shop is not there, which is a different and wrong statement.
got := PricedOnly([]models.Tenantproducts{{Products: []models.Products{{Productid: 1, Price: 0}}}})
if len(got) != 1 || len(got[0].Products) != 0 {
t.Errorf("expected the shop to survive with nothing on offer, got %v", got)
}
}
func TestPricingFilterDoesNotDisturbTheCallersSlice(t *testing.T) {
original := []models.Tenantproducts{{Products: []models.Products{{Productid: 1, Price: 10}, {Productid: 2, Price: 0}}}}
_ = PricedOnly(original)
if len(original[0].Products) != 2 {
t.Error("the caller's slice was modified")
}
}