diff --git a/internal/repository/product_batch.go b/internal/repository/product_batch.go index ba78151..053300e 100644 --- a/internal/repository/product_batch.go +++ b/internal/repository/product_batch.go @@ -242,12 +242,13 @@ WHERE store_id = $1 return ErrProductNotFound } + skuPH, skuArgs := productIDPlaceholders(parsed, 1) if _, err := tx.ExecContext(ctx, fmt.Sprintf(` UPDATE product.product_items SET deleted_at = COALESCE(deleted_at, NOW()), updated_at = NOW() WHERE deleted_at IS NULL AND product_id IN (%s) -`, ph), args...); err != nil { +`, skuPH), skuArgs...); err != nil { return fmt.Errorf("batch delete product skus: %w", err) } diff --git a/internal/repository/product_batch_test.go b/internal/repository/product_batch_test.go index 4c632d5..8e25dc7 100644 --- a/internal/repository/product_batch_test.go +++ b/internal/repository/product_batch_test.go @@ -1,6 +1,9 @@ package repository -import "testing" +import ( + "reflect" + "testing" +) func TestParseBatchProductIDs(t *testing.T) { parsed, unique, err := parseBatchProductIDs([]string{" 11111 ", "11111", "22222"}) @@ -18,3 +21,20 @@ func TestParseBatchProductIDs(t *testing.T) { t.Fatal("parseBatchProductIDs(nil) error = nil, want required") } } + +func TestProductIDPlaceholders(t *testing.T) { + ids := []int64{11111, 22222} + + gotPlaceholders, gotArgs := productIDPlaceholders(ids, 1) + if gotPlaceholders != "$1, $2" { + t.Fatalf("placeholders starting at 1 = %q, want %q", gotPlaceholders, "$1, $2") + } + if !reflect.DeepEqual(gotArgs, []any{int64(11111), int64(22222)}) { + t.Fatalf("args = %v, want [11111 22222]", gotArgs) + } + + gotPlaceholders, _ = productIDPlaceholders(ids, 2) + if gotPlaceholders != "$2, $3" { + t.Fatalf("placeholders starting at 2 = %q, want %q", gotPlaceholders, "$2, $3") + } +}