Files
quasar/backend/dist/tests/models/game.spec.js
Benito Rodríguez a07096d7c7
Some checks failed
CI / lint (push) Failing after 1m5s
CI / test-backend (push) Has been skipped
CI / test-frontend (push) Has been skipped
CI / test-e2e (push) Has been skipped
feat: add UI components for alert dialog, badge, checkbox, dialog, label, select, sheet, table, textarea
- Implemented AlertDialog component with overlay, content, header, footer, title, description, action, and cancel functionalities.
- Created Badge component with variant support for different styles.
- Developed Checkbox component with custom styling and indicator.
- Added Dialog component with trigger, close, overlay, content, header, footer, title, and description.
- Introduced Label component for form elements.
- Built Select component with trigger, content, group, item, label, separator, and scroll buttons.
- Created Sheet component with trigger, close, overlay, content, header, footer, title, and description.
- Implemented Table component with header, body, footer, row, head, cell, and caption.
- Added Textarea component with custom styling.
- Established API service for game management with CRUD operations and metadata search functionalities.
- Updated dependencies in package lock files.
2026-03-18 19:21:36 +01:00

90 lines
3.8 KiB
JavaScript

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const fs_1 = __importDefault(require("fs"));
const os_1 = __importDefault(require("os"));
const path_1 = __importDefault(require("path"));
const child_process_1 = require("child_process");
const vitest_1 = require("vitest");
// Import PrismaClient dynamically after running `prisma generate`
// to allow the test setup to run `prisma generate`/`prisma migrate` first.
// Nota: Estos tests siguen TDD. Al principio deben FALLAR hasta que se creen migraciones.
(0, vitest_1.describe)('Prisma / Game model', () => {
const tmpDir = os_1.default.tmpdir();
const dbFile = path_1.default.join(tmpDir, `quasar-test-${Date.now()}-${Math.random().toString(36).slice(2)}.db`);
const databaseUrl = `file:${dbFile}`;
let prisma;
(0, vitest_1.beforeAll)(async () => {
// Asegurarse de que la DB de prueba no exista antes de empezar
try {
fs_1.default.unlinkSync(dbFile);
}
catch (e) {
/* ignore */
}
// Apuntar Prisma a la DB temporal
process.env.DATABASE_URL = databaseUrl;
// Ejecutar migraciones contra la DB de prueba
// Esto fallará si no hay migraciones: esperado en la fase TDD inicial
(0, child_process_1.execSync)('yarn prisma migrate deploy --schema=./prisma/schema.prisma', {
stdio: 'inherit',
cwd: path_1.default.resolve(__dirname, '..', '..'),
});
// Intentar requerir el cliente generado; si no existe, intentar generarlo (fallback)
let GeneratedPrismaClient;
try {
// eslint-disable-next-line @typescript-eslint/no-var-requires
GeneratedPrismaClient = require('@prisma/client').PrismaClient;
}
catch (e) {
try {
(0, child_process_1.execSync)('yarn prisma generate --schema=./prisma/schema.prisma', {
stdio: 'inherit',
cwd: path_1.default.resolve(__dirname, '..', '..'),
});
// eslint-disable-next-line @typescript-eslint/no-var-requires
GeneratedPrismaClient = require('@prisma/client').PrismaClient;
}
catch (err) {
// Si generation falla (por ejemplo PnP), reintentar require para mostrar mejor error
// eslint-disable-next-line @typescript-eslint/no-var-requires
GeneratedPrismaClient = require('@prisma/client').PrismaClient;
}
}
prisma = new GeneratedPrismaClient();
await prisma.$connect();
});
(0, vitest_1.afterAll)(async () => {
if (prisma) {
await prisma.$disconnect();
}
try {
fs_1.default.unlinkSync(dbFile);
}
catch (e) {
/* ignore */
}
});
(0, vitest_1.it)('can create a Game and read title/slug', async () => {
const created = await prisma.game.create({ data: { title: 'Test Game', slug: 'test-game' } });
const found = await prisma.game.findUnique({ where: { id: created.id } });
(0, vitest_1.expect)(found).toBeTruthy();
(0, vitest_1.expect)(found?.title).toBe('Test Game');
(0, vitest_1.expect)(found?.slug).toBe('test-game');
});
(0, vitest_1.it)('enforces unique slug constraint', async () => {
const slug = `unique-${Date.now()}`;
await prisma.game.create({ data: { title: 'G1', slug } });
let threw = false;
try {
await prisma.game.create({ data: { title: 'G2', slug } });
}
catch (err) {
threw = true;
}
(0, vitest_1.expect)(threw).toBe(true);
});
});