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
|
||||
*/
|
||||
17
backend/dist/tests/routes/import.spec.js
vendored
Normal file
17
backend/dist/tests/routes/import.spec.js
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const vitest_1 = require("vitest");
|
||||
const app_1 = require("../../src/app");
|
||||
(0, vitest_1.describe)('routes/import', () => {
|
||||
(0, vitest_1.it)('POST /api/import/scan devuelve 202 o 200', async () => {
|
||||
const app = (0, app_1.buildApp)();
|
||||
await app.ready();
|
||||
const res = await app.inject({
|
||||
method: 'POST',
|
||||
url: '/api/import/scan',
|
||||
payload: { persist: false },
|
||||
});
|
||||
(0, vitest_1.expect)([200, 202]).toContain(res.statusCode);
|
||||
await app.close();
|
||||
});
|
||||
});
|
||||
117
backend/dist/tests/routes/metadata.spec.js
vendored
Normal file
117
backend/dist/tests/routes/metadata.spec.js
vendored
Normal file
@@ -0,0 +1,117 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || (function () {
|
||||
var ownKeys = function(o) {
|
||||
ownKeys = Object.getOwnPropertyNames || function (o) {
|
||||
var ar = [];
|
||||
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
||||
return ar;
|
||||
};
|
||||
return ownKeys(o);
|
||||
};
|
||||
return function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const vitest_1 = require("vitest");
|
||||
const app_1 = require("../../src/app");
|
||||
const metadataService = __importStar(require("../../src/services/metadataService"));
|
||||
(0, vitest_1.describe)('Metadata API', () => {
|
||||
let app;
|
||||
(0, vitest_1.beforeEach)(async () => {
|
||||
app = (0, app_1.buildApp)();
|
||||
await app.ready();
|
||||
});
|
||||
(0, vitest_1.afterEach)(async () => {
|
||||
await app.close();
|
||||
vitest_1.vi.restoreAllMocks();
|
||||
});
|
||||
(0, vitest_1.describe)('GET /api/metadata/search', () => {
|
||||
(0, vitest_1.it)('debería devolver resultados cuando se busca un juego existente', async () => {
|
||||
const mockResults = [
|
||||
{
|
||||
source: 'igdb',
|
||||
externalIds: { igdb: 1 },
|
||||
title: 'The Legend of Zelda',
|
||||
slug: 'the-legend-of-zelda',
|
||||
releaseDate: '1986-02-21',
|
||||
genres: ['Adventure'],
|
||||
coverUrl: 'https://example.com/cover.jpg',
|
||||
},
|
||||
];
|
||||
vitest_1.vi.spyOn(metadataService, 'enrichGame').mockResolvedValue(mockResults[0]);
|
||||
const res = await app.inject({
|
||||
method: 'GET',
|
||||
url: '/api/metadata/search?q=zelda',
|
||||
});
|
||||
(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).toBeGreaterThan(0);
|
||||
(0, vitest_1.expect)(body[0].title).toContain('Zelda');
|
||||
});
|
||||
(0, vitest_1.it)('debería devolver lista vacía cuando no hay resultados', async () => {
|
||||
vitest_1.vi.spyOn(metadataService, 'enrichGame').mockResolvedValue(null);
|
||||
const res = await app.inject({
|
||||
method: 'GET',
|
||||
url: '/api/metadata/search?q=nonexistentgame12345',
|
||||
});
|
||||
(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(0);
|
||||
});
|
||||
(0, vitest_1.it)('debería devolver 400 si falta el parámetro query', async () => {
|
||||
const res = await app.inject({
|
||||
method: 'GET',
|
||||
url: '/api/metadata/search',
|
||||
});
|
||||
(0, vitest_1.expect)(res.statusCode).toBe(400);
|
||||
(0, vitest_1.expect)(res.json()).toHaveProperty('error');
|
||||
});
|
||||
(0, vitest_1.it)('debería devolver 400 si el parámetro query está vacío', async () => {
|
||||
const res = await app.inject({
|
||||
method: 'GET',
|
||||
url: '/api/metadata/search?q=',
|
||||
});
|
||||
(0, vitest_1.expect)(res.statusCode).toBe(400);
|
||||
});
|
||||
(0, vitest_1.it)('debería pasar el parámetro platform a enrichGame si se proporciona', async () => {
|
||||
const enrichSpy = vitest_1.vi.spyOn(metadataService, 'enrichGame').mockResolvedValue(null);
|
||||
const res = await app.inject({
|
||||
method: 'GET',
|
||||
url: '/api/metadata/search?q=mario&platform=Nintendo%2064',
|
||||
});
|
||||
(0, vitest_1.expect)(res.statusCode).toBe(200);
|
||||
(0, vitest_1.expect)(enrichSpy).toHaveBeenCalledWith({
|
||||
title: 'mario',
|
||||
platform: 'Nintendo 64',
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
/**
|
||||
* Metadatos:
|
||||
* Autor: GitHub Copilot
|
||||
* Última actualización: 2026-02-11
|
||||
*/
|
||||
255
backend/dist/tests/routes/roms.spec.js
vendored
Normal file
255
backend/dist/tests/routes/roms.spec.js
vendored
Normal file
@@ -0,0 +1,255 @@
|
||||
"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)('ROMs API', () => {
|
||||
let app;
|
||||
(0, vitest_1.beforeEach)(async () => {
|
||||
app = (0, app_1.buildApp)();
|
||||
await app.ready();
|
||||
// Limpiar base de datos antes de cada test (eliminar ROMs primero por foreign key)
|
||||
await prisma_1.prisma.romFile.deleteMany();
|
||||
await prisma_1.prisma.gamePlatform.deleteMany();
|
||||
await prisma_1.prisma.purchase.deleteMany();
|
||||
await prisma_1.prisma.artwork.deleteMany();
|
||||
await prisma_1.prisma.priceHistory.deleteMany();
|
||||
await prisma_1.prisma.game.deleteMany();
|
||||
});
|
||||
(0, vitest_1.afterEach)(async () => {
|
||||
await app.close();
|
||||
});
|
||||
(0, vitest_1.describe)('GET /api/roms', () => {
|
||||
(0, vitest_1.it)('debería devolver una lista vacía cuando no hay ROMs', async () => {
|
||||
const res = await app.inject({
|
||||
method: 'GET',
|
||||
url: '/api/roms',
|
||||
});
|
||||
(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 ROMs con sus propiedades', async () => {
|
||||
// Crear un ROM de prueba
|
||||
const rom = await prisma_1.prisma.romFile.create({
|
||||
data: {
|
||||
path: '/roms/games/',
|
||||
filename: 'game.zip',
|
||||
checksum: 'abc123def456',
|
||||
size: 1024,
|
||||
format: 'zip',
|
||||
},
|
||||
});
|
||||
const res = await app.inject({
|
||||
method: 'GET',
|
||||
url: '/api/roms',
|
||||
});
|
||||
(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].id).toBe(rom.id);
|
||||
(0, vitest_1.expect)(body[0].filename).toBe('game.zip');
|
||||
});
|
||||
(0, vitest_1.it)('debería incluir información del juego asociado', async () => {
|
||||
const game = await prisma_1.prisma.game.create({
|
||||
data: {
|
||||
title: 'Test Game',
|
||||
slug: 'test-game',
|
||||
},
|
||||
});
|
||||
const rom = await prisma_1.prisma.romFile.create({
|
||||
data: {
|
||||
path: '/roms/',
|
||||
filename: 'test-with-game.zip',
|
||||
checksum: 'checksum-game-123',
|
||||
size: 2048,
|
||||
format: 'zip',
|
||||
gameId: game.id,
|
||||
},
|
||||
});
|
||||
const res = await app.inject({
|
||||
method: 'GET',
|
||||
url: '/api/roms',
|
||||
});
|
||||
(0, vitest_1.expect)(res.statusCode).toBe(200);
|
||||
const body = res.json();
|
||||
// Buscar el ROM que creamos por checksum
|
||||
const createdRom = body.find((r) => r.checksum === 'checksum-game-123');
|
||||
(0, vitest_1.expect)(createdRom).toBeDefined();
|
||||
(0, vitest_1.expect)(createdRom.game).toBeDefined();
|
||||
(0, vitest_1.expect)(createdRom.game.title).toBe('Test Game');
|
||||
});
|
||||
});
|
||||
(0, vitest_1.describe)('GET /api/roms/:id', () => {
|
||||
(0, vitest_1.it)('debería retornar un ROM existente', async () => {
|
||||
const rom = await prisma_1.prisma.romFile.create({
|
||||
data: {
|
||||
path: '/roms/',
|
||||
filename: 'game1.zip',
|
||||
checksum: 'checksum1',
|
||||
size: 1024,
|
||||
format: 'zip',
|
||||
},
|
||||
});
|
||||
const res = await app.inject({
|
||||
method: 'GET',
|
||||
url: `/api/roms/${rom.id}`,
|
||||
});
|
||||
(0, vitest_1.expect)(res.statusCode).toBe(200);
|
||||
const body = res.json();
|
||||
(0, vitest_1.expect)(body.id).toBe(rom.id);
|
||||
(0, vitest_1.expect)(body.filename).toBe('game1.zip');
|
||||
});
|
||||
(0, vitest_1.it)('debería retornar 404 si el ROM no existe', async () => {
|
||||
const res = await app.inject({
|
||||
method: 'GET',
|
||||
url: '/api/roms/non-existing-id',
|
||||
});
|
||||
(0, vitest_1.expect)(res.statusCode).toBe(404);
|
||||
(0, vitest_1.expect)(res.json()).toHaveProperty('error');
|
||||
});
|
||||
(0, vitest_1.it)('debería incluir el juego asociado al ROM', async () => {
|
||||
const game = await prisma_1.prisma.game.create({
|
||||
data: {
|
||||
title: 'Zelda',
|
||||
slug: 'zelda',
|
||||
},
|
||||
});
|
||||
const rom = await prisma_1.prisma.romFile.create({
|
||||
data: {
|
||||
path: '/roms/',
|
||||
filename: 'zelda.zip',
|
||||
checksum: 'checksum2',
|
||||
size: 2048,
|
||||
format: 'zip',
|
||||
gameId: game.id,
|
||||
},
|
||||
});
|
||||
const res = await app.inject({
|
||||
method: 'GET',
|
||||
url: `/api/roms/${rom.id}`,
|
||||
});
|
||||
(0, vitest_1.expect)(res.statusCode).toBe(200);
|
||||
const body = res.json();
|
||||
(0, vitest_1.expect)(body.game).toBeDefined();
|
||||
(0, vitest_1.expect)(body.game.title).toBe('Zelda');
|
||||
});
|
||||
});
|
||||
(0, vitest_1.describe)('PUT /api/roms/:id/game', () => {
|
||||
(0, vitest_1.it)('debería vincular un juego a un ROM existente', async () => {
|
||||
const game = await prisma_1.prisma.game.create({
|
||||
data: {
|
||||
title: 'Mario',
|
||||
slug: 'mario',
|
||||
},
|
||||
});
|
||||
const rom = await prisma_1.prisma.romFile.create({
|
||||
data: {
|
||||
path: '/roms/',
|
||||
filename: 'mario.zip',
|
||||
checksum: 'checksum3',
|
||||
size: 512,
|
||||
format: 'zip',
|
||||
},
|
||||
});
|
||||
const res = await app.inject({
|
||||
method: 'PUT',
|
||||
url: `/api/roms/${rom.id}/game`,
|
||||
payload: {
|
||||
gameId: game.id,
|
||||
},
|
||||
});
|
||||
(0, vitest_1.expect)(res.statusCode).toBe(200);
|
||||
const body = res.json();
|
||||
(0, vitest_1.expect)(body.gameId).toBe(game.id);
|
||||
(0, vitest_1.expect)(body.game.title).toBe('Mario');
|
||||
});
|
||||
(0, vitest_1.it)('debería devolver 400 si el gameId es inválido', async () => {
|
||||
const rom = await prisma_1.prisma.romFile.create({
|
||||
data: {
|
||||
path: '/roms/',
|
||||
filename: 'game.zip',
|
||||
checksum: 'checksum4',
|
||||
size: 1024,
|
||||
format: 'zip',
|
||||
},
|
||||
});
|
||||
const res = await app.inject({
|
||||
method: 'PUT',
|
||||
url: `/api/roms/${rom.id}/game`,
|
||||
payload: {
|
||||
gameId: 'invalid-game-id',
|
||||
},
|
||||
});
|
||||
(0, vitest_1.expect)(res.statusCode).toBe(400);
|
||||
});
|
||||
(0, vitest_1.it)('debería devolver 404 si el ROM no existe', async () => {
|
||||
const game = await prisma_1.prisma.game.create({
|
||||
data: {
|
||||
title: 'Test',
|
||||
slug: 'test',
|
||||
},
|
||||
});
|
||||
const res = await app.inject({
|
||||
method: 'PUT',
|
||||
url: '/api/roms/non-existing-id/game',
|
||||
payload: {
|
||||
gameId: game.id,
|
||||
},
|
||||
});
|
||||
(0, vitest_1.expect)(res.statusCode).toBe(404);
|
||||
});
|
||||
(0, vitest_1.it)('debería devolver 400 si falta gameId', async () => {
|
||||
const rom = await prisma_1.prisma.romFile.create({
|
||||
data: {
|
||||
path: '/roms/',
|
||||
filename: 'game.zip',
|
||||
checksum: 'checksum5',
|
||||
size: 1024,
|
||||
format: 'zip',
|
||||
},
|
||||
});
|
||||
const res = await app.inject({
|
||||
method: 'PUT',
|
||||
url: `/api/roms/${rom.id}/game`,
|
||||
payload: {},
|
||||
});
|
||||
(0, vitest_1.expect)(res.statusCode).toBe(400);
|
||||
});
|
||||
});
|
||||
(0, vitest_1.describe)('DELETE /api/roms/:id', () => {
|
||||
(0, vitest_1.it)('debería eliminar un ROM existente', async () => {
|
||||
const rom = await prisma_1.prisma.romFile.create({
|
||||
data: {
|
||||
path: '/roms/',
|
||||
filename: 'delete-me.zip',
|
||||
checksum: 'checksum6',
|
||||
size: 1024,
|
||||
format: 'zip',
|
||||
},
|
||||
});
|
||||
const res = await app.inject({
|
||||
method: 'DELETE',
|
||||
url: `/api/roms/${rom.id}`,
|
||||
});
|
||||
(0, vitest_1.expect)(res.statusCode).toBe(204);
|
||||
// Verificar que el ROM fue eliminado
|
||||
const deletedRom = await prisma_1.prisma.romFile.findUnique({
|
||||
where: { id: rom.id },
|
||||
});
|
||||
(0, vitest_1.expect)(deletedRom).toBeNull();
|
||||
});
|
||||
(0, vitest_1.it)('debería devolver 404 si el ROM no existe', async () => {
|
||||
const res = await app.inject({
|
||||
method: 'DELETE',
|
||||
url: '/api/roms/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