mirror of
https://ids-dev.idsbuybuybuy.com/ids-ecommerce/ids-svc-product.git
synced 2026-11-29 16:57:41 +08:00
54 lines
1.6 KiB
Go
54 lines
1.6 KiB
Go
package repository
|
|
|
|
import "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)
|
|
}
|
|
}
|