mirror of
https://ids-dev.idsbuybuybuy.com/ids-ecommerce/ids-svc-product.git
synced 2026-11-29 16:57:41 +08:00
77 lines
2.3 KiB
Go
77 lines
2.3 KiB
Go
package repository
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestEscapeLikeLiteral(t *testing.T) {
|
|
input := `100%_off\\bundle`
|
|
if got, want := escapeLikeLiteral(input), `100\%\_off\\\\bundle`; got != want {
|
|
t.Fatalf("escapeLikeLiteral(%q) = %q, want %q", input, got, want)
|
|
}
|
|
}
|
|
|
|
func TestAggregateInventoryAdjustments(t *testing.T) {
|
|
got, err := aggregateInventoryAdjustments([]InventoryAdjustment{
|
|
{SKUID: "1002", Quantity: 3},
|
|
{SKUID: "1001", Quantity: 1},
|
|
{SKUID: "1001", Quantity: 2},
|
|
})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(got) != 2 {
|
|
t.Fatalf("len = %d, want 2", len(got))
|
|
}
|
|
if got[0] != (InventoryAdjustment{SKUID: "1001", Quantity: 3}) {
|
|
t.Fatalf("first adjustment = %#v", got[0])
|
|
}
|
|
if got[1] != (InventoryAdjustment{SKUID: "1002", Quantity: 3}) {
|
|
t.Fatalf("second adjustment = %#v", got[1])
|
|
}
|
|
}
|
|
|
|
func TestAggregateInventoryAdjustmentsRejectsInvalidSKUID(t *testing.T) {
|
|
_, err := aggregateInventoryAdjustments([]InventoryAdjustment{
|
|
{SKUID: "bad-sku", Quantity: 1},
|
|
})
|
|
if err == nil {
|
|
t.Fatal("expected invalid sku id error")
|
|
}
|
|
}
|
|
|
|
func TestReplaceProductLeafCategoryBindingsRequiresStoreScope(t *testing.T) {
|
|
err := replaceProductLeafCategoryBindings(nil, nil, "1001", []string{"2001"}, []string{"3001"}, StoreScope{})
|
|
if err != ErrStoreScopeRequired {
|
|
t.Fatalf("err = %v, want %v", err, ErrStoreScopeRequired)
|
|
}
|
|
}
|
|
|
|
func TestReplaceProductGroupBindingsRequiresStoreScope(t *testing.T) {
|
|
err := replaceProductGroupBindings(nil, nil, "1001", []string{"2001"}, []string{"3001"}, StoreScope{})
|
|
if err != ErrStoreScopeRequired {
|
|
t.Fatalf("err = %v, want %v", err, ErrStoreScopeRequired)
|
|
}
|
|
}
|
|
|
|
func TestProductListWhereUsesBusinessProductCategoryTree(t *testing.T) {
|
|
where, args := productListWhere(ProductListFilter{ProductCategoryID: "2001"}, StoreScope{StoreID: 1001})
|
|
for _, expected := range []string{
|
|
"WITH RECURSIVE category_descendants",
|
|
"product.product_category c",
|
|
"product.product_category_bindings pcb",
|
|
"pcb.product_category_id",
|
|
} {
|
|
if !strings.Contains(where, expected) {
|
|
t.Fatalf("category predicate missing %q:\n%s", expected, where)
|
|
}
|
|
}
|
|
if strings.Contains(where, "product.product_catalog_bindings") {
|
|
t.Fatalf("category predicate must not query storefront catalog bindings:\n%s", where)
|
|
}
|
|
if len(args) != 2 || args[0] != int64(1001) || args[1] != "2001" {
|
|
t.Fatalf("args = %#v, want [1001 2001]", args)
|
|
}
|
|
}
|