parent item mutations
Build and Publish / BuildAndDeployAmd64 (push) Failing after 5s
Build and Publish / BuildAndDeployArm64 (push) Failing after 7s

This commit is contained in:
2026-07-08 11:39:42 +02:00
parent e20793a6b3
commit 9f1eca07e9
14 changed files with 784 additions and 103 deletions
+30
View File
@@ -38,3 +38,33 @@ func TestAddItem_MergesByItemIdNotSku(t *testing.T) {
t.Fatalf("items = %d, want 2", len(g.Items))
}
}
// Re-adding the same parent (same ItemId + StoreId, no ParentId on the
// re-add itself) merges the quantity, and the proportional cascade resizes
// every direct child to match the new parent qty so a "+1 drill" leaves
// the bundle internally consistent.
func TestAddItem_MergeCascadesToChildren(t *testing.T) {
reg := NewCartMultationRegistry(NewCartMutationContext(nil))
g := NewCartGrain(1, time.Now())
ctx := context.Background()
if _, err := reg.Apply(ctx, g, &cart_messages.AddItem{ItemId: 100, Sku: "P", Quantity: 1, Price: 1000}); err != nil {
t.Fatalf("add parent: %v", err)
}
parentLine := g.Items[0].Id
if _, err := reg.Apply(ctx, g, &cart_messages.AddItem{ItemId: 101, Sku: "C1", Quantity: 1, Price: 100, ParentId: &parentLine}); err != nil {
t.Fatalf("add child: %v", err)
}
// Re-add the same parent — same ItemId, no ParentId on the re-add itself.
if _, err := reg.Apply(ctx, g, &cart_messages.AddItem{ItemId: 100, Sku: "P", Quantity: 1, Price: 1000}); err != nil {
t.Fatalf("re-add parent: %v", err)
}
// Parent qty 1 -> 2; child qty 1 -> 2 via cascade.
for _, it := range g.Items {
if it.Quantity != 2 {
t.Errorf("line %s qty = %d, want 2 (merge cascade)", it.Sku, it.Quantity)
}
}
}