ids-svc-product/internal/repository/product_repository_test.go
robinj0726 604dfeb06c feat: implement store scope validation and enforce it in product repository
- Added StoreScope struct with TenantID and StoreID fields.
- Introduced ErrStoreScopeRequired to handle missing store scope.
- Implemented Valid method to check if both TenantID and StoreID are present.
- Created requireWriteScope function to validate store scope before write operations.
- Updated product repository methods to require store scope for various operations.
- Added tests for StoreScope validation and requirement enforcement.
2026-09-13 00:12:44 +08:00

47 lines
1.3 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)
}
}