@@ -189,7 +189,7 @@ func TestClaimMyReward_HTTPFlow_RejectsWhenBelowThreshold(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// Si un produit configuré par l'admin (via ProductIDs explicite) pointe vers
|
||||
// Si un produit configuré par l'admin (via Products explicite) pointe vers
|
||||
// un produit supprimé/inexistant, la réclamation entière doit échouer — la
|
||||
// récompense ne doit pas être consommée sans qu'aucun produit ne soit livré
|
||||
// au client (ClaimPoolReward + AddRewardsToBasket sont dans la même
|
||||
@@ -202,7 +202,7 @@ func TestClaimMyReward_HTTPFlow_FailsAtomicallyWhenProductMissing(t *testing.T)
|
||||
configureRewardSettings(t, &models.PointsReward{
|
||||
Threshold: 20,
|
||||
CategoryConfigs: []models.RewardCategoryConfig{
|
||||
{Category: "test", Type: "free_product", ProductIDs: []int{999999999}, Quantity: 1},
|
||||
{Category: "test", Type: "free_product", Products: []models.RewardProductQuantity{{ProductID: 999999999, Quantity: 1}}},
|
||||
},
|
||||
})
|
||||
setClientPoolPoints(t, username, "pool_0", 20)
|
||||
@@ -241,8 +241,8 @@ func TestClaimMyReward_HTTPFlow_CategoryWithBothTypesSimultaneously(t *testing.T
|
||||
Threshold: 20,
|
||||
Description: "Un produit offert + un produit à -50%",
|
||||
CategoryConfigs: []models.RewardCategoryConfig{
|
||||
{Category: "test", Type: "free_product", ProductIDs: []int{freeProductID}, Quantity: 1},
|
||||
{Category: "test", Type: "half_price_product", ProductIDs: []int{halfProductID}, Quantity: 1},
|
||||
{Category: "test", Type: "free_product", Products: []models.RewardProductQuantity{{ProductID: freeProductID, Quantity: 1}}},
|
||||
{Category: "test", Type: "half_price_product", Products: []models.RewardProductQuantity{{ProductID: halfProductID, Quantity: 1}}},
|
||||
},
|
||||
})
|
||||
setClientPoolPoints(t, username, "pool_0", 20)
|
||||
@@ -279,3 +279,58 @@ func TestClaimMyReward_HTTPFlow_CategoryWithBothTypesSimultaneously(t *testing.T
|
||||
t.Errorf("produit de la config half_price_product: prix attendu = 50%% de 10.00€ = 5.00€: got=%.2f", halfRow.Price)
|
||||
}
|
||||
}
|
||||
|
||||
// Quand une catégorie n'est pas configurée en "tous les produits", chaque
|
||||
// produit sélectionné a sa propre quantité (ex: produit A à 2g offerts,
|
||||
// produit B à 1g offert, tous deux dans la même catégorie et le même type).
|
||||
func TestClaimMyReward_HTTPFlow_PerProductQuantityWithinSameCategoryAndType(t *testing.T) {
|
||||
cleanupStockTestData(t)
|
||||
username := newTestClient(t, "reward_http_per_product_qty")
|
||||
productA := newTestProduct(t, "RewardHTTPPerProductA", 5)
|
||||
productB := newTestProduct(t, "RewardHTTPPerProductB", 5)
|
||||
// newTestProduct crée les deux produits dans la catégorie "test".
|
||||
|
||||
configureRewardSettings(t, &models.PointsReward{
|
||||
Threshold: 20,
|
||||
Description: "Produit A 2g offert, produit B 1g offert",
|
||||
CategoryConfigs: []models.RewardCategoryConfig{
|
||||
{Category: "test", Type: "free_product", Products: []models.RewardProductQuantity{
|
||||
{ProductID: productA, Quantity: 2},
|
||||
{ProductID: productB, Quantity: 1},
|
||||
}},
|
||||
},
|
||||
})
|
||||
setClientPoolPoints(t, username, "pool_0", 20)
|
||||
|
||||
body, _ := json.Marshal(map[string]string{"pool_key": "pool_0"})
|
||||
c, rec := claimRewardContext(username, body)
|
||||
handlers.ClaimMyReward(c)
|
||||
|
||||
if rec.Code != http.StatusOK {
|
||||
t.Fatalf("status HTTP: got=%d body=%s", rec.Code, rec.Body.String())
|
||||
}
|
||||
|
||||
rows := basketRewardItems(t, username)
|
||||
if len(rows) != 2 {
|
||||
t.Fatalf("les deux produits récompense doivent être dans le panier: %+v", rows)
|
||||
}
|
||||
|
||||
var rowA, rowB *rewardBasketRow
|
||||
for i := range rows {
|
||||
switch rows[i].ProductID {
|
||||
case productA:
|
||||
rowA = &rows[i]
|
||||
case productB:
|
||||
rowB = &rows[i]
|
||||
}
|
||||
}
|
||||
if rowA == nil || rowB == nil {
|
||||
t.Fatalf("les deux produits attendus doivent être présents: %+v", rows)
|
||||
}
|
||||
if rowA.Quantity != 2 {
|
||||
t.Errorf("produit A: quantité attendue=2, got=%.2f", rowA.Quantity)
|
||||
}
|
||||
if rowB.Quantity != 1 {
|
||||
t.Errorf("produit B: quantité attendue=1, got=%.2f", rowB.Quantity)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user