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") } }