- 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.
80 lines
2.7 KiB
TypeScript
80 lines
2.7 KiB
TypeScript
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
import type { Mock } from 'vitest';
|
|
import { Readable } from 'stream';
|
|
|
|
vi.mock('../../src/services/fsScanner', () => ({ scanDirectory: vi.fn() }));
|
|
vi.mock('../../src/services/archiveReader', () => ({ streamArchiveEntry: vi.fn() }));
|
|
vi.mock('../../src/plugins/prisma', () => ({
|
|
default: {
|
|
game: { findFirst: vi.fn(), create: vi.fn(), update: vi.fn() },
|
|
},
|
|
}));
|
|
|
|
import importDirectory, { createSlug } from '../../src/services/importService';
|
|
import { scanDirectory } from '../../src/services/fsScanner';
|
|
import { streamArchiveEntry } from '../../src/services/archiveReader';
|
|
import prisma from '../../src/plugins/prisma';
|
|
import { createHash } from 'crypto';
|
|
|
|
beforeEach(() => {
|
|
vi.restoreAllMocks();
|
|
});
|
|
|
|
describe('services/importService (archive entries)', () => {
|
|
it('procesa una entrada interna usando streamArchiveEntry y crea Game con source=rom', async () => {
|
|
const files = [
|
|
{
|
|
path: '/roms/collection.zip::inner/rom1.bin',
|
|
containerPath: '/roms/collection.zip',
|
|
entryPath: 'inner/rom1.bin',
|
|
filename: 'rom1.bin',
|
|
name: 'inner/rom1.bin',
|
|
size: 123,
|
|
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]));
|
|
|
|
(prisma.game.findFirst as unknown as Mock).mockResolvedValue(null);
|
|
(prisma.game.create as unknown as Mock).mockResolvedValue({
|
|
id: 77,
|
|
title: 'ROM1',
|
|
slug: 'rom1',
|
|
});
|
|
|
|
const md5 = createHash('md5').update(data).digest('hex');
|
|
|
|
const summary = await importDirectory({ dir: '/roms', persist: true });
|
|
|
|
expect((streamArchiveEntry as unknown as Mock).mock.calls.length).toBe(1);
|
|
expect((streamArchiveEntry as unknown as Mock).mock.calls[0][0]).toBe('/roms/collection.zip');
|
|
expect((streamArchiveEntry as unknown as Mock).mock.calls[0][1]).toBe('inner/rom1.bin');
|
|
|
|
expect((prisma.game.findFirst as unknown as Mock).mock.calls[0][0]).toEqual({
|
|
where: { source: 'rom', romChecksum: md5 },
|
|
});
|
|
expect((prisma.game.create as unknown as Mock).mock.calls[0][0]).toEqual({
|
|
data: {
|
|
title: 'ROM1',
|
|
slug: 'rom1-1234567890123',
|
|
source: 'rom',
|
|
romPath: '/roms/collection.zip::inner/rom1.bin',
|
|
romFilename: 'rom1.bin',
|
|
romSize: 123,
|
|
romChecksum: md5,
|
|
romFormat: 'bin',
|
|
romHashes: expect.any(String),
|
|
addedAt: expect.any(Date),
|
|
lastSeenAt: expect.any(Date),
|
|
},
|
|
});
|
|
|
|
expect(summary).toEqual({ processed: 1, createdCount: 1, upserted: 0 });
|
|
});
|
|
});
|