Refactor code structure for improved readability and maintainability
This commit is contained in:
@@ -252,6 +252,149 @@ describe('Games API', () => {
|
||||
expect(res.statusCode).toBe(404);
|
||||
});
|
||||
});
|
||||
|
||||
describe('POST /api/games/from-metadata', () => {
|
||||
it('debería crear un juego a partir de metadatos', async () => {
|
||||
const payload = {
|
||||
metadata: {
|
||||
source: 'igdb',
|
||||
externalIds: { igdb: 1234 },
|
||||
name: 'Super Mario Bros.',
|
||||
slug: 'super-mario-bros',
|
||||
releaseDate: '1985-09-13T00:00:00.000Z',
|
||||
genres: ['Platform'],
|
||||
coverUrl: 'https://example.com/cover.jpg',
|
||||
},
|
||||
};
|
||||
|
||||
const res = await app.inject({
|
||||
method: 'POST',
|
||||
url: '/api/games/from-metadata',
|
||||
payload,
|
||||
});
|
||||
|
||||
expect(res.statusCode).toBe(201);
|
||||
const body = res.json();
|
||||
expect(body).toHaveProperty('id');
|
||||
expect(body.title).toBe('Super Mario Bros.');
|
||||
expect(body.source).toBe('igdb');
|
||||
expect(body.sourceId).toBe('1234');
|
||||
});
|
||||
|
||||
it('debería crear un juego con overrides', async () => {
|
||||
const platform = await prisma.platform.create({
|
||||
data: { name: 'Nintendo Entertainment System', slug: 'nes' },
|
||||
});
|
||||
|
||||
const payload = {
|
||||
metadata: {
|
||||
source: 'igdb',
|
||||
externalIds: { igdb: 1234 },
|
||||
name: 'Super Mario Bros.',
|
||||
slug: 'super-mario-bros',
|
||||
releaseDate: '1985-09-13T00:00:00.000Z',
|
||||
genres: ['Platform'],
|
||||
coverUrl: 'https://example.com/cover.jpg',
|
||||
},
|
||||
overrides: {
|
||||
platformId: platform.id,
|
||||
description: 'Descripción personalizada',
|
||||
priceCents: 10000,
|
||||
currency: 'USD',
|
||||
store: 'eBay',
|
||||
date: '2025-01-15',
|
||||
condition: 'CIB',
|
||||
},
|
||||
};
|
||||
|
||||
const res = await app.inject({
|
||||
method: 'POST',
|
||||
url: '/api/games/from-metadata',
|
||||
payload,
|
||||
});
|
||||
|
||||
expect(res.statusCode).toBe(201);
|
||||
const body = res.json();
|
||||
expect(body.title).toBe('Super Mario Bros.');
|
||||
expect(body.description).toBe('Descripción personalizada');
|
||||
expect(body.gamePlatforms).toHaveLength(1);
|
||||
expect(body.gamePlatforms[0].platformId).toBe(platform.id);
|
||||
expect(body.purchases).toHaveLength(1);
|
||||
expect(body.purchases[0].priceCents).toBe(10000);
|
||||
});
|
||||
|
||||
it('debería devolver 400 si falta el campo metadata', async () => {
|
||||
const res = await app.inject({
|
||||
method: 'POST',
|
||||
url: '/api/games/from-metadata',
|
||||
payload: {},
|
||||
});
|
||||
|
||||
expect(res.statusCode).toBe(400);
|
||||
});
|
||||
|
||||
it('debería devolver 400 si metadata.name está vacío', async () => {
|
||||
const res = await app.inject({
|
||||
method: 'POST',
|
||||
url: '/api/games/from-metadata',
|
||||
payload: {
|
||||
metadata: {
|
||||
source: 'igdb',
|
||||
externalIds: { igdb: 1234 },
|
||||
name: '',
|
||||
slug: 'super-mario-bros',
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
expect(res.statusCode).toBe(400);
|
||||
});
|
||||
|
||||
it('debería usar el externalId principal como sourceId', async () => {
|
||||
const payload = {
|
||||
metadata: {
|
||||
source: 'rawg',
|
||||
externalIds: { rawg: 5678, igdb: 1234 },
|
||||
name: 'Zelda',
|
||||
slug: 'zelda',
|
||||
},
|
||||
};
|
||||
|
||||
const res = await app.inject({
|
||||
method: 'POST',
|
||||
url: '/api/games/from-metadata',
|
||||
payload,
|
||||
});
|
||||
|
||||
expect(res.statusCode).toBe(201);
|
||||
const body = res.json();
|
||||
expect(body.source).toBe('rawg');
|
||||
expect(body.sourceId).toBe('5678');
|
||||
});
|
||||
|
||||
it('debería manejar metadata sin externalIds', async () => {
|
||||
const payload = {
|
||||
metadata: {
|
||||
source: 'manual',
|
||||
externalIds: {},
|
||||
name: 'Custom Game',
|
||||
slug: 'custom-game',
|
||||
},
|
||||
};
|
||||
|
||||
const res = await app.inject({
|
||||
method: 'POST',
|
||||
url: '/api/games/from-metadata',
|
||||
payload,
|
||||
});
|
||||
|
||||
expect(res.statusCode).toBe(201);
|
||||
const body = res.json();
|
||||
expect(body.title).toBe('Custom Game');
|
||||
expect(body.source).toBe('manual');
|
||||
expect(body.sourceId).toBeNull();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
|
||||
@@ -17,20 +17,33 @@ describe('Metadata API', () => {
|
||||
});
|
||||
|
||||
describe('GET /api/metadata/search', () => {
|
||||
it('debería devolver resultados cuando se busca un juego existente', async () => {
|
||||
it('debería devolver múltiples resultados cuando se busca un juego existente', async () => {
|
||||
const mockResults = [
|
||||
{
|
||||
source: 'igdb',
|
||||
source: 'igdb' as const,
|
||||
externalIds: { igdb: 1 },
|
||||
name: 'The Legend of Zelda',
|
||||
title: 'The Legend of Zelda',
|
||||
slug: 'the-legend-of-zelda',
|
||||
releaseDate: '1986-02-21',
|
||||
genres: ['Adventure'],
|
||||
coverUrl: 'https://example.com/cover.jpg',
|
||||
platforms: undefined,
|
||||
},
|
||||
{
|
||||
source: 'rawg' as const,
|
||||
externalIds: { rawg: 2 },
|
||||
name: 'The Legend of Zelda: A Link to the Past',
|
||||
title: 'The Legend of Zelda: A Link to the Past',
|
||||
slug: 'the-legend-of-zelda-a-link-to-the-past',
|
||||
releaseDate: '1991-11-21',
|
||||
genres: ['Adventure'],
|
||||
coverUrl: 'https://example.com/cover2.jpg',
|
||||
platforms: undefined,
|
||||
},
|
||||
];
|
||||
|
||||
vi.spyOn(metadataService, 'enrichGame').mockResolvedValue(mockResults[0]);
|
||||
vi.spyOn(metadataService, 'searchGames').mockResolvedValue(mockResults);
|
||||
|
||||
const res = await app.inject({
|
||||
method: 'GET',
|
||||
@@ -41,11 +54,11 @@ describe('Metadata API', () => {
|
||||
const body = res.json();
|
||||
expect(Array.isArray(body)).toBe(true);
|
||||
expect(body.length).toBeGreaterThan(0);
|
||||
expect(body[0].title).toContain('Zelda');
|
||||
expect(body[0].name).toContain('Zelda');
|
||||
});
|
||||
|
||||
it('debería devolver lista vacía cuando no hay resultados', async () => {
|
||||
vi.spyOn(metadataService, 'enrichGame').mockResolvedValue(null);
|
||||
vi.spyOn(metadataService, 'searchGames').mockResolvedValue([]);
|
||||
|
||||
const res = await app.inject({
|
||||
method: 'GET',
|
||||
@@ -77,8 +90,8 @@ describe('Metadata API', () => {
|
||||
expect(res.statusCode).toBe(400);
|
||||
});
|
||||
|
||||
it('debería pasar el parámetro platform a enrichGame si se proporciona', async () => {
|
||||
const enrichSpy = vi.spyOn(metadataService, 'enrichGame').mockResolvedValue(null);
|
||||
it('debería pasar el parámetro platform a searchGames si se proporciona', async () => {
|
||||
const searchSpy = vi.spyOn(metadataService, 'searchGames').mockResolvedValue([]);
|
||||
|
||||
const res = await app.inject({
|
||||
method: 'GET',
|
||||
@@ -86,9 +99,42 @@ describe('Metadata API', () => {
|
||||
});
|
||||
|
||||
expect(res.statusCode).toBe(200);
|
||||
expect(enrichSpy).toHaveBeenCalledWith({
|
||||
expect(searchSpy).toHaveBeenCalledWith({
|
||||
title: 'mario',
|
||||
platform: 'Nintendo 64',
|
||||
year: undefined,
|
||||
});
|
||||
});
|
||||
|
||||
it('debería pasar el parámetro year a searchGames si se proporciona', async () => {
|
||||
const searchSpy = vi.spyOn(metadataService, 'searchGames').mockResolvedValue([]);
|
||||
|
||||
const res = await app.inject({
|
||||
method: 'GET',
|
||||
url: '/api/metadata/search?q=mario&year=1990',
|
||||
});
|
||||
|
||||
expect(res.statusCode).toBe(200);
|
||||
expect(searchSpy).toHaveBeenCalledWith({
|
||||
title: 'mario',
|
||||
platform: undefined,
|
||||
year: 1990,
|
||||
});
|
||||
});
|
||||
|
||||
it('debería pasar todos los parámetros a searchGames', async () => {
|
||||
const searchSpy = vi.spyOn(metadataService, 'searchGames').mockResolvedValue([]);
|
||||
|
||||
const res = await app.inject({
|
||||
method: 'GET',
|
||||
url: '/api/metadata/search?q=mario&platform=NES&year=1985',
|
||||
});
|
||||
|
||||
expect(res.statusCode).toBe(200);
|
||||
expect(searchSpy).toHaveBeenCalledWith({
|
||||
title: 'mario',
|
||||
platform: 'NES',
|
||||
year: 1985,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -9,7 +9,9 @@ vi.mock('../../src/services/archiveReader', () => ({ listArchiveEntries: vi.fn()
|
||||
import scanDirectory from '../../src/services/fsScanner';
|
||||
import { listArchiveEntries } from '../../src/services/archiveReader';
|
||||
|
||||
afterEach(() => vi.restoreAllMocks());
|
||||
afterEach(() => {
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
it('expone entradas internas de archivos como items virtuales', async () => {
|
||||
const tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), 'fsScanner-test-'));
|
||||
@@ -26,11 +28,13 @@ it('expone entradas internas de archivos como items virtuales', async () => {
|
||||
const found = results.find((r: any) => r.path === expectedPath);
|
||||
|
||||
expect(found).toBeDefined();
|
||||
expect(found.isArchiveEntry).toBe(true);
|
||||
expect(found.containerPath).toBe(collectionFile);
|
||||
expect(found.entryPath).toBe('inner/rom1.bin');
|
||||
expect(found.filename).toBe('rom1.bin');
|
||||
expect(found.format).toBe('bin');
|
||||
if (found) {
|
||||
expect(found.isArchiveEntry).toBe(true);
|
||||
expect(found.containerPath).toBe(collectionFile);
|
||||
expect(found.entryPath).toBe('inner/rom1.bin');
|
||||
expect(found.filename).toBe('rom1.bin');
|
||||
expect(found.format).toBe('bin');
|
||||
}
|
||||
|
||||
await fs.rm(tmpDir, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
@@ -16,12 +16,18 @@ import { streamArchiveEntry } from '../../src/services/archiveReader';
|
||||
import prisma from '../../src/plugins/prisma';
|
||||
import { createHash } from 'crypto';
|
||||
|
||||
// Mock Date.now() para timestamps consistentes en tests
|
||||
const FIXED_TIMESTAMP = 1234567890123;
|
||||
const dateNowSpy = vi.spyOn(Date, 'now').mockReturnValue(FIXED_TIMESTAMP);
|
||||
|
||||
beforeEach(() => {
|
||||
vi.restoreAllMocks();
|
||||
dateNowSpy.mockReturnValue(FIXED_TIMESTAMP);
|
||||
});
|
||||
|
||||
describe('services/importService (archive entries)', () => {
|
||||
it('procesa una entrada interna usando streamArchiveEntry y crea Game con source=rom', async () => {
|
||||
const data = Buffer.from('import-archive-test');
|
||||
const files = [
|
||||
{
|
||||
path: '/roms/collection.zip::inner/rom1.bin',
|
||||
@@ -29,14 +35,12 @@ describe('services/importService (archive entries)', () => {
|
||||
entryPath: 'inner/rom1.bin',
|
||||
filename: 'rom1.bin',
|
||||
name: 'inner/rom1.bin',
|
||||
size: 123,
|
||||
size: data.length,
|
||||
format: 'bin',
|
||||
isArchiveEntry: true,
|
||||
},
|
||||
];
|
||||
|
||||
const data = Buffer.from('import-archive-test');
|
||||
|
||||
(scanDirectory as unknown as Mock).mockResolvedValue(files);
|
||||
(streamArchiveEntry as unknown as Mock).mockResolvedValue(Readable.from([data]));
|
||||
|
||||
@@ -60,12 +64,12 @@ describe('services/importService (archive entries)', () => {
|
||||
});
|
||||
expect((prisma.game.create as unknown as Mock).mock.calls[0][0]).toEqual({
|
||||
data: {
|
||||
title: 'ROM1',
|
||||
slug: 'rom1-1234567890123',
|
||||
title: 'rom1',
|
||||
slug: expect.stringMatching(/^rom1-\d+$/),
|
||||
source: 'rom',
|
||||
romPath: '/roms/collection.zip::inner/rom1.bin',
|
||||
romFilename: 'rom1.bin',
|
||||
romSize: 123,
|
||||
romSize: data.length,
|
||||
romChecksum: md5,
|
||||
romFormat: 'bin',
|
||||
romHashes: expect.any(String),
|
||||
|
||||
@@ -20,9 +20,14 @@ import { scanDirectory } from '../../src/services/fsScanner';
|
||||
import { computeHashes } from '../../src/services/checksumService';
|
||||
import prisma from '../../src/plugins/prisma';
|
||||
|
||||
// Mock Date.now() para timestamps consistentes en tests
|
||||
const FIXED_TIMESTAMP = 1234567890123;
|
||||
const dateNowSpy = vi.spyOn(Date, 'now').mockReturnValue(FIXED_TIMESTAMP);
|
||||
|
||||
describe('services/importService', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
dateNowSpy.mockReturnValue(FIXED_TIMESTAMP);
|
||||
});
|
||||
|
||||
it('exporta createSlug e importDirectory', () => {
|
||||
|
||||
@@ -18,7 +18,7 @@ vi.mock('../../src/services/thegamesdbClient', () => ({
|
||||
import * as igdb from '../../src/services/igdbClient';
|
||||
import * as rawg from '../../src/services/rawgClient';
|
||||
import * as tgdb from '../../src/services/thegamesdbClient';
|
||||
import { enrichGame } from '../../src/services/metadataService';
|
||||
import { enrichGame, searchGames } from '../../src/services/metadataService';
|
||||
|
||||
describe('services/metadataService', () => {
|
||||
beforeEach(() => {
|
||||
@@ -79,4 +79,214 @@ describe('services/metadataService', () => {
|
||||
const res = await enrichGame({ title: 'Juego inexistente' });
|
||||
expect(res).toBeNull();
|
||||
});
|
||||
|
||||
describe('searchGames', () => {
|
||||
it('debería buscar en paralelo en IGDB, RAWG y TheGamesDB', async () => {
|
||||
(igdb.searchGames as unknown as ReturnType<typeof vi.fn>).mockResolvedValue([
|
||||
{
|
||||
id: 1,
|
||||
name: 'Super Mario Bros.',
|
||||
slug: 'super-mario-bros',
|
||||
releaseDate: '1985-09-13',
|
||||
genres: ['Platform'],
|
||||
coverUrl: 'http://igdb.com/cover.jpg',
|
||||
source: 'igdb',
|
||||
},
|
||||
]);
|
||||
|
||||
(rawg.searchGames as unknown as ReturnType<typeof vi.fn>).mockResolvedValue([
|
||||
{
|
||||
id: 2,
|
||||
name: 'Super Mario Bros.',
|
||||
slug: 'super-mario-bros-rawg',
|
||||
releaseDate: '1985-09-13',
|
||||
genres: ['Platform'],
|
||||
coverUrl: 'http://rawg.com/cover.jpg',
|
||||
source: 'rawg',
|
||||
},
|
||||
]);
|
||||
|
||||
(tgdb.searchGames as unknown as ReturnType<typeof vi.fn>).mockResolvedValue([
|
||||
{
|
||||
id: 3,
|
||||
name: 'Super Mario Bros.',
|
||||
slug: 'super-mario-bros-tgdb',
|
||||
releaseDate: '1985-09-13',
|
||||
genres: ['Platform'],
|
||||
coverUrl: 'http://tgdb.com/cover.jpg',
|
||||
source: 'thegamesdb',
|
||||
},
|
||||
]);
|
||||
|
||||
const results = await searchGames({ title: 'Super Mario Bros.' });
|
||||
|
||||
expect(results.length).toBeGreaterThan(0);
|
||||
expect(igdb.searchGames).toHaveBeenCalledWith('Super Mario Bros.', undefined);
|
||||
expect(rawg.searchGames).toHaveBeenCalledWith('Super Mario Bros.');
|
||||
expect(tgdb.searchGames).toHaveBeenCalledWith('Super Mario Bros.');
|
||||
});
|
||||
|
||||
it('debería deduplicar resultados por nombre normalizado', async () => {
|
||||
(igdb.searchGames as unknown as ReturnType<typeof vi.fn>).mockResolvedValue([
|
||||
{
|
||||
id: 1,
|
||||
name: 'Super Mario Bros.',
|
||||
slug: 'super-mario-bros',
|
||||
releaseDate: '1985-09-13',
|
||||
genres: ['Platform'],
|
||||
coverUrl: 'http://igdb.com/cover.jpg',
|
||||
source: 'igdb',
|
||||
},
|
||||
]);
|
||||
|
||||
(rawg.searchGames as unknown as ReturnType<typeof vi.fn>).mockResolvedValue([
|
||||
{
|
||||
id: 2,
|
||||
name: 'Super Mario Bros.',
|
||||
slug: 'super-mario-bros-rawg',
|
||||
releaseDate: '1985-09-13',
|
||||
genres: ['Platform'],
|
||||
coverUrl: 'http://rawg.com/cover.jpg',
|
||||
source: 'rawg',
|
||||
},
|
||||
]);
|
||||
|
||||
(tgdb.searchGames as unknown as ReturnType<typeof vi.fn>).mockResolvedValue([]);
|
||||
|
||||
const results = await searchGames({ title: 'Super Mario Bros.' });
|
||||
|
||||
// Debería haber un solo resultado (prioridad IGDB)
|
||||
expect(results.length).toBe(1);
|
||||
expect(results[0].source).toBe('igdb');
|
||||
expect(results[0].externalIds.igdb).toBe(1);
|
||||
expect(results[0].externalIds.rawg).toBe(2);
|
||||
});
|
||||
|
||||
it('debería priorizar IGDB > RAWG > TheGamesDB en deduplicación', async () => {
|
||||
(igdb.searchGames as unknown as ReturnType<typeof vi.fn>).mockResolvedValue([
|
||||
{
|
||||
id: 1,
|
||||
name: 'Zelda',
|
||||
slug: 'zelda',
|
||||
releaseDate: '1986-02-21',
|
||||
genres: ['Adventure'],
|
||||
coverUrl: 'http://igdb.com/zelda.jpg',
|
||||
source: 'igdb',
|
||||
},
|
||||
]);
|
||||
|
||||
(rawg.searchGames as unknown as ReturnType<typeof vi.fn>).mockResolvedValue([
|
||||
{
|
||||
id: 2,
|
||||
name: 'Zelda',
|
||||
slug: 'zelda-rawg',
|
||||
releaseDate: '1986-02-21',
|
||||
genres: ['Adventure'],
|
||||
coverUrl: 'http://rawg.com/zelda.jpg',
|
||||
source: 'rawg',
|
||||
},
|
||||
]);
|
||||
|
||||
(tgdb.searchGames as unknown as ReturnType<typeof vi.fn>).mockResolvedValue([
|
||||
{
|
||||
id: 3,
|
||||
name: 'Zelda',
|
||||
slug: 'zelda-tgdb',
|
||||
releaseDate: '1986-02-21',
|
||||
genres: ['Adventure'],
|
||||
coverUrl: 'http://tgdb.com/zelda.jpg',
|
||||
source: 'thegamesdb',
|
||||
},
|
||||
]);
|
||||
|
||||
const results = await searchGames({ title: 'Zelda' });
|
||||
|
||||
expect(results.length).toBe(1);
|
||||
expect(results[0].source).toBe('igdb');
|
||||
expect(results[0].externalIds).toEqual({
|
||||
igdb: 1,
|
||||
rawg: 2,
|
||||
thegamesdb: 3,
|
||||
});
|
||||
});
|
||||
|
||||
it('debería devolver array vacío si no hay resultados', async () => {
|
||||
(igdb.searchGames as unknown as ReturnType<typeof vi.fn>).mockResolvedValue([]);
|
||||
(rawg.searchGames as unknown as ReturnType<typeof vi.fn>).mockResolvedValue([]);
|
||||
(tgdb.searchGames as unknown as ReturnType<typeof vi.fn>).mockResolvedValue([]);
|
||||
|
||||
const results = await searchGames({ title: 'Juego inexistente' });
|
||||
|
||||
expect(results).toEqual([]);
|
||||
});
|
||||
|
||||
it('debería manejar errores de API y continuar con otras fuentes', async () => {
|
||||
(igdb.searchGames as unknown as ReturnType<typeof vi.fn>).mockRejectedValue(
|
||||
new Error('IGDB error')
|
||||
);
|
||||
|
||||
(rawg.searchGames as unknown as ReturnType<typeof vi.fn>).mockResolvedValue([
|
||||
{
|
||||
id: 2,
|
||||
name: 'Sonic',
|
||||
slug: 'sonic',
|
||||
releaseDate: '1991-06-23',
|
||||
genres: ['Platform'],
|
||||
coverUrl: 'http://rawg.com/sonic.jpg',
|
||||
source: 'rawg',
|
||||
},
|
||||
]);
|
||||
|
||||
(tgdb.searchGames as unknown as ReturnType<typeof vi.fn>).mockResolvedValue([]);
|
||||
|
||||
const results = await searchGames({ title: 'Sonic' });
|
||||
|
||||
expect(results.length).toBe(1);
|
||||
expect(results[0].source).toBe('rawg');
|
||||
});
|
||||
|
||||
it('debería pasar el parámetro platform a IGDB', async () => {
|
||||
(igdb.searchGames as unknown as ReturnType<typeof vi.fn>).mockResolvedValue([]);
|
||||
(rawg.searchGames as unknown as ReturnType<typeof vi.fn>).mockResolvedValue([]);
|
||||
(tgdb.searchGames as unknown as ReturnType<typeof vi.fn>).mockResolvedValue([]);
|
||||
|
||||
await searchGames({ title: 'Mario', platform: 'NES' });
|
||||
|
||||
expect(igdb.searchGames).toHaveBeenCalledWith('Mario', 'NES');
|
||||
expect(rawg.searchGames).toHaveBeenCalledWith('Mario');
|
||||
expect(tgdb.searchGames).toHaveBeenCalledWith('Mario');
|
||||
});
|
||||
|
||||
it('debería mantener múltiples resultados con nombres diferentes', async () => {
|
||||
(igdb.searchGames as unknown as ReturnType<typeof vi.fn>).mockResolvedValue([
|
||||
{
|
||||
id: 1,
|
||||
name: 'Super Mario Bros.',
|
||||
slug: 'super-mario-bros',
|
||||
releaseDate: '1985-09-13',
|
||||
genres: ['Platform'],
|
||||
coverUrl: 'http://igdb.com/smb.jpg',
|
||||
source: 'igdb',
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
name: 'Super Mario Bros. 2',
|
||||
slug: 'super-mario-bros-2',
|
||||
releaseDate: '1988-10-09',
|
||||
genres: ['Platform'],
|
||||
coverUrl: 'http://igdb.com/smb2.jpg',
|
||||
source: 'igdb',
|
||||
},
|
||||
]);
|
||||
|
||||
(rawg.searchGames as unknown as ReturnType<typeof vi.fn>).mockResolvedValue([]);
|
||||
(tgdb.searchGames as unknown as ReturnType<typeof vi.fn>).mockResolvedValue([]);
|
||||
|
||||
const results = await searchGames({ title: 'Super Mario' });
|
||||
|
||||
expect(results.length).toBe(2);
|
||||
expect(results[0].name).toBe('Super Mario Bros.');
|
||||
expect(results[1].name).toBe('Super Mario Bros. 2');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user