variant and price

This commit is contained in:
2026-08-28 16:54:55 +05:30
parent 6c1ad472f2
commit 40500f936a
3 changed files with 101 additions and 21 deletions

View File

@@ -417,33 +417,77 @@ func TestOrderingAGroupedProductOffersEveryVariant(t *testing.T) {
}
}
// The order screen must not offer a size the branch has none of — the list that
// led there does not show it, and the two must agree.
func TestAVariantWithNoStockIsNotOfferedForOrder(t *testing.T) {
// The product screen shows what was tapped, in stock or not.
//
// Filtered, an out-of-stock product answered with zero rows and the screen had
// nothing to draw. Nothing is sold by showing it: the browse list never offers
// it, and CreateOrder refuses the line independently.
func TestTheProductScreenStillShowsAnEmptyProduct(t *testing.T) {
repo := &variantRepo{rows: []models.Products{
{Productid: 6995, Productname: "Strawberries 250g", Productstock: 0},
{Productid: 6996, Productname: "Strawberries 500g", Productstock: 9},
{Productid: 7085, Productname: "Cadbury 5 Star 18g", Productstock: 0},
}}
svc := NewProductService(repo, &fakeCatalogueService{})
got, err := svc.GetProductByVariant(1087, 44, 1097, 0)
got, err := svc.GetProductByVariant(1135, 0, 1170, 7085)
if err != nil {
t.Fatalf("GetProductByVariant: %v", err)
}
if len(got) != 1 || got[0].Productid != 6996 {
t.Fatalf("want only the stocked size, got %v", names(got))
if len(got) != 1 {
t.Fatalf("the tapped product vanished from its own screen: %v", names(got))
}
if got[0].Productstock != 0 {
t.Errorf("stock must survive so the app can grey the option out, got %d", got[0].Productstock)
}
}
// Oversold is not stock. Strawberries at Ragul Stores really did read -262.
func TestAnOversoldVariantIsNotOfferedForOrder(t *testing.T) {
// Every member of the family comes back, so the shopper sees the full range and
// the one they tapped is always among them. Tapping "Apple" used to return
// "Pineapple" — the only stocked member — which is not the product they asked
// for.
func TestTheWholeFamilyIsShownIncludingEmptyOnes(t *testing.T) {
repo := &variantRepo{rows: []models.Products{
{Productid: 6995, Productname: "Strawberries", Productstock: -262},
{Productid: 7014, Productname: "Apple", Productstock: 0},
{Productid: 6994, Productname: "Pineapple", Productstock: 50},
{Productid: 6989, Productname: "Jammu Apple", Productstock: 0},
}}
svc := NewProductService(repo, &fakeCatalogueService{})
got, _ := svc.GetProductByVariant(1087, 44, 1097, 0)
if len(got) != 0 {
t.Errorf("an oversold product was offered for order")
got, err := svc.GetProductByVariant(1087, 36, 1097, 7014)
if err != nil {
t.Fatalf("GetProductByVariant: %v", err)
}
if len(got) != 3 {
t.Fatalf("want all 3 family members, got %v", names(got))
}
tapped := false
for _, p := range got {
if p.Productid == 7014 {
tapped = true
}
}
if !tapped {
t.Error("the tapped product is missing from its own variant list")
}
}
// The browse list is the screen that must NOT offer an empty shelf, and it
// still does not. The two endpoints deliberately differ.
func TestBrowseStillHidesWhatTheShopDoesNotHave(t *testing.T) {
repo := newFakeRepo()
svc := NewProductService(repo, &fakeCatalogueService{})
result, err := svc.GetProductsBySubcategory(models.ProductFilter{
CategoryID: 2, TenantID: 1135, LocationID: 1170,
})
if err != nil {
t.Fatalf("GetProductsBySubcategory: %v", err)
}
groups, _ := result["details"].([]models.SubcategoryProductResponse)
var offered []models.Products
for _, g := range groups {
offered = append(offered, g.Products...)
}
if len(offered) != 1 || offered[0].Productid != 7086 {
t.Fatalf("browse should still offer only the stocked product, got %v", names(offered))
}
}