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