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.
34 lines
923 B
Go
34 lines
923 B
Go
package repository
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/jackc/pgx/v5/pgconn"
|
|
)
|
|
|
|
func TestStoreScopeValid(t *testing.T) {
|
|
if (StoreScope{}).Valid() {
|
|
t.Fatal("empty scope must be invalid")
|
|
}
|
|
if !(StoreScope{TenantID: 1, StoreID: 2}).Valid() {
|
|
t.Fatal("complete scope must be valid")
|
|
}
|
|
}
|
|
|
|
func TestRequireWriteScope(t *testing.T) {
|
|
if err := requireWriteScope(StoreScope{}); err != ErrStoreScopeRequired {
|
|
t.Fatalf("empty scope err = %v", err)
|
|
}
|
|
}
|
|
|
|
func TestDuplicateSPUNoConstraintNames(t *testing.T) {
|
|
old := &pgconn.PgError{Code: "23505", ConstraintName: "uq_products_spu_no"}
|
|
if !isPostgresConstraintError(old, "23505", "uq_products_spu_no") {
|
|
t.Fatal("old spu unique name must match")
|
|
}
|
|
next := &pgconn.PgError{Code: "23505", ConstraintName: "uq_products_store_spu_no"}
|
|
if !isPostgresConstraintError(next, "23505", "uq_products_store_spu_no") {
|
|
t.Fatal("store-scoped spu unique name must match")
|
|
}
|
|
}
|