187 lines
6.5 KiB
TypeScript
187 lines
6.5 KiB
TypeScript
|
|
// Script para probar y verificar los endpoints del User Dashboard
|
|||
|
|
// Ejecutar con: node --loader ts-node/esm test-user-endpoints.ts
|
|||
|
|
|
|||
|
|
import { PrismaClient } from '@prisma/client'
|
|||
|
|
|
|||
|
|
const prisma = new PrismaClient()
|
|||
|
|
|
|||
|
|
async function testUserEndpoints() {
|
|||
|
|
console.log('🧪 Testing User Dashboard Endpoints...\n')
|
|||
|
|
|
|||
|
|
// ID de usuario de prueba (reemplazar con tu Discord ID)
|
|||
|
|
const TEST_USER_ID = '123456789' // CAMBIAR POR TU ID
|
|||
|
|
|
|||
|
|
try {
|
|||
|
|
// ========================================
|
|||
|
|
// 1. VERIFICAR/CREAR SUSCRIPCIÓN
|
|||
|
|
// ========================================
|
|||
|
|
console.log('1️⃣ Verificando UserSubscription...')
|
|||
|
|
|
|||
|
|
let subscription = await prisma.userSubscription.findUnique({
|
|||
|
|
where: { userId: TEST_USER_ID }
|
|||
|
|
})
|
|||
|
|
|
|||
|
|
if (!subscription) {
|
|||
|
|
console.log(' ⚠️ No se encontró suscripción. Creando una de prueba...')
|
|||
|
|
|
|||
|
|
// Primero asegurar que el usuario existe
|
|||
|
|
await prisma.user.upsert({
|
|||
|
|
where: { id: TEST_USER_ID },
|
|||
|
|
create: {
|
|||
|
|
id: TEST_USER_ID,
|
|||
|
|
username: 'TestUser',
|
|||
|
|
discriminator: '0000',
|
|||
|
|
avatar: null
|
|||
|
|
},
|
|||
|
|
update: {}
|
|||
|
|
})
|
|||
|
|
|
|||
|
|
// Luego crear la suscripción
|
|||
|
|
subscription = await prisma.userSubscription.create({
|
|||
|
|
data: {
|
|||
|
|
user: { connect: { id: TEST_USER_ID } },
|
|||
|
|
importLimit: 500,
|
|||
|
|
maxVolume: 200,
|
|||
|
|
recommendationLevel: 'pro',
|
|||
|
|
expiresAt: new Date(Date.now() + 30 * 24 * 60 * 60 * 1000) // 30 días
|
|||
|
|
}
|
|||
|
|
})
|
|||
|
|
console.log(' ✅ Suscripción creada:', subscription)
|
|||
|
|
} else {
|
|||
|
|
console.log(' ✅ Suscripción encontrada:', subscription)
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// ========================================
|
|||
|
|
// 2. VERIFICAR/CREAR PLAYLISTS
|
|||
|
|
// ========================================
|
|||
|
|
console.log('\n2️⃣ Verificando MusicPlaylists...')
|
|||
|
|
|
|||
|
|
const existingPlaylists = await prisma.musicPlaylist.findMany({
|
|||
|
|
where: { userId: TEST_USER_ID },
|
|||
|
|
include: { _count: { select: { tracks: true } } }
|
|||
|
|
})
|
|||
|
|
|
|||
|
|
if (existingPlaylists.length === 0) {
|
|||
|
|
console.log(' ⚠️ No se encontraron playlists. Creando algunas de prueba...')
|
|||
|
|
|
|||
|
|
const guildId = '987654321' // ID de prueba de servidor
|
|||
|
|
|
|||
|
|
const playlist1 = await prisma.musicPlaylist.create({
|
|||
|
|
data: {
|
|||
|
|
userId: TEST_USER_ID,
|
|||
|
|
guildId: guildId,
|
|||
|
|
name: 'Favoritas',
|
|||
|
|
description: 'Mis canciones favoritas',
|
|||
|
|
isDefault: true
|
|||
|
|
}
|
|||
|
|
})
|
|||
|
|
|
|||
|
|
const playlist2 = await prisma.musicPlaylist.create({
|
|||
|
|
data: {
|
|||
|
|
userId: TEST_USER_ID,
|
|||
|
|
guildId: guildId,
|
|||
|
|
name: 'Rock Épico',
|
|||
|
|
description: 'Lo mejor del rock clásico',
|
|||
|
|
isDefault: false
|
|||
|
|
}
|
|||
|
|
})
|
|||
|
|
|
|||
|
|
console.log(' ✅ Playlists creadas:', [playlist1.name, playlist2.name])
|
|||
|
|
} else {
|
|||
|
|
console.log(` ✅ ${existingPlaylists.length} playlists encontradas:`)
|
|||
|
|
existingPlaylists.forEach(p => {
|
|||
|
|
console.log(` - ${p.name} (${p._count.tracks} tracks)`)
|
|||
|
|
})
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// ========================================
|
|||
|
|
// 3. CREAR CUPÓN DE PRUEBA
|
|||
|
|
// ========================================
|
|||
|
|
console.log('\n3️⃣ Creando cupón de prueba...')
|
|||
|
|
|
|||
|
|
const COUPON_CODE = 'TEST-VIP-2024'
|
|||
|
|
|
|||
|
|
let coupon = await prisma.coupon.findUnique({
|
|||
|
|
where: { code: COUPON_CODE }
|
|||
|
|
})
|
|||
|
|
|
|||
|
|
if (!coupon) {
|
|||
|
|
coupon = await prisma.coupon.create({
|
|||
|
|
data: {
|
|||
|
|
code: COUPON_CODE,
|
|||
|
|
type: 'ALL_ACCESS',
|
|||
|
|
value: 1000,
|
|||
|
|
maxUses: 10,
|
|||
|
|
usedCount: 0,
|
|||
|
|
daysValid: 30,
|
|||
|
|
expiresAt: new Date(Date.now() + 365 * 24 * 60 * 60 * 1000), // 1 año
|
|||
|
|
createdBy: 'system'
|
|||
|
|
}
|
|||
|
|
})
|
|||
|
|
console.log(` ✅ Cupón creado: ${COUPON_CODE}`)
|
|||
|
|
} else {
|
|||
|
|
console.log(` ✅ Cupón ya existe: ${COUPON_CODE}`)
|
|||
|
|
}
|
|||
|
|
console.log(` Usos: ${coupon.usedCount}/${coupon.maxUses}`)
|
|||
|
|
console.log(` Expira: ${coupon.expiresAt}`)
|
|||
|
|
|
|||
|
|
// ========================================
|
|||
|
|
// 4. VERIFICAR ESTRUCTURA DE RESPUESTA
|
|||
|
|
// ========================================
|
|||
|
|
console.log('\n4️⃣ Simulando respuesta de /api/user/me...')
|
|||
|
|
|
|||
|
|
const userDataResponse = {
|
|||
|
|
id: TEST_USER_ID,
|
|||
|
|
username: 'TestUser',
|
|||
|
|
avatar: null,
|
|||
|
|
subscription: subscription,
|
|||
|
|
level: 1,
|
|||
|
|
xp: 0,
|
|||
|
|
nextLevelXp: 100
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
console.log(' ✅ Estructura correcta:', JSON.stringify(userDataResponse, null, 2))
|
|||
|
|
|
|||
|
|
console.log('\n5️⃣ Simulando respuesta de /api/user/playlists...')
|
|||
|
|
const playlists = await prisma.musicPlaylist.findMany({
|
|||
|
|
where: { userId: TEST_USER_ID },
|
|||
|
|
include: { _count: { select: { tracks: true } } },
|
|||
|
|
orderBy: { updatedAt: 'desc' }
|
|||
|
|
})
|
|||
|
|
console.log(` ✅ ${playlists.length} playlists retornadas`)
|
|||
|
|
|
|||
|
|
// ========================================
|
|||
|
|
// RESUMEN
|
|||
|
|
// ========================================
|
|||
|
|
console.log('\n' + '='.repeat(50))
|
|||
|
|
console.log('✅ VERIFICACIÓN COMPLETADA')
|
|||
|
|
console.log('='.repeat(50))
|
|||
|
|
console.log(`
|
|||
|
|
📊 Resumen:
|
|||
|
|
- Usuario: ${TEST_USER_ID}
|
|||
|
|
- Suscripción VIP: ${subscription.expiresAt ? 'Activa hasta ' + subscription.expiresAt.toLocaleDateString() : 'Inactiva'}
|
|||
|
|
- Playlists: ${playlists.length}
|
|||
|
|
- Cupón de prueba: ${COUPON_CODE}
|
|||
|
|
|
|||
|
|
🧪 Para probar manualmente:
|
|||
|
|
1. Inicia sesión en http://localhost:5173
|
|||
|
|
2. Ve a /dash/me
|
|||
|
|
3. Deberías ver:
|
|||
|
|
✓ VIP Status: "VIP Active"
|
|||
|
|
✓ Volume Limit: ${subscription.maxVolume}%
|
|||
|
|
✓ Import Limit: ${subscription.importLimit}
|
|||
|
|
4. Canjea el cupón: ${COUPON_CODE}
|
|||
|
|
`)
|
|||
|
|
|
|||
|
|
} catch (error) {
|
|||
|
|
console.error('❌ Error:', error)
|
|||
|
|
} finally {
|
|||
|
|
await prisma.$disconnect()
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// Ejecutar
|
|||
|
|
testUserEndpoints()
|
|||
|
|
.then(() => process.exit(0))
|
|||
|
|
.catch(console.error)
|