feat: migrar backend unificado a Go 1.27 + SPA Vite embebido
This commit is contained in:
@@ -0,0 +1,218 @@
|
||||
package seed
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"cotizador/internal/auth"
|
||||
)
|
||||
|
||||
func TestSeedDataCounts(t *testing.T) {
|
||||
categorias := DefaultCategorias()
|
||||
if len(categorias) != 7 {
|
||||
t.Fatalf("expected 7 categorias, got %d", len(categorias))
|
||||
}
|
||||
|
||||
servicios := DefaultServicios()
|
||||
if len(servicios) != 58 {
|
||||
t.Fatalf("expected 58 servicios (exact count in prisma/seed.ts), got %d", len(servicios))
|
||||
}
|
||||
|
||||
// 1 paquete-general + 6 paquetes PyME = 7 paquetes total
|
||||
paquetesPyme := DefaultPaquetesPyme()
|
||||
if len(paquetesPyme) != 6 {
|
||||
t.Fatalf("expected 6 paquetes PyME (7 total with paquete-general), got %d", len(paquetesPyme))
|
||||
}
|
||||
if len(DefaultFasesGeneral()) != 4 {
|
||||
t.Fatalf("expected 4 fases in paquete-general, got %d", len(DefaultFasesGeneral()))
|
||||
}
|
||||
|
||||
bonos := DefaultBonos()
|
||||
if len(bonos) != 6 {
|
||||
t.Fatalf("expected 6 bonos, got %d", len(bonos))
|
||||
}
|
||||
|
||||
planes := DefaultFinanciamientoPlanes()
|
||||
if len(planes) != 4 {
|
||||
t.Fatalf("expected 4 financiamiento planes, got %d", len(planes))
|
||||
}
|
||||
expectedMeses := []int{3, 6, 9, 12}
|
||||
for i, m := range expectedMeses {
|
||||
if planes[i].Meses != m {
|
||||
t.Errorf("plan[%d].Meses = %d, want %d", i, planes[i].Meses, m)
|
||||
}
|
||||
}
|
||||
|
||||
configs := DefaultConfigs()
|
||||
if len(configs) != 16 {
|
||||
t.Fatalf("expected 16 config keys, got %d", len(configs))
|
||||
}
|
||||
}
|
||||
|
||||
func TestServicioIDsAndSoloAdmin(t *testing.T) {
|
||||
servicios := DefaultServicios()
|
||||
seen := make(map[string]bool, len(servicios))
|
||||
soloAdminIDs := make(map[string]bool)
|
||||
|
||||
for _, s := range servicios {
|
||||
id := ServicioID(s.Nombre, s.Orden)
|
||||
if seen[id] {
|
||||
t.Fatalf("duplicate servicio ID: %s", id)
|
||||
}
|
||||
seen[id] = true
|
||||
|
||||
if IsSoloAdmin(id, s.Nombre, s.SoloAdmin) {
|
||||
soloAdminIDs[id] = true
|
||||
}
|
||||
}
|
||||
|
||||
// Verify exact known slug IDs from prisma/seed.ts
|
||||
for _, want := range []string{
|
||||
"auditoria-en-sitio-web-2",
|
||||
"configuracion-y-puesta-en-marc-12",
|
||||
"plan-mensual-crm-bucefalo-18",
|
||||
"logo-e-identidad-101",
|
||||
"estrategia-empresarial-en-ecom-100",
|
||||
} {
|
||||
if !seen[want] {
|
||||
t.Errorf("expected slug ID %q not found in DefaultServicios", want)
|
||||
}
|
||||
}
|
||||
|
||||
// Verify soloAdmin flags on Bucefalo CRM items
|
||||
if len(soloAdminIDs) != 2 {
|
||||
t.Fatalf("expected exactly 2 soloAdmin servicios, got %d: %v", len(soloAdminIDs), soloAdminIDs)
|
||||
}
|
||||
if !soloAdminIDs["configuracion-y-puesta-en-marc-12"] {
|
||||
t.Errorf("expected configuracion-y-puesta-en-marc-12 to be soloAdmin")
|
||||
}
|
||||
if !soloAdminIDs["plan-mensual-crm-bucefalo-18"] {
|
||||
t.Errorf("expected plan-mensual-crm-bucefalo-18 to be soloAdmin")
|
||||
}
|
||||
|
||||
// Accented/case-insensitive Bucefalo detection
|
||||
if !IsSoloAdmin("otro-1", "Servicio Bucéfalo Extra", false) {
|
||||
t.Errorf("expected accented Bucéfalo name to trigger soloAdmin")
|
||||
}
|
||||
if IsSoloAdmin("auditoria-en-sitio-web-2", "Auditoria en Sitio Web", false) {
|
||||
t.Errorf("expected normal service NOT to trigger soloAdmin")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCategoriasAndPaqueteReferences(t *testing.T) {
|
||||
catSet := make(map[string]bool)
|
||||
for _, c := range DefaultCategorias() {
|
||||
catSet[c.Nombre] = true
|
||||
}
|
||||
|
||||
catAlias := DefaultCatAlias()
|
||||
var rows []servicioRow
|
||||
for _, s := range DefaultServicios() {
|
||||
catNombre, ok := catAlias[s.Categoria]
|
||||
if !ok {
|
||||
t.Errorf("servicio %q has unknown categoria alias %q", s.Nombre, s.Categoria)
|
||||
}
|
||||
if !catSet[catNombre] {
|
||||
t.Errorf("catAlias %q -> %q not found in DefaultCategorias", s.Categoria, catNombre)
|
||||
}
|
||||
var nivelPtr *string
|
||||
if s.Nivel != "" {
|
||||
n := s.Nivel
|
||||
nivelPtr = &n
|
||||
}
|
||||
rows = append(rows, servicioRow{
|
||||
ID: ServicioID(s.Nombre, s.Orden),
|
||||
Nombre: s.Nombre,
|
||||
Fase: s.Fase,
|
||||
Nivel: nivelPtr,
|
||||
})
|
||||
}
|
||||
|
||||
// Every service referenced in all 6 PyME packages must resolve uniquely
|
||||
for _, pq := range DefaultPaquetesPyme() {
|
||||
if !strings.HasPrefix(pq.ID, "paquete-") {
|
||||
t.Errorf("unexpected paquete ID %q", pq.ID)
|
||||
}
|
||||
for _, f := range pq.Fases {
|
||||
for _, ref := range f.Servicios {
|
||||
id, err := findServicioID(rows, ref.Nombre, ref.Nivel)
|
||||
if err != nil {
|
||||
t.Errorf("paquete %s fase %d: %v", pq.ID, f.Orden, err)
|
||||
}
|
||||
if id == "" {
|
||||
t.Errorf("paquete %s fase %d: empty id for %s", pq.ID, f.Orden, ref.Nombre)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigKeysUnique(t *testing.T) {
|
||||
seen := make(map[string]bool)
|
||||
for _, c := range DefaultConfigs() {
|
||||
if seen[c.Clave] {
|
||||
t.Fatalf("duplicate config clave: %s", c.Clave)
|
||||
}
|
||||
seen[c.Clave] = true
|
||||
}
|
||||
for _, required := range []string{"razon_social", "rfc", "clabe_interbancaria", "color_primario", "color_secundario", "logo_base64", "iva"} {
|
||||
if !seen[required] {
|
||||
t.Errorf("missing required config key %q", required)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestProvisionArgsAndPresets(t *testing.T) {
|
||||
// Presets sanity
|
||||
presets := DefaultAgentPresets()
|
||||
if len(presets) != 5 {
|
||||
t.Fatalf("expected 5 agent presets, got %d", len(presets))
|
||||
}
|
||||
for _, p := range presets {
|
||||
for _, sc := range p.Scopes {
|
||||
if !auth.IsValidScope(sc) {
|
||||
t.Errorf("preset %s has invalid scope %q", p.Nombre, sc)
|
||||
}
|
||||
if strings.Contains(sc, "aprobar") {
|
||||
t.Errorf("preset %s must NEVER contain an approval scope: %q", p.Nombre, sc)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// --list
|
||||
opts, err := parseProvisionArgs([]string{"--list"})
|
||||
if err != nil || !opts.List {
|
||||
t.Fatalf("expected --list to parse cleanly, got opts=%+v err=%v", opts, err)
|
||||
}
|
||||
|
||||
// --preset --rotate
|
||||
opts, err = parseProvisionArgs([]string{"--preset", "--rotate"})
|
||||
if err != nil || !opts.Preset || !opts.Rotate {
|
||||
t.Fatalf("expected --preset --rotate to parse cleanly, got opts=%+v err=%v", opts, err)
|
||||
}
|
||||
|
||||
// --nombre with valid scopes and rate limit
|
||||
opts, err = parseProvisionArgs([]string{
|
||||
"--nombre", "custom-agent",
|
||||
"--scopes", "catalogo:leer,clientes:leer",
|
||||
"--rate-limit", "90",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
if opts.Nombre != "custom-agent" || len(opts.Scopes) != 2 || opts.RateLimitPerMin != 90 || !opts.HasRateLimit {
|
||||
t.Fatalf("unexpected parsed opts: %+v", opts)
|
||||
}
|
||||
|
||||
// invalid scope rejected
|
||||
_, err = parseProvisionArgs([]string{"--nombre", "bad", "--scopes", "cotizaciones:aprobar"})
|
||||
if err == nil {
|
||||
t.Fatalf("expected error for invalid approval scope")
|
||||
}
|
||||
|
||||
// missing action rejected
|
||||
_, err = parseProvisionArgs([]string{})
|
||||
if err == nil {
|
||||
t.Fatalf("expected usage error when no flags given")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user