chore: build
This commit is contained in:
@@ -278,6 +278,55 @@ func TestUpdateProduct_UpdatesStockWhenProvided(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// productPriceActiveFlags relit active_price par palier de quantité pour un
|
||||
// produit, directement en base.
|
||||
func productPriceActiveFlags(t *testing.T, productID int) map[float64]bool {
|
||||
t.Helper()
|
||||
var rows []struct {
|
||||
Quantity float64 `gorm:"column:quantity"`
|
||||
ActivePrice bool `gorm:"column:active_price"`
|
||||
}
|
||||
if err := testDB.GDB.Raw(
|
||||
`SELECT quantity, active_price FROM product_prices WHERE product_id = ?`, productID,
|
||||
).Scan(&rows).Error; err != nil {
|
||||
t.Fatalf("lecture active_price: %v", err)
|
||||
}
|
||||
out := make(map[float64]bool, len(rows))
|
||||
for _, r := range rows {
|
||||
out[r.Quantity] = r.ActivePrice
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// Un prix explicitement désactivé (active_price=false) doit rester désactivé
|
||||
// après UpdateProduct — piège classique de GORM : un champ bool à sa valeur
|
||||
// zéro (false) avec un tag gorm "default" est omis de l'INSERT, laissant la
|
||||
// base appliquer son propre défaut (TRUE) à la place. Voir le commentaire sur
|
||||
// ProductPrice.ActivePrice dans models/product.go.
|
||||
func TestUpdateProduct_PersistsInactivePriceFlag(t *testing.T) {
|
||||
cleanupStockTestData(t)
|
||||
cat := newTestCategory(t, "CatInactive")
|
||||
productID := newTestProduct(t, "UPInactive", 5)
|
||||
|
||||
body := []byte(fmt.Sprintf(
|
||||
`{"name":"UPInactive","category":%q,"description":"d2","unit":"g","stock":10,"prices":[{"quantity":1,"price":5,"active_price":false},{"quantity":5,"price":20,"active_price":true}]}`,
|
||||
cat,
|
||||
))
|
||||
c, rec := updateProductJSONContext("admin", body, productID)
|
||||
handlers.UpdateProduct(c)
|
||||
if rec.Code != http.StatusOK {
|
||||
t.Fatalf("UpdateProduct valide doit réussir: got=%d body=%s", rec.Code, rec.Body.String())
|
||||
}
|
||||
|
||||
flags := productPriceActiveFlags(t, productID)
|
||||
if flags[1] != false {
|
||||
t.Errorf("palier qty=1 doit rester désactivé après UpdateProduct: got active_price=%v", flags[1])
|
||||
}
|
||||
if flags[5] != true {
|
||||
t.Errorf("palier qty=5 doit rester actif après UpdateProduct: got active_price=%v", flags[5])
|
||||
}
|
||||
}
|
||||
|
||||
// ── DeleteProduct ────────────────────────────────────────────────────────
|
||||
|
||||
func TestDeleteProduct_RemovesProductWithoutMedia(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user