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.
This commit is contained in:
228
backend/dist/tests/routes/games.spec.js
vendored
Normal file
228
backend/dist/tests/routes/games.spec.js
vendored
Normal file
@@ -0,0 +1,228 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const vitest_1 = require("vitest");
|
||||
const app_1 = require("../../src/app");
|
||||
const prisma_1 = require("../../src/plugins/prisma");
|
||||
(0, vitest_1.describe)('Games API', () => {
|
||||
let app;
|
||||
(0, vitest_1.beforeEach)(async () => {
|
||||
app = (0, app_1.buildApp)();
|
||||
await app.ready();
|
||||
// Limpiar base de datos antes de cada test
|
||||
// Orden importante: relaciones de FK primero
|
||||
await prisma_1.prisma.purchase.deleteMany();
|
||||
await prisma_1.prisma.gamePlatform.deleteMany();
|
||||
await prisma_1.prisma.artwork.deleteMany();
|
||||
await prisma_1.prisma.priceHistory.deleteMany();
|
||||
await prisma_1.prisma.game.deleteMany();
|
||||
await prisma_1.prisma.platform.deleteMany();
|
||||
});
|
||||
(0, vitest_1.afterEach)(async () => {
|
||||
await app.close();
|
||||
});
|
||||
(0, vitest_1.describe)('GET /api/games', () => {
|
||||
(0, vitest_1.it)('debería devolver una lista vacía cuando no hay juegos', async () => {
|
||||
const res = await app.inject({
|
||||
method: 'GET',
|
||||
url: '/api/games',
|
||||
});
|
||||
(0, vitest_1.expect)(res.statusCode).toBe(200);
|
||||
(0, vitest_1.expect)(res.json()).toEqual([]);
|
||||
});
|
||||
(0, vitest_1.it)('debería devolver una lista de juegos con todas sus propiedades', async () => {
|
||||
// Crear un juego de prueba
|
||||
const platform = await prisma_1.prisma.platform.create({
|
||||
data: { name: 'Nintendo', slug: 'nintendo' },
|
||||
});
|
||||
const game = await prisma_1.prisma.game.create({
|
||||
data: {
|
||||
title: 'The Legend of Zelda',
|
||||
slug: 'legend-of-zelda',
|
||||
description: 'Un videojuego clásico',
|
||||
source: 'manual',
|
||||
gamePlatforms: {
|
||||
create: {
|
||||
platformId: platform.id,
|
||||
},
|
||||
},
|
||||
purchases: {
|
||||
create: {
|
||||
priceCents: 5000,
|
||||
currency: 'USD',
|
||||
store: 'eBay',
|
||||
date: new Date('2025-01-15'),
|
||||
},
|
||||
},
|
||||
},
|
||||
include: {
|
||||
gamePlatforms: {
|
||||
include: {
|
||||
platform: true,
|
||||
},
|
||||
},
|
||||
purchases: true,
|
||||
},
|
||||
});
|
||||
const res = await app.inject({
|
||||
method: 'GET',
|
||||
url: '/api/games',
|
||||
});
|
||||
(0, vitest_1.expect)(res.statusCode).toBe(200);
|
||||
const body = res.json();
|
||||
(0, vitest_1.expect)(Array.isArray(body)).toBe(true);
|
||||
(0, vitest_1.expect)(body.length).toBe(1);
|
||||
(0, vitest_1.expect)(body[0]).toHaveProperty('id');
|
||||
(0, vitest_1.expect)(body[0]).toHaveProperty('title');
|
||||
});
|
||||
});
|
||||
(0, vitest_1.describe)('POST /api/games', () => {
|
||||
(0, vitest_1.it)('debería crear un juego válido con todos los campos', async () => {
|
||||
// Crear plataforma primero
|
||||
const platform = await prisma_1.prisma.platform.create({
|
||||
data: { name: 'Nintendo 64', slug: 'n64' },
|
||||
});
|
||||
const payload = {
|
||||
title: 'Super Mario 64',
|
||||
platformId: platform.id,
|
||||
description: 'Notas sobre el juego',
|
||||
priceCents: 15000,
|
||||
currency: 'USD',
|
||||
store: 'Local Shop',
|
||||
date: '2025-01-20',
|
||||
condition: 'CIB',
|
||||
};
|
||||
const res = await app.inject({
|
||||
method: 'POST',
|
||||
url: '/api/games',
|
||||
payload,
|
||||
});
|
||||
(0, vitest_1.expect)(res.statusCode).toBe(201);
|
||||
const body = res.json();
|
||||
(0, vitest_1.expect)(body).toHaveProperty('id');
|
||||
(0, vitest_1.expect)(body.title).toBe('Super Mario 64');
|
||||
(0, vitest_1.expect)(body.description).toBe('Notas sobre el juego');
|
||||
});
|
||||
(0, vitest_1.it)('debería fallar si falta el título (requerido)', async () => {
|
||||
const res = await app.inject({
|
||||
method: 'POST',
|
||||
url: '/api/games',
|
||||
payload: {
|
||||
platformId: 'non-existing-id',
|
||||
priceCents: 10000,
|
||||
},
|
||||
});
|
||||
(0, vitest_1.expect)(res.statusCode).toBe(400);
|
||||
});
|
||||
(0, vitest_1.it)('debería fallar si el título está vacío', async () => {
|
||||
const res = await app.inject({
|
||||
method: 'POST',
|
||||
url: '/api/games',
|
||||
payload: {
|
||||
title: '',
|
||||
platformId: 'some-id',
|
||||
},
|
||||
});
|
||||
(0, vitest_1.expect)(res.statusCode).toBe(400);
|
||||
});
|
||||
(0, vitest_1.it)('debería crear un juego con solo los campos requeridos', async () => {
|
||||
const res = await app.inject({
|
||||
method: 'POST',
|
||||
url: '/api/games',
|
||||
payload: {
|
||||
title: 'Game Title Only',
|
||||
},
|
||||
});
|
||||
(0, vitest_1.expect)(res.statusCode).toBe(201);
|
||||
const body = res.json();
|
||||
(0, vitest_1.expect)(body).toHaveProperty('id');
|
||||
(0, vitest_1.expect)(body.title).toBe('Game Title Only');
|
||||
});
|
||||
});
|
||||
(0, vitest_1.describe)('PUT /api/games/:id', () => {
|
||||
(0, vitest_1.it)('debería actualizar un juego existente', async () => {
|
||||
const game = await prisma_1.prisma.game.create({
|
||||
data: {
|
||||
title: 'Original Title',
|
||||
slug: 'original-title',
|
||||
source: 'manual',
|
||||
},
|
||||
});
|
||||
const res = await app.inject({
|
||||
method: 'PUT',
|
||||
url: `/api/games/${game.id}`,
|
||||
payload: {
|
||||
title: 'Updated Title',
|
||||
description: 'Updated description',
|
||||
},
|
||||
});
|
||||
(0, vitest_1.expect)(res.statusCode).toBe(200);
|
||||
const body = res.json();
|
||||
(0, vitest_1.expect)(body.title).toBe('Updated Title');
|
||||
(0, vitest_1.expect)(body.description).toBe('Updated description');
|
||||
});
|
||||
(0, vitest_1.it)('debería devolver 404 si el juego no existe', async () => {
|
||||
const res = await app.inject({
|
||||
method: 'PUT',
|
||||
url: '/api/games/non-existing-id',
|
||||
payload: {
|
||||
title: 'Some Title',
|
||||
},
|
||||
});
|
||||
(0, vitest_1.expect)(res.statusCode).toBe(404);
|
||||
});
|
||||
(0, vitest_1.it)('debería permitir actualización parcial', async () => {
|
||||
const game = await prisma_1.prisma.game.create({
|
||||
data: {
|
||||
title: 'Original Title',
|
||||
slug: 'original',
|
||||
description: 'Original description',
|
||||
source: 'manual',
|
||||
},
|
||||
});
|
||||
const res = await app.inject({
|
||||
method: 'PUT',
|
||||
url: `/api/games/${game.id}`,
|
||||
payload: {
|
||||
description: 'New description only',
|
||||
},
|
||||
});
|
||||
(0, vitest_1.expect)(res.statusCode).toBe(200);
|
||||
const body = res.json();
|
||||
(0, vitest_1.expect)(body.title).toBe('Original Title'); // No cambió
|
||||
(0, vitest_1.expect)(body.description).toBe('New description only'); // Cambió
|
||||
});
|
||||
});
|
||||
(0, vitest_1.describe)('DELETE /api/games/:id', () => {
|
||||
(0, vitest_1.it)('debería eliminar un juego existente', async () => {
|
||||
const game = await prisma_1.prisma.game.create({
|
||||
data: {
|
||||
title: 'Game to Delete',
|
||||
slug: 'game-to-delete',
|
||||
source: 'manual',
|
||||
},
|
||||
});
|
||||
const res = await app.inject({
|
||||
method: 'DELETE',
|
||||
url: `/api/games/${game.id}`,
|
||||
});
|
||||
(0, vitest_1.expect)(res.statusCode).toBe(204);
|
||||
// Verificar que el juego fue eliminado
|
||||
const deletedGame = await prisma_1.prisma.game.findUnique({
|
||||
where: { id: game.id },
|
||||
});
|
||||
(0, vitest_1.expect)(deletedGame).toBeNull();
|
||||
});
|
||||
(0, vitest_1.it)('debería devolver 404 si el juego no existe', async () => {
|
||||
const res = await app.inject({
|
||||
method: 'DELETE',
|
||||
url: '/api/games/non-existing-id',
|
||||
});
|
||||
(0, vitest_1.expect)(res.statusCode).toBe(404);
|
||||
});
|
||||
});
|
||||
});
|
||||
/**
|
||||
* Metadatos:
|
||||
* Autor: GitHub Copilot
|
||||
* Última actualización: 2026-02-11
|
||||
*/
|
||||
Reference in New Issue
Block a user